Skip to content

Commit

Permalink
✨ [#4798] Added custom confirmation modal
Browse files Browse the repository at this point in the history
  • Loading branch information
robinmolen committed Nov 11, 2024
1 parent 4c53505 commit cd63a65
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/openforms/js/components/admin/form_design/useConfirm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {useState} from 'react';

import ActionButton from '../forms/ActionButton';
import {Modal} from '../modals';

const useConfirm = (title, message) => {
const [promise, setPromise] = useState(null);

const confirm = () =>
new Promise((resolve, reject) => {
setPromise({resolve});
});

const handleClose = () => {
setPromise(null);
};

const handleConfirm = () => {
promise?.resolve(true);
handleClose();
};

const handleCancel = () => {
promise?.resolve(false);
handleClose();
};

const ConfirmationModal = () => (
<Modal
title={title}
isOpen={promise !== null}
contentModifiers={['with-form']}
closeModal={handleCancel}
>
<div style={{flexGrow: 1}}>{message}</div>
<div className="button-group">
<ActionButton text="confirm" className="default" onClick={handleConfirm} />
<ActionButton text="cancel" onClick={handleCancel} />
</div>
</Modal>
);
return [ConfirmationModal, confirm];
};

export default useConfirm;
5 changes: 5 additions & 0 deletions src/openforms/scss/components/admin/_button-group.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.button-group {
display: flex;
flex-wrap: wrap;
gap: 10px;
}
1 change: 1 addition & 0 deletions src/openforms/scss/components/admin/_index.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import './button';
@import './button-group';
@import './edit-panel';
@import './datetime';
@import './list';
Expand Down

0 comments on commit cd63a65

Please sign in to comment.