mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-23 04:51:49 +08: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>;
|
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 = () => {
|
const onConfirm = () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
_onConfirm?.()
|
return Promise.resolve(_onConfirm?.())
|
||||||
?.then(() => onSuccess?.())
|
.then(() => onSuccess?.())
|
||||||
.catch(console.error)
|
.catch(console.error)
|
||||||
.finally(() => autoClose && closeConfirmModal());
|
.finally(() => autoClose && closeConfirmModal());
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user