|
1 | 1 | "use client";
|
2 |
| -import SideMenu from "@codegouvfr/react-dsfr/SideMenu"; |
3 |
| -import { usePathname, useSearchParams } from "next/navigation"; |
| 2 | +import { CertificationStatus } from "@/graphql/generated/graphql"; |
| 3 | +import SideMenu, { SideMenuProps } from "@codegouvfr/react-dsfr/SideMenu"; |
| 4 | +import { useSearchParams } from "next/navigation"; |
4 | 5 | import { ReactNode } from "react";
|
5 | 6 |
|
6 | 7 | export default function CertificationsLayout({
|
7 | 8 | children,
|
8 | 9 | }: {
|
9 | 10 | children: ReactNode;
|
10 | 11 | }) {
|
11 |
| - const currentPathname = usePathname(); |
12 | 12 | const searchParams = useSearchParams();
|
13 | 13 |
|
| 14 | + const statusParam = searchParams.get("status") || undefined; |
14 | 15 | const searchFilter = searchParams.get("search") || "";
|
| 16 | + const visibleParam = searchParams.get("visible") || undefined; |
15 | 17 |
|
16 |
| - const hrefSideMenu = (path: string, category: string) => { |
| 18 | + const hrefSideMenu = (status?: string, visible?: "true" | "false") => { |
17 | 19 | const params = new URLSearchParams();
|
| 20 | + if (status) { |
| 21 | + params.set("status", status); |
| 22 | + } |
| 23 | + |
| 24 | + if (visible) { |
| 25 | + params.set("visible", visible); |
| 26 | + } |
| 27 | + |
18 | 28 | params.set("page", "1");
|
19 |
| - params.set("CATEGORY", category); |
20 | 29 |
|
21 | 30 | if (searchFilter) {
|
22 | 31 | params.set("search", searchFilter);
|
23 | 32 | }
|
24 | 33 |
|
25 |
| - return `${path}/?${params.toString()}`; |
| 34 | + return `/responsable-certifications/certifications/?${params.toString()}`; |
26 | 35 | };
|
27 | 36 |
|
28 |
| - const menuItem = ({ |
29 |
| - text, |
30 |
| - path, |
31 |
| - category, |
32 |
| - defaultMenuItem, |
33 |
| - }: { |
34 |
| - text: string; |
35 |
| - path: string; |
36 |
| - category: string; |
37 |
| - defaultMenuItem?: boolean; |
38 |
| - }) => ({ |
39 |
| - isActive: |
40 |
| - (currentPathname.startsWith(path) && |
41 |
| - searchParams.get("CATEGORY") === category) || |
42 |
| - (!searchParams.get("CATEGORY") && defaultMenuItem), |
| 37 | + const menuItem = ( |
| 38 | + text: string, |
| 39 | + status?: CertificationStatus, |
| 40 | + visible?: "true" | "false", |
| 41 | + ): SideMenuProps.Item => ({ |
| 42 | + isActive: status === statusParam && visible === visibleParam, |
43 | 43 | linkProps: {
|
44 |
| - href: hrefSideMenu(path, category), |
| 44 | + href: hrefSideMenu(status, visible), |
45 | 45 | target: "_self",
|
46 | 46 | },
|
47 | 47 | text,
|
48 | 48 | });
|
49 | 49 |
|
50 | 50 | const validatedManuItems = [
|
51 |
| - menuItem({ |
52 |
| - text: "Visibles", |
53 |
| - path: "/responsable-certifications/certifications/", |
54 |
| - category: "VISIBLE", |
55 |
| - }), |
56 |
| - menuItem({ |
57 |
| - text: "Invisibles", |
58 |
| - path: "/responsable-certifications/certifications/", |
59 |
| - category: "INVISIBLE", |
60 |
| - }), |
| 51 | + menuItem("Visibles", "VALIDE_PAR_CERTIFICATEUR", "true"), |
| 52 | + menuItem("Invisibles", "VALIDE_PAR_CERTIFICATEUR", "false"), |
61 | 53 | ];
|
62 | 54 |
|
63 | 55 | const toValidateMenuItems = [
|
64 |
| - menuItem({ |
65 |
| - text: "À valider", |
66 |
| - path: "/responsable-certifications/certifications/", |
67 |
| - category: "TO_VALIDATE", |
68 |
| - defaultMenuItem: true, |
69 |
| - }), |
| 56 | + menuItem("À valider", "A_VALIDER_PAR_CERTIFICATEUR"), |
70 | 57 | ];
|
71 | 58 |
|
72 | 59 | return (
|
|
0 commit comments