import { useState } from "react"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "../ui/dialog"; import { t } from "@/utils"; import { settingsData } from "@/redux/reducer/settingSlice"; import { useSelector } from "react-redux"; import TermsAndPrivacyLinks from "./TermsAndPrivacyLinks"; import { setIsLoginOpen } from "@/redux/reducer/globalStateSlice"; import { MdOutlineEmail, MdOutlineLocalPhone } from "react-icons/md"; import RegisterWithEmailForm from "./RegisterWithEmailForm"; import RegisterWithMobileForm from "./RegisterWithMobileForm"; import { Button } from "../ui/button"; const RegisterModal = ({ setIsMailSentSuccess, IsRegisterModalOpen, setIsRegisterModalOpen, }) => { // Get Global data const settings = useSelector(settingsData); const [descriptionState, setDescriptionState] = useState({ type: "register", // "register" | "otp" phoneNumber: "", }); const [isOTPScreen, setIsOTPScreen] = useState(false); // Active authentication methods const mobile_authentication = Number(settings?.mobile_authentication); const email_authentication = Number(settings?.email_authentication); // Toggle between email and mobile registration const [IsRegisterWithEmail, setIsRegisterWithEmail] = useState( !mobile_authentication == 1 ); const OnHide = () => { setIsRegisterModalOpen(false); }; const handleLoginClick = () => { OnHide(); setIsLoginOpen(true); }; const handleChangeClick = () => { setIsOTPScreen(false); setDescriptionState({ type: "register", phoneNumber: "" }); }; // Show divider when alternative auth methods (email/mobile toggle) are available const showOrSignInWith = !isOTPScreen && ((IsRegisterWithEmail && mobile_authentication == 1) || (!IsRegisterWithEmail && email_authentication == 1)); return ( <> e.preventDefault()} className="px-[40px] sm:py-[50px] sm:px-[90px]" > {descriptionState.type === "otp" ? ( t("verifyOtp") ) : ( <> {t("welcomeTo")}{" "} {settings?.company_name} )} {descriptionState.type === "otp" ? ( <> {t("sentTo")} {descriptionState.phoneNumber}{" "} {t("change")} ) : ( <> {t("haveAccount")}{" "} {t("logIn")} )}
{/* Show RegisterWithEmailForm when email auth is enabled */} {email_authentication === 1 && (mobile_authentication == 0 || IsRegisterWithEmail) && ( )} {/* Show RegisterWithMobileForm when mobile auth is enabled */} {mobile_authentication == 1 && (email_authentication == 0 || !IsRegisterWithEmail) && ( )} {/* Show divider when alternative auth methods are available */} {showOrSignInWith && (

{t("orSignUpWith")}


)} {/* Toggle buttons for switching between email and mobile */} {showOrSignInWith && (
{/* Show "Continue with Mobile" button when email is selected and mobile is enabled */} {IsRegisterWithEmail && mobile_authentication == 1 && ( )} {/* Show "Continue with Email" button when mobile is selected and email is enabled */} {!IsRegisterWithEmail && email_authentication === 1 && ( )}
)} {/* Terms and Privacy Links */} {!isOTPScreen && ( )}
); }; export default RegisterModal;