Skip to content

Commit

Permalink
feat(PackagingList) : disable inputs when fields are sealed
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitguigal committed Feb 10, 2025
1 parent 125f35a commit 29ec5b9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
7 changes: 4 additions & 3 deletions back/src/forms/pdf/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ export function getPackagingsRows(packagingInfos: PackagingInfo[]) {
")"
].join("");
} else if (volumes.length === 1) {
// Un seul type de volume ou de conditionnement de type Autre
// On ajoute ces valeurs après le type de conditionnement
// Exemple GRV 30l ou Benne 20m3 ou Autre Caisse plastique
// Un seul type de volume :
// On ajoute la valeur après le type de conditionnement
// en faisant un cas particulier pour le type Benne qui s'exprime en m3
// Exemple GRV 30l ou Benne 20m3
const volume = packagings[0].volume;
conditionnement = [
conditionnement,
Expand Down
3 changes: 2 additions & 1 deletion front/src/Apps/Forms/Components/TagsInput/TagsInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ const TagsInput = ({
<div key={idx}>
<Tag
className="fr-mb-1v"
dismissible
dismissible={!disabled}
nativeButtonProps={{
type: "button",
disabled,
onClick: () => {
onDeleteTag(idx);
}
Expand Down
6 changes: 5 additions & 1 deletion front/src/form/bsdd/WasteInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export default function WasteInfo({ disabled }) {
<div className="form__row" style={{ flexDirection: "row" }}>
<Switch
label="Le déchet est conditionné pour pipeline"
disabled={disabled}
checked={isPipeline}
onChange={checked => {
const updatedPackagings = checked
Expand All @@ -198,7 +199,10 @@ export default function WasteInfo({ disabled }) {
{values.emitter?.type !== "APPENDIX1" && !isPipeline && (
<>
<h4 className="form__section-heading">Conditionnement</h4>
<PackagingList fieldName="wasteDetails.packagingInfos" />
<PackagingList
fieldName="wasteDetails.packagingInfos"
disabled={disabled}
/>
</>
)}

Expand Down
9 changes: 8 additions & 1 deletion front/src/form/bsdd/components/packagings/PackagingForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ type PackagingFormProps = {
packaging: PackagingInfoInput;
setPackaging: (packaging: PackagingInfoInput) => void;
packagingTypeOptions: { value: Packagings; label: string }[];
disabled?: boolean;
};

function PackagingForm({
packaging,
setPackaging,
packagingTypeOptions
packagingTypeOptions,
disabled = false
}: PackagingFormProps) {
const maxQuantity =
packaging.type === Packagings.Citerne || packaging.type === Packagings.Benne
Expand Down Expand Up @@ -45,6 +47,7 @@ function PackagingForm({
<div className="fr-col-md-6 fr-col-12">
<Select
label="Type"
disabled={disabled}
nativeSelectProps={{
value: packaging.type,
onChange: event => {
Expand Down Expand Up @@ -77,6 +80,7 @@ function PackagingForm({
<NonScrollableInput
label={`Volume en ${volumeUnit} (optionnel)`}
className="fr-mb-2w"
disabled={disabled}
nativeInputProps={{
type: "number",
inputMode: "decimal",
Expand Down Expand Up @@ -113,6 +117,7 @@ function PackagingForm({
className="fr-mb-2w"
state={quantityError ? "error" : "default"}
stateRelatedMessage={quantityError}
disabled={disabled}
nativeInputProps={{
type: "number",
inputMode: "numeric",
Expand All @@ -136,6 +141,7 @@ function PackagingForm({
<div className="fr-col-12">
<Input
label="Nom du type de contenant"
disabled={disabled}
nativeInputProps={{
value: packaging.other ?? "",
onChange: event =>
Expand All @@ -150,6 +156,7 @@ function PackagingForm({
<TagsInput
label="N° de contenant (optionnel)"
tags={packaging.identificationNumbers ?? []}
disabled={disabled}
onAddTag={tag =>
setPackaging({
...packaging,
Expand Down
6 changes: 5 additions & 1 deletion front/src/form/bsdd/components/packagings/PackagingList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import PackagingForm from "./PackagingForm";

type PackagingListProps = {
fieldName: string;
disabled?: boolean;
};

const packagingTypeOptions = [
Expand All @@ -15,7 +16,7 @@ const packagingTypeOptions = [
{ value: Packagings.Autre, label: "Autre" }
];

function PackagingList({ fieldName }: PackagingListProps) {
function PackagingList({ fieldName, disabled = false }: PackagingListProps) {
const [field] = useField<PackagingInfoInput[]>(fieldName);

const packagings = field.value;
Expand Down Expand Up @@ -47,11 +48,13 @@ function PackagingList({ fieldName }: PackagingListProps) {
packaging={p}
setPackaging={p => replace(idx, p)}
packagingTypeOptions={options}
disabled={disabled}
/>
{packagings.length > 1 && (
<>
<button
type="button"
disabled={disabled}
className="fr-btn fr-btn--tertiary fr-mb-2w"
onClick={() => remove(idx)}
>
Expand All @@ -66,6 +69,7 @@ function PackagingList({ fieldName }: PackagingListProps) {
<div className="fr-grid-row fr-grid-row--right fr-mb-4w">
<button
type="button"
disabled={disabled}
className="fr-btn fr-btn--secondary"
onClick={() => {
push({ type: "", quantity: "" });
Expand Down

0 comments on commit 29ec5b9

Please sign in to comment.