2023-03-30 01:02:14 +02:00
|
|
|
import { Button, Form, FormButtons, SubmitButton } from 'react-basics';
|
|
|
|
import useApi from 'hooks/useApi';
|
|
|
|
import useMessages from 'hooks/useMessages';
|
|
|
|
|
2023-04-10 01:04:28 +02:00
|
|
|
export default function TeamLeaveForm({ teamId, userId, teamName, onSave, onClose }) {
|
2023-03-30 01:02:14 +02:00
|
|
|
const { formatMessage, labels, messages, FormattedMessage } = useMessages();
|
|
|
|
const { del, useMutation } = useApi();
|
2023-04-10 01:04:28 +02:00
|
|
|
const { mutate, error, isLoading } = useMutation(() => del(`/team/${teamId}/users/${userId}`));
|
2023-03-30 01:02:14 +02:00
|
|
|
|
2023-04-10 01:04:28 +02:00
|
|
|
const handleSubmit = async () => {
|
|
|
|
mutate(
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
onSuccess: async () => {
|
|
|
|
onSave();
|
|
|
|
onClose();
|
|
|
|
},
|
2023-03-30 01:02:14 +02:00
|
|
|
},
|
2023-04-10 01:04:28 +02:00
|
|
|
);
|
2023-03-30 01:02:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Form onSubmit={handleSubmit} error={error}>
|
|
|
|
<p>
|
2023-04-08 22:14:22 +02:00
|
|
|
<FormattedMessage {...messages.confirmLeave} values={{ name: <b>{teamName}</b> }} />
|
2023-03-30 01:02:14 +02:00
|
|
|
</p>
|
|
|
|
<FormButtons flex>
|
|
|
|
<SubmitButton variant="danger" disabled={isLoading}>
|
|
|
|
{formatMessage(labels.leave)}
|
|
|
|
</SubmitButton>
|
|
|
|
<Button onClick={onClose}>{formatMessage(labels.cancel)}</Button>
|
|
|
|
</FormButtons>
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
}
|