import React from "react"; import { useTranslations } from "@/hooks/translations"; import { useDispatch, useSelector } from "react-redux"; import useSteps from "@/hooks/palmistry/use-steps"; import Button from "@/components/palmistry/button/button"; import Input from "@/components/palmistry/input/input"; import { actions, selectors } from "@/store"; import Title from "@/components/Title"; import Loader, { LoaderColor } from "@/components/Loader"; import { useAuthentication } from "@/hooks/authentication/use-authentication"; import { ESourceAuthorization } from "@/api/resources/User"; import metricService, { EGoals, EMetrics, } from "@/services/metric/metricService"; import { useSession } from "@/hooks/session/useSession"; const emailRegex = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/; export default function StepEmail() { const { translate } = useTranslations(); const dispatch = useDispatch(); const { updateSession } = useSession(); const steps = useSteps(); const [email, setEmail] = React.useState(steps.storedValue); const storedName = useSelector(selectors.selectUser)?.profile?.full_name || ""; const [name, setName] = React.useState(storedName); const [emailIsValid, setEmailIsValid] = React.useState(false); const [nameIsValid, setNameIsValid] = React.useState(true); const [isAuth, setIsAuth] = React.useState(false); const { error, isLoading, authorization } = useAuthentication(); const onChangeEmail = (value: string) => { setEmail(value); }; const onChangeName = (value: string) => { setName(value); }; React.useEffect(() => { if (steps.storedValue) setEmail(steps.storedValue); }, [steps.storedValue]); React.useEffect(() => { const emailIsValid = email.match(emailRegex) !== null; setEmailIsValid(emailIsValid); if (emailIsValid) { dispatch(actions.form.addEmail(email)); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [email]); React.useEffect(() => { setNameIsValid(true); dispatch( actions.user.update({ username: name, }) ); // eslint-disable-next-line react-hooks/exhaustive-deps }, [name]); const authorize = async () => { await updateSession( { profile: { name, }, }, ESourceAuthorization["aura.palmistry"] ); await authorization(email, ESourceAuthorization["aura.palmistry"]); metricService.reachGoal(EGoals.ENTERED_EMAIL_PALMISTRY, [EMetrics.YANDEX]); metricService.reachGoal(EGoals.ENTERED_EMAIL, [ EMetrics.KLAVIYO, EMetrics.YANDEX, EMetrics.FACEBOOK, ]); metricService.reachGoal(EGoals.LEAD, [EMetrics.FACEBOOK]); setIsAuth(true); }; const onNext = async () => { await authorize(); steps.saveCurrent(email); steps.goNext(); }; return ( <>

Enter your email to get your advanced Palmistry reading with AURA

We don’t share any personal information.

By clicking "Continue" below you agree to AURA{" "} EULA {" "} and{" "} Privacy Policy .

{isLoading && } {error?.length && ( Something went wrong )} ); }