umami/src/app/(main)/settings/users/UserDeleteForm.tsx

37 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-01-24 00:32:35 +01:00
import { Button, Form, FormButtons, SubmitButton } from 'react-basics';
import useApi from 'components/hooks/useApi';
import useMessages from 'components/hooks/useMessages';
2023-04-21 17:00:42 +02:00
export function UserDeleteForm({ userId, username, onSave, onClose }) {
2023-03-22 22:05:55 +01:00
const { formatMessage, FormattedMessage, labels, messages } = useMessages();
2023-12-03 12:07:03 +01:00
const { del, useMutation } = useApi();
const { mutate, error, isPending } = useMutation({ mutationFn: () => del(`/users/${userId}`) });
2023-12-03 12:07:03 +01:00
const handleSubmit = async (data: any) => {
mutate(data, {
onSuccess: async () => {
onSave();
2023-01-25 16:42:46 +01:00
onClose();
},
});
};
return (
2023-01-10 08:59:26 +01:00
<Form onSubmit={handleSubmit} error={error}>
<p>
<FormattedMessage {...messages.confirmDelete} values={{ target: <b>{username}</b> }} />
</p>
<FormButtons flex>
2023-12-03 12:07:03 +01:00
<SubmitButton variant="danger" disabled={isPending}>
2023-01-25 16:42:46 +01:00
{formatMessage(labels.delete)}
</SubmitButton>
2023-12-03 12:07:03 +01:00
<Button disabled={isPending} onClick={onClose}>
2023-01-24 00:32:35 +01:00
{formatMessage(labels.cancel)}
</Button>
</FormButtons>
</Form>
);
}
2023-04-21 17:00:42 +02:00
export default UserDeleteForm;