Skip to content

Commit f358fe8

Browse files
author
Philip
committed
feat: personalise alert settings page with target user's name
When an approver edits another user's alert settings, display the user's first name in the title and full name in the description instead of generic text. Fetch the target user by ID and pass to the form component. Also adds breadcrumb for the alert settings edit route. Made-with: Cursor
1 parent 1d466b7 commit f358fe8

4 files changed

Lines changed: 47 additions & 8 deletions

File tree

src/app/(auth)/account/alert-settings/[id]/page.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { notFound } from 'next/navigation';
33

44
import type { TypeAlertSettingsIn } from '@/__generated__/data-contracts';
55
import { getAlertsUserUserId } from '@/actions/getAlertsUserUserId';
6-
import { getUsersMe } from '@/actions/getUsersMe';
6+
import { getSession } from '@/actions/getSession';
7+
import { getUsersById } from '@/actions/getUserById';
78
import { patchAlertsUserUserId } from '@/actions/patchAlertsUserUserId';
89
import { AlertSettingsForm } from '@/components/account/alert-settings/AlertSettingsForm';
910
import { isAgencyApprover } from '@/utils/Roles';
@@ -20,10 +21,11 @@ export default async function EditUserAlertSettingsPage({
2021
}) {
2122
const { id } = await params;
2223

23-
const user = await getUsersMe();
24+
const session = await getSession();
2425
const alertSettings = await getAlertsUserUserId(id);
26+
const user = await getUsersById(id);
2527

26-
if (!isAgencyApprover(user.role)) {
28+
if (!isAgencyApprover(session?.user.role)) {
2729
notFound();
2830
}
2931

@@ -45,6 +47,7 @@ export default async function EditUserAlertSettingsPage({
4547
return (
4648
<div>
4749
<AlertSettingsForm
50+
user={user}
4851
defaultValues={defaultValues}
4952
selfEdit={false}
5053
onSubmit={onSubmit}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { getTranslations } from 'next-intl/server';
2+
3+
import { getUsersById } from '@/actions/getUserById';
4+
import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage } from '@/ui/breadcrumbs/breadcrumbs';
5+
6+
export default async function BreadcrumbOrganisationSlot({
7+
params,
8+
}: { params: Promise<{ id: string }> }) {
9+
const { id } = await params;
10+
const t = await getTranslations('Breadcrumb');
11+
const user = await getUsersById(id);
12+
13+
return (
14+
<Breadcrumb>
15+
<BreadcrumbList>
16+
<BreadcrumbItem>
17+
<BreadcrumbLink href="/">Home</BreadcrumbLink>
18+
</BreadcrumbItem>
19+
<BreadcrumbItem>
20+
<BreadcrumbLink href="/account">{t('account')}</BreadcrumbLink>
21+
</BreadcrumbItem>
22+
<BreadcrumbItem>
23+
<BreadcrumbLink href="/account/distribution-list">{t('distribution-list')}</BreadcrumbLink>
24+
</BreadcrumbItem>
25+
<BreadcrumbItem>
26+
<BreadcrumbPage>
27+
{user.first_name}
28+
{' '}
29+
{user.last_name}
30+
</BreadcrumbPage>
31+
</BreadcrumbItem>
32+
</BreadcrumbList>
33+
</Breadcrumb>
34+
);
35+
}

src/components/account/alert-settings/AlertSettingsForm.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useState } from 'react';
55
import type { SubmitHandler, UseFormRegister } from 'react-hook-form';
66
import { FormProvider, useForm } from 'react-hook-form';
77

8-
import type { TypeAlertSettingsIn } from '@/__generated__/data-contracts';
8+
import type { TypeAlertSettingsIn, TypeUserOut } from '@/__generated__/data-contracts';
99
import Accordion from '@/ui/accordion/accordion';
1010
import Button from '@/ui/button/button';
1111
import Checkboxes from '@/ui/checkboxes/checkboxes';
@@ -49,12 +49,13 @@ function Option({
4949
}
5050

5151
type AlertSettingsFormProps = {
52+
user?: TypeUserOut;
5253
defaultValues: AlertSettingsSchema;
5354
selfEdit?: boolean;
5455
onSubmit: (data: TypeAlertSettingsIn) => Promise<void>;
5556
};
5657

57-
const AlertSettingsForm = ({ defaultValues, selfEdit = true, onSubmit: onSubmitAction }: AlertSettingsFormProps) => {
58+
const AlertSettingsForm = ({ user, defaultValues, selfEdit = true, onSubmit: onSubmitAction }: AlertSettingsFormProps) => {
5859
const t = useTranslations('Forms.Alert_settings');
5960
const tCommon = useTranslations('Common');
6061

@@ -105,8 +106,8 @@ const AlertSettingsForm = ({ defaultValues, selfEdit = true, onSubmit: onSubmitA
105106
)
106107
: (
107108
<>
108-
<h1 className="govuk-heading-xl">{t('title', { whose: selfEdit ? 'your' : 'user\'s' })}</h1>
109-
<p className="govuk-body">{t('description')}</p>
109+
<h1 className="govuk-heading-xl">{t('title', { whose: selfEdit ? 'your' : user?.first_name ? `${user.first_name}'s` : 'user\'s' })}</h1>
110+
<p className="govuk-body">{t('description', { to: user?.first_name ? `${user.first_name} ${user.last_name}` : 'you' })}</p>
110111
{selfEdit && (
111112
<WarningText>
112113
{t('warning')}

src/locales/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1772,7 +1772,7 @@
17721772
},
17731773
"Alert_settings": {
17741774
"title": "Edit {whose} alert settings",
1775-
"description": "We will send you notifications according to the settings selected on this page.",
1775+
"description": "We will send {to} notifications according to the settings selected on this page.",
17761776
"warning": "Changing these settings is only recommended if advised by the National Space Operations Centre.",
17771777
"conjunction_alerts": "Conjunction alerts",
17781778
"self_which": "Which {type} alerts would you like to receive?",

0 commit comments

Comments
 (0)