Skip to content
This repository was archived by the owner on Dec 1, 2025. It is now read-only.

Commit 32fd377

Browse files
authored
Merge pull request #131 from thepensionsregulator/feature-insurer-card
Cards section + Insurer Card base
2 parents 30c941d + 46a7c96 commit 32fd377

23 files changed

Lines changed: 848 additions & 27 deletions

File tree

.docz/doczrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default {
1414
'license',
1515
'readme',
1616
].map((word) => `${word.toUpperCase()}.md`),
17-
menu: ['Home', 'Core', 'Forms', 'Layout'],
17+
menu: ['Home', 'Core', 'Forms', 'Layout', 'Cards'],
1818
themeConfig: {
1919
mode: 'light',
2020
showDarkModeSwitch: false,

doczrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default {
1414
'license',
1515
'readme',
1616
].map((word) => `${word.toUpperCase()}.md`),
17-
menu: ['Home', 'Core', 'Forms', 'Layout'],
17+
menu: ['Home', 'Core', 'Forms', 'Layout', 'Cards'],
1818
themeConfig: {
1919
mode: 'light',
2020
showDarkModeSwitch: false,
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from 'react';
2+
import { render } from '@testing-library/react';
3+
import { Insurer } from '../cards/insurer/insurer';
4+
import { axe } from 'jest-axe';
5+
6+
const noop = () => Promise.resolve();
7+
8+
const insurer = {
9+
id: '',
10+
schemeRoleId: 123,
11+
effectiveDate: '1997-04-01T00:00:00',
12+
organisationReference: 123,
13+
organisationName: 'Some Organisation Name',
14+
insurerCompanyReference: '12345678',
15+
addressLine1: 'Napier House',
16+
addressLine2: 'Trafalgar Pl',
17+
addressLine3: '',
18+
postTown: 'Brighton',
19+
postCode: 'BN1 4DW',
20+
county: 'West Sussex',
21+
postcode: '',
22+
countryId: '',
23+
telephoneNumber: '01273 222 111',
24+
emailAddress: 'john.wick@warnerbros.com',
25+
};
26+
27+
describe('Insurer Preview', () => {
28+
test('is accessible', async () => {
29+
const { container } = render(
30+
<Insurer
31+
onSaveType={noop}
32+
onRemove={noop}
33+
onCorrect={(_value) => {}}
34+
complete={true}
35+
insurer={insurer}
36+
/>,
37+
);
38+
39+
const results = await axe(container);
40+
expect(results).toHaveNoViolations();
41+
});
42+
});

packages/layout/src/components/cards/components/card.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const StyledCardToolbar: React.FC = ({ children }) => {
2424
};
2525

2626
type ToolbarProps = {
27-
type: 'trustee' | 'employer';
27+
type: 'trustee' | 'employer' | 'insurer';
2828
title: string;
2929
subtitle?: string;
3030
};
@@ -39,9 +39,7 @@ export const Toolbar: React.FC<ToolbarProps> = ({
3939
cfg={{ flexDirection: 'column', pb: 2 }}
4040
className={styles.toolbarBottomBorder}
4141
>
42-
<P cfg={{ color: 'neutral.6', fontSize: 3 }}>
43-
Edit {type === 'trustee' ? 'trustee' : 'employer'}
44-
</P>
42+
<P cfg={{ color: 'neutral.6', fontSize: 3 }}>Edit {type}</P>
4543
<H3 cfg={{ fontWeight: 3 }}>{title}</H3>
4644
</Flex>
4745
{subtitle && (

packages/layout/src/components/cards/components/content.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import styles from './content.module.scss';
66
export const Loading = () => <div className={styles.loading} />;
77

88
type ContentProps = {
9-
type: 'trustee' | 'employer';
9+
type: 'trustee' | 'employer' | 'insurer';
1010
title?: string;
1111
loading?: boolean;
1212
breadcrumbs?: any;

packages/layout/src/components/cards/components/toolbar.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import styles from '../cards.module.scss';
66

77
export type ToolbarProps = {
88
complete: boolean;
9-
subtitle: Function;
9+
subtitle?: Function;
1010
buttonLeft: Function;
1111
buttonRight: Function;
1212
};
@@ -33,7 +33,9 @@ export const Toolbar: React.FC<ToolbarProps> = ({
3333
}}
3434
>
3535
{buttonLeft()}
36-
<Flex cfg={{ mt: 1, flexDirection: 'column' }}>{subtitle()}</Flex>
36+
{subtitle && (
37+
<Flex cfg={{ mt: 1, flexDirection: 'column' }}>{subtitle()}</Flex>
38+
)}
3739
</Flex>
3840
<Flex
3941
cfg={{

packages/layout/src/components/cards/employer/context.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import React, { createContext, useContext, ReactElement, useMemo } from 'react';
1+
import React, { createContext, useContext, ReactElement } from 'react';
22
import { useMachine } from '@xstate/react';
33
import employerMachine, { EmployerContext as EC } from './employerMachine';
44
import { State, EventData } from 'xstate';
55
import { SpaceProps } from '@tpr/core';
66
import { i18n as i18nDefaults, EmployerI18nProps } from './i18n';
7-
import { merge } from 'lodash';
7+
import { useI18n } from '../hooks/use-i18n';
88

99
export const EmployerContext = createContext<EmployerContextProps>({
1010
current: {},
@@ -66,10 +66,7 @@ export const EmployerProvider = ({
6666
i18n: i18nOverrides = {},
6767
...rest
6868
}: EmployerProviderProps) => {
69-
const i18n = useMemo(() => merge(i18nDefaults, i18nOverrides), [
70-
i18nDefaults,
71-
i18nOverrides,
72-
]);
69+
const i18n = useI18n(i18nDefaults, i18nOverrides);
7370
const [current, send] = useMachine(employerMachine, {
7471
context: {
7572
complete,

packages/layout/src/components/cards/employer/employer.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
name: Employer
3-
menu: Layout
4-
route: /layout/employer
3+
menu: Cards
4+
route: /cards/employer
55
---
66

77
import { Props } from 'docz';
@@ -12,7 +12,7 @@ import { Employer } from './employer';
1212

1313
# Employer
1414

15-
Employer for tpr apps
15+
Employer Card for tpr apps
1616

1717
## Usage
1818

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { useMemo } from 'react';
2+
import { merge } from 'lodash';
3+
4+
export const useI18n = <T, J>(i18nDefaults: T, i18nOverrides: J) => {
5+
const i18n = useMemo(() => merge(i18nDefaults, i18nOverrides), [
6+
i18nDefaults,
7+
i18nOverrides,
8+
]);
9+
10+
return i18n;
11+
};
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import React, { createContext, useContext, ReactElement } from 'react';
2+
import { useMachine } from '@xstate/react';
3+
import insurerMachine, { InsurerContext as EC } from './insurerMachine';
4+
import { State, EventData } from 'xstate';
5+
import { SpaceProps } from '@tpr/core';
6+
import { i18n as i18nDefaults, InsurerI18nProps } from './i18n';
7+
import { useI18n } from '../hooks/use-i18n';
8+
9+
export const InsurerContext = createContext<InsurerContextProps>({
10+
current: {},
11+
send: (_, __) => ({}),
12+
onCorrect: () => {},
13+
onRemove: Promise.resolve,
14+
onSaveType: Promise.resolve,
15+
i18n: i18nDefaults,
16+
});
17+
18+
type RenderProps = (_props: InsurerContextProps) => ReactElement;
19+
20+
export interface InsurerContextProps
21+
extends Omit<InsurerProviderProps, 'insurer'> {
22+
send: (event: any, payload?: EventData) => Partial<State<EC, any, any, any>>;
23+
current: Partial<State<EC, any, any, any>>;
24+
}
25+
26+
export type RecursivePartial<T> = {
27+
[P in keyof T]?: RecursivePartial<T[P]>;
28+
};
29+
30+
export type InsurerProps = {
31+
id: string;
32+
schemeRoleId: number;
33+
effectiveDate: string;
34+
organisationReference: number;
35+
organisationName: string;
36+
insurerCompanyReference: string;
37+
addressLine1: string;
38+
addressLine2: string;
39+
addressLine3: string;
40+
postTown: string;
41+
county: string;
42+
postcode: string;
43+
countryId: string;
44+
telephoneNumber: string;
45+
emailAddress: string;
46+
[key: string]: any;
47+
};
48+
49+
export interface InsurerProviderProps {
50+
complete?: boolean;
51+
onCorrect?: (...args: any[]) => void;
52+
onRemove?: (...args: any[]) => Promise<any>;
53+
onSaveType?: (...args: any[]) => Promise<any>;
54+
testId?: string;
55+
/** insurer props from the API */
56+
insurer: Partial<InsurerProps>;
57+
children?: RenderProps | ReactElement;
58+
/** overwrite any text that you need */
59+
i18n?: RecursivePartial<InsurerI18nProps>;
60+
/** cfg space props */
61+
cfg?: SpaceProps;
62+
}
63+
64+
export const InsurerProvider = ({
65+
complete,
66+
insurer,
67+
children,
68+
i18n: i18nOverrides = {},
69+
...rest
70+
}: InsurerProviderProps) => {
71+
const i18n = useI18n(i18nDefaults, i18nOverrides);
72+
const [current, send] = useMachine(insurerMachine, {
73+
context: {
74+
complete,
75+
insurer,
76+
},
77+
});
78+
79+
const ui =
80+
typeof children === 'function'
81+
? children({ current, send, i18n, ...rest })
82+
: children;
83+
return (
84+
<InsurerContext.Provider value={{ current, send, i18n, ...rest }}>
85+
{ui}
86+
</InsurerContext.Provider>
87+
);
88+
};
89+
90+
export const useInsurerContext = (): InsurerContextProps => {
91+
const insurerUtils = useContext(InsurerContext);
92+
if (!insurerUtils) {
93+
throw new Error(
94+
`Insurer compound components cannot be rendered outside the InsurerProvider component`,
95+
);
96+
}
97+
return insurerUtils;
98+
};

0 commit comments

Comments
 (0)