2022-12-27 01:57:59 +01:00
|
|
|
import { useMutation } from '@tanstack/react-query';
|
2023-01-24 00:32:35 +01:00
|
|
|
import { Button, Form, FormButtons, SubmitButton } from 'react-basics';
|
2023-03-22 22:05:55 +01:00
|
|
|
import useApi from 'hooks/useApi';
|
|
|
|
import useMessages from 'hooks/useMessages';
|
2022-12-27 01:57:59 +01:00
|
|
|
|
2023-01-25 16:42:46 +01:00
|
|
|
export default function UserDeleteForm({ userId, username, onSave, onClose }) {
|
2023-03-22 22:05:55 +01:00
|
|
|
const { formatMessage, FormattedMessage, labels, messages } = useMessages();
|
2022-12-29 00:43:22 +01:00
|
|
|
const { del } = useApi();
|
2023-01-25 16:42:46 +01:00
|
|
|
const { mutate, error, isLoading } = useMutation(() => del(`/users/${userId}`));
|
2022-12-27 01:57:59 +01:00
|
|
|
|
|
|
|
const handleSubmit = async data => {
|
|
|
|
mutate(data, {
|
|
|
|
onSuccess: async () => {
|
|
|
|
onSave();
|
2023-01-25 16:42:46 +01:00
|
|
|
onClose();
|
2022-12-27 01:57:59 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2023-01-10 08:59:26 +01:00
|
|
|
<Form onSubmit={handleSubmit} error={error}>
|
2023-01-28 06:53:13 +01:00
|
|
|
<p>
|
2023-04-08 22:14:22 +02:00
|
|
|
<FormattedMessage {...messages.confirmDelete} values={{ target: <b>{username}</b> }} />
|
2023-01-28 06:53:13 +01:00
|
|
|
</p>
|
2022-12-27 01:57:59 +01:00
|
|
|
<FormButtons flex>
|
2023-01-28 06:53:13 +01:00
|
|
|
<SubmitButton variant="danger" disabled={isLoading}>
|
2023-01-25 16:42:46 +01:00
|
|
|
{formatMessage(labels.delete)}
|
2022-12-27 01:57:59 +01:00
|
|
|
</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)}
|
2022-12-27 01:57:59 +01:00
|
|
|
</Button>
|
|
|
|
</FormButtons>
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
}
|