2024-05-02 08:17:56 -05:00
|
|
|
import Modal from "../Modal";
|
2024-05-24 16:12:47 -05:00
|
|
|
import Button from "../ui/Button";
|
2024-06-09 08:27:16 -05:00
|
|
|
import { useTranslation } from "next-i18next";
|
2024-08-01 15:54:19 -05:00
|
|
|
import { useDeleteUser } from "@/hooks/store/admin/users";
|
|
|
|
import { useState } from "react";
|
2024-05-02 08:17:56 -05:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
onClose: Function;
|
|
|
|
userId: number;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function DeleteUserModal({ onClose, userId }: Props) {
|
2024-06-09 08:27:16 -05:00
|
|
|
const { t } = useTranslation();
|
2024-05-02 08:17:56 -05:00
|
|
|
|
2024-08-01 15:54:19 -05:00
|
|
|
const [submitLoader, setSubmitLoader] = useState(false);
|
|
|
|
const deleteUser = useDeleteUser();
|
2024-05-02 08:17:56 -05:00
|
|
|
|
2024-08-01 15:54:19 -05:00
|
|
|
const submit = async () => {
|
|
|
|
if (!submitLoader) {
|
|
|
|
setSubmitLoader(true);
|
2024-05-02 08:17:56 -05:00
|
|
|
|
2024-08-01 15:54:19 -05:00
|
|
|
await deleteUser.mutateAsync(userId, {
|
|
|
|
onSuccess: () => {
|
|
|
|
onClose();
|
|
|
|
},
|
|
|
|
});
|
2024-05-02 08:17:56 -05:00
|
|
|
|
2024-08-01 15:54:19 -05:00
|
|
|
setSubmitLoader(false);
|
2024-07-16 19:33:33 -05:00
|
|
|
}
|
2024-05-02 08:17:56 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal toggleModal={onClose}>
|
2024-06-09 08:27:16 -05:00
|
|
|
<p className="text-xl font-thin text-red-500">{t("delete_user")}</p>
|
2024-05-02 08:17:56 -05:00
|
|
|
|
|
|
|
<div className="divider mb-3 mt-1"></div>
|
|
|
|
|
|
|
|
<div className="flex flex-col gap-3">
|
2024-06-09 08:27:16 -05:00
|
|
|
<p>{t("confirm_user_deletion")}</p>
|
2024-05-02 08:17:56 -05:00
|
|
|
|
|
|
|
<div role="alert" className="alert alert-warning">
|
|
|
|
<i className="bi-exclamation-triangle text-xl" />
|
|
|
|
<span>
|
2024-06-09 08:27:16 -05:00
|
|
|
<b>{t("warning")}:</b> {t("irreversible_action_warning")}
|
2024-05-02 08:17:56 -05:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
|
2024-08-01 15:54:19 -05:00
|
|
|
<Button className="ml-auto" intent="destructive" onClick={submit}>
|
2024-05-02 08:17:56 -05:00
|
|
|
<i className="bi-trash text-xl" />
|
2024-06-09 08:27:16 -05:00
|
|
|
{t("delete_confirmation")}
|
2024-05-24 16:12:47 -05:00
|
|
|
</Button>
|
2024-05-02 08:17:56 -05:00
|
|
|
</div>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|