umami/src/app/(main)/settings/websites/[id]/WebsiteDeleteForm.tsx

64 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-01-06 06:56:36 +00:00
import {
Button,
Form,
FormRow,
FormButtons,
FormInput,
SubmitButton,
TextField,
} from 'react-basics';
import useApi from 'components/hooks/useApi';
import useMessages from 'components/hooks/useMessages';
2023-12-06 03:22:14 +00:00
import { useContext } from 'react';
import SettingsContext from '../../SettingsContext';
const CONFIRM_VALUE = 'DELETE';
2023-12-03 11:07:03 +00:00
export function WebsiteDeleteForm({
websiteId,
onSave,
onClose,
}: {
websiteId: string;
onSave?: () => void;
onClose?: () => void;
}) {
2023-04-14 00:10:04 +00:00
const { formatMessage, labels, messages, FormattedMessage } = useMessages();
2023-12-06 03:22:14 +00:00
const { websitesUrl } = useContext(SettingsContext);
2023-01-10 07:59:26 +00:00
const { del, useMutation } = useApi();
2023-12-03 11:07:03 +00:00
const { mutate, error } = useMutation({
2023-12-06 03:22:14 +00:00
mutationFn: (data: any) => del(`${websitesUrl}/${websiteId}`, data),
2023-12-03 11:07:03 +00:00
});
2023-12-06 03:22:14 +00:00
const handleSubmit = async (data: any) => {
mutate(data, {
onSuccess: async () => {
onSave();
onClose();
},
});
};
return (
2023-01-10 07:59:26 +00:00
<Form onSubmit={handleSubmit} error={error}>
2023-04-14 00:10:04 +00:00
<p>
2023-04-14 00:20:42 +00:00
<FormattedMessage
2024-01-19 00:46:40 +00:00
{...messages.actionConfirmation}
2023-04-14 00:20:42 +00:00
values={{ confirmation: <b>{CONFIRM_VALUE}</b> }}
/>
2023-04-14 00:10:04 +00:00
</p>
2023-01-25 15:42:46 +00:00
<FormRow label={formatMessage(labels.confirm)}>
2023-01-06 06:56:36 +00:00
<FormInput name="confirmation" rules={{ validate: value => value === CONFIRM_VALUE }}>
<TextField autoComplete="off" />
</FormInput>
</FormRow>
<FormButtons flex>
2023-01-25 15:42:46 +00:00
<SubmitButton variant="danger">{formatMessage(labels.delete)}</SubmitButton>
<Button onClick={onClose}>{formatMessage(labels.cancel)}</Button>
</FormButtons>
</Form>
);
}
2023-04-21 15:00:42 +00:00
export default WebsiteDeleteForm;