diff --git a/frontend/src/components/BCAlert/BCAlert2.jsx b/frontend/src/components/BCAlert/BCAlert2.jsx index e7b1d684d..fd92913ab 100644 --- a/frontend/src/components/BCAlert/BCAlert2.jsx +++ b/frontend/src/components/BCAlert/BCAlert2.jsx @@ -70,6 +70,9 @@ export const BCAlert2 = forwardRef( setSeverity(severity) setMessage(message) setTriggerCount((prevCount) => prevCount + 1) + }, + clearAlert: () => { + setAlertStatus('fadeOut') } })) diff --git a/frontend/src/components/BCDataGrid/BCGridEditor.jsx b/frontend/src/components/BCDataGrid/BCGridEditor.jsx index 03c9b4649..7482add28 100644 --- a/frontend/src/components/BCDataGrid/BCGridEditor.jsx +++ b/frontend/src/components/BCDataGrid/BCGridEditor.jsx @@ -181,6 +181,7 @@ export const BCGridEditor = ({ params.event.target.dataset.action && onAction ) { + alertRef.current.clearAlert() const action = params.event.target.dataset.action const transaction = await onAction(action, params) @@ -207,6 +208,7 @@ export const BCGridEditor = ({ const handleAddRowsInternal = useCallback( async (numRows) => { + alertRef.current.clearAlert() let newRows = [] if (onAction) { diff --git a/frontend/src/views/FuelSupplies/AddEditFuelSupplies.jsx b/frontend/src/views/FuelSupplies/AddEditFuelSupplies.jsx index 4badf3167..9d3ae3134 100644 --- a/frontend/src/views/FuelSupplies/AddEditFuelSupplies.jsx +++ b/frontend/src/views/FuelSupplies/AddEditFuelSupplies.jsx @@ -64,24 +64,30 @@ export const AddEditFuelSupplies = () => { severity: location.state.severity || 'info' }) } - }, [location?.state?.message, location?.state?.severity]); + }, [location?.state?.message, location?.state?.severity]) - const validate = (params, validationFn, errorMessage, alertRef, field = null) => { - const value = field ? params.node?.data[field] : params; + const validate = ( + params, + validationFn, + errorMessage, + alertRef, + field = null + ) => { + const value = field ? params.node?.data[field] : params if (field && params.colDef.field !== field) { - return true; + return true } if (!validationFn(value)) { alertRef.current?.triggerAlert({ message: errorMessage, - severity: 'error', - }); - return false; + severity: 'error' + }) + return false } - return true; // Proceed with the update - }; + return true // Proceed with the update + } const onGridReady = useCallback( async (params) => { @@ -172,12 +178,12 @@ export const AddEditFuelSupplies = () => { const isValid = validate( params, (value) => { - return value !== null && !isNaN(value) && value > 0; + return value !== null && !isNaN(value) && value > 0 }, 'Quantity supplied must be greater than 0.', alertRef, - 'quantity', - ); + 'quantity' + ) if (!isValid) { return