Skip to content

Commit

Permalink
Merge pull request #1491 from bcgov/feat/kevin-1456
Browse files Browse the repository at this point in the history
feat: clear alert on action
  • Loading branch information
kevin-hashimoto authored Dec 18, 2024
2 parents 38c46c1 + 01026ee commit 3c9e779
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
3 changes: 3 additions & 0 deletions frontend/src/components/BCAlert/BCAlert2.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ export const BCAlert2 = forwardRef(
setSeverity(severity)
setMessage(message)
setTriggerCount((prevCount) => prevCount + 1)
},
clearAlert: () => {
setAlertStatus('fadeOut')
}
}))

Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/BCDataGrid/BCGridEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -207,6 +208,7 @@ export const BCGridEditor = ({

const handleAddRowsInternal = useCallback(
async (numRows) => {
alertRef.current.clearAlert()
let newRows = []

if (onAction) {
Expand Down
30 changes: 18 additions & 12 deletions frontend/src/views/FuelSupplies/AddEditFuelSupplies.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3c9e779

Please sign in to comment.