umami/components/pages/settings/websites/WebsiteDeleteForm.js

51 lines
1.3 KiB
JavaScript
Raw Normal View History

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';
const CONFIRM_VALUE = 'DELETE';
2023-04-21 17:00:42 +02:00
export function WebsiteDeleteForm({ websiteId, onSave, onClose }) {
2023-04-14 02:10:04 +02:00
const { formatMessage, labels, messages, FormattedMessage } = useMessages();
2023-01-10 08:59:26 +01:00
const { del, useMutation } = useApi();
2023-01-25 16:42:46 +01:00
const { mutate, error } = useMutation(data => del(`/websites/${websiteId}`, data));
const handleSubmit = async data => {
mutate(data, {
onSuccess: async () => {
onSave();
onClose();
},
});
};
return (
2023-01-10 08:59:26 +01:00
<Form onSubmit={handleSubmit} error={error}>
2023-04-14 02:10:04 +02:00
<p>
2023-04-14 02:20:42 +02:00
<FormattedMessage
{...messages.deleteWebsite}
values={{ confirmation: <b>{CONFIRM_VALUE}</b> }}
/>
2023-04-14 02:10:04 +02:00
</p>
2023-01-25 16:42:46 +01:00
<FormRow label={formatMessage(labels.confirm)}>
2023-01-06 07:56:36 +01:00
<FormInput name="confirmation" rules={{ validate: value => value === CONFIRM_VALUE }}>
<TextField autoComplete="off" />
</FormInput>
</FormRow>
<FormButtons flex>
2023-01-25 16:42:46 +01:00
<SubmitButton variant="danger">{formatMessage(labels.delete)}</SubmitButton>
<Button onClick={onClose}>{formatMessage(labels.cancel)}</Button>
</FormButtons>
</Form>
);
}
2023-04-21 17:00:42 +02:00
export default WebsiteDeleteForm;