Skip to content

Commit 31cad39

Browse files
committed
feat(website): vae collective code input page now supports a default codeInscription as an url search param
1 parent 420a520 commit 31cad39

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

packages/reva-website/src/app/inscription-candidat/vae-collective/_components/VaeCollectiveCodeForm.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ const zodSchema = z.object({
3232

3333
type FormData = z.infer<typeof zodSchema>;
3434

35-
export function VaeCollectiveCodeForm() {
35+
export function VaeCollectiveCodeForm({
36+
defaultValues,
37+
}: {
38+
defaultValues?: FormData;
39+
}) {
3640
const router = useRouter();
3741
const { graphqlClient } = useGraphQlClient();
3842

@@ -45,9 +49,7 @@ export function VaeCollectiveCodeForm() {
4549
clearErrors,
4650
} = useForm<FormData>({
4751
resolver: zodResolver(zodSchema),
48-
defaultValues: {
49-
code: "",
50-
},
52+
defaultValues,
5153
reValidateMode: "onSubmit",
5254
});
5355

packages/reva-website/src/app/inscription-candidat/vae-collective/page.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import { CandidateBackground } from "@/components/layout/full-height-blue-layout
55

66
import { VaeCollectiveCodeForm } from "./_components/VaeCollectiveCodeForm";
77

8-
export default function VaeCollectiveCodePage() {
8+
export default async function VaeCollectiveCodePage({
9+
searchParams,
10+
}: {
11+
searchParams: Promise<{ codeInscription?: string }>;
12+
}) {
13+
const { codeInscription } = await searchParams;
14+
915
return (
1016
<MainLayout>
1117
<CandidateBackground>
@@ -19,7 +25,11 @@ export default function VaeCollectiveCodePage() {
1925
</p>
2026
<div className="flex flex-col lg:flex-row lg:justify-between gap-20 lg:gap-28">
2127
<div className="w-full flex-basis-1/2 my-10">
22-
<VaeCollectiveCodeForm />
28+
<VaeCollectiveCodeForm
29+
defaultValues={{
30+
code: codeInscription ?? "",
31+
}}
32+
/>
2333
</div>
2434
<div className="flex flex-col flex-basis-1/2 my-auto">
2535
<p className="text-xl leading-relaxed">

packages/reva-website/tests/vae-collective.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,16 @@ test.describe("VAE Collective Code Page", () => {
132132
),
133133
).toBeVisible();
134134
});
135+
136+
test("should prefill the code input when a code is provided in the url", async ({
137+
page,
138+
}) => {
139+
await page.goto(
140+
"/inscription-candidat/vae-collective?codeInscription=ABCD1234",
141+
);
142+
143+
const codeInput = page.getByRole("textbox");
144+
145+
await expect(codeInput).toHaveValue("ABCD1234");
146+
});
135147
});

0 commit comments

Comments
 (0)