-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(admin,api): add on-site page for AAP settings v3 and refactor ov…
…erall - Implemented the on-site page for AAP settings v3, allowing users to manage on-site agency information. - Refactored various components and hooks to improve code readability and maintainability.
- Loading branch information
Showing
13 changed files
with
699 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
packages/reva-admin-react/src/app/(aap)/agencies-settings-v3/on-site/page.tsx
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
...p)/agencies-settings-v3/organisms/[organismId]/on-site/_components/onSiteOrganism.hook.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { useGraphQlClient } from "@/components/graphql/graphql-client/GraphqlClient"; | ||
import { graphql } from "@/graphql/generated"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { useParams } from "next/navigation"; | ||
|
||
const getOrganismQuery = graphql(` | ||
query getOrganismForOrganismOnSitePage($organismId: ID!) { | ||
organism_getOrganism(id: $organismId) { | ||
id | ||
label | ||
informationsCommerciales { | ||
id | ||
nom | ||
telephone | ||
siteInternet | ||
emailContact | ||
} | ||
remoteZones | ||
managedDegrees { | ||
id | ||
degree { | ||
id | ||
label | ||
} | ||
} | ||
domaines { | ||
id | ||
label | ||
} | ||
conventionCollectives { | ||
id | ||
label | ||
} | ||
} | ||
} | ||
`); | ||
|
||
export const useOnSiteOrganism = () => { | ||
const { organismId } = useParams<{ organismId: string }>(); | ||
const { graphqlClient } = useGraphQlClient(); | ||
|
||
const { data: getOrganismResponse } = useQuery({ | ||
queryKey: [organismId, "organism"], | ||
queryFn: () => graphqlClient.request(getOrganismQuery, { organismId }), | ||
enabled: !!organismId, | ||
}); | ||
|
||
const organism = getOrganismResponse?.organism_getOrganism; | ||
|
||
const organismName = | ||
organism?.informationsCommerciales?.nom || organism?.label; | ||
|
||
return { organism, organismId, organismName }; | ||
}; |
44 changes: 44 additions & 0 deletions
44
.../(aap)/agencies-settings-v3/organisms/[organismId]/on-site/domaines-ccns-degrees/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"use client"; | ||
import { FormOptionalFieldsDisclaimer } from "@/components/form-optional-fields-disclaimer/FormOptionalFieldsDisclaimer"; | ||
import { Breadcrumb } from "@codegouvfr/react-dsfr/Breadcrumb"; | ||
import DomainesCcnsDegreesForm from "../../_components/domaines-ccns-degrees-form/DomainesCcnsDegreesForm"; | ||
import { useOnSiteOrganism } from "../_components/onSiteOrganism.hook"; | ||
|
||
const DomainesCcnsDegreesOnSitePage = () => { | ||
const { organismId, organismName } = useOnSiteOrganism(); | ||
|
||
return ( | ||
<div className="flex flex-col"> | ||
<Breadcrumb | ||
currentPageLabel="Filières, branches et niveaux" | ||
homeLinkProps={{ | ||
href: `/`, | ||
}} | ||
segments={[ | ||
{ | ||
label: "Paramètres", | ||
linkProps: { href: "/agencies-settings-v3" }, | ||
}, | ||
{ | ||
label: organismName, | ||
linkProps: { | ||
href: `/agencies-settings-v3/organisms/${organismId}/on-site`, | ||
}, | ||
}, | ||
]} | ||
/> | ||
<h1>Filières, branches et niveaux</h1> | ||
<FormOptionalFieldsDisclaimer /> | ||
<p> | ||
Sélectionnez toutes les filières, branches et niveaux gérés par votre | ||
structure. | ||
</p> | ||
<DomainesCcnsDegreesForm | ||
organismId={organismId} | ||
backButtonUrl={`/agencies-settings-v3/organisms/${organismId}/on-site`} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default DomainesCcnsDegreesOnSitePage; |
71 changes: 71 additions & 0 deletions
71
...-settings-v3/organisms/[organismId]/on-site/information/organismInformationOnSite.hook.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { useGraphQlClient } from "@/components/graphql/graphql-client/GraphqlClient"; | ||
import { graphql } from "@/graphql/generated"; | ||
import { CreateOrUpdateInformationsCommercialesInput } from "@/graphql/generated/graphql"; | ||
|
||
import { useMutation, useQuery } from "@tanstack/react-query"; | ||
import { useParams } from "next/navigation"; | ||
|
||
const getOrganismQuery = graphql(` | ||
query getOrganismForInformationOnSitePage($organismId: ID!) { | ||
organism_getOrganism(id: $organismId) { | ||
id | ||
label | ||
informationsCommerciales { | ||
id | ||
nom | ||
telephone | ||
siteInternet | ||
emailContact | ||
adresseNumeroEtNomDeRue | ||
adresseInformationsComplementaires | ||
adresseCodePostal | ||
adresseVille | ||
conformeNormesAccessbilite | ||
} | ||
} | ||
} | ||
`); | ||
|
||
const createOrUpdateInformationsCommercialesMutation = graphql(` | ||
mutation createOrUpdateInformationsCommercialesMutation( | ||
$createOrUpdateInformationsCommercialesInput: CreateOrUpdateInformationsCommercialesInput! | ||
) { | ||
organism_createOrUpdateInformationsCommerciales( | ||
informationsCommerciales: $createOrUpdateInformationsCommercialesInput | ||
) { | ||
id | ||
} | ||
} | ||
`); | ||
|
||
export const useOrganismInformationOnSite = () => { | ||
const { graphqlClient } = useGraphQlClient(); | ||
const { organismId } = useParams<{ organismId: string }>(); | ||
const { data, isLoading } = useQuery({ | ||
queryKey: [organismId, "organism"], | ||
queryFn: () => | ||
graphqlClient.request(getOrganismQuery, { | ||
organismId, | ||
}), | ||
}); | ||
|
||
const { mutateAsync: createOrUpdateInformationsCommerciales } = useMutation({ | ||
mutationFn: ( | ||
informationsCommerciales: CreateOrUpdateInformationsCommercialesInput, | ||
) => | ||
graphqlClient.request(createOrUpdateInformationsCommercialesMutation, { | ||
createOrUpdateInformationsCommercialesInput: informationsCommerciales, | ||
}), | ||
}); | ||
|
||
const organism = data?.organism_getOrganism; | ||
const informationsCommerciales = organism?.informationsCommerciales; | ||
|
||
return { | ||
organism, | ||
isLoading, | ||
organismId, | ||
informationsCommerciales, | ||
createOrUpdateInformationsCommerciales, | ||
}; | ||
}; |
85 changes: 85 additions & 0 deletions
85
...ct/src/app/(aap)/agencies-settings-v3/organisms/[organismId]/on-site/information/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
"use client"; | ||
|
||
import { ConformiteNormeAccessibilite } from "@/graphql/generated/graphql"; | ||
import Breadcrumb from "@codegouvfr/react-dsfr/Breadcrumb"; | ||
import OrganismInformationForm from "../../../_components/OrganismInformationForm"; | ||
import { OrganismInformationFormData } from "../../../_components/organismInformationFormSchema"; | ||
import { useOrganismInformationOnSite } from "./organismInformationOnSite.hook"; | ||
|
||
const InformationsOnSitePage = () => { | ||
const { | ||
organism, | ||
informationsCommerciales, | ||
organismId, | ||
createOrUpdateInformationsCommerciales, | ||
} = useOrganismInformationOnSite(); | ||
const handleSubmit = async (data: OrganismInformationFormData) => { | ||
const input = { | ||
organismId, | ||
nom: data.nom, | ||
telephone: data.telephone, | ||
siteInternet: data.siteInternet, | ||
emailContact: data.emailContact, | ||
adresseNumeroEtNomDeRue: data.adresseNumeroEtNomDeRue, | ||
adresseInformationsComplementaires: | ||
data.adresseInformationsComplementaires, | ||
adresseCodePostal: data.adresseCodePostal, | ||
adresseVille: data.adresseVille, | ||
conformeNormesAccessbilite: | ||
data.conformeNormesAccessibilite as ConformiteNormeAccessibilite, | ||
}; | ||
|
||
await createOrUpdateInformationsCommerciales(input); | ||
}; | ||
|
||
const organismName = | ||
organism?.informationsCommerciales?.nom || organism?.label; | ||
|
||
if (!organism) { | ||
return null; | ||
} | ||
const defaultData = { | ||
adresseNumeroEtNomDeRue: | ||
informationsCommerciales?.adresseNumeroEtNomDeRue ?? "", | ||
adresseInformationsComplementaires: | ||
informationsCommerciales?.adresseInformationsComplementaires ?? "", | ||
adresseCodePostal: informationsCommerciales?.adresseCodePostal ?? "", | ||
adresseVille: informationsCommerciales?.adresseVille ?? "", | ||
nom: informationsCommerciales?.nom ?? "", | ||
telephone: informationsCommerciales?.telephone ?? "", | ||
siteInternet: informationsCommerciales?.siteInternet ?? "", | ||
emailContact: informationsCommerciales?.emailContact ?? "", | ||
conformeNormesAccessibilite: | ||
informationsCommerciales?.conformeNormesAccessbilite as any, | ||
}; | ||
|
||
return ( | ||
<div className="flex flex-col"> | ||
<Breadcrumb | ||
currentPageLabel={"Informations affichées au candidat"} | ||
homeLinkProps={{ | ||
href: `/`, | ||
}} | ||
segments={[ | ||
{ | ||
label: "Paramètres", | ||
linkProps: { href: "/agencies-settings-v3" }, | ||
}, | ||
{ | ||
label: organismName, | ||
linkProps: { | ||
href: `/agencies-settings-v3/organisms/${organismId}/on-site`, | ||
}, | ||
}, | ||
]} | ||
/> | ||
<OrganismInformationForm | ||
mutationOnSubmit={handleSubmit} | ||
pathRedirection={`/agencies-settings-v3/organisms/${organismId}/on-site`} | ||
defaultData={defaultData} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default InformationsOnSitePage; |
Oops, something went wrong.