Skip to content

Commit

Permalink
Fix vhu identifications inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
providenz committed Jan 6, 2025
1 parent 9f61133 commit 8949788
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ et le projet suit un schéma de versionning inspiré de [Calendar Versioning](ht

- Pour le Bsvhu lors d'un transport routier, la plaque d'immatriculation est désormais obligatoire et les poids de déchets sont limités à 40 T (50 kT pour les autres modes) [PR 3719](https://github.com/MTES-MCT/trackdechets/pull/3719)

#### :bug: Corrections de bugs

- Correction de la mise à jour des numéros d'identification sur le bsvhu [PR 3876](https://github.com/MTES-MCT/trackdechets/pull/3876)

# [2024.12.1] 17/12/2024

#### :rocket: Nouvelles fonctionnalités
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,27 @@ const IdentificationNumber = ({
function identificationNumberReducer(state, action) {
switch (action.type) {
case SET_INPUT_CODE:
return { ...state, inputCode: action.payload };
return { ...state, inputCode: action.payload, touched: true };

case ADD_CODE: {
if (!state.codes.length && defaultValue?.length) {
if (!state.codes.length && defaultValue?.length && !state.touched) {
// initial
return {
...state,
codes: [...state.codes, ...defaultValue],
inputCode: ""
inputCode: "",
touched: true
};
}
if (!state.inputCode || state.codes.includes(state.inputCode)) {
return state;
}

return {
...state,
codes: [...state.codes, state.inputCode],
inputCode: ""
inputCode: "",
touched: true
};
}
case REMOVE_CODE: {
Expand All @@ -53,7 +58,7 @@ const IdentificationNumber = ({

return {
...state,
codes
codes: [...codes]
};
}
}
Expand Down Expand Up @@ -81,7 +86,8 @@ const IdentificationNumber = ({

const [state, dispatch] = useReducer(identificationNumberReducer, {
codes: getValues(name),
inputCode: ""
inputCode: "",
touched: false
});

useEffect(() => {
Expand Down Expand Up @@ -116,8 +122,11 @@ const IdentificationNumber = ({
className="fr-mr-2v"
nativeButtonProps={{
type: "button",
onClick: () =>
!disabled && dispatch({ type: REMOVE_CODE, payload: idx }),
onClick: () => {
return (
!disabled && dispatch({ type: REMOVE_CODE, payload: idx })
);
},
...{ "data-testid": "tagInputIdentificationNumber" }
}}
>
Expand Down

0 comments on commit 8949788

Please sign in to comment.