forked from Goutam/lynkeduppro-crm
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 948abf75fd | |||
| 34cb44cfa8 | |||
| f38fa80bde | |||
| 86af77c92b | |||
| 27e7bdf8f5 | |||
| 64be4b9b3f | |||
| 5186497c50 | |||
| 0e8a207640 | |||
| 7570fe7be3 | |||
| 6e1a895e7e | |||
| 74caae0710 |
+1
-1
@@ -9,7 +9,7 @@
|
||||
"lint": "eslint"
|
||||
},
|
||||
"dependencies": {
|
||||
"@abe-kap/appshell-sdk": "^0.2.0",
|
||||
"@abe-kap/appshell-sdk": "^0.2.3",
|
||||
"clsx": "^2.1.1",
|
||||
"lucide-react": "^1.21.0",
|
||||
"next": "16.2.9",
|
||||
|
||||
@@ -106,6 +106,11 @@
|
||||
.sb-user .av { width: 30px; height: 30px; border-radius: 8px; object-fit: cover; flex: 0 0 30px; }
|
||||
.sb-user .nm { font-size: 12.5px; font-weight: 600; }
|
||||
.sb-user .rl { font-size: 11px; color: var(--faint); }
|
||||
.sb-user .nm, .sb-user .rl { max-width: 130px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.sb-user-menu { position: absolute; bottom: 56px; left: 12px; right: 12px; z-index: 30; padding: 6px; border-radius: 12px; border: 1px solid var(--border-2); background: var(--panel); box-shadow: var(--shadow), 0 8px 30px -12px rgba(0,0,0,0.55); animation: ds-rise 0.14s ease; }
|
||||
.sb-user-menu button { display: flex; align-items: center; gap: 9px; width: 100%; padding: 9px 10px; border: 0; border-radius: 9px; background: none; color: var(--text-2); font-family: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; text-align: left; }
|
||||
.sb-user-menu button:hover { background: var(--panel-2); }
|
||||
.sb-user-menu button.danger { color: var(--red, #ef4444); }
|
||||
|
||||
/* ---- main ---- */
|
||||
.dash-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useAuth, useAppShell } from "@abe-kap/appshell-sdk/react";
|
||||
import { PortalAside, PanelBrand } from "@/components/portal/parts";
|
||||
import { RegisterFlow } from "@/components/portal/register-flow";
|
||||
import { CookieBanner } from "@/components/portal/bits";
|
||||
import { isShellConfigured } from "@/lib/appshell";
|
||||
|
||||
/**
|
||||
* Post-OAuth onboarding — a first-time Google user completes their CRM profile
|
||||
* (everything except email, which Google already verified). Only reachable while
|
||||
* authenticated; unauthenticated visitors are sent back to sign in.
|
||||
*/
|
||||
export default function OnboardingPage() {
|
||||
const router = useRouter();
|
||||
const { status } = useAuth();
|
||||
const { ready } = useAppShell();
|
||||
|
||||
useEffect(() => {
|
||||
if (isShellConfigured() && ready && status === "unauthenticated") router.replace("/portal/login");
|
||||
}, [ready, status, router]);
|
||||
|
||||
return (
|
||||
<main className="portal-main">
|
||||
<span className="portal-grid" />
|
||||
<div className="portal-split anim-in">
|
||||
<PortalAside />
|
||||
<section className="portal-panel">
|
||||
<div style={{ width: "100%", maxWidth: 420 }}>
|
||||
<PanelBrand />
|
||||
<RegisterFlow mode="onboard" />
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<CookieBanner />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useAuth } from "@abe-kap/appshell-sdk/react";
|
||||
import { useAuth, useAppShell } from "@abe-kap/appshell-sdk/react";
|
||||
import { isShellConfigured } from "@/lib/appshell";
|
||||
|
||||
/**
|
||||
@@ -14,16 +14,21 @@ import { isShellConfigured } from "@/lib/appshell";
|
||||
export function AuthGate({ children }: { children: React.ReactNode }) {
|
||||
const router = useRouter();
|
||||
const { status } = useAuth();
|
||||
const { ready } = useAppShell();
|
||||
const shell = isShellConfigured();
|
||||
|
||||
useEffect(() => {
|
||||
if (shell && status === "unauthenticated") router.replace("/portal/login");
|
||||
}, [shell, status, router]);
|
||||
// Only bounce to login once the SDK has finished booting AND restore() has
|
||||
// resolved to unauthenticated. Redirecting while boot is still in flight would
|
||||
// drop a perfectly valid session on reload (the status is transiently not-yet
|
||||
// "authenticated" during boot).
|
||||
if (shell && ready && status === "unauthenticated") router.replace("/portal/login");
|
||||
}, [shell, ready, status, router]);
|
||||
|
||||
if (shell && status !== "authenticated") {
|
||||
if (shell && (!ready || status !== "authenticated")) {
|
||||
return (
|
||||
<div style={{ minHeight: "60vh", display: "grid", placeItems: "center", color: "var(--muted, #888)" }}>
|
||||
{status === "loading" ? "Loading your workspace…" : "Redirecting to sign in…"}
|
||||
{ready && status === "unauthenticated" ? "Redirecting to sign in…" : "Loading your workspace…"}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
"use client";
|
||||
|
||||
import { ChevronsUpDown } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { ChevronsUpDown, LogOut } from "lucide-react";
|
||||
import { useAuth } from "@abe-kap/appshell-sdk/react";
|
||||
import { Icon } from "./ui";
|
||||
import { user } from "./account-data";
|
||||
|
||||
function initialsOf(name: string): string {
|
||||
return name.split(/\s+/).filter(Boolean).slice(0, 2).map((p) => p[0]).join("").toUpperCase() || "?";
|
||||
}
|
||||
|
||||
export type NavItem = { key: string; label: string; icon: string; subtitle?: string };
|
||||
export type NavGroup = { title: string; items: NavItem[] };
|
||||
|
||||
@@ -61,6 +68,22 @@ export const NAV_GROUPS: NavGroup[] = [
|
||||
export const NAV_ITEMS: NavItem[] = NAV_GROUPS.flatMap((g) => g.items);
|
||||
|
||||
export function Sidebar({ active, onSelect }: { active: string; onSelect: (k: string) => void }) {
|
||||
const router = useRouter();
|
||||
const { user: me, logout, context } = useAuth();
|
||||
const [menuOpen, setMenuOpen] = useState(false);
|
||||
// Real signed-in identity from the App Context Envelope; fall back to the static
|
||||
// demo user only when the Shell isn't wired.
|
||||
const roleLabel = context?.scope?.role ? context.scope.role.charAt(0).toUpperCase() + context.scope.role.slice(1) : "";
|
||||
const name = me?.displayName || user.name;
|
||||
const initials = me ? initialsOf(me.displayName) : user.initials;
|
||||
const secondary = me?.email || roleLabel || user.role;
|
||||
|
||||
async function signOut() {
|
||||
setMenuOpen(false);
|
||||
try { await logout(); } catch { /* ignore — proceed to portal either way */ }
|
||||
router.replace("/portal/login");
|
||||
}
|
||||
|
||||
return (
|
||||
<aside className="dash-sidebar">
|
||||
<div className="dash-brand">
|
||||
@@ -82,12 +105,20 @@ export function Sidebar({ active, onSelect }: { active: string; onSelect: (k: st
|
||||
))}
|
||||
</nav>
|
||||
|
||||
<div className="sb-foot">
|
||||
<button className="sb-user">
|
||||
<span className="av" style={{ background: user.avatarGradient, display: "grid", placeItems: "center", color: "#fff", fontWeight: 700, fontSize: 12 }}>{user.initials}</span>
|
||||
<div style={{ flex: 1, textAlign: "left" }}>
|
||||
<div className="nm">{user.name}</div>
|
||||
<div className="rl">{user.role}</div>
|
||||
<div className="sb-foot" style={{ position: "relative" }}>
|
||||
{menuOpen && (
|
||||
<>
|
||||
<div className="tm-menu-scrim" onClick={() => setMenuOpen(false)} />
|
||||
<div className="sb-user-menu" role="menu">
|
||||
<button className="danger" onClick={signOut}><LogOut size={15} /> Sign out</button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
<button className="sb-user" onClick={() => setMenuOpen((o) => !o)} aria-haspopup="menu" aria-expanded={menuOpen}>
|
||||
<span className="av" style={{ background: user.avatarGradient, display: "grid", placeItems: "center", color: "#fff", fontWeight: 700, fontSize: 12 }}>{initials}</span>
|
||||
<div style={{ flex: 1, textAlign: "left", minWidth: 0 }}>
|
||||
<div className="nm">{name}</div>
|
||||
<div className="rl" style={{ overflow: "hidden", textOverflow: "ellipsis" }}>{secondary}</div>
|
||||
</div>
|
||||
<ChevronsUpDown size={15} />
|
||||
</button>
|
||||
|
||||
@@ -1,20 +1,33 @@
|
||||
"use client";
|
||||
|
||||
import { Sun, Moon, ChevronDown } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Sun, Moon, ChevronDown, LogOut } from "lucide-react";
|
||||
import { useAuth } from "@abe-kap/appshell-sdk/react";
|
||||
import { Icon } from "./ui";
|
||||
import { user } from "./account-data";
|
||||
import { useAuth } from "@abe-kap/appshell-sdk/react";
|
||||
|
||||
function initialsOf(name: string): string {
|
||||
return name.split(/\s+/).filter(Boolean).slice(0, 2).map((p) => p[0]).join("").toUpperCase();
|
||||
return name.split(/\s+/).filter(Boolean).slice(0, 2).map((p) => p[0]).join("").toUpperCase() || "?";
|
||||
}
|
||||
|
||||
export function Topbar({ theme, onToggle, title, subtitle }: { theme: "dark" | "light"; onToggle: () => void; title: string; subtitle: string }) {
|
||||
// When signed in through the Shell, show the real identity from the App Context
|
||||
// Envelope; otherwise fall back to the static demo user.
|
||||
const { user: me } = useAuth();
|
||||
const router = useRouter();
|
||||
const { user: me, logout, context } = useAuth();
|
||||
const [menuOpen, setMenuOpen] = useState(false);
|
||||
const roleLabel = context?.scope?.role ? context.scope.role.charAt(0).toUpperCase() + context.scope.role.slice(1) : "";
|
||||
const name = me?.displayName || user.name;
|
||||
const initials = me ? initialsOf(me.displayName) : user.initials;
|
||||
const secondary = me?.email || roleLabel || user.role;
|
||||
|
||||
async function signOut() {
|
||||
setMenuOpen(false);
|
||||
try { await logout(); } catch { /* ignore */ }
|
||||
router.replace("/portal/login");
|
||||
}
|
||||
|
||||
return (
|
||||
<header className="dash-topbar">
|
||||
<div className="dash-title">
|
||||
@@ -30,14 +43,24 @@ export function Topbar({ theme, onToggle, title, subtitle }: { theme: "dark" | "
|
||||
<Icon name="bell" size={18} />
|
||||
<span style={{ position: "absolute", top: 9, right: 10, width: 7, height: 7, borderRadius: 99, background: "var(--orange)", border: "2px solid var(--panel)" }} />
|
||||
</button>
|
||||
<button className="top-user">
|
||||
<div className="top-user-wrap" style={{ position: "relative" }}>
|
||||
<button className="top-user" onClick={() => setMenuOpen((o) => !o)} aria-haspopup="menu" aria-expanded={menuOpen}>
|
||||
<span className="av" style={{ background: user.avatarGradient, display: "grid", placeItems: "center", color: "#fff", fontWeight: 700, fontSize: 12 }}>{initials}</span>
|
||||
<div style={{ textAlign: "left" }}>
|
||||
<div style={{ textAlign: "left", minWidth: 0 }}>
|
||||
<div className="nm">{name}</div>
|
||||
<div className="rl">{user.role}</div>
|
||||
<div className="rl" style={{ overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", maxWidth: 150 }}>{secondary}</div>
|
||||
</div>
|
||||
<ChevronDown size={16} />
|
||||
</button>
|
||||
{menuOpen && (
|
||||
<>
|
||||
<div className="tm-menu-scrim" onClick={() => setMenuOpen(false)} />
|
||||
<div className="tm-menu-pop" role="menu">
|
||||
<button className="danger" onClick={signOut}><LogOut size={15} /> Sign out</button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
|
||||
@@ -145,18 +145,13 @@ export function startSocial(provider: "google" | "microsoft" | "apple"): boolean
|
||||
if (url) { window.location.href = url; return true; }
|
||||
return false;
|
||||
}
|
||||
export function SocialButtons({ onPick, verb = "Continue" }: { onPick: (p: "google" | "microsoft" | "apple") => void; verb?: string }) {
|
||||
export function SocialButtons({ onPick, verb = "Continue" }: { onPick: (p: "google") => void; verb?: string }) {
|
||||
// Only Google is offered (Microsoft/Apple intentionally hidden).
|
||||
return (
|
||||
<div className="col gap-3">
|
||||
<button className="btn btn-oauth" type="button" onClick={() => onPick("google")}>
|
||||
<GoogleMark /> {verb} with Google
|
||||
</button>
|
||||
<button className="btn btn-oauth" type="button" onClick={() => onPick("microsoft")}>
|
||||
<MicrosoftMark /> {verb} with Microsoft / Outlook
|
||||
</button>
|
||||
<button className="btn btn-oauth" type="button" onClick={() => onPick("apple")}>
|
||||
<AppleMark /> {verb} with Apple
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
PasswordStrength,
|
||||
} from "./bits";
|
||||
import { lookupAccount, maskEmail, type Account } from "./data";
|
||||
import { useAuth } from "@abe-kap/appshell-sdk/react";
|
||||
import { useAuth, useAppShell } from "@abe-kap/appshell-sdk/react";
|
||||
import { isShellConfigured } from "@/lib/appshell";
|
||||
|
||||
// Map the portal's social button ids to Supabase OAuth provider ids.
|
||||
@@ -25,12 +25,25 @@ const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
export function LoginFlow() {
|
||||
const router = useRouter();
|
||||
const { login, loginWithOAuth, completeOAuthLogin } = useAuth();
|
||||
const { ready, sdk } = useAppShell();
|
||||
const [step, setStep] = useState<Step>("identify");
|
||||
const [email, setEmail] = useState("");
|
||||
const [account, setAccount] = useState<Account | null>(null);
|
||||
const [provider, setProvider] = useState<string>("");
|
||||
const [remember, setRemember] = useState(false);
|
||||
const [flash, setFlash] = useState<string>("");
|
||||
const [otpChannel, setOtpChannel] = useState<"email" | "sms">("email");
|
||||
|
||||
// Minimal account stand-in for passwordless entry points (Shell mode).
|
||||
function blankAccount(): Account {
|
||||
return { firstName: "", name: "", initials: "", hasPasskey: false, hasTotp: false, hasPush: false, maskedEmail: maskEmail(email || ""), maskedPhone: "", maskedWa: "" };
|
||||
}
|
||||
// Direct "sign in with phone" → the one-time-code screen, SMS preselected.
|
||||
function startPhoneLogin() {
|
||||
setAccount(blankAccount());
|
||||
setOtpChannel("sms");
|
||||
replace("otp");
|
||||
}
|
||||
|
||||
/* ---- history hash sync ---- */
|
||||
function push(s: Step) {
|
||||
@@ -58,11 +71,28 @@ export function LoginFlow() {
|
||||
if (!isShellConfigured()) return;
|
||||
const code = new URLSearchParams(window.location.search).get("code");
|
||||
if (!code) return;
|
||||
// Wait until the SDK has booted — completeOAuthLogin no-ops (returns null) if
|
||||
// sdk.auth isn't ready yet, and this effect only re-runs when `ready` flips.
|
||||
if (!ready) { setStep("connecting"); return; }
|
||||
setStep("connecting");
|
||||
completeOAuthLogin(code)
|
||||
.then((ace) => { if (ace) router.replace("/dashboard"); else replace("identify"); })
|
||||
.catch(() => { setFlash("Sign-in with that provider didn't complete. Try again."); replace("identify"); });
|
||||
}, [completeOAuthLogin, router]);
|
||||
.then(async (ace) => {
|
||||
if (!ace) { replace("identify"); return; }
|
||||
// First-time Google user (no CRM profile yet) → complete onboarding; an
|
||||
// existing profile → straight to the dashboard.
|
||||
let registered = false;
|
||||
try {
|
||||
const st = await sdk.query<{ registered: boolean }>("crm.account.registrationStatus");
|
||||
registered = !!st?.registered;
|
||||
} catch { registered = false; }
|
||||
window.history.replaceState({}, "", "/portal/login");
|
||||
router.replace(registered ? "/dashboard" : "/portal/onboarding");
|
||||
})
|
||||
.catch(() => {
|
||||
setFlash("Google sign-in didn't complete. Please try again.");
|
||||
replace("identify");
|
||||
});
|
||||
}, [ready, completeOAuthLogin, router, sdk]);
|
||||
|
||||
/* ---- auth resolution ---- */
|
||||
function afterAuth(factor: "password" | "passkey" | "otp" | "totp" | "push" | "social") {
|
||||
@@ -100,6 +130,7 @@ export function LoginFlow() {
|
||||
hasPasskey: false, hasTotp: false, hasPush: false,
|
||||
maskedEmail: maskEmail(email), maskedPhone: "", maskedWa: "",
|
||||
});
|
||||
setOtpChannel("email");
|
||||
replace("password");
|
||||
return;
|
||||
}
|
||||
@@ -116,14 +147,18 @@ export function LoginFlow() {
|
||||
/* =================================================================== */
|
||||
return (
|
||||
<div className="card anim-fade-up" key={step}>
|
||||
{step === "identify" && <Identify email={email} setEmail={setEmail} onSocial={onSocial} onEmail={identifyEmail} toRegister={() => router.push("/portal/register")} />}
|
||||
{step === "identify" && (
|
||||
<>
|
||||
{flash && <div style={{ marginBottom: 16 }}><FlashNote tone="error">{flash}</FlashNote></div>}
|
||||
<Identify email={email} setEmail={setEmail} onSocial={onSocial} onEmail={identifyEmail} onPhone={startPhoneLogin} toRegister={() => router.push("/portal/register")} />
|
||||
</>
|
||||
)}
|
||||
|
||||
{step === "connecting" && (
|
||||
<div className="interstitial">
|
||||
<Spinner lg />
|
||||
<div>
|
||||
<h1 style={{ fontSize: 20 }}>{provider ? `Connecting to ${cap(provider)}…` : "Looking up your account…"}</h1>
|
||||
{provider && <p className="sub" style={{ marginTop: 6 }}>Demo mode — no provider keys configured.</p>}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
@@ -162,11 +197,11 @@ export function LoginFlow() {
|
||||
)}
|
||||
|
||||
{step === "password" && account && (
|
||||
<Password account={account} email={email} login={login} onAuthenticated={() => router.replace("/dashboard")} flash={flash} onBack={back} onForgot={() => push("fp_confirm")} onOtp={() => replace("otp")} onLocked={() => setFlash("This account is temporarily locked.")} onOk={() => afterAuth("password")} />
|
||||
<Password account={account} email={email} login={login} onAuthenticated={() => router.replace("/dashboard")} flash={flash} onBack={back} onForgot={() => push("fp_confirm")} onOtp={() => { setOtpChannel("email"); replace("otp"); }} onLocked={() => setFlash("This account is temporarily locked.")} onOk={() => afterAuth("password")} />
|
||||
)}
|
||||
|
||||
{step === "otp" && account && (
|
||||
<OtpVerify account={account} email={email} remember={remember} setRemember={setRemember} onBack={back} onVerified={() => afterAuth("otp")} onAuthenticated={() => router.replace("/dashboard")} />
|
||||
<OtpVerify account={account} email={email} initialChannel={otpChannel} remember={remember} setRemember={setRemember} onBack={back} onVerified={() => afterAuth("otp")} onAuthenticated={() => router.replace("/dashboard")} />
|
||||
)}
|
||||
|
||||
{step === "another" && account && (
|
||||
@@ -230,9 +265,9 @@ export function LoginFlow() {
|
||||
|
||||
/* ============================ screens ============================ */
|
||||
|
||||
function Identify({ email, setEmail, onSocial, onEmail, toRegister }: {
|
||||
function Identify({ email, setEmail, onSocial, onEmail, onPhone, toRegister }: {
|
||||
email: string; setEmail: (v: string) => void;
|
||||
onSocial: (p: "google" | "microsoft" | "apple") => void; onEmail: () => void; toRegister: () => void;
|
||||
onSocial: (p: "google") => void; onEmail: () => void; onPhone: () => void; toRegister: () => void;
|
||||
}) {
|
||||
const [showEmail, setShowEmail] = useState(false);
|
||||
const valid = EMAIL_RE.test(email);
|
||||
@@ -263,6 +298,9 @@ function Identify({ email, setEmail, onSocial, onEmail, toRegister }: {
|
||||
</button>
|
||||
</form>
|
||||
)}
|
||||
{isShellConfigured() && (
|
||||
<button className="link" style={{ marginTop: 14, display: "block" }} onClick={onPhone}><Icon name="sms" size={15} /> Sign in with a phone number instead</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<p className="foot-note">New homeowner or contractor? <button className="link" onClick={toRegister}>Register here</button></p>
|
||||
@@ -271,7 +309,6 @@ function Identify({ email, setEmail, onSocial, onEmail, toRegister }: {
|
||||
<span><Icon name="shield" size={13} /> Licensed & Insured</span>
|
||||
<span><Icon name="check" size={13} /> Drone-Powered</span>
|
||||
</div>
|
||||
<p className="demo-hint">Demo: any email signs in; an email starting with “new” shows “not found”.</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -306,7 +343,6 @@ function Passkey({ account, onBack, onPassword, onAnother, onSuccess, onFail }:
|
||||
<button className="link" onClick={onPassword}>Use your password instead</button>
|
||||
<button className="link" onClick={onAnother}>Try another way</button>
|
||||
</div>
|
||||
<p className="demo-hint">Demo: passkey always succeeds here.</p>
|
||||
<button hidden onClick={onFail} />
|
||||
</div>
|
||||
);
|
||||
@@ -357,20 +393,19 @@ function Password({ account, email, login, onAuthenticated, flash, onBack, onFor
|
||||
</form>
|
||||
<div className="row between" style={{ marginTop: 16 }}>
|
||||
<button className="link" onClick={onForgot}>Forgot password?</button>
|
||||
<button className="link" onClick={onOtp}>Sign in using email OTP</button>
|
||||
<button className="link" onClick={onOtp}>Sign in with a one-time code</button>
|
||||
</div>
|
||||
{!isShellConfigured() && <p className="demo-hint">Demo: any password works; type “wrong” to see the lockout. Password always needs 2-step next.</p>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function OtpVerify({ account, email, remember, setRemember, onBack, onVerified, onAuthenticated }: {
|
||||
account: Account; email: string; remember: boolean; setRemember: (v: boolean) => void; onBack: () => void; onVerified: () => void; onAuthenticated: () => void;
|
||||
function OtpVerify({ account, email, initialChannel = "email", remember, setRemember, onBack, onVerified, onAuthenticated }: {
|
||||
account: Account; email: string; initialChannel?: "email" | "sms"; remember: boolean; setRemember: (v: boolean) => void; onBack: () => void; onVerified: () => void; onAuthenticated: () => void;
|
||||
}) {
|
||||
const { sendEmailOtp, verifyEmailOtp, sendPhoneOtp, verifyPhoneOtp } = useAuth();
|
||||
const shell = isShellConfigured();
|
||||
// In Shell mode only email + SMS are real Supabase OTP channels; hide WhatsApp.
|
||||
const [channel, setChannel] = useState<"email" | "sms" | "wa">("email");
|
||||
const [channel, setChannel] = useState<"email" | "sms" | "wa">(initialChannel);
|
||||
const [phone, setPhone] = useState("");
|
||||
const [sent, setSent] = useState(false);
|
||||
const [busy, setBusy] = useState(false);
|
||||
@@ -440,7 +475,6 @@ function OtpVerify({ account, email, remember, setRemember, onBack, onVerified,
|
||||
<span />
|
||||
</div>
|
||||
<RememberDevice checked={remember} onChange={setRemember} note="2-step is still required at each sign-in." />
|
||||
{!shell && <p className="demo-hint">Demo: any 6 digits verify; “000000” shows an error.</p>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -495,7 +529,6 @@ function Totp({ remember, setRemember, onBack, onVerified }: { remember: boolean
|
||||
{setupKey ? "Enter a 6-digit code instead" : "Enter setup key instead"}
|
||||
</button>
|
||||
<RememberDevice checked={remember} onChange={setRemember} />
|
||||
<p className="demo-hint">Demo: any 6 digits verify; “000000” fails.</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -514,7 +547,6 @@ function PushApprove({ onBack, onApproved, onCancel }: { onBack: () => void; onA
|
||||
<p className="sub" style={{ textAlign: "center" }}>{approved ? "Your sign-in was approved." : "We sent a notification to your mobile app. Approve it to continue."}</p>
|
||||
<div className="interstitial">{approved ? <Icon name="check" size={30} /> : <Spinner lg />}</div>
|
||||
{!approved && <button className="btn" onClick={onCancel}>Cancel</button>}
|
||||
<p className="demo-hint">Demo: auto-approves after ~3 seconds.</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -598,7 +630,6 @@ function ForgotCode({ onBack, onOk }: { onBack: () => void; onOk: () => void })
|
||||
<div style={{ marginTop: 18 }}><OtpBoxes onComplete={(c) => (c === "000000" ? setError(true) : onOk())} error={error} /></div>
|
||||
{error && <div style={{ marginTop: 12 }}><FlashNote tone="error">Incorrect code.</FlashNote></div>}
|
||||
<div style={{ marginTop: 14 }}><ResendLink seconds={30} /></div>
|
||||
<p className="demo-hint">Demo: any 6 digits work; “000000” fails.</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { useRouter } from "next/navigation";
|
||||
import { Icon, Avatar } from "./icons";
|
||||
import {
|
||||
StepBack, FlashNote, Badge, OtpBoxes, ResendLink, RememberDevice,
|
||||
SocialButtons, startSocial, PasswordStrength, LegalModal,
|
||||
PasswordStrength, LegalModal,
|
||||
} from "./bits";
|
||||
import {
|
||||
countryCodes, relationshipOptions, addressCountries,
|
||||
@@ -19,9 +19,13 @@ type Addr = { line1?: string; line2?: string; city?: string; state?: string; pos
|
||||
const STEPS = ["Account", "Verify", "Address"];
|
||||
const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
|
||||
export function RegisterFlow() {
|
||||
export function RegisterFlow({ mode = "register" }: { mode?: "register" | "onboard" }) {
|
||||
// "onboard" = an already-authenticated OAuth (Google) user completing their CRM
|
||||
// profile: email is skipped (Google-verified), the auth account already exists so
|
||||
// we only SET a password + persist the profile, and the OTP-verify step is skipped.
|
||||
const onboard = mode === "onboard";
|
||||
const router = useRouter();
|
||||
const { register } = useAuth();
|
||||
const { register, setPassword, getUserEmail } = useAuth();
|
||||
const { sdk } = useAppShell();
|
||||
const [step, setStep] = useState(0);
|
||||
const [submitErr, setSubmitErr] = useState("");
|
||||
@@ -50,6 +54,15 @@ export function RegisterFlow() {
|
||||
const [emailVerified, setEmailVerified] = useState(false);
|
||||
const [phoneVerified, setPhoneVerified] = useState(false);
|
||||
|
||||
// Onboarding: prefill the verified email from the Google session (the ACE omits it).
|
||||
useEffect(() => {
|
||||
if (!onboard) return;
|
||||
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 isSelf = relationship === "Customer" || relationship === "Owner";
|
||||
const isEmployee = relationship === "Employee";
|
||||
const country = countryCodes.find((c) => c.code === cc)!;
|
||||
@@ -76,8 +89,11 @@ export function RegisterFlow() {
|
||||
|
||||
if (isShellConfigured()) {
|
||||
setSubmitErr("");
|
||||
// 1) Auth account — appshell → Supabase (SSO users already have a session).
|
||||
if (!sso) {
|
||||
// 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; }
|
||||
}
|
||||
@@ -97,8 +113,9 @@ export function RegisterFlow() {
|
||||
mailingSameAsRegistered: mailingSame,
|
||||
consentTerms: termsOk, consentPrivacy: privacyOk,
|
||||
});
|
||||
} catch (e) {
|
||||
console.warn("crm.account.register failed (continuing):", e);
|
||||
} catch {
|
||||
if (onboard) { setSubmitErr("Couldn't save your profile. Please try again."); return; }
|
||||
// register mode: non-fatal — the auth account exists; the profile can be filled in later.
|
||||
}
|
||||
}
|
||||
router.push("/dashboard");
|
||||
@@ -106,10 +123,11 @@ export function RegisterFlow() {
|
||||
|
||||
return (
|
||||
<div className="card anim-fade-up">
|
||||
<Stepper current={step} />
|
||||
<Stepper current={step} labels={STEP_LABELS} />
|
||||
|
||||
{step === 0 && (
|
||||
<StepAccount
|
||||
onboard={onboard}
|
||||
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}
|
||||
@@ -123,7 +141,7 @@ export function RegisterFlow() {
|
||||
/>
|
||||
)}
|
||||
|
||||
{step === 1 && (
|
||||
{step === 1 && !onboard && (
|
||||
<StepVerify
|
||||
emailValue={sso?.email || email} cc={cc} phone={phone} country={country}
|
||||
emailVerified={emailVerified} setEmailVerified={setEmailVerified}
|
||||
@@ -132,10 +150,10 @@ export function RegisterFlow() {
|
||||
/>
|
||||
)}
|
||||
|
||||
{step === 2 && (
|
||||
{((onboard && step === 1) || (!onboard && step === 2)) && (
|
||||
<>
|
||||
{submitErr && <div style={{ marginBottom: 14 }}><FlashNote tone="error">{submitErr}</FlashNote></div>}
|
||||
<StepAddress sameAs={mailingSame} setSameAs={setMailingSame} onRegAddr={setRegAddr} onMailAddr={setMailAddr} onBack={() => setStep(1)} onFinish={finish} />
|
||||
<StepAddress sameAs={mailingSame} setSameAs={setMailingSame} onRegAddr={setRegAddr} onMailAddr={setMailAddr} onBack={() => setStep(onboard ? 0 : 1)} onFinish={finish} />
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
@@ -153,28 +171,19 @@ 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;
|
||||
valid: boolean; onContinue: () => void; toLogin: () => void; onboard?: boolean;
|
||||
}) {
|
||||
const [phase, setPhase] = useState<"sso" | "profile">("sso");
|
||||
// Onboarding (OAuth) starts on the profile step — email is already known + verified.
|
||||
const [phase, setPhase] = useState<"sso" | "profile">(p.onboard ? "profile" : "sso");
|
||||
const [modal, setModal] = useState<null | "terms" | "privacy">(null);
|
||||
|
||||
function pickSso(provider: "google" | "microsoft" | "apple") {
|
||||
if (startSocial(provider)) return;
|
||||
const mockEmail = `you@${provider === "microsoft" ? "outlook.com" : provider + ".com"}`;
|
||||
p.setSso({ provider, email: mockEmail });
|
||||
p.setEmail(mockEmail);
|
||||
setPhase("profile");
|
||||
}
|
||||
|
||||
if (phase === "sso") {
|
||||
const valid = EMAIL_RE.test(p.email);
|
||||
return (
|
||||
<div>
|
||||
<h1>Create your account</h1>
|
||||
<p className="sub">Sign up with a provider or your email to get started.</p>
|
||||
<p className="sub">Enter your email to get started.</p>
|
||||
<div style={{ marginTop: 20 }}>
|
||||
<SocialButtons onPick={pickSso} verb="Sign up" />
|
||||
<div className="divider">or continue with email</div>
|
||||
<form onSubmit={(e) => { e.preventDefault(); if (valid) { p.setSso(null); setPhase("profile"); } }}>
|
||||
<div className="field">
|
||||
<label className="label">Email address</label>
|
||||
@@ -200,7 +209,7 @@ function StepAccount(p: {
|
||||
{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} /> Creating account for {p.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>
|
||||
|
||||
@@ -299,7 +308,7 @@ 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}>Create Account & Verify <Icon name="arrowR" size={16} /></button>
|
||||
<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>
|
||||
|
||||
{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); }} />}
|
||||
@@ -414,7 +423,6 @@ function VerifyChannel({ kind, initial, country, cc, initialPhone, verified, onV
|
||||
<div style={{ marginTop: 12 }}><ResendLink seconds={60} /></div>
|
||||
</div>
|
||||
)}
|
||||
<p className="demo-hint">Demo: any 6 digits verify; “000000” fails. Email with “full”/“bo” shows send errors.</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -592,10 +600,10 @@ function AddressBlock({ idPrefix, onChange }: { idPrefix: string; onChange?: (a:
|
||||
}
|
||||
|
||||
/* ====================== stepper ====================== */
|
||||
function Stepper({ current }: { current: number }) {
|
||||
function Stepper({ current, labels = STEPS }: { current: number; labels?: string[] }) {
|
||||
return (
|
||||
<div className="steps">
|
||||
{STEPS.map((label, i) => {
|
||||
{labels.map((label, i) => {
|
||||
const done = i < current, on = i === current;
|
||||
return (
|
||||
<div key={label} style={{ display: "contents" }}>
|
||||
|
||||
Reference in New Issue
Block a user