Skip to content

Commit f797f20

Browse files
reverted spacing and styling to original, but kept focus
1 parent fba441e commit f797f20

File tree

2 files changed

+100
-7
lines changed

2 files changed

+100
-7
lines changed

packages/cpt-ui/src/components/EpsRoleSelectionPage.tsx

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ import {
77
Details,
88
Table,
99
ErrorSummary,
10-
InsetText
10+
InsetText,
11+
Card
1112
} from "nhsuk-react-components"
1213

1314
import {useAuth} from "@/context/AuthProvider"
14-
import EpsCard from "@/components/EpsCard"
1515
import EpsSpinner from "@/components/EpsSpinner"
1616
import {RoleDetails} from "@cpt-ui-common/common-types"
1717
import {Button} from "./ReactRouterButton"
1818
import {FRONTEND_PATHS} from "@/constants/environment"
1919
import {getSearchParams} from "@/helpers/getSearchParams"
2020
import {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.
2325
export 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>

packages/cpt-ui/src/styles/card.scss

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,23 @@
88
align-items: flex-start;
99
}
1010

11+
&__layout {
12+
display: flex;
13+
justify-content: space-between;
14+
align-items: flex-start;
15+
}
16+
17+
&__address {
18+
text-align: right;
19+
margin-left: 20px;
20+
}
21+
1122
&__org-focus-area {
1223
outline: none;
24+
color: #005eb8;
25+
cursor: pointer;
26+
position: relative;
27+
display: block;
1328

1429
&:hover {
1530
.eps-card__org-name {
@@ -28,14 +43,21 @@
2843
content: "";
2944
position: absolute;
3045
bottom: -4px;
31-
left: -4px;
32-
right: -4px;
46+
3347
height: 4px;
3448
background-color: #212b32;
3549
}
3650

51+
.eps-card__org-name .nhsuk-heading-s {
52+
text-decoration: underline !important;
53+
text-decoration-color: #212b32 !important;
54+
text-decoration-thickness: 2px !important;
55+
}
56+
3757
.eps-card__org-name {
38-
text-decoration: none !important;
58+
text-decoration: underline !important;
59+
text-decoration-color: #212b32 !important;
60+
text-decoration-thickness: 2px !important;
3961
}
4062

4163
.nhsuk-heading-s {
@@ -48,10 +70,15 @@
4870
&__org-name {
4971
color: #005eb8;
5072
cursor: pointer;
73+
text-decoration: underline !important;
74+
text-decoration-thickness: 2px !important;
75+
text-underline-offset: 2px !important;
5176

5277
.nhsuk-heading-s {
5378
font-size: 1.1875rem;
54-
text-decoration: underline;
79+
text-decoration: underline !important;
80+
text-decoration-thickness: 2px !important;
81+
text-underline-offset: 2px !important;
5582
}
5683
}
5784

0 commit comments

Comments
 (0)