strapi-plugin-config-sync/admin/src/components/ConfirmModal/index.jsx

84 lines
2.3 KiB
React
Raw Normal View History

2022-11-28 17:00:35 +01:00
import React, { useState } from 'react';
import { useIntl } from 'react-intl';
2022-11-28 17:00:35 +01:00
import { useSelector } from 'react-redux';
2021-10-14 17:13:12 +02:00
import {
Dialog,
DialogBody,
DialogFooter,
Flex,
Typography,
Stack,
Button,
2022-11-28 17:00:35 +01:00
Checkbox,
Divider,
Box,
} from '@strapi/design-system';
import { ExclamationMarkCircle } from '@strapi/icons';
2021-03-20 16:51:34 +01:00
const ConfirmModal = ({ isOpen, onClose, onSubmit, type }) => {
2022-11-28 17:00:35 +01:00
const soft = useSelector((state) => state.getIn(['config', 'appEnv', 'config', 'soft'], false));
const [force, setForce] = useState(false);
const { formatMessage } = useIntl();
2021-03-21 17:55:14 +01:00
if (!isOpen) return null;
2021-03-20 16:51:34 +01:00
return (
2021-10-14 17:13:12 +02:00
<Dialog
onClose={onClose}
2023-10-11 20:46:51 +02:00
title={formatMessage({ id: "config-sync.popUpWarning.Confirmation" })}
2021-03-20 16:51:34 +01:00
isOpen={isOpen}
2021-10-14 17:13:12 +02:00
>
<DialogBody icon={<ExclamationMarkCircle />}>
2021-10-14 17:13:12 +02:00
<Stack size={2}>
<Flex justifyContent="center">
2022-03-16 21:29:54 +01:00
<Typography variant="omega" id="confirm-description" style={{ textAlign: 'center' }}>
{formatMessage({ id: `config-sync.popUpWarning.warning.${type}_1` })}<br />
{formatMessage({ id: `config-sync.popUpWarning.warning.${type}_2` })}
2022-03-16 21:29:54 +01:00
</Typography>
</Flex>
2021-10-14 17:13:12 +02:00
</Stack>
</DialogBody>
2022-11-28 17:00:35 +01:00
{(soft && type === 'import') && (
<React.Fragment>
<Divider />
<Box padding={4}>
<Checkbox
onValueChange={(value) => setForce(value)}
value={force}
name="force"
hint="Check this to ignore the soft setting."
>
{formatMessage({ id: 'config-sync.popUpWarning.force' })}
</Checkbox>
</Box>
</React.Fragment>
)}
2021-10-14 17:13:12 +02:00
<DialogFooter
startAction={(
<Button
onClick={() => {
onClose();
}}
variant="tertiary"
>
{formatMessage({ id: 'config-sync.popUpWarning.button.cancel' })}
2021-10-14 17:13:12 +02:00
</Button>
)}
endAction={(
<Button
variant="secondary"
onClick={() => {
onClose();
2022-11-28 17:00:35 +01:00
onSubmit(force);
}}
>
{formatMessage({ id: `config-sync.popUpWarning.button.${type}` })}
2021-10-14 17:13:12 +02:00
</Button>
)} />
</Dialog>
2021-03-20 16:51:34 +01:00
);
2021-10-14 17:13:12 +02:00
};
export default ConfirmModal;