umami/src/app/(main)/settings/teams/TeamDeleteForm.tsx

47 lines
1 KiB
TypeScript
Raw Normal View History

2024-02-04 08:44:20 +00:00
'use client';
import { useApi, useMessages } from 'components/hooks';
import { touch } from 'store/cache';
import TypeConfirmationForm from 'components/common/TypeConfirmationForm';
const CONFIRM_VALUE = 'DELETE';
2023-02-02 19:59:38 +00:00
2023-12-03 11:07:03 +00:00
export function TeamDeleteForm({
teamId,
onSave,
onClose,
}: {
teamId: string;
onSave?: () => void;
onClose?: () => void;
2023-12-03 11:07:03 +00:00
}) {
const { labels, formatMessage } = useMessages();
2023-02-02 19:59:38 +00:00
const { del, useMutation } = useApi();
2023-12-03 11:07:03 +00:00
const { mutate, error, isPending } = useMutation({
mutationFn: (data: any) => del(`/teams/${teamId}`, data),
});
2023-02-02 19:59:38 +00:00
const handleConfirm = async () => {
mutate(null, {
2023-02-02 19:59:38 +00:00
onSuccess: async () => {
touch('teams');
2023-10-08 01:55:14 +00:00
onSave?.();
onClose?.();
2023-02-02 19:59:38 +00:00
},
});
};
return (
<TypeConfirmationForm
confirmationValue={CONFIRM_VALUE}
onConfirm={handleConfirm}
onClose={onClose}
isLoading={isPending}
error={error}
buttonLabel={formatMessage(labels.delete)}
buttonVariant="danger"
/>
2023-02-02 19:59:38 +00:00
);
}
2023-04-21 15:00:42 +00:00
export default TeamDeleteForm;