forked from Goutam/lynkeduppro-crm
feat(profile): wire Profile to the be-crm profile data door
New src/lib/profile-api.ts (useProfileData) mirrors team-api: live (crm.account/ kyc/notifications/consent) or local mock, one interface. profile.tsx consumes it — Personal (verify-to-reveal + change contact OTP), KYC (real file upload/remove), Notifications (matrix, timezone, windows, add/verify destination), Privacy (consent). Security + Devices stay on the mock (Shell-owned).
This commit is contained in:
@@ -3,15 +3,20 @@
|
||||
// ============================================================
|
||||
// Profile — header card + 6 tabs:
|
||||
// Personal Info · KYC · Security · Notifications · Privacy · Devices
|
||||
//
|
||||
// Personal / KYC / Notifications / Privacy are served by the be-crm profile
|
||||
// module (via useProfileData → live data door, or the local mock when the Shell
|
||||
// isn't configured). Security & Devices are Shell-owned and stay on the mock.
|
||||
// ============================================================
|
||||
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import {
|
||||
user, kycDocTypes, kyc as kycSeed, contactPrefs, contactDestinations,
|
||||
contactTimezones, contactTimes, loginActivity, consentGroups,
|
||||
passwordStrength, maskEmail, maskPhone,
|
||||
type KycSlot, type NotifCategory, type ConsentGroup,
|
||||
user, loginActivity, passwordStrength,
|
||||
} from "./account-data";
|
||||
import {
|
||||
useProfileData,
|
||||
type ProfileData, type UiAccount, type UiKycSlot, type ContactKind, type KycKey, type NotifChannel, type UploadFile,
|
||||
} from "@/lib/profile-api";
|
||||
import {
|
||||
Avatar, Btn, Field, Icon, Modal, OtpField, PageHead, Pill, SegTabs,
|
||||
StatusDot, Toggle, useToast,
|
||||
@@ -26,7 +31,27 @@ const TABS = [
|
||||
{ value: "devices", label: "Devices", icon: "devices" },
|
||||
];
|
||||
|
||||
/** Read a picked File into the base64 shape a data-door command carries. */
|
||||
function readFileAsUpload(file: File): Promise<UploadFile> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
const base64 = String(reader.result).split(",")[1] ?? "";
|
||||
resolve({ fileName: file.name, contentType: file.type || "application/octet-stream", base64 });
|
||||
};
|
||||
reader.onerror = () => reject(reader.error ?? new Error("could not read file"));
|
||||
reader.readAsDataURL(file);
|
||||
});
|
||||
}
|
||||
|
||||
/** Turn a thrown data-door error into a short, readable toast message. */
|
||||
function errText(e: unknown): string {
|
||||
const m = e instanceof Error ? e.message : String(e);
|
||||
return m.replace(/^\d+\s*[-:]\s*/, "").slice(0, 160) || "Something went wrong.";
|
||||
}
|
||||
|
||||
export function Profile() {
|
||||
const p = useProfileData();
|
||||
const [tab, setTab] = useState("personal");
|
||||
|
||||
return (
|
||||
@@ -36,19 +61,26 @@ export function Profile() {
|
||||
title="Profile"
|
||||
subtitle="Manage your identity, verification, security and preferences."
|
||||
icon="user"
|
||||
actions={<Pill tone="green"><StatusDot status="online" /> Account active</Pill>}
|
||||
actions={<Pill tone={p.account.status === "active" ? "green" : "red"}><StatusDot status={p.account.status === "active" ? "online" : "offline"} /> Account {p.account.status}</Pill>}
|
||||
/>
|
||||
|
||||
<ProfileHeaderCard />
|
||||
{p.error && (
|
||||
<div className="callout tone-red" style={{ marginBottom: 16 }}>
|
||||
<Icon name="alert" size={18} />
|
||||
<div><strong>Couldn't load your profile.</strong><span>{p.error}</span></div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<ProfileHeaderCard account={p.account} />
|
||||
|
||||
<SegTabs tabs={TABS} value={tab} onChange={setTab} />
|
||||
|
||||
<div className="view-body">
|
||||
{tab === "personal" && <PersonalInfoTab />}
|
||||
{tab === "kyc" && <KycTab />}
|
||||
{tab === "personal" && <PersonalInfoTab p={p} />}
|
||||
{tab === "kyc" && <KycTab p={p} />}
|
||||
{tab === "security" && <SecurityTab />}
|
||||
{tab === "notifications" && <NotificationsTab />}
|
||||
{tab === "privacy" && <PrivacyTab />}
|
||||
{tab === "notifications" && <NotificationsTab p={p} />}
|
||||
{tab === "privacy" && <PrivacyTab p={p} />}
|
||||
{tab === "devices" && <DevicesTab />}
|
||||
</div>
|
||||
</div>
|
||||
@@ -59,35 +91,36 @@ export function Profile() {
|
||||
/* Header card */
|
||||
/* ============================================================ */
|
||||
|
||||
function ProfileHeaderCard() {
|
||||
function ProfileHeaderCard({ account }: { account: UiAccount }) {
|
||||
const { push } = useToast();
|
||||
const locale = [account.sector, account.pocket].filter(Boolean).join(" · ") || "Location on file";
|
||||
return (
|
||||
<div className="card profile-hero">
|
||||
<div className="profile-hero-bg" />
|
||||
<div className="profile-hero-main">
|
||||
<div className="profile-hero-avatar">
|
||||
<Avatar initials={user.initials} gradient={user.avatarGradient} size={86} square />
|
||||
<Avatar initials={account.initials} gradient={account.avatarGradient} size={86} square />
|
||||
<button className="profile-hero-cam" aria-label="Change photo" onClick={() => push({ tone: "info", title: "Photo upload", desc: "Choose a JPG or PNG up to 5 MB." })}>
|
||||
<Icon name="camera" size={14} />
|
||||
</button>
|
||||
</div>
|
||||
<div className="profile-hero-id">
|
||||
<div className="profile-hero-name">
|
||||
{user.name}
|
||||
{account.name}
|
||||
<Icon name="check-circle" size={18} className="verified-badge" />
|
||||
</div>
|
||||
<div className="profile-hero-role">{user.role} · Member since {user.memberSince}</div>
|
||||
<div className="profile-hero-role">{account.role} · Member since {account.memberSince}</div>
|
||||
<div className="profile-hero-chips">
|
||||
<span className="hero-chip"><Icon name="pin" size={13} /> {user.sector} · {user.pocket}</span>
|
||||
<span className="hero-chip"><Icon name="owners" size={13} /> {user.category}</span>
|
||||
<span className="hero-chip accent"><Icon name="check" size={13} /> House {user.plot}</span>
|
||||
<span className="hero-chip"><Icon name="pin" size={13} /> {locale}</span>
|
||||
{account.category && <span className="hero-chip"><Icon name="owners" size={13} /> {account.category}</span>}
|
||||
{account.plot && <span className="hero-chip accent"><Icon name="check" size={13} /> House {account.plot}</span>}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="profile-hero-stats">
|
||||
<HeroStat value={user.category} label="Category" />
|
||||
<HeroStat value={user.size} label="House size" />
|
||||
<HeroStat value="33%" label="KYC complete" accent="var(--orange)" />
|
||||
<HeroStat value={account.category ?? "—"} label="Category" />
|
||||
<HeroStat value={account.size ?? "—"} label="House size" />
|
||||
<HeroStat value={`${account.kycCompletionPct}%`} label="KYC complete" accent="var(--orange)" />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
@@ -105,31 +138,30 @@ function HeroStat({ value, label, accent }: { value: string; label: string; acce
|
||||
/* Tab: Personal Info — verify-to-reveal + change email/mobile */
|
||||
/* ============================================================ */
|
||||
|
||||
type ContactKind = "email" | "mobile" | "whatsapp";
|
||||
|
||||
function PersonalInfoTab() {
|
||||
function PersonalInfoTab({ p }: { p: ProfileData }) {
|
||||
const { push } = useToast();
|
||||
const [verified, setVerified] = useState(false);
|
||||
const [plot, setPlot] = useState("");
|
||||
const { account } = p;
|
||||
const verified = account.revealed;
|
||||
const [house, setHouse] = useState("");
|
||||
const [err, setErr] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [change, setChange] = useState<null | ContactKind>(null);
|
||||
|
||||
// editable contact values (live-updating after OTP confirmation)
|
||||
const [contacts, setContacts] = useState({ email: user.email.full, mobile: user.mobile.full, whatsapp: user.whatsapp.full });
|
||||
|
||||
function verify() {
|
||||
if (plot.trim() === user.plot) { setVerified(true); setErr(""); push({ tone: "success", title: "Verified", desc: "Your full details are now visible and editable." }); }
|
||||
else setErr(`That doesn't match the house number on file (hint: it's ${user.plot}).`);
|
||||
async function verify() {
|
||||
if (!house.trim()) return;
|
||||
setBusy(true); setErr("");
|
||||
try {
|
||||
const ok = await p.reveal(house.trim());
|
||||
if (ok) push({ tone: "success", title: "Verified", desc: "Your full details are now visible and editable." });
|
||||
else setErr("That doesn't match the house number on file.");
|
||||
} catch (e) { setErr(errText(e)); }
|
||||
finally { setBusy(false); }
|
||||
}
|
||||
|
||||
function mask(kind: ContactKind, full: string) {
|
||||
return kind === "email" ? maskEmail(full) : maskPhone(full);
|
||||
}
|
||||
|
||||
const contactRows: { key: ContactKind; label: string; full: string; masked: string }[] = [
|
||||
{ key: "email", label: "Email", full: contacts.email, masked: mask("email", contacts.email) },
|
||||
{ key: "mobile", label: "Mobile", full: contacts.mobile, masked: mask("mobile", contacts.mobile) },
|
||||
{ key: "whatsapp", label: "WhatsApp", full: contacts.whatsapp, masked: mask("whatsapp", contacts.whatsapp) },
|
||||
const contactRows: { key: ContactKind; label: string; value: string }[] = [
|
||||
{ key: "email", label: "Email", value: account.email },
|
||||
{ key: "mobile", label: "Mobile", value: account.mobile },
|
||||
{ key: "whatsapp", label: "WhatsApp", value: account.whatsapp },
|
||||
];
|
||||
|
||||
return (
|
||||
@@ -150,10 +182,10 @@ function PersonalInfoTab() {
|
||||
<span>Sensitive details are masked. Enter your house number to unmask and edit them.</span>
|
||||
</div>
|
||||
<div className="reveal-gate-form">
|
||||
<input className="ds-input" placeholder="House number" value={plot} maxLength={6}
|
||||
onChange={(e) => { setPlot(e.target.value.replace(/\D/g, "")); setErr(""); }}
|
||||
<input className="ds-input" placeholder="House number" value={house} maxLength={16}
|
||||
onChange={(e) => { setHouse(e.target.value); setErr(""); }}
|
||||
onKeyDown={(e) => e.key === "Enter" && verify()} />
|
||||
<Btn icon="check" onClick={verify}>Reveal</Btn>
|
||||
<Btn icon="check" onClick={verify} disabled={busy || !house.trim()}>{busy ? "Verifying…" : "Reveal"}</Btn>
|
||||
</div>
|
||||
{err && <div className="ds-field-err"><Icon name="alert" size={12} /> {err}</div>}
|
||||
</div>
|
||||
@@ -164,7 +196,7 @@ function PersonalInfoTab() {
|
||||
<div className="kv" key={f.key}>
|
||||
<dt>{f.label}</dt>
|
||||
<dd className={verified ? "kv-edit" : "masked"}>
|
||||
{verified ? f.full : f.masked}
|
||||
{f.value}
|
||||
{verified && (
|
||||
<button className="kv-edit-btn" aria-label={`Edit ${f.label}`} onClick={() => setChange(f.key)}><Icon name="edit" size={13} /></button>
|
||||
)}
|
||||
@@ -188,64 +220,82 @@ function PersonalInfoTab() {
|
||||
: <Pill tone="muted"><Icon name="lock" size={12} /> Protected</Pill>}
|
||||
</div>
|
||||
<dl className="kv-list">
|
||||
<div className="kv"><dt>Full name</dt><dd>{user.name}</dd></div>
|
||||
<div className="kv"><dt>Role</dt><dd>{user.role}</dd></div>
|
||||
<div className="kv"><dt>Member since</dt><dd>{user.memberSince}</dd></div>
|
||||
<div className="kv"><dt>Account status</dt><dd><Pill tone="green"><StatusDot status="online" /> Active</Pill></dd></div>
|
||||
<div className="kv"><dt>Full name</dt><dd>{account.name}</dd></div>
|
||||
<div className="kv"><dt>Role</dt><dd>{account.role}</dd></div>
|
||||
{account.allotmentNo && <div className="kv"><dt>Allotment no.</dt><dd>{account.allotmentNo}</dd></div>}
|
||||
<div className="kv"><dt>Member since</dt><dd>{account.memberSince}</dd></div>
|
||||
<div className="kv"><dt>Account status</dt><dd><Pill tone={account.status === "active" ? "green" : "red"}><StatusDot status={account.status === "active" ? "online" : "offline"} /> {account.status === "active" ? "Active" : "Suspended"}</Pill></dd></div>
|
||||
<div className="kv">
|
||||
<dt>PAN</dt>
|
||||
<dd className={verified ? "kv-edit" : "masked"}>{verified ? user.pan.full : user.pan.masked}{verified && <span className="kv-lock"><Icon name="lock" size={12} /> via KYC</span>}</dd>
|
||||
<dd className={verified ? "kv-edit" : "masked"}>{account.pan}{verified && <span className="kv-lock"><Icon name="lock" size={12} /> via KYC</span>}</dd>
|
||||
</div>
|
||||
<div className="kv">
|
||||
<dt>Aadhaar</dt>
|
||||
<dd className={verified ? "kv-edit" : "masked"}>{verified ? user.aadhaar.full : user.aadhaar.masked}{verified && <span className="kv-lock"><Icon name="lock" size={12} /> via KYC</span>}</dd>
|
||||
<dd className={verified ? "kv-edit" : "masked"}>{account.aadhaar}{verified && <span className="kv-lock"><Icon name="lock" size={12} /> via KYC</span>}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
<p className="muted-note"><Icon name="info" size={13} /> PAN & Aadhaar are managed under the KYC tab and can't be edited here.</p>
|
||||
</div>
|
||||
|
||||
<ChangeContactModal
|
||||
kind={change}
|
||||
current={change ? contacts[change] : ""}
|
||||
onClose={() => setChange(null)}
|
||||
onSave={(kind, value) => setContacts((c) => ({ ...c, [kind]: value }))}
|
||||
/>
|
||||
<ChangeContactModal p={p} kind={change} onClose={() => setChange(null)} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const CONTACT_LABEL: Record<ContactKind, string> = { email: "email", mobile: "mobile", whatsapp: "WhatsApp number" };
|
||||
|
||||
// OTP-to-registered-mobile flow for changing a contact field. On confirm the
|
||||
// new value is saved back so the Personal Info card updates live.
|
||||
function ChangeContactModal({ kind, current, onClose, onSave }: {
|
||||
kind: null | ContactKind; current: string; onClose: () => void; onSave: (kind: ContactKind, value: string) => void;
|
||||
}) {
|
||||
// OTP-to-registered-mobile flow for changing a contact field. The one-time code
|
||||
// is always sent to the registered mobile (never the new destination), then the
|
||||
// new value is persisted only after the code verifies.
|
||||
function ChangeContactModal({ p, kind, onClose }: { p: ProfileData; kind: null | ContactKind; onClose: () => void }) {
|
||||
const { push } = useToast();
|
||||
const [step, setStep] = useState<"enter" | "otp">("enter");
|
||||
const [val, setVal] = useState("");
|
||||
const [otp, setOtp] = useState("");
|
||||
const [challengeId, setChallengeId] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
// prefill with the current value whenever a new field is opened
|
||||
useEffect(() => {
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||
if (kind) { setStep("enter"); setVal(current); setOtp(""); }
|
||||
}, [kind, current]);
|
||||
if (kind) { setStep("enter"); setVal(""); setOtp(""); setChallengeId(""); setBusy(false); }
|
||||
}, [kind]);
|
||||
|
||||
function close() { setStep("enter"); setVal(""); setOtp(""); onClose(); }
|
||||
|
||||
const isEmail = kind === "email";
|
||||
const label = kind ? CONTACT_LABEL[kind] : "";
|
||||
|
||||
async function sendCode() {
|
||||
if (!kind) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
const id = await p.requestContactChangeOtp(kind, val.trim());
|
||||
setChallengeId(id); setStep("otp");
|
||||
push({ tone: "info", title: "Code sent", desc: "A one-time code was sent to your registered mobile." });
|
||||
} catch (e) { push({ tone: "error", title: "Couldn't send code", desc: errText(e) }); }
|
||||
finally { setBusy(false); }
|
||||
}
|
||||
async function confirm() {
|
||||
if (!kind) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await p.changeContact(kind, val.trim(), challengeId, otp);
|
||||
push({ tone: "success", title: `${label[0].toUpperCase()}${label.slice(1)} updated`, desc: "Your change has been confirmed." });
|
||||
close();
|
||||
} catch (e) { push({ tone: "error", title: "Couldn't confirm", desc: errText(e) }); }
|
||||
finally { setBusy(false); }
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
open={kind != null} onClose={close}
|
||||
icon={isEmail ? "mail" : kind === "whatsapp" ? "chat" : "phone"}
|
||||
title={`Change ${label}`}
|
||||
subtitle={step === "enter" ? "We'll send a code to your registered mobile to confirm." : `Enter the 6-digit code sent to ${user.mobile.masked}`}
|
||||
subtitle={step === "enter" ? "We'll send a code to your registered mobile to confirm." : "Enter the 6-digit code sent to your registered mobile."}
|
||||
footer={
|
||||
step === "enter"
|
||||
? <><Btn variant="ghost" onClick={close}>Cancel</Btn><Btn icon="send" disabled={!val.trim() || val.trim() === current} onClick={() => { setStep("otp"); push({ tone: "info", title: "Code sent", desc: `OTP sent to your registered mobile ${user.mobile.masked}.` }); }}>Send code</Btn></>
|
||||
: <><Btn variant="ghost" onClick={() => setStep("enter")}>Back</Btn><Btn icon="check" disabled={otp.length < 6} onClick={() => { if (kind) onSave(kind, val.trim()); push({ tone: "success", title: `${label[0].toUpperCase()}${label.slice(1)} updated`, desc: "Your change has been confirmed." }); close(); }}>Confirm</Btn></>
|
||||
? <><Btn variant="ghost" onClick={close}>Cancel</Btn><Btn icon="send" disabled={busy || !val.trim()} onClick={sendCode}>{busy ? "Sending…" : "Send code"}</Btn></>
|
||||
: <><Btn variant="ghost" onClick={() => setStep("enter")}>Back</Btn><Btn icon="check" disabled={busy || otp.length < 6} onClick={confirm}>{busy ? "Confirming…" : "Confirm"}</Btn></>
|
||||
}
|
||||
>
|
||||
{step === "enter" ? (
|
||||
@@ -255,7 +305,7 @@ function ChangeContactModal({ kind, current, onClose, onSave }: {
|
||||
) : (
|
||||
<div className="otp-wrap">
|
||||
<OtpField value={otp} onChange={setOtp} />
|
||||
<button className="link-inline" onClick={() => push({ tone: "info", title: "Code resent" })}>Resend code</button>
|
||||
<button className="link-inline" onClick={sendCode} disabled={busy}>Resend code</button>
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
@@ -266,54 +316,52 @@ function ChangeContactModal({ kind, current, onClose, onSave }: {
|
||||
/* Tab: KYC — inline upload, ID≠address, photo mandatory, % */
|
||||
/* ============================================================ */
|
||||
|
||||
function KycTab() {
|
||||
function KycTab({ p }: { p: ProfileData }) {
|
||||
const { push } = useToast();
|
||||
const [slots, setSlots] = useState<KycSlot[]>(kycSeed.slots);
|
||||
const { slots, docTypes, completionPct } = p.kyc;
|
||||
// Doc type chosen for a slot but not yet uploaded (be-crm only persists it on upload).
|
||||
const [pending, setPending] = useState<Partial<Record<KycKey, string>>>({});
|
||||
|
||||
const idDoc = slots.find((s) => s.key === "id")?.docId ?? null;
|
||||
const addrDoc = slots.find((s) => s.key === "address")?.docId ?? null;
|
||||
const docIdFor = (key: KycKey) => pending[key] ?? slots.find((s) => s.key === key)?.docId ?? null;
|
||||
const idDoc = docIdFor("id");
|
||||
const addrDoc = docIdFor("address");
|
||||
|
||||
const completion = useMemo(() => {
|
||||
const done = slots.filter((s) => s.status === "verified" || s.status === "uploaded").length;
|
||||
return Math.round((done / slots.length) * 100);
|
||||
}, [slots]);
|
||||
|
||||
function options(key: KycSlot["key"]) {
|
||||
function options(key: KycKey) {
|
||||
const want = key === "id" ? ["id", "any"] : key === "address" ? ["address", "any"] : [];
|
||||
return kycDocTypes.filter((d) => want.includes(d.use));
|
||||
return docTypes.filter((d) => want.includes(d.use));
|
||||
}
|
||||
|
||||
function pickDoc(key: KycSlot["key"], docId: string) {
|
||||
// enforce two-different-documents rule between ID and address
|
||||
function pickDoc(key: KycKey, docId: string) {
|
||||
if (key === "id" && docId === addrDoc) { push({ tone: "error", title: "Pick a different document", desc: "Identity and address proofs must be two different documents." }); return; }
|
||||
if (key === "address" && docId === idDoc) { push({ tone: "error", title: "Pick a different document", desc: "Address and identity proofs must be two different documents." }); return; }
|
||||
setSlots((s) => s.map((x) => x.key === key ? { ...x, docId } : x));
|
||||
setPending((s) => ({ ...s, [key]: docId }));
|
||||
}
|
||||
async function upload(key: KycKey, file: File) {
|
||||
const docId = key === "photo" ? null : docIdFor(key);
|
||||
if (key !== "photo" && !docId) { push({ tone: "error", title: "Select a document type first" }); return; }
|
||||
try {
|
||||
await p.uploadKyc(key, docId, await readFileAsUpload(file));
|
||||
setPending((s) => { const n = { ...s }; delete n[key]; return n; });
|
||||
push({ tone: "success", title: "Uploaded", desc: "Your document is queued for review." });
|
||||
} catch (e) { push({ tone: "error", title: "Upload failed", desc: errText(e) }); }
|
||||
}
|
||||
async function remove(key: KycKey) {
|
||||
try { await p.removeKyc(key); push({ tone: "info", title: "Removed" }); }
|
||||
catch (e) { push({ tone: "error", title: "Couldn't remove", desc: errText(e) }); }
|
||||
}
|
||||
|
||||
function upload(key: KycSlot["key"]) {
|
||||
const slot = slots.find((s) => s.key === key)!;
|
||||
if (key !== "photo" && !slot.docId) { push({ tone: "error", title: "Select a document type first" }); return; }
|
||||
const name = key === "photo" ? "selfie.jpg" : `${slot.docId}_upload.pdf`;
|
||||
setSlots((s) => s.map((x) => x.key === key ? { ...x, fileName: name, status: "uploaded", note: "Under review" } : x));
|
||||
push({ tone: "success", title: "Uploaded", desc: "Your document is queued for review." });
|
||||
}
|
||||
|
||||
function remove(key: KycSlot["key"]) {
|
||||
setSlots((s) => s.map((x) => x.key === key ? { ...x, fileName: null, docId: key === "photo" ? null : x.docId, status: "missing", note: undefined } : x));
|
||||
}
|
||||
|
||||
const photoDone = slots.find((s) => s.key === "photo")!.status !== "missing";
|
||||
const photoDone = (slots.find((s) => s.key === "photo")?.status ?? "missing") !== "missing";
|
||||
const docLabel = (id: string | null) => docTypes.find((d) => d.id === id)?.label ?? "Not chosen";
|
||||
|
||||
return (
|
||||
<div className="grid-side">
|
||||
<div className="card">
|
||||
<div className="card-head">
|
||||
<h3>Verification documents</h3>
|
||||
<Pill tone="orange">{completion}% complete</Pill>
|
||||
<Pill tone="orange">{completionPct}% complete</Pill>
|
||||
</div>
|
||||
|
||||
<div className="kyc-progress">
|
||||
<div className="kyc-progress-bar"><span style={{ width: `${completion}%` }} /></div>
|
||||
<div className="kyc-progress-bar"><span style={{ width: `${completionPct}%` }} /></div>
|
||||
<div className="kyc-progress-legend">
|
||||
{slots.map((s) => (
|
||||
<span key={s.key} className={`kyc-leg ${s.status}`}>
|
||||
@@ -327,7 +375,8 @@ function KycTab() {
|
||||
|
||||
<div className="kyc-slots">
|
||||
{slots.map((slot) => (
|
||||
<KycSlotRow key={slot.key} slot={slot} options={options(slot.key)} onPick={(d) => pickDoc(slot.key, d)} onUpload={() => upload(slot.key)} onRemove={() => remove(slot.key)} />
|
||||
<KycSlotRow key={slot.key} slot={slot} docId={docIdFor(slot.key)} docTypes={docTypes} options={options(slot.key)}
|
||||
onPick={(d) => pickDoc(slot.key, d)} onUpload={(f) => upload(slot.key, f)} onRemove={() => remove(slot.key)} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
@@ -343,19 +392,22 @@ function KycTab() {
|
||||
</ul>
|
||||
<div className="kyc-doc-pairs">
|
||||
<div className="muted-note"><Icon name="info" size={13} /> Current selection</div>
|
||||
<div className="pair-row"><span>Identity</span><Pill tone="blue">{kycDocTypes.find((d) => d.id === idDoc)?.label ?? "Not chosen"}</Pill></div>
|
||||
<div className="pair-row"><span>Address</span><Pill tone="purple">{kycDocTypes.find((d) => d.id === addrDoc)?.label ?? "Not chosen"}</Pill></div>
|
||||
<div className="pair-row"><span>Identity</span><Pill tone="blue">{docLabel(idDoc)}</Pill></div>
|
||||
<div className="pair-row"><span>Address</span><Pill tone="purple">{docLabel(addrDoc)}</Pill></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function KycSlotRow({ slot, options, onPick, onUpload, onRemove }: {
|
||||
slot: KycSlot; options: typeof kycDocTypes; onPick: (d: string) => void; onUpload: () => void; onRemove: () => void;
|
||||
function KycSlotRow({ slot, docId, docTypes, options, onPick, onUpload, onRemove }: {
|
||||
slot: UiKycSlot; docId: string | null; docTypes: { id: string; label: string; hint: string; formats: string; maxMb: number }[];
|
||||
options: { id: string; label: string }[]; onPick: (d: string) => void; onUpload: (f: File) => void; onRemove: () => void;
|
||||
}) {
|
||||
const fileRef = useRef<HTMLInputElement>(null);
|
||||
const tone = slot.status === "verified" ? "green" : slot.status === "uploaded" ? "blue" : slot.status === "rejected" ? "red" : "muted";
|
||||
const docMeta = kycDocTypes.find((d) => d.id === slot.docId);
|
||||
const docMeta = docTypes.find((d) => d.id === docId);
|
||||
const accept = slot.key === "photo" ? "image/*" : "application/pdf,image/jpeg,image/png";
|
||||
return (
|
||||
<div className={`kyc-slot status-${slot.status}`}>
|
||||
<div className="kyc-slot-ic"><Icon name={slot.key === "photo" ? "camera" : slot.key === "id" ? "user" : "pin"} size={18} /></div>
|
||||
@@ -366,23 +418,27 @@ function KycSlotRow({ slot, options, onPick, onUpload, onRemove }: {
|
||||
</div>
|
||||
|
||||
{slot.key !== "photo" && (
|
||||
<select className="ds-select" value={slot.docId ?? ""} onChange={(e) => onPick(e.target.value)}>
|
||||
<select className="ds-select" value={docId ?? ""} onChange={(e) => onPick(e.target.value)}>
|
||||
<option value="" disabled>Select document type…</option>
|
||||
{options.map((o) => <option key={o.id} value={o.id}>{o.label}</option>)}
|
||||
</select>
|
||||
)}
|
||||
|
||||
{docMeta && <div className="kyc-slot-hint">{docMeta.hint} · {docMeta.formats} · ≤ {docMeta.maxMb} MB</div>}
|
||||
{docMeta && <div className="kyc-slot-hint">{docMeta.hint ? `${docMeta.hint} · ` : ""}{docMeta.formats} · ≤ {docMeta.maxMb} MB</div>}
|
||||
{slot.status === "rejected" && slot.note && <div className="ds-field-err"><Icon name="alert" size={12} /> {slot.note}</div>}
|
||||
|
||||
<input ref={fileRef} type="file" accept={accept} hidden
|
||||
onChange={(e) => { const f = e.target.files?.[0]; if (f) onUpload(f); e.target.value = ""; }} />
|
||||
|
||||
{slot.fileName ? (
|
||||
<div className="kyc-file">
|
||||
<Icon name="paperclip" size={14} />
|
||||
<span className="kyc-file-name">{slot.fileName}</span>
|
||||
{slot.note && <span className="kyc-file-note">{slot.note}</span>}
|
||||
{slot.note && slot.status !== "rejected" && <span className="kyc-file-note">{slot.note}</span>}
|
||||
<button className="ds-iconbtn sm" aria-label="Remove" onClick={onRemove}><Icon name="trash" size={14} /></button>
|
||||
</div>
|
||||
) : (
|
||||
<button className="kyc-drop" onClick={onUpload}>
|
||||
<button className="kyc-drop" onClick={() => fileRef.current?.click()}>
|
||||
<Icon name="upload" size={16} /> Click to upload {slot.key === "photo" ? "a photo" : "document"}
|
||||
</button>
|
||||
)}
|
||||
@@ -392,7 +448,7 @@ function KycSlotRow({ slot, options, onPick, onUpload, onRemove }: {
|
||||
}
|
||||
|
||||
/* ============================================================ */
|
||||
/* Tab: Security */
|
||||
/* Tab: Security (Shell-owned — local mock) */
|
||||
/* ============================================================ */
|
||||
|
||||
function SecurityTab() {
|
||||
@@ -478,24 +534,29 @@ function SettingRow({ icon, title, desc, children }: { icon: string; title: stri
|
||||
/* Tab: Notifications */
|
||||
/* ============================================================ */
|
||||
|
||||
function NotificationsTab() {
|
||||
function NotificationsTab({ p }: { p: ProfileData }) {
|
||||
const { push } = useToast();
|
||||
const [prefs, setPrefs] = useState<NotifCategory[]>(contactPrefs);
|
||||
const [tz, setTz] = useState(contactTimezones[0]);
|
||||
const [times, setTimes] = useState(contactTimes);
|
||||
const channels: { key: keyof NotifCategory; label: string; icon: string }[] = [
|
||||
const { prefs, timezone, timezoneOptions, windows, destinations } = p.notifications;
|
||||
const [addOpen, setAddOpen] = useState(false);
|
||||
const [verifyId, setVerifyId] = useState<string | null>(null);
|
||||
const channels: { key: NotifChannel; label: string; icon: string }[] = [
|
||||
{ key: "email", label: "Email", icon: "mail" },
|
||||
{ key: "sms", label: "SMS", icon: "phone" },
|
||||
{ key: "whatsapp", label: "WhatsApp", icon: "chat" },
|
||||
{ key: "push", label: "Push", icon: "bell" },
|
||||
];
|
||||
|
||||
function toggle(catId: string, ch: keyof NotifCategory) {
|
||||
setPrefs((p) => p.map((c) => {
|
||||
if (c.id !== catId) return c;
|
||||
if (c.locked) { push({ tone: "info", title: "Required notifications", desc: "Security alerts can't be turned off." }); return c; }
|
||||
return { ...c, [ch]: !c[ch] } as NotifCategory;
|
||||
}));
|
||||
async function toggle(cat: (typeof prefs)[number], ch: NotifChannel) {
|
||||
if (cat.locked) { push({ tone: "info", title: "Required notifications", desc: "Security alerts can't be turned off." }); return; }
|
||||
try { await p.setPreference(cat.id, ch, !cat[ch]); }
|
||||
catch (e) { push({ tone: "error", title: "Couldn't save", desc: errText(e) }); }
|
||||
}
|
||||
async function toggleWindow(w: (typeof windows)[number]) {
|
||||
try { await p.setContactWindow(w.label, { startTime: w.startTime, endTime: w.endTime, enabled: !w.enabled }); }
|
||||
catch (e) { push({ tone: "error", title: "Couldn't save", desc: errText(e) }); }
|
||||
}
|
||||
async function changeTz(tz: string) {
|
||||
try { await p.setTimezone(tz); } catch (e) { push({ tone: "error", title: "Couldn't save", desc: errText(e) }); }
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -515,7 +576,7 @@ function NotificationsTab() {
|
||||
</span>
|
||||
{channels.map((c) => (
|
||||
<span key={c.key} className="notif-ch">
|
||||
<Toggle checked={Boolean(cat[c.key])} disabled={cat.locked} onChange={() => toggle(cat.id, c.key)} label={`${cat.label} ${c.label}`} />
|
||||
<Toggle checked={Boolean(cat[c.key])} disabled={cat.locked} onChange={() => toggle(cat, c.key)} label={`${cat.label} ${c.label}`} />
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
@@ -527,13 +588,13 @@ function NotificationsTab() {
|
||||
<div className="card">
|
||||
<div className="card-head"><h3>Contact-time window</h3></div>
|
||||
<Field label="Timezone">
|
||||
<select className="ds-select" value={tz} onChange={(e) => setTz(e.target.value)}>
|
||||
{contactTimezones.map((t) => <option key={t} value={t}>{t}</option>)}
|
||||
<select className="ds-select" value={timezone} onChange={(e) => changeTz(e.target.value)}>
|
||||
{timezoneOptions.map((t) => <option key={t} value={t}>{t}</option>)}
|
||||
</select>
|
||||
</Field>
|
||||
<div className="time-windows">
|
||||
{times.map((t) => (
|
||||
<button key={t.id} className={`time-win ${t.enabled ? "on" : ""}`} onClick={() => setTimes((s) => s.map((x) => x.id === t.id ? { ...x, enabled: !x.enabled } : x))}>
|
||||
{windows.map((t) => (
|
||||
<button key={t.label} className={`time-win ${t.enabled ? "on" : ""}`} onClick={() => toggleWindow(t)}>
|
||||
<Icon name={t.enabled ? "check-circle" : "clock"} size={15} />
|
||||
<span className="tw-label">{t.label}</span>
|
||||
<span className="tw-range">{t.range}</span>
|
||||
@@ -546,76 +607,155 @@ function NotificationsTab() {
|
||||
<div className="card">
|
||||
<div className="card-head"><h3>Destinations</h3></div>
|
||||
<div className="dest-list">
|
||||
{contactDestinations.map((d) => (
|
||||
{destinations.length === 0 && <p className="muted-note"><Icon name="info" size={13} /> No extra destinations yet.</p>}
|
||||
{destinations.map((d) => (
|
||||
<div className="dest-row" key={d.id}>
|
||||
<span className="dest-ic"><Icon name={d.channel === "email" ? "mail" : d.channel === "sms" ? "phone" : "chat"} size={15} /></span>
|
||||
<div className="dest-txt"><div className="dest-label">{d.label}{d.primary && <Pill tone="orange">Primary</Pill>}</div><div className="dest-val">{d.value}</div></div>
|
||||
{d.verified ? <Pill tone="green"><Icon name="check" size={12} /> Verified</Pill> : <Btn variant="outline" size="sm" onClick={() => push({ tone: "info", title: "Verification sent" })}>Verify</Btn>}
|
||||
{d.verified ? <Pill tone="green"><Icon name="check" size={12} /> Verified</Pill> : <Btn variant="outline" size="sm" onClick={() => setVerifyId(d.id)}>Verify</Btn>}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<Btn variant="ghost" icon="plus" onClick={() => push({ tone: "info", title: "Add destination" })}>Add destination</Btn>
|
||||
<Btn variant="ghost" icon="plus" onClick={() => setAddOpen(true)}>Add destination</Btn>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<AddDestinationModal p={p} open={addOpen} onClose={() => setAddOpen(false)} />
|
||||
<VerifyDestinationModal p={p} id={verifyId} onClose={() => setVerifyId(null)} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function AddDestinationModal({ p, open, onClose }: { p: ProfileData; open: boolean; onClose: () => void }) {
|
||||
const { push } = useToast();
|
||||
const [channel, setChannel] = useState<"email" | "sms" | "whatsapp">("email");
|
||||
const [label, setLabel] = useState("");
|
||||
const [value, setValue] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
useEffect(() => {
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||
if (open) { setChannel("email"); setLabel(""); setValue(""); setBusy(false); }
|
||||
}, [open]);
|
||||
|
||||
async function save() {
|
||||
setBusy(true);
|
||||
try {
|
||||
await p.addDestination(channel, label.trim() || channel, value.trim());
|
||||
push({ tone: "success", title: "Destination added", desc: "Verify it to start receiving messages there." });
|
||||
onClose();
|
||||
} catch (e) { push({ tone: "error", title: "Couldn't add", desc: errText(e) }); }
|
||||
finally { setBusy(false); }
|
||||
}
|
||||
const isEmail = channel === "email";
|
||||
return (
|
||||
<Modal open={open} onClose={onClose} icon="plus" title="Add a destination"
|
||||
subtitle="Add another address or number, then verify it with a one-time code."
|
||||
footer={<><Btn variant="ghost" onClick={onClose}>Cancel</Btn><Btn icon="check" disabled={busy || !value.trim()} onClick={save}>{busy ? "Adding…" : "Add destination"}</Btn></>}
|
||||
>
|
||||
<Field label="Channel">
|
||||
<select className="ds-select" value={channel} onChange={(e) => setChannel(e.target.value as "email" | "sms" | "whatsapp")}>
|
||||
<option value="email">Email</option>
|
||||
<option value="sms">SMS</option>
|
||||
<option value="whatsapp">WhatsApp</option>
|
||||
</select>
|
||||
</Field>
|
||||
<Field label="Label" hint="A name to recognise this destination.">
|
||||
<input className="ds-input" placeholder={isEmail ? "Work email" : "Alternate mobile"} value={label} onChange={(e) => setLabel(e.target.value)} />
|
||||
</Field>
|
||||
<Field label={isEmail ? "Email address" : "Phone number"}>
|
||||
<input className="ds-input" type={isEmail ? "email" : "tel"} placeholder={isEmail ? "you@example.com" : "+91 90000 00000"} value={value} onChange={(e) => setValue(e.target.value)} />
|
||||
</Field>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
function VerifyDestinationModal({ p, id, onClose }: { p: ProfileData; id: string | null; onClose: () => void }) {
|
||||
const { push } = useToast();
|
||||
const [otp, setOtp] = useState("");
|
||||
const [challengeId, setChallengeId] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [sent, setSent] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!id) return;
|
||||
let cancelled = false;
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||
setOtp(""); setChallengeId(""); setSent(false); setBusy(true);
|
||||
p.requestDestinationOtp(id)
|
||||
.then((cid) => { if (!cancelled) { setChallengeId(cid); setSent(true); } })
|
||||
.catch((e) => { if (!cancelled) push({ tone: "error", title: "Couldn't send code", desc: errText(e) }); })
|
||||
.finally(() => { if (!cancelled) setBusy(false); });
|
||||
return () => { cancelled = true; };
|
||||
}, [id, p, push]);
|
||||
|
||||
async function confirm() {
|
||||
if (!id) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await p.verifyDestination(id, challengeId, otp);
|
||||
push({ tone: "success", title: "Destination verified" });
|
||||
onClose();
|
||||
} catch (e) { push({ tone: "error", title: "Couldn't verify", desc: errText(e) }); }
|
||||
finally { setBusy(false); }
|
||||
}
|
||||
return (
|
||||
<Modal open={id != null} onClose={onClose} icon="shield-check" title="Verify destination"
|
||||
subtitle="Enter the 6-digit code sent to your registered mobile."
|
||||
footer={<><Btn variant="ghost" onClick={onClose}>Cancel</Btn><Btn icon="check" disabled={busy || otp.length < 6} onClick={confirm}>{busy ? "Verifying…" : "Verify"}</Btn></>}
|
||||
>
|
||||
<div className="otp-wrap">
|
||||
<OtpField value={otp} onChange={setOtp} />
|
||||
<span className="muted-note">{sent ? "A code was sent to your registered mobile." : "Sending a code…"}</span>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
/* ============================================================ */
|
||||
/* Tab: Privacy & Consent */
|
||||
/* ============================================================ */
|
||||
|
||||
function PrivacyTab() {
|
||||
function PrivacyTab({ p }: { p: ProfileData }) {
|
||||
const { push } = useToast();
|
||||
const [groups, setGroups] = useState<ConsentGroup[]>(consentGroups);
|
||||
|
||||
function toggle(gid: string, iid: string) {
|
||||
setGroups((gs) => gs.map((g) => g.id !== gid ? g : {
|
||||
...g,
|
||||
items: g.items.map((it) => {
|
||||
if (it.id !== iid) return it;
|
||||
if (it.locked) { push({ tone: "info", title: "Required consent", desc: "Statutory consents can't be withdrawn while active." }); return it; }
|
||||
return { ...it, granted: !it.granted };
|
||||
}),
|
||||
}));
|
||||
async function toggle(gid: string, iid: string, locked: boolean, granted: boolean) {
|
||||
if (locked) { push({ tone: "info", title: "Required consent", desc: "Statutory consents can't be withdrawn while active." }); return; }
|
||||
try { await p.setConsent(gid, iid, !granted); }
|
||||
catch (e) { push({ tone: "error", title: "Couldn't save", desc: errText(e) }); }
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="consent-cols">
|
||||
{groups.map((g) => (
|
||||
<div className="card" key={g.id}>
|
||||
<div className="card-head">
|
||||
<h3>{g.title}</h3>
|
||||
{g.id === "marketing" && <Pill tone="muted">Optional</Pill>}
|
||||
{g.id === "essential" && <Pill tone="red"><Icon name="lock" size={12} /> Required</Pill>}
|
||||
</div>
|
||||
<div className="consent-list">
|
||||
{g.items.map((it) => (
|
||||
<div className={`consent-item ${it.locked ? "locked" : ""}`} key={it.id}>
|
||||
<div className="consent-txt">
|
||||
<div className="consent-label">{it.label}{it.locked && <Icon name="lock" size={12} className="lock-ic" />}</div>
|
||||
<div className="consent-desc">{it.desc}</div>
|
||||
{p.consent.map((g) => {
|
||||
const required = g.items.some((it) => it.locked);
|
||||
return (
|
||||
<div className="card" key={g.id}>
|
||||
<div className="card-head">
|
||||
<h3>{g.title}</h3>
|
||||
{required
|
||||
? <Pill tone="red"><Icon name="lock" size={12} /> Required</Pill>
|
||||
: <Pill tone="muted">Optional</Pill>}
|
||||
</div>
|
||||
<div className="consent-list">
|
||||
{g.items.map((it) => (
|
||||
<div className={`consent-item ${it.locked ? "locked" : ""}`} key={it.id}>
|
||||
<div className="consent-txt">
|
||||
<div className="consent-label">{it.label}{it.locked && <Icon name="lock" size={12} className="lock-ic" />}</div>
|
||||
{it.desc && <div className="consent-desc">{it.desc}</div>}
|
||||
</div>
|
||||
<Toggle checked={it.granted} disabled={it.locked} onChange={() => toggle(g.id, it.id, it.locked, it.granted)} label={it.label} />
|
||||
</div>
|
||||
<Toggle checked={it.granted} disabled={it.locked} onChange={() => toggle(g.id, it.id)} label={it.label} />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
{g.id === "marketing" && groups.find((x) => x.id === "marketing")!.items.find((i) => i.id === "promos")!.granted && (
|
||||
<div className="consent-sub">
|
||||
<div className="muted-note">Promotional sub-preferences</div>
|
||||
{["Product offers", "Surveys & feedback", "Partner news"].map((s, i) => (
|
||||
<label className="consent-sub-row" key={s}><span>{s}</span><Toggle checked={i === 0} onChange={() => {}} label={s} /></label>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/* ============================================================ */
|
||||
/* Tab: Devices */
|
||||
/* Tab: Devices (Shell-owned — local mock) */
|
||||
/* ============================================================ */
|
||||
|
||||
function DevicesTab() {
|
||||
|
||||
Reference in New Issue
Block a user