Skip to content

Commit 5e8adce

Browse files
committed
Add the currentlySelectedRole logic and the mockUserInfo file
1 parent e7ce279 commit 5e8adce

File tree

4 files changed

+112
-20
lines changed

4 files changed

+112
-20
lines changed

.vscode/eps-prescription-tracker-ui.code-workspace

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@
144144
"typescript.tsdk": "eps-prescription-tracker-ui-monorepo/node_modules/typescript/lib",
145145
"eslint.useFlatConfig": true,
146146
"eslint.format.enable": true,
147-
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
147+
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
148+
"[typescriptreact]": {
149+
"editor.defaultFormatter": "vscode.typescript-language-features"
150+
}
148151
},
149152
"extensions": {
150153
"recommendations": [

packages/cpt-ui/app/selectyourrole/page.tsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {AuthContext} from "@/context/AuthProvider"
77
import {useAccess} from '@/context/AccessProvider'
88

99
import EpsCard, {EpsCardProps} from "@/components/EpsCard"
10-
import EpsSpinner from "@/components/EpsSpinner";
10+
import EpsSpinner from "@/components/EpsSpinner"
1111

1212
import {SELECT_YOUR_ROLE_PAGE_TEXT} from "@/constants/ui-strings/CardStrings"
1313

@@ -58,7 +58,7 @@ const {
5858
noRoleName,
5959
noAddress,
6060
errorDuringRoleSelection
61-
} = SELECT_YOUR_ROLE_PAGE_TEXT;
61+
} = SELECT_YOUR_ROLE_PAGE_TEXT
6262

6363
export default function SelectYourRolePage() {
6464
const {setNoAccess} = useAccess()
@@ -67,6 +67,7 @@ export default function SelectYourRolePage() {
6767
const [redirecting, setRedirecting] = useState<boolean>(false)
6868
const [rolesWithAccess, setRolesWithAccess] = useState<RolesWithAccessProps[]>([])
6969
const [rolesWithoutAccess, setRolesWithoutAccess] = useState<RolesWithoutAccessProps[]>([])
70+
const [selectedRole, setCurrentlySelectedRole] = useState<RoleDetails | undefined>(undefined)
7071

7172
const router = useRouter()
7273
const auth = useContext(AuthContext)
@@ -76,11 +77,12 @@ export default function SelectYourRolePage() {
7677
setError(null)
7778
setRolesWithAccess([])
7879
setRolesWithoutAccess([])
80+
setCurrentlySelectedRole(undefined)
7981

8082
if (!auth?.isSignedIn || !auth) {
8183
setLoading(false)
8284
setError(null)
83-
return;
85+
return
8486
}
8587

8688
try {
@@ -105,11 +107,10 @@ export default function SelectYourRolePage() {
105107

106108
const rolesWithAccess = userInfo.roles_with_access
107109
const rolesWithoutAccess = userInfo.roles_without_access
108-
// Unused for now
109-
// const currentlySelectedRole = userInfo.currently_selected_role ? {
110-
// ...userInfo.currently_selected_role,
111-
// uuid: `selected_role_0`
112-
// } : undefined
110+
const currentlySelectedRole = userInfo.currently_selected_role ? {
111+
...userInfo.currently_selected_role,
112+
uuid: `selected_role_0`
113+
} : undefined
113114

114115
// Populate the EPS card props
115116
setRolesWithAccess(
@@ -132,6 +133,7 @@ export default function SelectYourRolePage() {
132133
}))
133134
)
134135

136+
setCurrentlySelectedRole(currentlySelectedRole)
135137
setNoAccess(rolesWithAccess.length === 0)
136138

137139
// Redirect if conditions are met
@@ -212,9 +214,12 @@ export default function SelectYourRolePage() {
212214
}
213215

214216
const noAccess = rolesWithAccess.length === 0
215-
216-
console.log("Title for no access:", SELECT_YOUR_ROLE_PAGE_TEXT.titleNoAccess);
217-
console.log("No Access State:", noAccess);
217+
const insetTextMessage = selectedRole
218+
? `You are currently logged in at ${selectedRole.org_name} (ODS: ${selectedRole.org_code}) with ${selectedRole.role_name}.`
219+
: ""
220+
221+
console.log("Title for no access:", SELECT_YOUR_ROLE_PAGE_TEXT.titleNoAccess)
222+
console.log("No Access State:", noAccess)
218223

219224
return (
220225
<main id="main-content" className="nhsuk-main-wrapper">
@@ -238,7 +243,7 @@ export default function SelectYourRolePage() {
238243
<section aria-label="Login Information">
239244
<InsetText>
240245
<span className="nhsuk-u-visually-hidden">{insetText.visuallyHidden}</span>
241-
<p>{insetText.message}</p>
246+
<p>{insetTextMessage}</p>
242247
</InsetText>
243248
{/* Confirm Button */}
244249
<Button href={confirmButton.link}>{confirmButton.text}</Button>

packages/trackerUserInfoLambda/src/handler.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {DynamoDBDocumentClient} from "@aws-sdk/lib-dynamodb"
99

1010
import {fetchAndVerifyCIS2Tokens, getUsernameFromEvent} from "./cis2TokenHelpers"
1111
import {fetchUserInfo, updateDynamoTable} from "./userInfoHelpers"
12+
import {mockUserInfo} from "./mockUserInfo"
1213

1314
const logger = new Logger({serviceName: "trackerUserInfo"})
1415

@@ -70,14 +71,29 @@ const lambdaHandler = async (event: APIGatewayProxyEvent): Promise<APIGatewayPro
7071
// eslint-disable-next-line
7172
const {cis2AccessToken, cis2IdToken} = await fetchAndVerifyCIS2Tokens(event, documentClient, logger)
7273

73-
const userInfoResponse = await fetchUserInfo(
74-
cis2AccessToken,
75-
CPT_ACCESS_ACTIVITY_CODES,
76-
undefined,
77-
logger
78-
)
79-
74+
// Mock user info for testing AEA-4645
75+
let userInfoResponse
8076
const username = getUsernameFromEvent(event)
77+
78+
if (username === "555043304334") {
79+
userInfoResponse = mockUserInfo()
80+
} else {
81+
userInfoResponse = await fetchUserInfo(
82+
cis2AccessToken,
83+
CPT_ACCESS_ACTIVITY_CODES,
84+
undefined,
85+
logger
86+
)
87+
}
88+
89+
// const userInfoResponse = await fetchUserInfo(
90+
// cis2AccessToken,
91+
// CPT_ACCESS_ACTIVITY_CODES,
92+
// undefined,
93+
// logger
94+
// )
95+
96+
// const username = getUsernameFromEvent(event)
8197
updateDynamoTable(username, userInfoResponse, documentClient, logger)
8298

8399
return {
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// mockUserInfo.ts
2+
import {TrackerUserInfo, RoleDetails} from "./userInfoTypes"
3+
4+
export const mockUserInfo = (): TrackerUserInfo => {
5+
const rolesWithAccess: Array<RoleDetails> = [
6+
{
7+
role_name: "General Medical Practitioner",
8+
role_id: "555043304334",
9+
org_code: "N82668"
10+
},
11+
{
12+
role_name: "General Medical Practitioner",
13+
role_id: "555043304334",
14+
org_code: "A21293"
15+
},
16+
{
17+
role_name: "General Medical Practitioner",
18+
role_id: "555043304334",
19+
org_code: "B84610"
20+
}
21+
]
22+
23+
const rolesWithoutAccess: Array<RoleDetails> = [
24+
{
25+
role_name: "Registration Authority Agent",
26+
role_id: "555043304334",
27+
org_code: "X09"
28+
},
29+
{
30+
role_name: "General Medical Practitioner",
31+
role_id: "555043304334",
32+
org_code: "A22279"
33+
},
34+
{
35+
role_name: "Consultant",
36+
role_id: "555043304334",
37+
org_code: "RCD"
38+
},
39+
{
40+
role_name: "Registration Authority Manager",
41+
role_id: "555043304334",
42+
org_code: "5BR"
43+
},
44+
{
45+
role_name: "Demographic Supervisor",
46+
role_id: "555043304334",
47+
org_code: "8JD29"
48+
},
49+
{
50+
role_name: "General Medical Practitioner",
51+
role_id: "555043304334",
52+
org_code: "P84009"
53+
}
54+
]
55+
56+
const currentlySelectedRole: RoleDetails = {
57+
role_name: "Health Professional Access Role",
58+
role_id: "555043304334",
59+
org_code: "ODS: FG419",
60+
org_name: "GREENE'S PHARMACY"
61+
}
62+
63+
return {
64+
roles_with_access: rolesWithAccess,
65+
roles_without_access: rolesWithoutAccess,
66+
currently_selected_role: currentlySelectedRole
67+
}
68+
}

0 commit comments

Comments
 (0)