-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
168 additions
and
157 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
162 changes: 162 additions & 0 deletions
162
packages/applications/ssr/src/components/pages/lauréat/modifier/ModifierLauréatFields.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,162 @@ | ||
/* eslint-disable react/jsx-props-no-spreading */ | ||
'use client'; | ||
|
||
import Button from '@codegouvfr/react-dsfr/Button'; | ||
import Input from '@codegouvfr/react-dsfr/Input'; | ||
import { useState } from 'react'; | ||
import Select from '@codegouvfr/react-dsfr/SelectNext'; | ||
|
||
import { Candidature } from '@potentiel-domain/candidature'; | ||
|
||
import { getTechnologieTypeLabel } from '../../candidature/helpers'; | ||
|
||
type FieldProps<T> = { candidature: T; lauréat: T; estEnCoursDeModification?: boolean }; | ||
type ProjectFieldProps<T> = FieldProps<T> & { label: string; name: string }; | ||
|
||
const ProjectField = <T extends string | number>({ | ||
candidature, | ||
lauréat, | ||
label, | ||
name, | ||
estEnCoursDeModification, | ||
}: ProjectFieldProps<T>) => { | ||
const [linked, setLinked] = useState(candidature === lauréat); | ||
const [candidatureValue, setCandidatureValue] = useState(candidature); | ||
const [lauréatValue, setLauréatValue] = useState(lauréat); | ||
|
||
const onButtonClick = () => { | ||
setLinked((l) => !l); | ||
setLauréatValue(candidatureValue); | ||
}; | ||
|
||
return ( | ||
<div className="flex flex-row items-center gap-4 w-full"> | ||
<div className="flex-1 font-semibold">{label}</div> | ||
<div className="flex-1 flex "> | ||
<input | ||
name={`candidature.${name}`} | ||
type="hidden" | ||
value={candidatureValue} | ||
disabled={candidatureValue === candidature} | ||
/> | ||
<Input | ||
label="" | ||
nativeInputProps={{ | ||
value: candidatureValue, | ||
onChange: (ev) => { | ||
setCandidatureValue(ev.target.value as T); | ||
if (linked) { | ||
setLauréatValue(ev.target.value as T); | ||
} | ||
}, | ||
}} | ||
/> | ||
</div> | ||
<div className="flex-1 flex flex-row gap-2 items-center"> | ||
<input | ||
name={`laureat.${name}`} | ||
type="hidden" | ||
value={lauréatValue} | ||
disabled={lauréatValue === lauréat} | ||
/> | ||
<Input | ||
disabled={estEnCoursDeModification || linked} | ||
label="" | ||
nativeInputProps={{ | ||
value: lauréatValue, | ||
onChange: (ev) => { | ||
setLauréatValue(ev.target.value as T); | ||
if (linked) { | ||
setCandidatureValue(ev.target.value as T); | ||
} | ||
}, | ||
}} | ||
addon={ | ||
<Button | ||
type="button" | ||
iconId={linked ? 'fr-icon-lock-unlock-fill' : 'fr-icon-lock-fill'} | ||
title="Appliquer les changements au projet" | ||
onClick={onButtonClick} | ||
disabled={estEnCoursDeModification} | ||
nativeButtonProps={{ 'aria-label': 'Appliquer les changements au projet' }} | ||
/> | ||
} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export const ActionnaireField = ({ | ||
candidature, | ||
lauréat, | ||
estEnCoursDeModification, | ||
}: FieldProps<string>) => { | ||
return ( | ||
<ProjectField | ||
candidature={candidature} | ||
lauréat={lauréat} | ||
estEnCoursDeModification={estEnCoursDeModification} | ||
label="Actionnaire(s)" | ||
name="actionnaire" | ||
/> | ||
); | ||
}; | ||
|
||
export const ReprésentantLégalField = ({ | ||
candidature, | ||
lauréat, | ||
estEnCoursDeModification, | ||
}: FieldProps<string>) => { | ||
return ( | ||
<ProjectField | ||
candidature={candidature} | ||
lauréat={lauréat} | ||
estEnCoursDeModification={estEnCoursDeModification} | ||
label="Nom représentant légal" | ||
name="nomRepresentantLegal" | ||
/> | ||
); | ||
}; | ||
|
||
export const TechnologieField = ({ candidature, lauréat }: FieldProps<string>) => { | ||
const [candidatureValue, setCandidatureValue] = useState(candidature); | ||
|
||
return ( | ||
<div className="flex flex-row items-center gap-4 w-full"> | ||
<div className="flex-1 font-semibold">Technologie</div> | ||
<div className="flex-1 flex "> | ||
<input | ||
name={`candidature.technologie`} | ||
type="hidden" | ||
value={candidatureValue} | ||
disabled={candidatureValue === candidature} | ||
/> | ||
<Select | ||
label="" | ||
nativeSelectProps={{ | ||
defaultValue: candidature, | ||
required: true, | ||
'aria-required': true, | ||
onChange: (ev) => { | ||
setCandidatureValue(ev.target.value); | ||
}, | ||
}} | ||
options={Candidature.TypeTechnologie.types.map((type) => ({ | ||
value: type, | ||
label: getTechnologieTypeLabel(type), | ||
}))} | ||
/> | ||
</div> | ||
<div className="flex-1 flex flex-row gap-2 items-center"> | ||
<Input | ||
disabled | ||
label="" | ||
nativeInputProps={{ | ||
value: lauréat, | ||
}} | ||
/> | ||
</div> | ||
</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