@@ -7,17 +7,19 @@ import {
77 Details ,
88 Table ,
99 ErrorSummary ,
10- InsetText
10+ InsetText ,
11+ Card
1112} from "nhsuk-react-components"
1213
1314import { useAuth } from "@/context/AuthProvider"
14- import EpsCard from "@/components/EpsCard"
1515import EpsSpinner from "@/components/EpsSpinner"
1616import { RoleDetails } from "@cpt-ui-common/common-types"
1717import { Button } from "./ReactRouterButton"
1818import { FRONTEND_PATHS } from "@/constants/environment"
1919import { getSearchParams } from "@/helpers/getSearchParams"
2020import { logger } from "@/helpers/logger"
21+ import axios from "axios"
22+ import { handleRestartLogin } from "@/helpers/logout"
2123
2224// This is passed to the EPS card component.
2325export type RolesWithAccessProps = {
@@ -90,6 +92,24 @@ export default function RoleSelectionPage({
9092 const [ roleCardPropsWithAccess , setRoleCardPropsWithAccess ] = useState < Array < RolesWithAccessProps > > ( [ ] )
9193 const [ roleCardPropsWithoutAccess , setRoleCardPropsWithoutAccess ] = useState < Array < RolesWithoutAccessProps > > ( [ ] )
9294
95+ const handleSetSelectedRole = async (
96+ e : React . MouseEvent | React . KeyboardEvent ,
97+ roleCardProps : RolesWithAccessProps
98+ ) => {
99+ e . preventDefault ( )
100+ try {
101+ await auth . updateSelectedRole ( roleCardProps . role )
102+ navigate ( roleCardProps . link )
103+ } catch ( err ) {
104+ if ( axios . isAxiosError ( err ) && ( err . response ?. status === 401 ) ) {
105+ const invalidSessionCause = err . response ?. data ?. invalidSessionCause
106+ handleRestartLogin ( auth , invalidSessionCause )
107+ return
108+ }
109+ logger . error ( "Error selecting role:" , err )
110+ }
111+ }
112+
93113 useEffect ( ( ) => {
94114 // Transform roles data for display
95115 setRoleCardPropsWithAccess ( ( ! auth . hasNoAccess )
@@ -237,7 +257,53 @@ export default function RoleSelectionPage({
237257 { roleCardPropsWithAccess
238258 . filter ( ( duplicateRole ) => duplicateRole . role . role_id !== auth . selectedRole ?. role_id )
239259 . map ( ( roleCardProps : RolesWithAccessProps ) => (
240- < EpsCard { ...roleCardProps } key = { roleCardProps . uuid } />
260+ < Card
261+ key = { roleCardProps . uuid }
262+ data-testid = "eps-card"
263+ className = "nhsuk-card nhsuk-card--primary nhsuk-u-margin-bottom-4"
264+ >
265+ < Card . Content >
266+ < div className = "eps-card__layout" >
267+ < div >
268+ < div
269+ tabIndex = { 0 }
270+ className = "eps-card__org-focus-area"
271+ onKeyDown = { ( e ) => {
272+ if ( e . key === "Enter" || e . key === " " ) {
273+ e . preventDefault ( )
274+ handleSetSelectedRole ( e , roleCardProps )
275+ }
276+ } }
277+ onClick = { ( e ) => {
278+ e . preventDefault ( )
279+ handleSetSelectedRole ( e , roleCardProps )
280+ } }
281+ >
282+ < Card . Heading className = "nhsuk-heading-s eps-card__org-name" >
283+ { roleCardProps . role . org_name || noOrgName }
284+ < br />
285+ (ODS: { roleCardProps . role . org_code || noODSCode } )
286+ </ Card . Heading >
287+ </ div >
288+ < Card . Description className = "nhsuk-u-margin-top-2" >
289+ { roleCardProps . role . role_name || noRoleName }
290+ </ Card . Description >
291+ </ div >
292+ < div className = "eps-card__address" >
293+ < Card . Description >
294+ { ( roleCardProps . role . site_address || contentText . noAddress )
295+ . split ( "\n" )
296+ . map ( ( line : string , index : number ) => (
297+ < span key = { index } >
298+ { line }
299+ < br />
300+ </ span >
301+ ) ) }
302+ </ Card . Description >
303+ </ div >
304+ </ div >
305+ </ Card . Content >
306+ </ Card >
241307 ) ) }
242308 </ div >
243309 </ Col >
0 commit comments