You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
in my mantine project we have made the following helper:
import { openConfirmModal } from "@mantine/modals";
import { OpenConfirmModal } from "@mantine/modals/lib/context";
export type OpenAsyncConfirmModalParams = OpenConfirmModal;
/*
* Helper that allows using async/await with mantine's confirm modals
*/
export function openAsyncConfirmModal({
onClose,
onConfirm,
onCancel,
...modalParamsRest
}: OpenAsyncConfirmModalParams) {
return new Promise<boolean>((resolve) => {
openConfirmModal({
onConfirm: () => {
onConfirm?.();
resolve(true);
},
onCancel: () => {
onCancel?.();
resolve(false);
},
onClose: () => {
onClose?.();
resolve(false);
},
...modalParamsRest,
});
});
}
the idea being that we could use it like so:
<Button onClick={() => {
const confirmed = await openAsyncConfirmModal({
title: "Destructive action",
children: (
<Text>
The action you wish to perform cannot be reversed. Do you wish to proceed?
</Text>
),
labels: {
confirm: "Delete",
cancel: "Cancel",
},
});
if (!confirmed) return;
// Perform destructive action
}}>Perform Destructive Action</Button>
what do you think of incorporating this as a first class feature? I looked into the code and saw openConfirmModal uses a reducer under the hood, so its not immediately obvious to me how it'd be implemented, but if given some pointers I'd be happy to take on the feature work
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
in my mantine project we have made the following helper:
the idea being that we could use it like so:
what do you think of incorporating this as a first class feature? I looked into the code and saw
openConfirmModal
uses a reducer under the hood, so its not immediately obvious to me how it'd be implemented, but if given some pointers I'd be happy to take on the feature workBeta Was this translation helpful? Give feedback.
All reactions