diff --git a/src/components/portal/register-flow.tsx b/src/components/portal/register-flow.tsx index 162eb31..c9829e4 100644 --- a/src/components/portal/register-flow.tsx +++ b/src/components/portal/register-flow.tsx @@ -11,18 +11,26 @@ import { countryCodes, relationshipOptions, addressCountries, TERMS, PRIVACY, passwordStrength, type AddrCountry, } from "./data"; -import { useAuth } from "@abe-kap/appshell-sdk/react"; +import { useAuth, useAppShell } from "@abe-kap/appshell-sdk/react"; import { isShellConfigured } from "@/lib/appshell"; +type Addr = { line1?: string; line2?: string; city?: string; state?: string; postalCode?: string; country?: string; locality?: string }; + const STEPS = ["Account", "Verify", "Address"]; const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; export function RegisterFlow() { const router = useRouter(); const { register } = useAuth(); + const { sdk } = useAppShell(); const [step, setStep] = useState(0); const [submitErr, setSubmitErr] = useState(""); + // address (lifted from StepAddress/AddressBlock so finish() can persist it) + const [regAddr, setRegAddr] = useState({}); + const [mailAddr, setMailAddr] = useState({}); + const [mailingSame, setMailingSame] = useState(true); + // shared form state const [sso, setSso] = useState<{ provider: string; email: string } | null>(null); const [email, setEmail] = useState(""); @@ -65,12 +73,33 @@ export function RegisterFlow() { allotteeNames: isSelf ? null : `${alloeFirst} ${alloeLast}`.trim(), }; try { localStorage.setItem("lup_profile", JSON.stringify(profile)); } catch { /* ignore */ } - // With the Shell live, create the real account through appshell → BFF. SSO users - // already have a session from OAuth, so only email/password sign-ups register here. - if (isShellConfigured() && !sso) { + + if (isShellConfigured()) { setSubmitErr(""); - try { await register(finalEmail, pw); } - catch { setSubmitErr("We couldn't create that account. The email may already be registered."); return; } + // 1) Auth account — appshell → Supabase (SSO users already have a session). + if (!sso) { + try { await register(finalEmail, pw); } + catch { setSubmitErr("We couldn't create that account. The email may already be registered."); return; } + } + // 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. + try { + const mailing = mailingSame ? regAddr : mailAddr; + await sdk.command("crm.account.register", { + email: finalEmail, + firstName: first, lastName: last, + phoneCc: cc, phoneNumber: phone.replace(/\D/g, ""), + persona: relationship, + isAllottee: isSelf, + ...(isSelf ? {} : { allotteeId: alloeNo, allotteeFirstName: alloeFirst, allotteeLastName: alloeLast }), + registeredAddress: regAddr, + mailingAddress: mailing, + mailingSameAsRegistered: mailingSame, + consentTerms: termsOk, consentPrivacy: privacyOk, + }); + } catch (e) { + console.warn("crm.account.register failed (continuing):", e); + } } router.push("/dashboard"); } @@ -106,7 +135,7 @@ export function RegisterFlow() { {step === 2 && ( <> {submitErr &&
{submitErr}
} - setStep(1)} onFinish={finish} /> + setStep(1)} onFinish={finish} /> )} @@ -391,8 +420,7 @@ function VerifyChannel({ kind, initial, country, cc, initialPhone, verified, onV } /* ====================== STEP 3 — ADDRESS ====================== */ -function StepAddress({ onBack, onFinish }: { onBack: () => void; onFinish: () => void }) { - const [sameAs, setSameAs] = useState(true); +function StepAddress({ sameAs, setSameAs, onRegAddr, onMailAddr, onBack, onFinish }: { sameAs: boolean; setSameAs: (v: boolean) => void; onRegAddr: (a: Addr) => void; onMailAddr: (a: Addr) => void; onBack: () => void; onFinish: () => void }) { return (
@@ -400,7 +428,7 @@ function StepAddress({ onBack, onFinish }: { onBack: () => void; onFinish: () =>

Add your registered address and where we should send mail.

- +