2022-12-27 01:57:59 +01:00
|
|
|
import { useMutation } from '@tanstack/react-query';
|
2022-12-28 05:20:44 +01:00
|
|
|
import useApi from 'hooks/useApi';
|
2022-12-27 01:57:59 +01:00
|
|
|
import { Button, Form, FormButtons, FormInput, SubmitButton, TextField } from 'react-basics';
|
|
|
|
import styles from './Form.module.css';
|
|
|
|
|
|
|
|
const CONFIRM_VALUE = 'DELETE';
|
|
|
|
|
|
|
|
export default function WebsiteDeleteForm({ websiteId, onSave, onClose }) {
|
2022-12-29 00:43:22 +01:00
|
|
|
const { del } = useApi();
|
2022-12-27 01:57:59 +01:00
|
|
|
const { mutate, error, isLoading } = useMutation(data => del(`/websites/${websiteId}`, data));
|
|
|
|
|
|
|
|
const handleSubmit = async data => {
|
|
|
|
mutate(data, {
|
|
|
|
onSuccess: async () => {
|
|
|
|
onSave();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Form className={styles.form} onSubmit={handleSubmit} error={error}>
|
|
|
|
<div>
|
|
|
|
To delete this website, type <b>{CONFIRM_VALUE}</b> in the box below to confirm.
|
|
|
|
</div>
|
|
|
|
<FormInput
|
|
|
|
name="confirmation"
|
|
|
|
label="Confirm"
|
|
|
|
rules={{ validate: value => value === CONFIRM_VALUE }}
|
|
|
|
>
|
|
|
|
<TextField autoComplete="off" />
|
|
|
|
</FormInput>
|
|
|
|
<FormButtons flex>
|
|
|
|
<SubmitButton variant="primary" className={styles.button} disabled={isLoading}>
|
|
|
|
Save
|
|
|
|
</SubmitButton>
|
|
|
|
<Button className={styles.button} disabled={isLoading} onClick={onClose}>
|
|
|
|
Cancel
|
|
|
|
</Button>
|
|
|
|
</FormButtons>
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
}
|