2023-02-04 16:59:52 +00:00
|
|
|
import { Button, Form, FormButtons, SubmitButton } from 'react-basics';
|
2024-01-29 02:33:40 +00:00
|
|
|
import { useApi } from 'components/hooks';
|
|
|
|
|
import { useMessages } from 'components/hooks';
|
2023-10-08 01:55:14 +00:00
|
|
|
import { setValue } from 'store/cache';
|
2023-02-02 19:59:38 +00:00
|
|
|
|
2023-12-03 11:07:03 +00:00
|
|
|
export function TeamDeleteForm({
|
|
|
|
|
teamId,
|
|
|
|
|
teamName,
|
|
|
|
|
onSave,
|
|
|
|
|
onClose,
|
|
|
|
|
}: {
|
|
|
|
|
teamId: string;
|
|
|
|
|
teamName: string;
|
|
|
|
|
onSave: () => void;
|
|
|
|
|
onClose: () => void;
|
|
|
|
|
}) {
|
2023-03-22 21:05:55 +00:00
|
|
|
const { formatMessage, labels, messages, FormattedMessage } = 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 handleSubmit = async data => {
|
|
|
|
|
mutate(data, {
|
|
|
|
|
onSuccess: async () => {
|
2023-10-08 01:55:14 +00:00
|
|
|
setValue('teams', Date.now());
|
|
|
|
|
onSave?.();
|
|
|
|
|
onClose?.();
|
2023-02-02 19:59:38 +00:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Form onSubmit={handleSubmit} error={error}>
|
2023-02-04 16:59:52 +00:00
|
|
|
<p>
|
2023-04-14 05:28:29 +00:00
|
|
|
<FormattedMessage {...messages.confirmDelete} values={{ target: <b>{teamName}</b> }} />
|
2023-02-04 16:59:52 +00:00
|
|
|
</p>
|
2023-02-02 19:59:38 +00:00
|
|
|
<FormButtons flex>
|
2023-12-03 11:07:03 +00:00
|
|
|
<SubmitButton variant="danger" disabled={isPending}>
|
2023-02-04 16:59:52 +00:00
|
|
|
{formatMessage(labels.delete)}
|
|
|
|
|
</SubmitButton>
|
2023-02-02 19:59:38 +00:00
|
|
|
<Button onClick={onClose}>{formatMessage(labels.cancel)}</Button>
|
|
|
|
|
</FormButtons>
|
|
|
|
|
</Form>
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-04-21 15:00:42 +00:00
|
|
|
|
|
|
|
|
export default TeamDeleteForm;
|