Skip to content

Commit

Permalink
update gender field from PP in personal info screen (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
faiza-jahanzeb authored Feb 26, 2025
1 parent eab81ea commit c26ae90
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
21 changes: 11 additions & 10 deletions frontend/app/routes/protected/person-case/personal-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as v from 'valibot';

import type { Info, Route } from './+types/personal-info';

import { getGenders, getLocalizedGenders } from '~/.server/services/locale-data-service';
import { requireAuth } from '~/.server/utils/auth-utils';
import { i18nRedirect } from '~/.server/utils/route-utils';
import { Button } from '~/components/button';
Expand All @@ -27,15 +28,13 @@ import { REGEX_PATTERNS } from '~/utils/regex-utils';

type PersonalInformationSessionData = NonNullable<SessionData['inPersonSINCase']['personalInformation']>;

const VALID_GENDERS = ['female', 'male', 'other'];

export const handle = {
i18nNamespace: [...parentHandle.i18nNamespace, 'protected'],
} as const satisfies RouteHandle;

export async function loader({ context, request }: Route.LoaderArgs) {
requireAuth(context.session, new URL(request.url), ['user']);
const { t } = await getTranslation(request, handle.i18nNamespace);
const { t, lang } = await getTranslation(request, handle.i18nNamespace);

return {
documentTitle: t('protected:personal-information.page-title'),
Expand All @@ -45,6 +44,7 @@ export async function loader({ context, request }: Route.LoaderArgs) {
lastNamePreviouslyUsed: context.session.inPersonSINCase?.personalInformation?.lastNamePreviouslyUsed ?? [],
gender: context.session.inPersonSINCase?.personalInformation?.gender,
},
localizedGenders: getLocalizedGenders(lang),
};
}

Expand Down Expand Up @@ -79,7 +79,10 @@ export async function action({ context, request }: Route.ActionArgs) {
v.regex(REGEX_PATTERNS.NON_DIGIT, t('protected:personal-information.last-name-at-birth.format')),
),
lastNamePreviouslyUsed: v.optional(v.array(v.string())),
gender: v.picklist(VALID_GENDERS, t('protected:personal-information.gender.required')),
gender: v.picklist(
getGenders().map(({ id }) => id),
t('protected:personal-information.gender.required'),
),
}) satisfies v.GenericSchema<PersonalInformationSessionData>;

const input = {
Expand Down Expand Up @@ -119,12 +122,10 @@ export default function PersonalInformation({ loaderData, params }: Route.Compon
const [lastNames, setLastNames] = useState(loaderData.defaultFormValues.lastNamePreviouslyUsed);
const [srAnnouncement, setSrAnnouncement] = useState('');

const GENDER = ['female', 'male', 'other'] as const;

const genderOptions = GENDER.map((value) => ({
value: value,
children: t(`protected:personal-information.gender.options.${value}` as const),
defaultChecked: value === loaderData.defaultFormValues.gender,
const genderOptions = loaderData.localizedGenders.map(({ id, name }) => ({
value: id,
children: name,
defaultChecked: id === loaderData.defaultFormValues.gender,
}));

function handleAddFirstName() {
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/routes/protected/person-case/primary-docs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ function PrimaryDocsFields({
const genderOptions = genders.map(({ id, name }) => ({
value: id,
children: name,
defaultChecked: name === defaultValues?.gender,
defaultChecked: id === defaultValues?.gender,
}));

return (
Expand Down

0 comments on commit c26ae90

Please sign in to comment.