umami/components/pages/settings/teams/TeamLeaveForm.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

import { Button, Form, FormButtons, SubmitButton } from 'react-basics';
import useApi from 'hooks/useApi';
import useMessages from 'hooks/useMessages';
2023-04-21 17:00:42 +02:00
export function TeamLeaveForm({ teamId, userId, teamName, onSave, onClose }) {
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-04-10 01:04:28 +02:00
const handleSubmit = async () => {
mutate(
{},
{
onSuccess: async () => {
onSave();
onClose();
},
},
2023-04-10 01:04:28 +02:00
);
};
return (
<Form onSubmit={handleSubmit} error={error}>
<p>
<FormattedMessage {...messages.confirmLeave} values={{ name: <b>{teamName}</b> }} />
</p>
<FormButtons flex>
<SubmitButton variant="danger" disabled={isLoading}>
{formatMessage(labels.leave)}
</SubmitButton>
<Button onClick={onClose}>{formatMessage(labels.cancel)}</Button>
</FormButtons>
</Form>
);
}
2023-04-21 17:00:42 +02:00
export default TeamLeaveForm;