ldc-supportweb/resources/ts/back/Components/BtnResetPassword.tsx
2026-05-21 13:27:47 +02:00

75 lines
1.9 KiB
TypeScript

// * Packages
import { router } from "@inertiajs/react";
import { route } from "ziggy-js";
import { LoaderCircleIcon, SendIcon } from "lucide-react";
import { useState } from "react";
// * Other
import BtnOptionnalLinkWithTooltip from "@/back/Components/BtnOptionnalLinkWithTooltip";
import useTrans from "@/hooks/use-translations";
import { useToast } from "@/hooks/use-toast";
import { UserModel } from "@/back/types/global";
export default function BtnResetPassword({ model }: { model: UserModel }) {
const { toast } = useToast();
const [isSending, setIsSending] = useState(false);
// Translations.
const transResetPassword = useTrans("auth.reset_password");
const transMailSent = useTrans("auth.mail_sent");
const transMailSentDesc = useTrans("auth.mail_sent_user_desc", {
params: { email: model.email },
});
const handleSendResetLink = () => {
setIsSending(true);
router.post(
route("back.users.send-reset-password-link", model),
{},
{
onSuccess: () => {
toast({
title: transMailSent,
description: transMailSentDesc,
});
},
onError: () => {
toast({
title: "nope",
description: "nope",
variant: "destructive",
});
},
onFinish: () => {
setIsSending(false);
},
},
);
};
return (
<form
onSubmit={(e) => {
e.preventDefault();
handleSendResetLink();
}}
>
<BtnOptionnalLinkWithTooltip
content={
<>
{transResetPassword}
{isSending ? (
<LoaderCircleIcon className="animate-spin" />
) : (
<SendIcon />
)}
</>
}
tooltipContent={useTrans("auth.send_link")}
disabled={isSending}
variant="secondary"
size="default"
type="submit"
/>
</form>
);
}