umami/components/pages/settings/users/UserDeleteForm.js

42 lines
1.2 KiB
JavaScript
Raw Normal View History

import { useMutation } from '@tanstack/react-query';
2022-12-28 05:20:44 +01:00
import useApi from 'hooks/useApi';
2023-01-24 00:32:35 +01:00
import { Button, Form, FormButtons, SubmitButton } from 'react-basics';
import { defineMessages, useIntl } from 'react-intl';
import { labels } from 'components/messages';
2023-01-24 00:32:35 +01:00
const messages = defineMessages({
confirm: { id: 'label.confirm', defaultMessage: 'Confirm' },
warning: {
id: 'message.confirm-delete-user',
defaultMessage: 'Are you sure you want to delete this user?',
},
});
export default function UserDeleteForm({ userId, onSave, onClose }) {
2023-01-24 00:32:35 +01:00
const { formatMessage } = useIntl();
const { del } = useApi();
const { mutate, error, isLoading } = useMutation(data => del(`/users/${userId}`, data));
const handleSubmit = async data => {
mutate(data, {
onSuccess: async () => {
onSave();
},
});
};
return (
2023-01-10 08:59:26 +01:00
<Form onSubmit={handleSubmit} error={error}>
2023-01-24 00:32:35 +01:00
<p>{formatMessage(messages.warning)}</p>
<FormButtons flex>
2023-01-10 08:59:26 +01:00
<SubmitButton variant="primary" disabled={isLoading}>
2023-01-24 00:32:35 +01:00
{formatMessage(labels.save)}
</SubmitButton>
2023-01-10 08:59:26 +01:00
<Button disabled={isLoading} onClick={onClose}>
2023-01-24 00:32:35 +01:00
{formatMessage(labels.cancel)}
</Button>
</FormButtons>
</Form>
);
}