2023-01-06 07:56:36 +01:00
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
Form,
|
|
|
|
FormRow,
|
|
|
|
FormButtons,
|
|
|
|
FormInput,
|
|
|
|
SubmitButton,
|
|
|
|
TextField,
|
|
|
|
} from 'react-basics';
|
2023-01-25 16:42:46 +01:00
|
|
|
import useApi from 'hooks/useApi';
|
2023-03-22 22:05:55 +01:00
|
|
|
import useMessages from 'hooks/useMessages';
|
2022-12-27 01:57:59 +01:00
|
|
|
|
|
|
|
const CONFIRM_VALUE = 'RESET';
|
|
|
|
|
|
|
|
export default function WebsiteResetForm({ websiteId, onSave, onClose }) {
|
2023-03-22 22:05:55 +01:00
|
|
|
const { formatMessage, labels, messages } = useMessages();
|
2023-01-10 08:59:26 +01:00
|
|
|
const { post, useMutation } = useApi();
|
2023-01-25 16:42:46 +01:00
|
|
|
const { mutate, error } = useMutation(data => post(`/websites/${websiteId}/reset`, data));
|
2022-12-27 01:57:59 +01:00
|
|
|
|
|
|
|
const handleSubmit = async data => {
|
|
|
|
mutate(data, {
|
|
|
|
onSuccess: async () => {
|
|
|
|
onSave();
|
2023-01-28 06:53:13 +01:00
|
|
|
onClose();
|
2022-12-27 01:57:59 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2023-01-10 08:59:26 +01:00
|
|
|
<Form onSubmit={handleSubmit} error={error}>
|
2023-01-25 16:42:46 +01:00
|
|
|
<p>{formatMessage(messages.resetWebsite, { confirmation: CONFIRM_VALUE })}</p>
|
|
|
|
<FormRow label={formatMessage(labels.confirm)}>
|
2023-01-06 07:56:36 +01:00
|
|
|
<FormInput name="confirm" rules={{ validate: value => value === CONFIRM_VALUE }}>
|
|
|
|
<TextField autoComplete="off" />
|
|
|
|
</FormInput>
|
|
|
|
</FormRow>
|
2022-12-27 01:57:59 +01:00
|
|
|
<FormButtons flex>
|
2023-01-25 16:42:46 +01:00
|
|
|
<SubmitButton variant="danger">{formatMessage(labels.reset)}</SubmitButton>
|
|
|
|
<Button onClick={onClose}>{formatMessage(labels.cancel)}</Button>
|
2022-12-27 01:57:59 +01:00
|
|
|
</FormButtons>
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
}
|