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

33 lines
1.0 KiB
JavaScript
Raw Normal View History

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>
<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>
);
}