|
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
|
|
} from "./data";
|
|
|
|
|
import { useAuth, useAppShell } from "@abe-kap/appshell-sdk/react";
|
|
|
|
|
import { isShellConfigured } from "@/lib/appshell";
|
|
|
|
|
import { MOCK_OTP, DEMO_OTP } from "@/lib/otp";
|
|
|
|
|
|
|
|
|
|
type Addr = { line1?: string; line2?: string; city?: string; state?: string; postalCode?: string; country?: string; locality?: string };
|
|
|
|
|
|
|
|
|
@@ -25,10 +26,14 @@ export function RegisterFlow({ mode = "register" }: { mode?: "register" | "onboa
|
|
|
|
|
// we only SET a password + persist the profile, and the OTP-verify step is skipped.
|
|
|
|
|
const onboard = mode === "onboard";
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
const { register, setPassword, getUserEmail } = useAuth();
|
|
|
|
|
const { register, setPassword, getUserEmail, addPhone, verifyPhone } = useAuth();
|
|
|
|
|
const { sdk } = useAppShell();
|
|
|
|
|
const [step, setStep] = useState(0);
|
|
|
|
|
const [submitErr, setSubmitErr] = useState("");
|
|
|
|
|
// Verifying a phone via Supabase needs a live session. Onboarding already has one
|
|
|
|
|
// (Google OAuth); registration creates the account when leaving the Account step,
|
|
|
|
|
// then attaches + verifies the phone on it. `creating` guards the Account button.
|
|
|
|
|
const [creating, setCreating] = useState(false);
|
|
|
|
|
|
|
|
|
|
// address (lifted from StepAddress/AddressBlock so finish() can persist it)
|
|
|
|
|
const [regAddr, setRegAddr] = useState<Addr>({});
|
|
|
|
@@ -50,18 +55,19 @@ export function RegisterFlow({ mode = "register" }: { mode?: "register" | "onboa
|
|
|
|
|
const [termsOk, setTermsOk] = useState(false);
|
|
|
|
|
const [privacyOk, setPrivacyOk] = useState(false);
|
|
|
|
|
|
|
|
|
|
// verify step
|
|
|
|
|
const [emailVerified, setEmailVerified] = useState(false);
|
|
|
|
|
// verify step (email is trusted without an OTP — see verifyValid below)
|
|
|
|
|
const [phoneVerified, setPhoneVerified] = useState(false);
|
|
|
|
|
|
|
|
|
|
// Onboarding: prefill the verified email from the Google session (the ACE omits it).
|
|
|
|
|
// Onboarding: prefill the verified email — from the session-storage hint the login
|
|
|
|
|
// page stashed at OAuth time, then confirmed via the live Supabase session.
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!onboard) return;
|
|
|
|
|
try { const cached = sessionStorage.getItem("onboard_email"); if (cached) setEmail(cached); } catch { /* ignore */ }
|
|
|
|
|
getUserEmail().then((e) => { if (e) setEmail(e); }).catch(() => { /* ignore */ });
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
}, [onboard]);
|
|
|
|
|
|
|
|
|
|
const STEP_LABELS = onboard ? ["Profile", "Address"] : STEPS;
|
|
|
|
|
const STEP_LABELS = onboard ? ["Profile", "Verify", "Address"] : STEPS;
|
|
|
|
|
|
|
|
|
|
const isSelf = relationship === "Customer" || relationship === "Owner";
|
|
|
|
|
const isEmployee = relationship === "Employee";
|
|
|
|
@@ -74,7 +80,26 @@ export function RegisterFlow({ mode = "register" }: { mode?: "register" | "onboa
|
|
|
|
|
first.trim() && last.trim() && EMAIL_RE.test(sso?.email || email) && phoneOk && pwOk &&
|
|
|
|
|
termsOk && privacyOk && (isSelf || (alloeIdOk && (isEmployee || (alloeFirst.trim() && alloeLast.trim()))));
|
|
|
|
|
|
|
|
|
|
const step2Valid = emailVerified && phoneVerified;
|
|
|
|
|
// Email is already trusted in both flows (registration: Supabase auto-confirms on
|
|
|
|
|
// signup; onboarding: Google-verified), so the Verify step only gates on the phone.
|
|
|
|
|
const verifyValid = phoneVerified;
|
|
|
|
|
|
|
|
|
|
// Registration: create the auth account when leaving the Account step, so the phone
|
|
|
|
|
// can be attached + verified against a live session at the Verify step. Onboarding
|
|
|
|
|
// is already authenticated, so it just advances.
|
|
|
|
|
async function leaveAccountStep() {
|
|
|
|
|
if (onboard || !isShellConfigured() || sso) { setStep(1); return; }
|
|
|
|
|
setSubmitErr("");
|
|
|
|
|
setCreating(true);
|
|
|
|
|
try {
|
|
|
|
|
await register(email, pw);
|
|
|
|
|
setStep(1);
|
|
|
|
|
} catch {
|
|
|
|
|
setSubmitErr("We couldn't create that account. The email may already be registered.");
|
|
|
|
|
} finally {
|
|
|
|
|
setCreating(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function finish() {
|
|
|
|
|
const finalEmail = sso?.email || email;
|
|
|
|
@@ -89,13 +114,12 @@ export function RegisterFlow({ mode = "register" }: { mode?: "register" | "onboa
|
|
|
|
|
|
|
|
|
|
if (isShellConfigured()) {
|
|
|
|
|
setSubmitErr("");
|
|
|
|
|
// 1) Auth account. Onboarding users are already authenticated via Google — set
|
|
|
|
|
// a password so email+password login works too. Everyone else registers now.
|
|
|
|
|
if (onboard) {
|
|
|
|
|
try { if (pw) await setPassword(pw); } catch { /* non-fatal — the profile still saves */ }
|
|
|
|
|
} else if (!sso) {
|
|
|
|
|
try { await register(finalEmail, pw); }
|
|
|
|
|
catch { setSubmitErr("We couldn't create that account. The email may already be registered."); return; }
|
|
|
|
|
// 1) Auth account already exists at this point — registration created it when
|
|
|
|
|
// leaving the Account step; onboarding users signed in via Google. Onboarding
|
|
|
|
|
// additionally sets a password so email+password login works too (the phone was
|
|
|
|
|
// just verified against the same live session).
|
|
|
|
|
if (onboard && pw) {
|
|
|
|
|
try { await setPassword(pw); } catch { /* non-fatal — the profile still saves */ }
|
|
|
|
|
}
|
|
|
|
|
// 2) Persist the full CRM registration payload to be-crm (name, phone, persona,
|
|
|
|
|
// allottee, both addresses, consent). Non-fatal: the auth account exists either way.
|
|
|
|
@@ -118,6 +142,8 @@ export function RegisterFlow({ mode = "register" }: { mode?: "register" | "onboa
|
|
|
|
|
// register mode: non-fatal — the auth account exists; the profile can be filled in later.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Consume the OAuth→onboarding handoff so a stale hint can't re-open onboarding.
|
|
|
|
|
try { sessionStorage.removeItem("onboard_email"); } catch { /* ignore */ }
|
|
|
|
|
router.push("/dashboard");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -126,8 +152,10 @@ export function RegisterFlow({ mode = "register" }: { mode?: "register" | "onboa
|
|
|
|
|
<Stepper current={step} labels={STEP_LABELS} />
|
|
|
|
|
|
|
|
|
|
{step === 0 && (
|
|
|
|
|
<>
|
|
|
|
|
{submitErr && <div style={{ marginBottom: 14 }}><FlashNote tone="error">{submitErr}</FlashNote></div>}
|
|
|
|
|
<StepAccount
|
|
|
|
|
onboard={onboard}
|
|
|
|
|
onboard={onboard} creating={creating}
|
|
|
|
|
sso={sso} setSso={setSso} email={email} setEmail={setEmail}
|
|
|
|
|
first={first} setFirst={setFirst} last={last} setLast={setLast}
|
|
|
|
|
cc={cc} setCc={setCc} phone={phone} setPhone={setPhone} phoneOk={phoneOk} country={country}
|
|
|
|
@@ -137,23 +165,23 @@ export function RegisterFlow({ mode = "register" }: { mode?: "register" | "onboa
|
|
|
|
|
alloeFirst={alloeFirst} setAlloeFirst={setAlloeFirst} alloeLast={alloeLast} setAlloeLast={setAlloeLast}
|
|
|
|
|
termsOk={termsOk} setTermsOk={setTermsOk} privacyOk={privacyOk} setPrivacyOk={setPrivacyOk}
|
|
|
|
|
valid={!!step0Valid}
|
|
|
|
|
onContinue={() => setStep(1)} toLogin={() => router.push("/portal/login")}
|
|
|
|
|
onContinue={leaveAccountStep} toLogin={() => router.push("/portal/login")}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{step === 1 && !onboard && (
|
|
|
|
|
{step === 1 && (
|
|
|
|
|
<StepVerify
|
|
|
|
|
emailValue={sso?.email || email} cc={cc} phone={phone} country={country}
|
|
|
|
|
emailVerified={emailVerified} setEmailVerified={setEmailVerified}
|
|
|
|
|
cc={cc} phone={phone} country={country}
|
|
|
|
|
phoneVerified={phoneVerified} setPhoneVerified={setPhoneVerified}
|
|
|
|
|
valid={step2Valid} onBack={() => setStep(0)} onContinue={() => setStep(2)}
|
|
|
|
|
valid={verifyValid} onBack={() => setStep(0)} onContinue={() => setStep(2)}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{((onboard && step === 1) || (!onboard && step === 2)) && (
|
|
|
|
|
{step === 2 && (
|
|
|
|
|
<>
|
|
|
|
|
{submitErr && <div style={{ marginBottom: 14 }}><FlashNote tone="error">{submitErr}</FlashNote></div>}
|
|
|
|
|
<StepAddress sameAs={mailingSame} setSameAs={setMailingSame} onRegAddr={setRegAddr} onMailAddr={setMailAddr} onBack={() => setStep(onboard ? 0 : 1)} onFinish={finish} />
|
|
|
|
|
<StepAddress sameAs={mailingSame} setSameAs={setMailingSame} onRegAddr={setRegAddr} onMailAddr={setMailAddr} onBack={() => setStep(1)} onFinish={finish} />
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
@@ -171,7 +199,7 @@ function StepAccount(p: {
|
|
|
|
|
alloeNo: string; setAlloeNo: (v: string) => void; alloeIdOk: boolean;
|
|
|
|
|
alloeFirst: string; setAlloeFirst: (v: string) => void; alloeLast: string; setAlloeLast: (v: string) => void;
|
|
|
|
|
termsOk: boolean; setTermsOk: (v: boolean) => void; privacyOk: boolean; setPrivacyOk: (v: boolean) => void;
|
|
|
|
|
valid: boolean; onContinue: () => void; toLogin: () => void; onboard?: boolean;
|
|
|
|
|
valid: boolean; onContinue: () => void; toLogin: () => void; onboard?: boolean; creating?: boolean;
|
|
|
|
|
}) {
|
|
|
|
|
// Onboarding (OAuth) starts on the profile step — email is already known + verified.
|
|
|
|
|
const [phase, setPhase] = useState<"sso" | "profile">(p.onboard ? "profile" : "sso");
|
|
|
|
@@ -181,6 +209,7 @@ function StepAccount(p: {
|
|
|
|
|
const valid = EMAIL_RE.test(p.email);
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<StepBack onClick={p.toLogin} />
|
|
|
|
|
<h1>Create your account</h1>
|
|
|
|
|
<p className="sub">Enter your email to get started.</p>
|
|
|
|
|
<div style={{ marginTop: 20 }}>
|
|
|
|
@@ -202,15 +231,19 @@ function StepAccount(p: {
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
{/* Non-onboarding users can step back to the email screen; onboarding starts
|
|
|
|
|
here (email came from Google), so there's nothing to go back to. */}
|
|
|
|
|
{!p.onboard && <StepBack onClick={() => setPhase("sso")} />}
|
|
|
|
|
<h1>Complete your profile</h1>
|
|
|
|
|
<p className="sub">Tell us a bit about you to set up your account.</p>
|
|
|
|
|
|
|
|
|
|
<div style={{ marginTop: 16 }}>
|
|
|
|
|
{p.sso ? (
|
|
|
|
|
<div className="conn-banner conn-green"><Icon name="check" size={16} /> Connected with {cap(p.sso.provider)} · {p.sso.email}</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="conn-banner conn-blue"><Icon name="mail" size={16} /> {p.onboard ? "Signed in as" : "Creating account for"} {p.email}</div>
|
|
|
|
|
)}
|
|
|
|
|
<div className="field" style={{ marginTop: 16 }}>
|
|
|
|
|
<label className="label">Email address</label>
|
|
|
|
|
<div className="input-wrap">
|
|
|
|
|
<span className="input-ico"><Icon name="mail" size={17} /></span>
|
|
|
|
|
<input className="input" type="email" value={p.email} disabled readOnly aria-label="Email address" />
|
|
|
|
|
</div>
|
|
|
|
|
<span className="faint" style={{ fontSize: 12 }}>{p.onboard ? "Verified with Google — this can't be changed." : "The email you're registering with."}</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="row gap-3" style={{ marginTop: 18, alignItems: "center" }}>
|
|
|
|
@@ -308,7 +341,9 @@ function StepAccount(p: {
|
|
|
|
|
|
|
|
|
|
{!p.valid && <p className="hint-line">Fill all required fields and accept both documents to continue.</p>}
|
|
|
|
|
|
|
|
|
|
<button className="btn btn-primary" style={{ marginTop: 14 }} disabled={!p.valid} onClick={p.onContinue}>{p.onboard ? "Continue" : "Create Account & Verify"} <Icon name="arrowR" size={16} /></button>
|
|
|
|
|
<button className="btn btn-primary" style={{ marginTop: 14 }} disabled={!p.valid || p.creating} onClick={p.onContinue}>
|
|
|
|
|
{p.creating ? "Creating account…" : p.onboard ? "Continue" : "Create Account & Verify"} {!p.creating && <Icon name="arrowR" size={16} />}
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
{modal === "terms" && <LegalModal doc={TERMS} onClose={() => setModal(null)} onReviewed={() => { reviewed.terms = true; setModal(null); }} />}
|
|
|
|
|
{modal === "privacy" && <LegalModal doc={PRIVACY} onClose={() => setModal(null)} onReviewed={() => { reviewed.privacy = true; setModal(null); }} />}
|
|
|
|
@@ -318,10 +353,13 @@ function StepAccount(p: {
|
|
|
|
|
// module-level reviewed flags (per mount lifetime) — enables the checkboxes after a doc is read
|
|
|
|
|
const reviewed = { terms: false, privacy: false };
|
|
|
|
|
|
|
|
|
|
/* ====================== STEP 1 — VERIFY ====================== */
|
|
|
|
|
/* ====================== STEP 1 — VERIFY PHONE ======================
|
|
|
|
|
Email is already trusted (registration: Supabase auto-confirms on signup;
|
|
|
|
|
onboarding: Google-verified), so this step only verifies the phone via a real
|
|
|
|
|
SMS OTP: addPhone() → Twilio texts a code → verifyPhone() confirms it. Both
|
|
|
|
|
run against the live Supabase session established in the previous step. */
|
|
|
|
|
function StepVerify(p: {
|
|
|
|
|
emailValue: string; cc: string; phone: string; country: typeof countryCodes[number];
|
|
|
|
|
emailVerified: boolean; setEmailVerified: (v: boolean) => void;
|
|
|
|
|
cc: string; phone: string; country: typeof countryCodes[number];
|
|
|
|
|
phoneVerified: boolean; setPhoneVerified: (v: boolean) => void;
|
|
|
|
|
valid: boolean; onBack: () => void; onContinue: () => void;
|
|
|
|
|
}) {
|
|
|
|
@@ -329,12 +367,11 @@ function StepVerify(p: {
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<StepBack onClick={p.onBack} />
|
|
|
|
|
<h1>Verify email & phone</h1>
|
|
|
|
|
<p className="sub">Confirm both so we can secure your account.</p>
|
|
|
|
|
<h1>Verify your phone</h1>
|
|
|
|
|
<p className="sub">We'll text a one-time code to confirm your number. Your email is already verified.</p>
|
|
|
|
|
|
|
|
|
|
<div className="col gap-4" style={{ marginTop: 16 }}>
|
|
|
|
|
<VerifyChannel kind="email" initial={p.emailValue} country={p.country} cc={p.cc} initialPhone={p.phone} verified={p.emailVerified} onVerified={() => p.setEmailVerified(true)} />
|
|
|
|
|
<VerifyChannel kind="phone" initial={p.emailValue} country={p.country} cc={p.cc} initialPhone={p.phone} verified={p.phoneVerified} onVerified={() => p.setPhoneVerified(true)} />
|
|
|
|
|
<PhoneVerify cc={p.cc} country={p.country} initialPhone={p.phone} verified={p.phoneVerified} onVerified={() => p.setPhoneVerified(true)} />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div style={{ marginTop: 14 }}><RememberDevice checked={remember} onChange={setRemember} /></div>
|
|
|
|
@@ -343,40 +380,53 @@ function StepVerify(p: {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type SendState = "idle" | "sending" | "ok" | "invalid_email" | "mailbox_full" | "bounce_risk" | "invalid_mobile";
|
|
|
|
|
function VerifyChannel({ kind, initial, country, cc, initialPhone, verified, onVerified }: {
|
|
|
|
|
kind: "email" | "phone"; initial: string; country: typeof countryCodes[number]; cc: string; initialPhone: string;
|
|
|
|
|
type SendState = "idle" | "sending" | "sent" | "invalid_mobile" | "send_error";
|
|
|
|
|
function PhoneVerify({ cc, country, initialPhone, verified, onVerified }: {
|
|
|
|
|
cc: string; country: typeof countryCodes[number]; initialPhone: string;
|
|
|
|
|
verified: boolean; onVerified: () => void;
|
|
|
|
|
}) {
|
|
|
|
|
const [value, setValue] = useState(kind === "email" ? initial : initialPhone);
|
|
|
|
|
const [via, setVia] = useState<"primary" | "wa">("primary");
|
|
|
|
|
const { addPhone, verifyPhone } = useAuth();
|
|
|
|
|
const [value, setValue] = useState(initialPhone);
|
|
|
|
|
const [state, setState] = useState<SendState>("idle");
|
|
|
|
|
const [otpError, setOtpError] = useState(false);
|
|
|
|
|
const primaryLabel = kind === "email" ? "Email" : "SMS";
|
|
|
|
|
const [otpError, setOtpError] = useState("");
|
|
|
|
|
const e164 = `${cc}${value.replace(/\D/g, "")}`;
|
|
|
|
|
|
|
|
|
|
function send() {
|
|
|
|
|
async function send() {
|
|
|
|
|
if (value.replace(/\D/g, "").length !== country.digits) { setState("invalid_mobile"); return; }
|
|
|
|
|
setState("sending");
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
if (kind === "email") {
|
|
|
|
|
if (!EMAIL_RE.test(value)) return setState("invalid_email");
|
|
|
|
|
if (value.includes("full")) return setState("mailbox_full");
|
|
|
|
|
if (value.includes("bo")) return setState("bounce_risk");
|
|
|
|
|
return setState("ok");
|
|
|
|
|
} else {
|
|
|
|
|
if (value.replace(/\D/g, "").length !== country.digits) return setState("invalid_mobile");
|
|
|
|
|
return setState("ok");
|
|
|
|
|
setOtpError("");
|
|
|
|
|
if (MOCK_OTP) { setState("sent"); return; } // demo: skip Twilio entirely
|
|
|
|
|
try {
|
|
|
|
|
await addPhone(e164); // Supabase → Twilio sends the SMS OTP
|
|
|
|
|
setState("sent");
|
|
|
|
|
} catch {
|
|
|
|
|
setState("send_error");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function submit(code: string) {
|
|
|
|
|
setOtpError("");
|
|
|
|
|
if (MOCK_OTP) {
|
|
|
|
|
if (code === DEMO_OTP) onVerified();
|
|
|
|
|
else setOtpError(`Demo mode — enter ${DEMO_OTP} to verify.`);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
await verifyPhone(e164, code); // confirm the OTP (phone_change)
|
|
|
|
|
onVerified();
|
|
|
|
|
} catch {
|
|
|
|
|
setOtpError("That code didn't match. Check the SMS and try again.");
|
|
|
|
|
}
|
|
|
|
|
}, 700);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (verified) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="vchannel verified">
|
|
|
|
|
<div className="row between">
|
|
|
|
|
<span className="row gap-2" style={{ fontWeight: 600, fontSize: 14 }}><Icon name={kind === "email" ? "mail" : "phone"} size={16} /> {kind === "email" ? "Email" : "Mobile"}</span>
|
|
|
|
|
<span className="row gap-2" style={{ fontWeight: 600, fontSize: 14 }}><Icon name="phone" size={16} /> Mobile</span>
|
|
|
|
|
<Badge tone="green"><Icon name="check" size={12} /> Verified</Badge>
|
|
|
|
|
</div>
|
|
|
|
|
<p className="faint" style={{ fontSize: 12.5, marginTop: 8 }}>{kind === "email" ? value : `${cc} ${value}`}</p>
|
|
|
|
|
<p className="faint" style={{ fontSize: 12.5, marginTop: 8 }}>{cc} {value}</p>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
@@ -384,43 +434,34 @@ function VerifyChannel({ kind, initial, country, cc, initialPhone, verified, onV
|
|
|
|
|
return (
|
|
|
|
|
<div className="vchannel">
|
|
|
|
|
<div className="row between" style={{ marginBottom: 12 }}>
|
|
|
|
|
<span className="row gap-2" style={{ fontWeight: 600, fontSize: 14 }}><Icon name={kind === "email" ? "mail" : "phone"} size={16} /> {kind === "email" ? "Email address" : "Mobile number"}</span>
|
|
|
|
|
<span className="row gap-2" style={{ fontWeight: 600, fontSize: 14 }}><Icon name="phone" size={16} /> Mobile number</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{kind === "email" ? (
|
|
|
|
|
<input className="input" value={value} onChange={(e) => { setValue(e.target.value); setState("idle"); }} placeholder="you@example.com" />
|
|
|
|
|
) : (
|
|
|
|
|
<div className="phone-row">
|
|
|
|
|
<span className="input cc-select" style={{ display: "flex", alignItems: "center", justifyContent: "center", gap: 7 }}>
|
|
|
|
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
|
|
|
|
<img className="cc-flag-img static" src={flagUrl(country.flag)} alt={country.name} width={22} height={16} />
|
|
|
|
|
{cc}
|
|
|
|
|
</span>
|
|
|
|
|
<input className="input grow" inputMode="numeric" value={value} onChange={(e) => { setValue(e.target.value.replace(/\D/g, "")); setState("idle"); }} placeholder={country.example} />
|
|
|
|
|
<input className="input grow" inputMode="numeric" value={value} disabled={state === "sent"} onChange={(e) => { setValue(e.target.value.replace(/\D/g, "")); setState("idle"); }} placeholder={country.example} />
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<div className="row between" style={{ marginTop: 12 }}>
|
|
|
|
|
<div className="seg">
|
|
|
|
|
<button className={via === "primary" ? "on" : ""} onClick={() => setVia("primary")}>{primaryLabel}</button>
|
|
|
|
|
<button className={via === "wa" ? "on" : ""} onClick={() => setVia("wa")}><Icon name="whatsapp" size={14} /> WhatsApp</button>
|
|
|
|
|
</div>
|
|
|
|
|
<button className="btn btn-sm" style={{ width: "auto" }} disabled={state === "sending" || state === "ok"} onClick={send}>
|
|
|
|
|
{state === "sending" ? "Sending…" : "Send code"}
|
|
|
|
|
<span className="faint" style={{ fontSize: 12 }}>{MOCK_OTP ? "Demo verification (no SMS sent)." : "Standard SMS rates may apply."}</span>
|
|
|
|
|
<button className="btn btn-sm" style={{ width: "auto" }} disabled={state === "sending" || state === "sent"} onClick={send}>
|
|
|
|
|
{state === "sending" ? "Sending…" : state === "sent" ? "Sent" : "Send code"}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{state === "ok" && <p className="faint" style={{ fontSize: 12, marginTop: 10 }}>OTP sent via {via === "wa" ? "WhatsApp" : primaryLabel}.</p>}
|
|
|
|
|
{state === "invalid_email" && <div style={{ marginTop: 10 }}><FlashNote tone="error">That email address looks invalid.</FlashNote></div>}
|
|
|
|
|
{state === "mailbox_full" && <div style={{ marginTop: 10 }}><FlashNote tone="warn">This mailbox appears full — try another email.</FlashNote></div>}
|
|
|
|
|
{state === "bounce_risk" && <div style={{ marginTop: 10 }}><FlashNote tone="warn">High bounce risk for this address.</FlashNote></div>}
|
|
|
|
|
{state === "sent" && <p className="faint" style={{ fontSize: 12, marginTop: 10 }}>{MOCK_OTP ? `Demo mode — enter ${DEMO_OTP} to verify (SMS temporarily disabled).` : `Code sent to ${cc} ${value} by SMS.`}</p>}
|
|
|
|
|
{state === "invalid_mobile" && <div style={{ marginTop: 10 }}><FlashNote tone="error">Enter a valid {country.digits}-digit mobile number.</FlashNote></div>}
|
|
|
|
|
{state === "send_error" && <div style={{ marginTop: 10 }}><FlashNote tone="error">Couldn't send the code. Check the number and try again.</FlashNote></div>}
|
|
|
|
|
|
|
|
|
|
{state === "ok" && (
|
|
|
|
|
{state === "sent" && (
|
|
|
|
|
<div style={{ marginTop: 14 }}>
|
|
|
|
|
<OtpBoxes onComplete={(c) => { if (c === "000000") setOtpError(true); else { setOtpError(false); onVerified(); } }} error={otpError} />
|
|
|
|
|
{otpError && <div style={{ marginTop: 10 }}><FlashNote tone="error">Incorrect code.</FlashNote></div>}
|
|
|
|
|
<div style={{ marginTop: 12 }}><ResendLink seconds={60} /></div>
|
|
|
|
|
<OtpBoxes onComplete={submit} error={!!otpError} />
|
|
|
|
|
{otpError && <div style={{ marginTop: 10 }}><FlashNote tone="error">{otpError}</FlashNote></div>}
|
|
|
|
|
<div style={{ marginTop: 12 }}><ResendLink seconds={60} onResend={send} /></div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|