Skip to content

Commit

Permalink
add OrganizationHeader component
Browse files Browse the repository at this point in the history
  • Loading branch information
adelloste committed Jan 30, 2024
1 parent 5e1eb41 commit beb4469
Show file tree
Hide file tree
Showing 8 changed files with 509 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { Divider, H3, LabelSmall, VSpacer } from "@pagopa/io-app-design-system";
import React, { PropsWithChildren } from "react";
import { StyleSheet, View } from "react-native";
import {
ContentWrapper,
Divider,
H3,
LabelSmall,
VSpacer
} from "@pagopa/io-app-design-system";
import { localeDateFormat } from "../../../../utils/locale";
import I18n from "../../../../i18n";
import { ServicePublic } from "../../../../../definitions/backend/ServicePublic";
import { logoForService } from "../../../../utils/services";
import { OrganizationHeader } from "./OrganizationHeader";

export type MessageDetailHeaderProps = PropsWithChildren<{
createdAt: Date;
Expand All @@ -12,12 +19,6 @@ export type MessageDetailHeaderProps = PropsWithChildren<{
service?: ServicePublic;
}>;

const styles = StyleSheet.create({
header: {
paddingHorizontal: 24
}
});

const MessageHeaderContent = ({
subject,
createdAt
Expand All @@ -36,13 +37,23 @@ const MessageHeaderContent = ({

export const MessageDetailHeader = ({
children,
service,
...rest
}: MessageDetailHeaderProps) => (
<View style={styles.header}>
<ContentWrapper>
{children}
<MessageHeaderContent {...rest} />
<VSpacer size={8} />
<Divider />
{/* TODO: Add MessageHeaderService */}
</View>
{service && (
<>
<OrganizationHeader
logoUri={logoForService(service)}
organizationName={service.organization_name}
serviceName={service.service_name}
/>
<Divider />
</>
)}
</ContentWrapper>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React from "react";
import { ImageURISource, StyleSheet, View } from "react-native";
import {
Avatar,
IOSpacingScale,
IOStyles,
LabelSmall
} from "@pagopa/io-app-design-system";

export type OrganizationHeaderProps = {
organizationName: string;
serviceName: string;
logoUri: ImageURISource;
accessibilityLabel?: string;
};

const ITEM_PADDING_VERTICAL: IOSpacingScale = 6;
const AVATAR_MARGIN_LEFT: IOSpacingScale = 16;

const styles = StyleSheet.create({
item: {
flexDirection: "row",
alignItems: "center",
justifyContent: "space-between",
paddingVertical: ITEM_PADDING_VERTICAL
},
itemAvatar: {
marginLeft: AVATAR_MARGIN_LEFT
}
});

export const OrganizationHeader = ({
logoUri,
organizationName,
serviceName,
...rest
}: OrganizationHeaderProps) => (
<View {...rest} accessible={true} style={styles.item}>
<View style={IOStyles.flex}>
<LabelSmall fontSize="regular" color="grey-700">
{organizationName}
</LabelSmall>
<LabelSmall fontSize="regular" color="blueIO-500">
{serviceName}
</LabelSmall>
</View>
<View style={styles.itemAvatar}>
<Avatar logoUri={logoUri} size="small" shape="circle" />
</View>
</View>
);
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,22 @@ describe("MessageDetailHeader component", () => {
const component = render(
<MessageDetailHeader
{...defaultProps}
sender="Sender"
sender="#### Sender ####"
service={service}
/>
);
expect(component.toJSON()).toMatchSnapshot();
});

it("should render the organization info when the service is defined", () => {
const component = render(
<MessageDetailHeader
{...defaultProps}
sender="#### Sender ####"
service={service}
/>
);
expect(component.queryByText(service.organization_name)).not.toBeNull();
expect(component.queryByText(service.service_name)).not.toBeNull();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from "react";
import { render } from "@testing-library/react-native";
import { OrganizationHeader } from "../OrganizationHeader";

describe("OrganizationHeader component", () => {
it("should match the snapshot", () => {
const component = render(
<OrganizationHeader
logoUri={{
uri: "https://eo.wikipedia.org/wiki/Universala_Esperanto-Asocio#/media/Dosiero:Universala_Esperanto-Asocio.png"
}}
organizationName={"Universala Esperanto-Asocio"}
serviceName={"Avviso"}
/>
);
expect(component.toJSON()).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,138 @@ exports[`MessageDetailHeader component should match the snapshot with all props
}
}
/>
<View
accessible={true}
style={
Object {
"alignItems": "center",
"flexDirection": "row",
"justifyContent": "space-between",
"paddingVertical": 6,
}
}
>
<View
style={
Object {
"flex": 1,
}
}
>
<Text
allowFontScaling={false}
color="grey-700"
defaultColor="blue"
defaultWeight="Bold"
font="TitilliumWeb"
fontSize="regular"
fontStyle={
Object {
"fontSize": 14,
"lineHeight": 21,
}
}
style={
Array [
Object {
"fontSize": 14,
"lineHeight": 21,
},
Object {
"color": "#555C70",
"fontFamily": "Titillium Web",
"fontStyle": "normal",
"fontWeight": "700",
},
]
}
weight="Bold"
>
Organization foo
</Text>
<Text
allowFontScaling={false}
color="blueIO-500"
defaultColor="blue"
defaultWeight="Bold"
font="TitilliumWeb"
fontSize="regular"
fontStyle={
Object {
"fontSize": 14,
"lineHeight": 21,
}
}
style={
Array [
Object {
"fontSize": 14,
"lineHeight": 21,
},
Object {
"color": "#0B3EE3",
"fontFamily": "Titillium Web",
"fontStyle": "normal",
"fontWeight": "700",
},
]
}
weight="Bold"
>
health
</Text>
</View>
<View
style={
Object {
"marginLeft": 16,
}
}
>
<View
style={
Array [
Object {
"borderColor": "rgba(14,15,19,0.1)",
"borderWidth": 1,
"overflow": "hidden",
"resizeMode": "contain",
},
Object {
"backgroundColor": "#FFFFFF",
"borderRadius": 22,
"height": 44,
"padding": 6,
"width": 44,
},
]
}
>
<Image
onError={[Function]}
source={
Object {
"uri": "https://assets.cdn.io.italia.it/logos/services/serviceid.png",
}
}
style={
Object {
"height": "100%",
"width": "100%",
}
}
/>
</View>
</View>
</View>
<View
style={
Object {
"backgroundColor": "#D2D6E3",
"height": 0.5,
}
}
/>
</View>
`;

Expand Down
Loading

0 comments on commit beb4469

Please sign in to comment.