Files
formbricks/apps/web/modules/auth/verification-requested/components/request-verification-email.tsx
T
Dhruwang Jariwala f80d1b32b7 chore: Auth module revamp (#4335)
Co-authored-by: pandeymangg <anshuman.pandey9999@gmail.com>
Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
2024-11-26 08:28:13 +00:00

49 lines
1.5 KiB
TypeScript

"use client";
import { getFormattedErrorMessage } from "@/lib/utils/helper";
import { Button } from "@/modules/ui/components/button";
import { useTranslations } from "next-intl";
import { useEffect } from "react";
import toast from "react-hot-toast";
import { resendVerificationEmailAction } from "../actions";
interface RequestVerificationEmailProps {
email: string | null;
}
export const RequestVerificationEmail = ({ email }: RequestVerificationEmailProps) => {
const t = useTranslations();
useEffect(() => {
const handleVisibilityChange = () => {
if (document.visibilityState === "visible") {
location.reload();
}
};
document.addEventListener("visibilitychange", handleVisibilityChange);
return () => {
document.removeEventListener("visibilitychange", handleVisibilityChange);
};
}, []);
const requestVerificationEmail = async () => {
if (!email) return toast.error(t("auth.verification-requested.no_email_provided"));
const response = await resendVerificationEmailAction({ email });
if (response?.data) {
toast.success(t("auth.verification-requested.verification_email_successfully_sent"));
} else {
const errorMessage = getFormattedErrorMessage(response);
toast.error(errorMessage);
}
};
return (
<>
<Button variant="secondary" onClick={requestVerificationEmail} className="w-full justify-center">
{t("auth.verification-requested.resend_verification_email")}
</Button>
</>
);
};