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

44 lines
993 B
TypeScript
Raw Normal View History

import { useApi, useMessages } from 'components/hooks';
import TypeConfirmationForm from 'components/common/TypeConfirmationForm';
const CONFIRM_VALUE = 'DELETE';
2023-12-03 11:07:03 +00:00
export function WebsiteDeleteForm({
websiteId,
onSave,
onClose,
}: {
websiteId: string;
onSave?: () => void;
onClose?: () => void;
}) {
const { formatMessage, labels } = useMessages();
2023-01-10 07:59:26 +00:00
const { del, useMutation } = useApi();
const { mutate, isPending, error } = useMutation({
2024-01-29 11:15:22 +00:00
mutationFn: (data: any) => del(`/websites/${websiteId}`, data),
2023-12-03 11:07:03 +00:00
});
const handleConfirm = async () => {
mutate(null, {
onSuccess: async () => {
onSave?.();
onClose?.();
},
});
};
return (
<TypeConfirmationForm
confirmationValue={CONFIRM_VALUE}
onConfirm={handleConfirm}
onClose={onClose}
isLoading={isPending}
error={error}
buttonLabel={formatMessage(labels.delete)}
buttonVariant="danger"
/>
);
}
2023-04-21 15:00:42 +00:00
export default WebsiteDeleteForm;