mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
fix(component): useConfirmModal can't be closed automatically when 'onConfirm' is non-async (#6439)
This commit is contained in:
@@ -36,3 +36,24 @@ export const UsingHook = () => {
|
||||
|
||||
return <Button onClick={showConfirm}>Show confirm</Button>;
|
||||
};
|
||||
|
||||
export const AutoClose = () => {
|
||||
const { openConfirmModal } = useConfirmModal();
|
||||
|
||||
const onConfirm = () => {
|
||||
openConfirmModal({
|
||||
cancelText: 'Cancel',
|
||||
confirmButtonOptions: {
|
||||
children: 'Confirm',
|
||||
},
|
||||
title: 'Confirm Modal',
|
||||
children: 'Are you sure you want to confirm?',
|
||||
onConfirm: () => console.log('Confirmed'),
|
||||
onCancel: () => {
|
||||
console.log('Cancelled');
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return <Button onClick={onConfirm}>Show confirm</Button>;
|
||||
};
|
||||
|
||||
@@ -104,8 +104,8 @@ export const ConfirmModalProvider = ({ children }: PropsWithChildren) => {
|
||||
|
||||
const onConfirm = () => {
|
||||
setLoading(true);
|
||||
_onConfirm?.()
|
||||
?.then(() => onSuccess?.())
|
||||
return Promise.resolve(_onConfirm?.())
|
||||
.then(() => onSuccess?.())
|
||||
.catch(console.error)
|
||||
.finally(() => autoClose && closeConfirmModal());
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user