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

Commit 51dd226

Browse files
committed
in house admin all screens created and mostly working
1 parent 95f749a commit 51dd226

26 files changed

Lines changed: 1238 additions & 86 deletions
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React from 'react';
2+
import { render } from '@testing-library/react';
3+
import { Employer } from '../cards/employer/employer';
4+
import { axe } from 'jest-axe';
5+
6+
const noop = () => Promise.resolve();
7+
8+
const employer = {
9+
schemeRoleId: 123,
10+
employerType: 'principal-and-participating' as 'principal-and-participating',
11+
organisationReference: 0,
12+
companiesHouseNumber: 'AB123456',
13+
registeredCharityNumber: '123',
14+
organisationName: 'The Pensions Regulator',
15+
addressLine1: 'Napier House',
16+
addressLine2: 'Trafalgar Pl',
17+
postTown: 'Brighton',
18+
postCode: 'BN1 4DW',
19+
county: 'West Sussex',
20+
countryId: '',
21+
effectiveDate: '1997-04-01T00:00:00',
22+
};
23+
24+
describe('Employer Preview', () => {
25+
test('is accessible', async () => {
26+
const { container } = render(
27+
<Employer
28+
onSaveType={noop}
29+
onRemove={noop}
30+
onCorrect={(_value) => {}}
31+
complete={true}
32+
employer={employer}
33+
/>,
34+
);
35+
36+
const results = await axe(container);
37+
expect(results).toHaveNoViolations();
38+
});
39+
});
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import React from 'react';
2+
import { render } from '@testing-library/react';
3+
import { InHouseAdmin } from '../cards/inHouseAdmin/inHouseAdmin';
4+
import { axe } from 'jest-axe';
5+
6+
const noop = () => Promise.resolve();
7+
8+
const inHouseAdmin = {
9+
schemeRoleId: '123',
10+
title: 'Mr',
11+
firstname: 'John',
12+
lastname: 'Smoth',
13+
effectiveDate: '1997-04-01T00:00:00',
14+
addressLine1: 'Napier House',
15+
addressLine2: 'Trafalgar Pl',
16+
addressLine3: '',
17+
postTown: 'Brighton',
18+
postCode: 'BN1 4DW',
19+
county: 'West Sussex',
20+
countryId: '',
21+
telephoneNumber: '01273 222 111',
22+
emailAddress: 'john.wick@warnerbros.com',
23+
};
24+
25+
describe('InHouseAdmin Preview', () => {
26+
test('is accessible', async () => {
27+
const { container } = render(
28+
<InHouseAdmin
29+
onSaveContacts={noop}
30+
onSaveAddress={noop}
31+
onSaveName={noop}
32+
onRemove={noop}
33+
onCorrect={(_value) => {}}
34+
complete={true}
35+
addressAPI={{
36+
get: (_endpont) => Promise.resolve(),
37+
limit: 100,
38+
}}
39+
inHouseAdmin={inHouseAdmin}
40+
/>,
41+
);
42+
43+
const results = await axe(container);
44+
expect(results).toHaveNoViolations();
45+
});
46+
});

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ export const StyledCardToolbar: React.FC = ({ children }) => {
2525

2626
type ToolbarProps = {
2727
type: 'trustee' | 'employer' | 'insurer' | 'inHouseAdmin';
28+
typeName?: string;
2829
title: string;
2930
subtitle?: string;
3031
};
3132
export const Toolbar: React.FC<ToolbarProps> = ({
3233
type = 'trustee',
34+
typeName,
3335
title,
3436
subtitle,
3537
}) => {
@@ -39,7 +41,9 @@ export const Toolbar: React.FC<ToolbarProps> = ({
3941
cfg={{ flexDirection: 'column', pb: 2 }}
4042
className={styles.toolbarBottomBorder}
4143
>
42-
<P cfg={{ color: 'neutral.6', fontSize: 3 }}>Edit {type}</P>
44+
<P cfg={{ color: 'neutral.6', fontSize: 3 }}>
45+
Edit {typeName ? typeName : type}
46+
</P>
4347
<H3 cfg={{ fontWeight: 3 }}>{title}</H3>
4448
</Flex>
4549
{subtitle && (

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ export const Loading = () => <div className={styles.loading} />;
77

88
type ContentProps = {
99
type: 'trustee' | 'employer' | 'insurer' | 'inHouseAdmin';
10+
typeName?: string;
1011
title?: string;
1112
loading?: boolean;
1213
breadcrumbs?: any;
1314
subtitle?: string;
1415
};
1516
export const Content: React.FC<ContentProps> = ({
1617
type,
18+
typeName,
1719
children,
1820
title,
1921
loading = false,
@@ -29,7 +31,14 @@ export const Content: React.FC<ContentProps> = ({
2931
>
3032
{loading && <Loading />}
3133
{Breadcrumbs && <Breadcrumbs />}
32-
{title && <Toolbar type={type} title={title} subtitle={subtitle} />}
34+
{title && (
35+
<Toolbar
36+
type={type}
37+
typeName={typeName}
38+
title={title}
39+
subtitle={subtitle}
40+
/>
41+
)}
3342
{children}
3443
</div>
3544
);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export interface EmployerProviderProps {
4040
}
4141

4242
export type EmployerProps = {
43-
schemeRoleId: number;
43+
schemeRoleId: string | number;
4444
employerType:
4545
| 'participating-employer'
4646
| 'principal-employer'

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

Lines changed: 62 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,30 @@ import { State, EventData } from 'xstate';
77
import { SpaceProps } from '@tpr/core';
88
import { i18n as i18nDefaults, InHouseAdminI18nProps } from './i18n';
99
import { useI18n } from '../hooks/use-i18n';
10+
import { splitObjectIntoTwo } from '../../../utils';
1011

1112
export const InHouseAdminContext = createContext<InHouseAdminContextProps>({
1213
current: {},
1314
send: (_, __) => ({}),
1415
onCorrect: () => {},
1516
onRemove: Promise.resolve,
16-
onSaveType: Promise.resolve,
17+
onSaveContacts: Promise.resolve,
18+
onSaveAddress: Promise.resolve,
19+
onSaveName: Promise.resolve,
1720
i18n: i18nDefaults,
21+
addressAPI: {
22+
get: (endpoint) => Promise.resolve(endpoint),
23+
limit: 50,
24+
},
1825
});
1926

27+
type AddressAPIType = {
28+
/** API instance with auth to get a list of addresses */
29+
get: (endpoint: string) => Promise<any>;
30+
/** limit of items to display per search */
31+
limit: number;
32+
};
33+
2034
type RenderProps = (_props: InHouseAdminContextProps) => ReactElement;
2135

2236
export interface InHouseAdminContextProps
@@ -32,40 +46,70 @@ export type RecursivePartial<T> = {
3246
[P in keyof T]?: RecursivePartial<T[P]>;
3347
};
3448

35-
export type InHouseAdminProps = {
49+
interface InHouseAdmin {
3650
id: string;
37-
schemeRoleId: string;
51+
schemeRoleId: string | number;
3852
title: string;
3953
firstname: string;
4054
lastname: string;
4155
effectiveDate: string;
56+
countryId: string;
57+
telephoneNumber: string;
58+
emailAddress: string;
59+
addressAPI: AddressAPIType;
60+
}
61+
62+
export interface InHouseAdminWithContactsProps extends InHouseAdmin {
63+
address: Partial<{
64+
addressLine1: string;
65+
addressLine2: string;
66+
addressLine3: string;
67+
postTown: string;
68+
county: string;
69+
postCode: string;
70+
country: string;
71+
}>;
72+
}
73+
74+
export interface InHouseAdminProps extends InHouseAdmin {
4275
addressLine1: string;
4376
addressLine2: string;
4477
addressLine3: string;
4578
postTown: string;
4679
county: string;
47-
postcode: string;
48-
countryId: string;
49-
telephoneNumber: string;
50-
emailAddress: string;
51-
[key: string]: any;
52-
};
80+
postCode: string;
81+
country: string;
82+
}
5383

5484
export interface InHouseAdminProviderProps {
5585
complete?: boolean;
5686
onCorrect?: (...args: any[]) => void;
5787
onRemove?: (...args: any[]) => Promise<any>;
58-
onSaveType?: (...args: any[]) => Promise<any>;
88+
onSaveContacts?: (...args: any[]) => Promise<any>;
89+
onSaveAddress?: (...args: any[]) => Promise<any>;
90+
onSaveName?: (...args: any[]) => Promise<any>;
5991
testId?: string;
6092
/** inHouseAdmin props from the API */
6193
inHouseAdmin: Partial<InHouseAdminProps>;
6294
children?: RenderProps | ReactElement;
95+
addressAPI: AddressAPIType;
6396
/** overwrite any text that you need */
6497
i18n?: RecursivePartial<InHouseAdminI18nProps>;
6598
/** cfg space props */
6699
cfg?: SpaceProps;
67100
}
68101

102+
const addressFields = [
103+
'addressLine1',
104+
'addressLine2',
105+
'addressLine3',
106+
'postTown',
107+
'county',
108+
'country',
109+
'postCode',
110+
'countryId',
111+
];
112+
69113
export const InHouseAdminProvider = ({
70114
complete,
71115
inHouseAdmin,
@@ -74,10 +118,17 @@ export const InHouseAdminProvider = ({
74118
...rest
75119
}: InHouseAdminProviderProps) => {
76120
const i18n = useI18n(i18nDefaults, i18nOverrides);
121+
const [modifiedAdmin, adminAddress] = splitObjectIntoTwo(
122+
inHouseAdmin,
123+
addressFields,
124+
);
77125
const [current, send] = useMachine(inHouseAdminMachine, {
78126
context: {
79127
complete,
80-
inHouseAdmin,
128+
inHouseAdmin: {
129+
...modifiedAdmin,
130+
address: adminAddress,
131+
},
81132
},
82133
});
83134

0 commit comments

Comments
 (0)