Skip to content

Commit bd81ea2

Browse files
authored
fix: format and check phone number from MCP data (#2125)
1 parent 3444c68 commit bd81ea2

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

packages/app/src/api/core-domain/infra/auth/MonCompteProProvider.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export function MonCompteProProvider<P extends MonCompteProProfile>(
5555
id: profile.sub,
5656
email: profile.email,
5757
name: profile.given_name,
58-
phone_number: profile.phone_number,
58+
phone_number: profile.phone_number?.replace(/[.\-\s]/g, ""), //TODO: remove when handled in MCP
5959
};
6060
},
6161
...options,

packages/app/src/components/RHF/DeclarantFields.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Button from "@codegouvfr/react-dsfr/Button";
33
import Input from "@codegouvfr/react-dsfr/Input";
44
import { cx } from "@codegouvfr/react-dsfr/tools/cx";
55
import { type SimpleObject } from "@common/utils/types";
6+
import { useEffect } from "react";
67
import { useFormContext } from "react-hook-form";
78

89
import { Grid, GridCol } from "../../design-system/base/Grid";
@@ -31,13 +32,22 @@ export const DeclarantFields = <FormType extends SimpleObject>({
3132
register,
3233
formState: { errors },
3334
setValue,
35+
getValues,
36+
watch,
37+
trigger,
3438
} = useFormContext<FakeFormType>();
3539

3640
const firstnameKey = firstname as FakeKey;
3741
const lastnameKey = lastname as FakeKey;
3842
const phoneNumberKey = phoneNumber as FakeKey;
3943
const emailKey = email as FakeKey;
4044

45+
const phoneValue = watch(phoneNumberKey) || getValues(phoneNumberKey);
46+
47+
useEffect(() => {
48+
trigger();
49+
}, [phoneValue]);
50+
4151
return (
4252
<>
4353
<Grid haveGutters>

0 commit comments

Comments
 (0)