2020-03-27 13:59:38 -07:00
|
|
|
import PropTypes from 'prop-types';
|
2022-01-10 14:17:52 -08:00
|
|
|
import React from 'react';
|
2020-03-27 13:59:38 -07:00
|
|
|
import { injectIntl, FormattedMessage } from 'react-intl';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2021-03-15 17:29:42 -07:00
|
|
|
import { SimpleForm, FieldsGroup, Checkbox } from 'soapbox/features/forms';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2022-03-21 11:09:01 -07:00
|
|
|
import { Modal } from '../../../components/ui';
|
2020-03-27 13:59:38 -07:00
|
|
|
|
|
|
|
export default @injectIntl
|
|
|
|
class ConfirmationModal extends React.PureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
2021-12-30 08:38:57 -08:00
|
|
|
heading: PropTypes.node,
|
|
|
|
icon: PropTypes.node,
|
2020-03-27 13:59:38 -07:00
|
|
|
message: PropTypes.node.isRequired,
|
2021-03-15 17:29:42 -07:00
|
|
|
confirm: PropTypes.node.isRequired,
|
2020-03-27 13:59:38 -07:00
|
|
|
onClose: PropTypes.func.isRequired,
|
|
|
|
onConfirm: PropTypes.func.isRequired,
|
|
|
|
secondary: PropTypes.string,
|
|
|
|
onSecondary: PropTypes.func,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
onCancel: PropTypes.func,
|
2021-03-15 17:29:42 -07:00
|
|
|
checkbox: PropTypes.node,
|
2020-03-27 13:59:38 -07:00
|
|
|
};
|
|
|
|
|
2021-03-15 17:29:42 -07:00
|
|
|
state = {
|
|
|
|
checked: false,
|
|
|
|
}
|
|
|
|
|
2020-03-27 13:59:38 -07:00
|
|
|
handleClick = () => {
|
2022-01-30 09:46:57 -08:00
|
|
|
this.props.onClose('CONFIRM');
|
2020-03-27 13:59:38 -07:00
|
|
|
this.props.onConfirm();
|
|
|
|
}
|
|
|
|
|
|
|
|
handleSecondary = () => {
|
2022-01-30 09:46:57 -08:00
|
|
|
this.props.onClose('CONFIRM');
|
2020-03-27 13:59:38 -07:00
|
|
|
this.props.onSecondary();
|
|
|
|
}
|
|
|
|
|
|
|
|
handleCancel = () => {
|
2020-04-14 11:44:40 -07:00
|
|
|
const { onClose, onCancel } = this.props;
|
2022-01-30 09:46:57 -08:00
|
|
|
onClose('CONFIRM');
|
2020-03-27 13:59:38 -07:00
|
|
|
if (onCancel) onCancel();
|
|
|
|
}
|
|
|
|
|
2021-03-15 17:29:42 -07:00
|
|
|
handleCheckboxChange = e => {
|
|
|
|
this.setState({ checked: e.target.checked });
|
|
|
|
}
|
|
|
|
|
2020-04-14 14:47:35 -07:00
|
|
|
render() {
|
2022-03-21 11:09:01 -07:00
|
|
|
const { heading, message, confirm, secondary, checkbox } = this.props;
|
2021-03-15 17:29:42 -07:00
|
|
|
const { checked } = this.state;
|
2020-03-27 13:59:38 -07:00
|
|
|
|
|
|
|
return (
|
2022-03-21 11:09:01 -07:00
|
|
|
<Modal
|
|
|
|
title={heading}
|
|
|
|
confirmationAction={this.handleClick}
|
|
|
|
confirmationText={confirm}
|
|
|
|
confirmationDisabled={checkbox && !checked}
|
|
|
|
confirmationTheme='danger'
|
|
|
|
cancelText={<FormattedMessage id='confirmation_modal.cancel' defaultMessage='Cancel' />}
|
|
|
|
cancelAction={this.handleCancel}
|
|
|
|
secondaryText={secondary}
|
2022-04-07 12:23:00 -07:00
|
|
|
secondaryAction={this.props.onSecondary && this.handleSecondary}
|
2022-03-21 11:09:01 -07:00
|
|
|
>
|
2022-03-29 06:40:02 -07:00
|
|
|
<p className='text-gray-600 dark:text-gray-300'>{message}</p>
|
2022-03-21 11:09:01 -07:00
|
|
|
|
|
|
|
<div className='mt-2'>
|
|
|
|
{checkbox && <div className='confirmation-modal__checkbox'>
|
|
|
|
<SimpleForm>
|
|
|
|
<FieldsGroup>
|
|
|
|
<Checkbox
|
|
|
|
onChange={this.handleCheckboxChange}
|
|
|
|
label={checkbox}
|
|
|
|
checked={checked}
|
|
|
|
/>
|
|
|
|
</FieldsGroup>
|
|
|
|
</SimpleForm>
|
|
|
|
</div>}
|
2020-03-27 13:59:38 -07:00
|
|
|
</div>
|
2022-03-21 11:09:01 -07:00
|
|
|
</Modal>
|
2020-03-27 13:59:38 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|