2023-02-04 17:59:52 +01:00
|
|
|
import { Button, Form, FormButtons, SubmitButton } from 'react-basics';
|
|
|
|
import { useIntl, FormattedMessage } from 'react-intl';
|
2023-02-02 20:59:38 +01:00
|
|
|
import { labels, messages } from 'components/messages';
|
|
|
|
import useApi from 'hooks/useApi';
|
|
|
|
|
2023-02-04 17:59:52 +01:00
|
|
|
export default function TeamDeleteForm({ teamId, teamName, onSave, onClose }) {
|
2023-02-02 20:59:38 +01:00
|
|
|
const { formatMessage } = useIntl();
|
|
|
|
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>
|
|
|
|
<FormattedMessage {...messages.deleteTeamWarning} values={{ name: <b>{teamName}</b> }} />
|
|
|
|
</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>
|
|
|
|
);
|
|
|
|
}
|