2022-12-28 05:20:44 +01:00
|
|
|
import useApi from 'hooks/useApi';
|
2023-01-06 07:56:36 +01:00
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
Form,
|
|
|
|
FormRow,
|
|
|
|
FormButtons,
|
|
|
|
FormInput,
|
|
|
|
SubmitButton,
|
|
|
|
TextField,
|
|
|
|
} from 'react-basics';
|
2022-12-27 01:57:59 +01:00
|
|
|
|
|
|
|
const CONFIRM_VALUE = 'DELETE';
|
|
|
|
|
|
|
|
export default function WebsiteDeleteForm({ websiteId, onSave, onClose }) {
|
2023-01-10 08:59:26 +01:00
|
|
|
const { del, useMutation } = 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 (
|
2023-01-10 08:59:26 +01:00
|
|
|
<Form onSubmit={handleSubmit} error={error}>
|
2022-12-27 01:57:59 +01:00
|
|
|
<div>
|
|
|
|
To delete this website, type <b>{CONFIRM_VALUE}</b> in the box below to confirm.
|
|
|
|
</div>
|
2023-01-06 07:56:36 +01:00
|
|
|
<FormRow label="Confirm">
|
|
|
|
<FormInput name="confirmation" rules={{ validate: value => value === CONFIRM_VALUE }}>
|
|
|
|
<TextField autoComplete="off" />
|
|
|
|
</FormInput>
|
|
|
|
</FormRow>
|
2022-12-27 01:57:59 +01:00
|
|
|
<FormButtons flex>
|
2023-01-10 08:59:26 +01:00
|
|
|
<SubmitButton variant="primary" disabled={isLoading}>
|
2022-12-27 01:57:59 +01:00
|
|
|
Save
|
|
|
|
</SubmitButton>
|
2023-01-10 08:59:26 +01:00
|
|
|
<Button disabled={isLoading} onClick={onClose}>
|
2022-12-27 01:57:59 +01:00
|
|
|
Cancel
|
|
|
|
</Button>
|
|
|
|
</FormButtons>
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
}
|