Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: clear alert on action #1491

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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