2024-02-08 07:48:51 +00:00
|
|
|
import { useApi, useMessages, useModified } from 'components/hooks';
|
2024-01-29 09:32:05 +00:00
|
|
|
import ConfirmationForm from 'components/common/ConfirmationForm';
|
2023-03-29 23:02:14 +00:00
|
|
|
|
2023-12-03 11:07:03 +00:00
|
|
|
export function TeamLeaveForm({
|
|
|
|
|
teamId,
|
|
|
|
|
userId,
|
|
|
|
|
teamName,
|
|
|
|
|
onSave,
|
|
|
|
|
onClose,
|
|
|
|
|
}: {
|
|
|
|
|
teamId: string;
|
|
|
|
|
userId: string;
|
|
|
|
|
teamName: string;
|
|
|
|
|
onSave: () => void;
|
|
|
|
|
onClose: () => void;
|
|
|
|
|
}) {
|
2023-03-29 23:02:14 +00:00
|
|
|
const { formatMessage, labels, messages, FormattedMessage } = useMessages();
|
|
|
|
|
const { del, useMutation } = useApi();
|
2023-12-03 11:07:03 +00:00
|
|
|
const { mutate, error, isPending } = useMutation({
|
|
|
|
|
mutationFn: () => del(`/teams/${teamId}/users/${userId}`),
|
|
|
|
|
});
|
2024-02-08 07:48:51 +00:00
|
|
|
const { touch } = useModified();
|
2023-03-29 23:02:14 +00:00
|
|
|
|
2024-01-29 09:32:05 +00:00
|
|
|
const handleConfirm = async () => {
|
2023-12-03 11:07:03 +00:00
|
|
|
mutate(null, {
|
|
|
|
|
onSuccess: async () => {
|
2024-02-07 07:42:37 +00:00
|
|
|
touch('teams:members');
|
2023-12-03 11:07:03 +00:00
|
|
|
onSave();
|
|
|
|
|
onClose();
|
2023-03-29 23:02:14 +00:00
|
|
|
},
|
2023-12-03 11:07:03 +00:00
|
|
|
});
|
2023-03-29 23:02:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2024-01-29 09:32:05 +00:00
|
|
|
<ConfirmationForm
|
|
|
|
|
buttonLabel={formatMessage(labels.leave)}
|
|
|
|
|
message={
|
2024-02-07 19:33:35 +00:00
|
|
|
<FormattedMessage {...messages.confirmLeave} values={{ target: <b>{teamName}</b> }} />
|
2024-01-29 09:32:05 +00:00
|
|
|
}
|
|
|
|
|
onConfirm={handleConfirm}
|
|
|
|
|
onClose={onClose}
|
|
|
|
|
isLoading={isPending}
|
|
|
|
|
error={error}
|
|
|
|
|
/>
|
2023-03-29 23:02:14 +00:00
|
|
|
);
|
|
|
|
|
}
|
2023-04-21 15:00:42 +00:00
|
|
|
|
|
|
|
|
export default TeamLeaveForm;
|