22
33import { useRouter } from "next/navigation" ;
44import { Controller } from "react-hook-form" ;
5+ import { useIsImpersonating } from "~/modules/auth" ;
56import { saveCompliancePathSchema } from "~/modules/declaration-remuneration/schemas" ;
67import type { CampaignDeadlines } from "~/modules/domain" ;
78import { NewTabNotice } from "~/modules/layout/shared/NewTabNotice" ;
@@ -27,17 +28,20 @@ type Props = {
2728function JointEvaluationOption ( {
2829 checked,
2930 deadline,
31+ disabled,
3032 onChange,
3133} : {
3234 checked : boolean ;
3335 deadline : Date ;
36+ disabled ?: boolean ;
3437 onChange : ( ) => void ;
3538} ) {
3639 return (
3740 < div className = "fr-fieldset__element" >
3841 < CompliancePathOption
3942 checked = { checked }
4043 deadline = { deadline }
44+ disabled = { disabled }
4145 id = "path-joint"
4246 learnMoreHref = "https://travail-emploi.gouv.fr/droit-du-travail/egalite-professionnelle"
4347 learnMoreLabel = "En savoir plus sur évaluation conjointe des rémunérations"
@@ -69,17 +73,20 @@ function JointEvaluationOption({
6973function JustifyOption ( {
7074 checked,
7175 deadline,
76+ disabled,
7277 onChange,
7378} : {
7479 checked : boolean ;
7580 deadline : Date ;
81+ disabled ?: boolean ;
7682 onChange : ( ) => void ;
7783} ) {
7884 return (
7985 < div className = "fr-fieldset__element" >
8086 < CompliancePathOption
8187 checked = { checked }
8288 deadline = { deadline }
89+ disabled = { disabled }
8390 id = "path-justify"
8491 name = "compliance-path"
8592 onChange = { onChange }
@@ -100,11 +107,13 @@ function JustifyOption({
100107}
101108
102109function SecondRoundOptions ( {
110+ disabled,
103111 justificationDeadline,
104112 jointEvaluationDeadline,
105113 selectedPath,
106114 setSelectedPath,
107115} : {
116+ disabled ?: boolean ;
108117 justificationDeadline : Date ;
109118 jointEvaluationDeadline : Date ;
110119 selectedPath : CompliancePathValue | undefined ;
@@ -115,11 +124,13 @@ function SecondRoundOptions({
115124 < JustifyOption
116125 checked = { selectedPath === "justify" }
117126 deadline = { justificationDeadline }
127+ disabled = { disabled }
118128 onChange = { ( ) => setSelectedPath ( "justify" ) }
119129 />
120130 < JointEvaluationOption
121131 checked = { selectedPath === "joint_evaluation" }
122132 deadline = { jointEvaluationDeadline }
133+ disabled = { disabled }
123134 onChange = { ( ) => setSelectedPath ( "joint_evaluation" ) }
124135 />
125136 </ >
@@ -128,12 +139,14 @@ function SecondRoundOptions({
128139
129140function FirstRoundOptions ( {
130141 correctiveActionDeadline,
142+ disabled,
131143 jointEvaluationDeadline,
132144 justificationDeadline,
133145 selectedPath,
134146 setSelectedPath,
135147} : {
136148 correctiveActionDeadline : Date ;
149+ disabled ?: boolean ;
137150 jointEvaluationDeadline : Date ;
138151 justificationDeadline : Date ;
139152 selectedPath : CompliancePathValue | undefined ;
@@ -144,6 +157,7 @@ function FirstRoundOptions({
144157 < JustifyOption
145158 checked = { selectedPath === "justify" }
146159 deadline = { justificationDeadline }
160+ disabled = { disabled }
147161 onChange = { ( ) => setSelectedPath ( "justify" ) }
148162 />
149163
@@ -156,6 +170,7 @@ function FirstRoundOptions({
156170 < CompliancePathOption
157171 checked = { selectedPath === "corrective_action" }
158172 deadline = { correctiveActionDeadline }
173+ disabled = { disabled }
159174 id = "path-corrective"
160175 learnMoreHref = "https://travail-emploi.gouv.fr/droit-du-travail/egalite-professionnelle"
161176 learnMoreLabel = "En savoir plus sur actions correctives et seconde déclaration"
@@ -194,12 +209,23 @@ function FirstRoundOptions({
194209 < JointEvaluationOption
195210 checked = { selectedPath === "joint_evaluation" }
196211 deadline = { jointEvaluationDeadline }
212+ disabled = { disabled }
197213 onChange = { ( ) => setSelectedPath ( "joint_evaluation" ) }
198214 />
199215 </ >
200216 ) ;
201217}
202218
219+ function getCompliancePathHref ( path : CompliancePathValue ) : string {
220+ if ( path === "corrective_action" ) {
221+ return "/declaration-remuneration/parcours-conformite/etape/1" ;
222+ }
223+ if ( path === "joint_evaluation" ) {
224+ return "/declaration-remuneration/parcours-conformite/evaluation-conjointe" ;
225+ }
226+ return "/avis-cse" ;
227+ }
228+
203229export function CompliancePathChoice ( {
204230 campaignDeadlines,
205231 currentYear,
@@ -209,6 +235,7 @@ export function CompliancePathChoice({
209235 pdfDownloadHref,
210236} : Props ) {
211237 const router = useRouter ( ) ;
238+ const isImpersonating = useIsImpersonating ( ) ;
212239
213240 const form = useZodForm ( saveCompliancePathSchema , {
214241 defaultValues : { path : initialPath } ,
@@ -300,6 +327,7 @@ export function CompliancePathChoice({
300327
301328 { isSecondRound ? (
302329 < SecondRoundOptions
330+ disabled = { isImpersonating }
303331 jointEvaluationDeadline = {
304332 campaignDeadlines . decl2JointEvaluationDeadline
305333 }
@@ -314,6 +342,7 @@ export function CompliancePathChoice({
314342 correctiveActionDeadline = {
315343 campaignDeadlines . decl2ModificationDeadline
316344 }
345+ disabled = { isImpersonating }
317346 jointEvaluationDeadline = {
318347 campaignDeadlines . decl1JointEvaluationDeadline
319348 }
@@ -330,6 +359,9 @@ export function CompliancePathChoice({
330359
331360 < FormActions
332361 isSubmitting = { mutation . isPending }
362+ mimoquageNextHref = {
363+ initialPath ? getCompliancePathHref ( initialPath ) : undefined
364+ }
333365 nextDisabled = { ! selectedPath }
334366 nextLabel = "Suivant"
335367 previousHref = "/declaration-remuneration/etape/6"
0 commit comments