mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-24 18:26:20 +01:00
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
import { useMutation } from '@tanstack/react-query';
|
|
import useApi from 'hooks/useApi';
|
|
import { Button, Form, FormButtons, SubmitButton } from 'react-basics';
|
|
import { useIntl, FormattedMessage } from 'react-intl';
|
|
import { labels, messages } from 'components/messages';
|
|
|
|
export default function UserDeleteForm({ userId, username, onSave, onClose }) {
|
|
const { formatMessage } = useIntl();
|
|
const { del } = useApi();
|
|
const { mutate, error, isLoading } = useMutation(() => del(`/users/${userId}`));
|
|
|
|
const handleSubmit = async data => {
|
|
mutate(data, {
|
|
onSuccess: async () => {
|
|
onSave();
|
|
onClose();
|
|
},
|
|
});
|
|
};
|
|
|
|
return (
|
|
<Form onSubmit={handleSubmit} error={error}>
|
|
<p>
|
|
<FormattedMessage
|
|
{...messages.deleteUserWarning}
|
|
values={{ username: <b>{username}</b> }}
|
|
/>
|
|
</p>
|
|
<FormButtons flex>
|
|
<SubmitButton variant="danger" disabled={isLoading}>
|
|
{formatMessage(labels.delete)}
|
|
</SubmitButton>
|
|
<Button disabled={isLoading} onClick={onClose}>
|
|
{formatMessage(labels.cancel)}
|
|
</Button>
|
|
</FormButtons>
|
|
</Form>
|
|
);
|
|
}
|