umami/src/app/(main)/settings/teams/[teamId]/team/TeamDeleteForm.tsx

46 lines
1 KiB
TypeScript
Raw Normal View History

import { useApi, useMessages } from 'components/hooks';
2024-02-05 03:53:06 +00:00
import { touch } from 'store/modified';
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: () => del(`/teams/${teamId}`),
2023-12-03 11:07:03 +00:00
});
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;