2023-02-04 17:59:52 +01:00
|
|
|
import { Button, Form, FormButtons, SubmitButton } from 'react-basics';
|
2023-02-02 20:59:38 +01:00
|
|
|
import useApi from 'hooks/useApi';
|
2023-03-22 22:05:55 +01:00
|
|
|
import useMessages from 'hooks/useMessages';
|
2023-02-02 20:59:38 +01:00
|
|
|
|
2023-02-04 17:59:52 +01:00
|
|
|
export default function TeamDeleteForm({ teamId, teamName, onSave, onClose }) {
|
2023-03-22 22:05:55 +01:00
|
|
|
const { formatMessage, labels, messages, FormattedMessage } = useMessages();
|
2023-02-02 20:59:38 +01:00
|
|
|
const { del, useMutation } = useApi();
|
2023-02-04 17:59:52 +01:00
|
|
|
const { mutate, error, isLoading } = useMutation(data => del(`/teams/${teamId}`, data));
|
2023-02-02 20:59:38 +01:00
|
|
|
|
|
|
|
const handleSubmit = async data => {
|
|
|
|
mutate(data, {
|
|
|
|
onSuccess: async () => {
|
|
|
|
onSave();
|
|
|
|
onClose();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Form onSubmit={handleSubmit} error={error}>
|
2023-02-04 17:59:52 +01:00
|
|
|
<p>
|
2023-04-14 07:28:29 +02:00
|
|
|
<FormattedMessage {...messages.confirmDelete} values={{ target: <b>{teamName}</b> }} />
|
2023-02-04 17:59:52 +01:00
|
|
|
</p>
|
2023-02-02 20:59:38 +01:00
|
|
|
<FormButtons flex>
|
2023-02-04 17:59:52 +01:00
|
|
|
<SubmitButton variant="danger" disabled={isLoading}>
|
|
|
|
{formatMessage(labels.delete)}
|
|
|
|
</SubmitButton>
|
2023-02-02 20:59:38 +01:00
|
|
|
<Button onClick={onClose}>{formatMessage(labels.cancel)}</Button>
|
|
|
|
</FormButtons>
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
}
|