From 7afc480199721d1fe3f2959c6b9d4cd77312b162 Mon Sep 17 00:00:00 2001 From: "K. Allagbe" Date: Tue, 3 Dec 2024 15:20:07 -0500 Subject: [PATCH] issue #362: improve validation & error handling --- src/components/VerifiedFieldComponents.tsx | 82 ++-- src/components/VerifiedQuantityMultiInput.tsx | 402 +++++++++--------- 2 files changed, 240 insertions(+), 244 deletions(-) diff --git a/src/components/VerifiedFieldComponents.tsx b/src/components/VerifiedFieldComponents.tsx index 1395e578..c13d6c6f 100644 --- a/src/components/VerifiedFieldComponents.tsx +++ b/src/components/VerifiedFieldComponents.tsx @@ -42,55 +42,58 @@ const VerifiedFieldWrapper: React.FC = ({ }); return ( - + {label} - {renderField({ setIsFocused, control, valuePath, verified })} - - ( - - onChange(!value)} - data-testid={`toggle-verified-btn-${verifiedPath}`} - aria-label={ + + + {renderField({ setIsFocused, control, valuePath, verified })} + + ( + - - - - )} - /> + onChange(!value)} + data-testid={`toggle-verified-btn-${verifiedPath}`} + aria-label={ + verified + ? t("verifiedField.unverify", { label }) + : t("verifiedField.verify", { label }) + } + > + + + + )} + /> + ); }; @@ -119,6 +122,7 @@ const VerifiedCheckbox: React.FC = ({ render={({ field }) => ( setIsFocused(true)} diff --git a/src/components/VerifiedQuantityMultiInput.tsx b/src/components/VerifiedQuantityMultiInput.tsx index 6621d05f..76b02546 100644 --- a/src/components/VerifiedQuantityMultiInput.tsx +++ b/src/components/VerifiedQuantityMultiInput.tsx @@ -2,14 +2,12 @@ import { DEFAULT_QUANTITY } from "@/types/types"; import AddIcon from "@mui/icons-material/Add"; import CheckIcon from "@mui/icons-material/Check"; import DeleteIcon from "@mui/icons-material/Delete"; -import ErrorOutlineIcon from "@mui/icons-material/ErrorOutline"; import { Autocomplete, Box, Button, Divider, IconButton, - InputBase, TextField, Tooltip, Typography, @@ -90,227 +88,221 @@ const VerifiedQuantityMultiInput: React.FC = ({ }; return ( - + {/* Label Section */} {label} - {/* Fields */} - {fields.map((fieldItem, index) => ( - - - {/* Value Input Field */} - ( - <> - setIsFocused(true)} - onBlur={(e) => { - setIsFocused(false); - field.onChange(e.target.value.trim()); - }} - aria-label={t( - "verifiedQuantityMultiInput.accessibility.valueInput", - )} - data-testid={`${quantitiesPath}.${index}.value`} - error={!!error} - /> - {error && ( - - - - )} - - )} - /> + {/* Fields */} + + {fields.map((fieldItem, index) => ( + + + {/* Value Input Field */} + ( + <> + setIsFocused(true)} + onBlur={(e) => { + setIsFocused(false); + field.onChange(e.target.value.trim()); + }} + aria-label={t( + "verifiedQuantityMultiInput.accessibility.valueInput", + )} + data-testid={`${quantitiesPath}.${index}.value`} + error={!!error} + helperText={error?.message ? t(error.message) : ""} + /> + + )} + /> + + {/* Unit Selection Field */} + ( + <> + { + field.onChange(newValue); + }} + onInputChange={(event, newInputValue) => { + field.onChange(newInputValue); + }} + value={field.value || ""} + disableClearable + slotProps={{ + popper: { + className: "!w-fit", + }, + }} + disabled={verified} + renderInput={(params) => ( + setIsFocused(true)} + onBlur={(e) => { + setIsFocused(false); + field.onChange(e.target.value.trim()); + }} + error={!!error} + helperText={error?.message ? t(error.message) : ""} + /> + )} + /> + + )} + /> - {/* Unit Selection Field */} - ( - <> - { - field.onChange(newValue); - }} - onInputChange={(event, newInputValue) => { - field.onChange(newInputValue); - }} - value={field.value || ""} - disableClearable - slotProps={{ - popper: { - className: "!w-fit", - }, - }} + {/* Delete Row Button */} + + + remove(index)} disabled={verified} - renderInput={(params) => ( - + aria-label={t( + "verifiedQuantityMultiInput.accessibility.deleteRowButton", )} - /> - {error && ( - - - - )} - - )} + data-testid={`delete-button-${quantitiesPath}-${index}`} + > + + + + + + - - {/* Delete Row Button */} - - - remove(index)} - disabled={verified} - aria-label={t( - "verifiedQuantityMultiInput.accessibility.deleteRowButton", - )} - data-testid={`delete-button-${quantitiesPath}-${index}`} - > - - - - - - - ))} + ))} - {/* Add Row Button */} - - + {/* Add Row Button */} + + - {/* Vertical Divider */} - + {/* Vertical Divider */} + - {/* Verified Toggle Button */} - ( - - toggleVerified(value, onChange)} - aria-label={t( - "verifiedQuantityMultiInput.accessibility.verifyToggleButton", - )} - data-testid={`toggle-verified-btn-${path}`} + {/* Verified Toggle Button */} + ( + - - - - )} - /> + toggleVerified(value, onChange)} + aria-label={t( + "verifiedQuantityMultiInput.accessibility.verifyToggleButton", + )} + data-testid={`toggle-verified-btn-${path}`} + > + + + + )} + /> + ); };