2022-06-12 07:14:46 -07:00
|
|
|
import React, { useState } from 'react';
|
|
|
|
import { FormattedMessage } from 'react-intl';
|
|
|
|
|
2022-09-16 10:37:28 -07:00
|
|
|
import List, { ListItem } from 'soapbox/components/list';
|
|
|
|
import { Modal, Stack, Text, Toggle } from 'soapbox/components/ui';
|
2022-06-12 07:14:46 -07:00
|
|
|
|
|
|
|
interface IConfirmationModal {
|
|
|
|
heading: React.ReactNode,
|
|
|
|
message: React.ReactNode,
|
|
|
|
confirm: React.ReactNode,
|
|
|
|
onClose: (type: string) => void,
|
|
|
|
onConfirm: () => void,
|
|
|
|
secondary: React.ReactNode,
|
|
|
|
onSecondary?: () => void,
|
|
|
|
onCancel: () => void,
|
|
|
|
checkbox?: JSX.Element,
|
|
|
|
}
|
|
|
|
|
|
|
|
const ConfirmationModal: React.FC<IConfirmationModal> = ({
|
|
|
|
heading,
|
|
|
|
message,
|
|
|
|
confirm,
|
|
|
|
onClose,
|
|
|
|
onConfirm,
|
|
|
|
secondary,
|
|
|
|
onSecondary,
|
|
|
|
onCancel,
|
|
|
|
checkbox,
|
|
|
|
}) => {
|
|
|
|
const [checked, setChecked] = useState(false);
|
|
|
|
|
|
|
|
const handleClick = () => {
|
|
|
|
onClose('CONFIRM');
|
|
|
|
onConfirm();
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleSecondary = () => {
|
|
|
|
onClose('CONFIRM');
|
|
|
|
onSecondary!();
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleCancel = () => {
|
|
|
|
onClose('CONFIRM');
|
|
|
|
if (onCancel) onCancel();
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleCheckboxChange: React.ChangeEventHandler<HTMLInputElement> = e => {
|
|
|
|
setChecked(e.target.checked);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
title={heading}
|
|
|
|
confirmationAction={handleClick}
|
|
|
|
confirmationText={confirm}
|
|
|
|
confirmationDisabled={checkbox && !checked}
|
|
|
|
confirmationTheme='danger'
|
|
|
|
cancelText={<FormattedMessage id='confirmation_modal.cancel' defaultMessage='Cancel' />}
|
|
|
|
cancelAction={handleCancel}
|
|
|
|
secondaryText={secondary}
|
|
|
|
secondaryAction={onSecondary && handleSecondary}
|
|
|
|
>
|
2022-09-16 10:37:28 -07:00
|
|
|
<Stack space={4}>
|
|
|
|
<Text>
|
|
|
|
{message}
|
|
|
|
</Text>
|
2022-06-12 07:14:46 -07:00
|
|
|
|
2022-09-16 10:37:28 -07:00
|
|
|
{checkbox && (
|
|
|
|
<List>
|
|
|
|
<ListItem label={checkbox}>
|
|
|
|
<Toggle
|
2022-06-12 07:14:46 -07:00
|
|
|
checked={checked}
|
2022-09-16 10:37:28 -07:00
|
|
|
onChange={handleCheckboxChange}
|
|
|
|
required
|
2022-06-12 07:14:46 -07:00
|
|
|
/>
|
2022-09-16 10:37:28 -07:00
|
|
|
</ListItem>
|
|
|
|
</List>
|
|
|
|
)}
|
|
|
|
</Stack>
|
2022-06-12 07:14:46 -07:00
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ConfirmationModal;
|