2021-09-11 17:02:34 +02:00
|
|
|
// @flow
|
|
|
|
import React from 'react';
|
|
|
|
import type { Node } from 'react';
|
|
|
|
import Button from 'component/button';
|
|
|
|
import Card from 'component/common/card';
|
|
|
|
import Spinner from 'component/spinner';
|
|
|
|
import { Modal } from 'modal/modal';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
title: string,
|
|
|
|
subtitle?: string | Node,
|
|
|
|
body?: string | Node,
|
|
|
|
labelOk?: string,
|
|
|
|
labelCancel?: string,
|
|
|
|
hideCancel?: boolean,
|
2022-03-02 15:44:01 +01:00
|
|
|
onConfirm: (closeModal: () => void, setIsBusy: (boolean) => void) => void,
|
2021-09-11 17:02:34 +02:00
|
|
|
// --- perform ---
|
|
|
|
doHideModal: () => void,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function ModalConfirm(props: Props) {
|
2022-03-02 15:44:01 +01:00
|
|
|
const { title, subtitle, body, labelOk, labelCancel, hideCancel, onConfirm, doHideModal } = props;
|
|
|
|
|
2021-09-11 17:02:34 +02:00
|
|
|
const [isBusy, setIsBusy] = React.useState(false);
|
|
|
|
|
|
|
|
function handleOnClick() {
|
|
|
|
if (onConfirm) {
|
|
|
|
onConfirm(doHideModal, setIsBusy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2022-06-02 16:34:02 +02:00
|
|
|
<Modal isOpen type="custom">
|
2021-09-11 17:02:34 +02:00
|
|
|
<Card
|
|
|
|
title={title}
|
|
|
|
subtitle={subtitle}
|
|
|
|
body={body}
|
|
|
|
actions={
|
2022-03-02 15:44:01 +01:00
|
|
|
<div className="section__actions">
|
|
|
|
<Button
|
|
|
|
button="primary"
|
|
|
|
label={isBusy ? <Spinner type="small" /> : labelOk || __('OK')}
|
|
|
|
disabled={isBusy}
|
|
|
|
onClick={handleOnClick}
|
|
|
|
/>
|
|
|
|
|
|
|
|
{!hideCancel && (
|
|
|
|
<Button button="link" label={labelCancel || __('Cancel')} disabled={isBusy} onClick={doHideModal} />
|
|
|
|
)}
|
|
|
|
</div>
|
2021-09-11 17:02:34 +02:00
|
|
|
}
|
|
|
|
/>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|