-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into POC-bascule
- Loading branch information
Showing
64 changed files
with
2,367 additions
and
187 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
...s/settings/operations/actions/AffectationSimulation/AffectationCLESimulationMetropole.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,50 @@ | ||
import React from "react"; | ||
import { useHistory } from "react-router-dom"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { useToggle } from "react-use"; | ||
import { HiOutlineInformationCircle } from "react-icons/hi"; | ||
|
||
import { AffectationRoutes, CohortDto, TaskName, TaskStatus } from "snu-lib"; | ||
import { Button, Tooltip } from "@snu/ds/admin"; | ||
|
||
import { AffectationService } from "@/services/affectationService"; | ||
import AffectationCLESimulationMetropoleModal from "./AffectationCLESimulationMetropoleModal"; | ||
|
||
interface AffectationCLESimulationMetropoleProps { | ||
session: CohortDto; | ||
} | ||
|
||
export default function AffectationCLESimulationMetropole({ session }: AffectationCLESimulationMetropoleProps) { | ||
const history = useHistory(); | ||
|
||
const [showModal, toggleModal] = useToggle(false); | ||
|
||
const { | ||
isPending: isLoading, | ||
isError, | ||
data: affectationStatus, | ||
} = useQuery<AffectationRoutes["GetAffectation"]["response"]>({ | ||
queryKey: ["affectation", "cle", session._id], // check SimulationHtsResultStartButton.tsx and AffectationCLESimulationMetropoleModal.tsx queryKey | ||
queryFn: async () => AffectationService.getAffectation(session._id!, "CLE"), | ||
}); | ||
|
||
const isValidSession = session.type === "CLE"; | ||
const isInProgress = affectationStatus && [TaskStatus.IN_PROGRESS, TaskStatus.PENDING].includes(affectationStatus?.simulation?.status as TaskStatus); | ||
|
||
return ( | ||
<div className="flex items-center justify-between px-4"> | ||
<div className="flex gap-2"> | ||
<div className="text-sm leading-5 font-bold">Affectation CLE (Metropole)</div> | ||
<Tooltip id="affectation-hts-metropole" title="Affectation CLE (Metropole)"> | ||
<HiOutlineInformationCircle className="text-gray-400" size={20} /> | ||
</Tooltip> | ||
{isInProgress && <div className="text-xs leading-4 font-normal text-orange-500 italic">Simulation en cours...</div>} | ||
</div> | ||
<div className="flex gap-2"> | ||
<Button title="Voir les simulations" type="wired" onClick={() => history.push(`?tab=simulations&cohort=${session.name}&action=${TaskName.AFFECTATION_CLE_SIMULATION}`)} /> | ||
<Button title="Lancer une simulation" onClick={toggleModal} loading={isInProgress || isLoading} disabled={!isValidSession || isLoading || isInProgress || isError} /> | ||
</div> | ||
{showModal && <AffectationCLESimulationMetropoleModal session={session} onClose={toggleModal} />} | ||
</div> | ||
); | ||
} |
97 changes: 97 additions & 0 deletions
97
...tings/operations/actions/AffectationSimulation/AffectationCLESimulationMetropoleModal.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,97 @@ | ||
import React from "react"; | ||
|
||
import { HiOutlineLightningBolt } from "react-icons/hi"; | ||
|
||
import { CohortDto, formatDepartement, Phase1Routes, region2department, RegionsMetropole, translate } from "snu-lib"; | ||
import { Button, CollapsableSelectSwitcher, Modal, SectionSwitcher } from "@snu/ds/admin"; | ||
import { useSetState } from "react-use"; | ||
import { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
import { AffectationService } from "@/services/affectationService"; | ||
import { toastr } from "react-redux-toastr"; | ||
import { capture } from "@/sentry"; | ||
|
||
interface AffectationHTSSimulationMetropoleProps { | ||
session: CohortDto; | ||
onClose: () => void; | ||
} | ||
|
||
export default function AffectationCLESimulationMetropoleModal({ session, onClose }: AffectationHTSSimulationMetropoleProps) { | ||
const queryClient = useQueryClient(); | ||
|
||
const [state, setState] = useSetState<{ | ||
departements: Record<string, string[]>; | ||
etranger: boolean; | ||
}>({ | ||
departements: RegionsMetropole.reduce((acc, region) => { | ||
acc[region] = region2department[region]; | ||
return acc; | ||
}, {}), | ||
etranger: true, | ||
}); | ||
|
||
const isReady = Object.values(state.departements).some((departements) => departements.length > 0); | ||
|
||
const { isPending, mutate } = useMutation({ | ||
mutationFn: async () => { | ||
return await AffectationService.postSimulationAffectationCLEMetropole(session._id!, { | ||
departements: Object.keys(state.departements).reduce((acc, region) => [...acc, ...state.departements[region]], []), | ||
etranger: state.etranger, | ||
}); | ||
}, | ||
onSuccess: (task) => { | ||
toastr.success("Le traitement a bien été ajouté", "", { timeOut: 5000 }); | ||
const queryKey = ["affectation", "cle", session._id]; | ||
const oldStatus = queryClient.getQueryData<Phase1Routes["GetSimulationsRoute"]["response"]>(queryKey) || []; | ||
queryClient.setQueryData(queryKey, { ...oldStatus, simulation: { status: task.status } }); | ||
onClose(); | ||
}, | ||
onError: (error: any) => { | ||
capture(error); | ||
toastr.error("Une erreur est survenue lors de l'ajout du traitement", translate(JSON.parse(error.message).message), { timeOut: 5000 }); | ||
}, | ||
}); | ||
|
||
return ( | ||
<Modal | ||
isOpen | ||
onClose={onClose} | ||
className="md:max-w-[800px]" | ||
content={ | ||
<div className="scroll-y-auto overflow-y-auto max-h-[80vh]"> | ||
<div className="flex flex-col items-center text-center gap-6 mb-8"> | ||
<div className="flex items-center"> | ||
<div className="flex items-center justify-center w-12 h-12 rounded-full bg-gray-50"> | ||
<HiOutlineLightningBolt className="w-6 h-6" /> | ||
</div> | ||
</div> | ||
<h1 className="font-bold text-xl m-0">Affectation CLE (Metropole)</h1> | ||
</div> | ||
<div className="flex items-start flex-col w-full gap-8"> | ||
<div className="flex flex-col w-full gap-2.5"> | ||
<h2 className="text-lg leading-7 font-bold m-0">Découpage territorial</h2> | ||
<div className="flex flex-col w-full"> | ||
{RegionsMetropole.map((region) => ( | ||
<CollapsableSelectSwitcher | ||
key={region} | ||
title={region} | ||
options={region2department[region].map((department) => ({ label: formatDepartement(department), value: department }))} | ||
values={state.departements[region]} | ||
onChange={(values) => setState({ departements: { ...state.departements, [region]: values } })} | ||
isOpen={false} | ||
/> | ||
))} | ||
<SectionSwitcher title="Etranger" value={state.etranger} onChange={(etranger) => setState({ etranger })} className="py-2.5" /> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
} | ||
footer={ | ||
<div className="flex items-center justify-between gap-6"> | ||
<Button title="Annuler" type="secondary" className="flex-1 justify-center" onClick={onClose} /> | ||
<Button disabled={!isReady || isPending} onClick={() => mutate()} title="Lancer une simulation" className="flex-1" /> | ||
</div> | ||
} | ||
/> | ||
); | ||
} |
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
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
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
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
19 changes: 19 additions & 0 deletions
19
admin/src/scenes/settings/operations/simulations/affectationCle/SimulationCleResultCell.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,19 @@ | ||
import React from "react"; | ||
|
||
import { SimulationAffectationCLETaskDto } from "snu-lib"; | ||
|
||
interface SimulationCleResultCellProps { | ||
simulation: unknown; | ||
} | ||
|
||
export default function SimulationCleResultCell({ simulation }: SimulationCleResultCellProps) { | ||
const simulationCle = simulation as SimulationAffectationCLETaskDto; | ||
|
||
return ( | ||
<div className="text-xs leading-4 font-normal"> | ||
<div>Classes : {simulationCle.metadata?.results?.classes ?? "--"}</div> | ||
<div>Erreurs : {simulationCle.metadata?.results?.erreurs ?? "--"}</div> | ||
<div>Affectés : {simulationCle.metadata?.results?.jeunesAffected ?? "--"}</div> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.