2024-02-04 08:44:20 +00:00
|
|
|
'use client';
|
2024-01-29 09:32:05 +00:00
|
|
|
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;
|
2024-01-29 09:32:05 +00:00
|
|
|
onSave?: () => void;
|
|
|
|
|
onClose?: () => void;
|
2023-12-03 11:07:03 +00:00
|
|
|
}) {
|
2024-01-29 09:32:05 +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
|
|
|
|
2024-01-29 09:32:05 +00:00
|
|
|
const handleConfirm = async () => {
|
|
|
|
|
mutate(null, {
|
2023-02-02 19:59:38 +00:00
|
|
|
onSuccess: async () => {
|
2024-01-29 09:32:05 +00:00
|
|
|
touch('teams');
|
2023-10-08 01:55:14 +00:00
|
|
|
onSave?.();
|
|
|
|
|
onClose?.();
|
2023-02-02 19:59:38 +00:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2024-01-29 09:32:05 +00:00
|
|
|
<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;
|