Backend modules from tastefully 8bd93d15: core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log, services-email. solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal from tastefully 8bd93d15. Copied as tracked files only. Literal secrets replaced with environment placeholders: - services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY, MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default) - services-system: JUMIO_TOKEN, JUMIO_SECRET (optional) - services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed - core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default removed, ipgeolocation key read from IPGEOLOCATION_API_KEY - services-system EkycAppConfig: commented Jumio credentials removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
166 lines
6.7 KiB
TypeScript
166 lines
6.7 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useRef, useState } from "react";
|
|
import { AnimatePresence, motion } from "framer-motion";
|
|
import { CalendarDays } from "lucide-react";
|
|
import { useTheme } from "@/app/lib/ThemeContext";
|
|
|
|
const MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
const WEEKDAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
const STEP_WORD = ["year", "month", "day"];
|
|
|
|
// Parse "YYYY-MM-DD" by splitting (no timezone shifts); month is 0-based.
|
|
const parse = (iso: string) => {
|
|
const [y, m, d] = iso.split("-").map(Number);
|
|
return y && m && d ? { y, m: m - 1, d } : null;
|
|
};
|
|
const pad = (n: number) => String(n).padStart(2, "0");
|
|
|
|
export default function DobPicker({ value, onChange, id }: { value: string; onChange: (iso: string) => void; id?: string }) {
|
|
const { isDark } = useTheme();
|
|
const fieldRef = useRef<HTMLButtonElement>(null);
|
|
const [open, setOpen] = useState(false);
|
|
const [step, setStep] = useState(0);
|
|
const [year, setYear] = useState(0);
|
|
const [month, setMonth] = useState(0);
|
|
|
|
const cur = parse(value);
|
|
const now = new Date();
|
|
const cutY = now.getFullYear() - 18;
|
|
const cutM = now.getMonth();
|
|
const cutD = now.getDate();
|
|
const minY = now.getFullYear() - 107;
|
|
const years = Array.from({ length: cutY - minY + 1 }, (_, i) => cutY - i);
|
|
|
|
const text = isDark ? "#FFFFFF" : "#1a1a1a";
|
|
const sheetBg = isDark ? "#1c1c1e" : "#FFFFFF";
|
|
const border = isDark ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.1)";
|
|
const field = { background: isDark ? "rgba(255,255,255,0.04)" : "#FAFAFA", border: `1px solid ${border}`, color: text };
|
|
|
|
const wasOpen = useRef(false);
|
|
useEffect(() => {
|
|
if (wasOpen.current && !open) fieldRef.current?.focus();
|
|
wasOpen.current = open;
|
|
}, [open]);
|
|
|
|
const close = () => setOpen(false);
|
|
const start = () => {
|
|
setStep(0);
|
|
setOpen(true);
|
|
};
|
|
|
|
const choiceCls = "min-h-[48px] rounded-xl text-lg transition-colors disabled:opacity-30 disabled:cursor-not-allowed";
|
|
const choice = (label: string | number, selected: boolean, onClick: () => void, disabled = false, scrollTo = false) => (
|
|
<button
|
|
key={label}
|
|
type="button"
|
|
disabled={disabled}
|
|
onClick={onClick}
|
|
ref={scrollTo ? (el) => el?.scrollIntoView?.({ block: "center" }) : undefined}
|
|
className={`${choiceCls} ${selected ? "font-bold text-tastefullyOrangeText" : ""}`}
|
|
style={{ border: `${selected ? 2 : 1}px solid ${selected ? "#FF6B00" : border}`, color: selected ? "var(--orange-text)" : text }}
|
|
>
|
|
{label}
|
|
</button>
|
|
);
|
|
|
|
const first = new Date(year, month, 1).getDay();
|
|
const days = new Date(year, month + 1, 0).getDate();
|
|
const inCutoffMonth = year === cutY && month === cutM;
|
|
const selectedYear = cur?.y ?? 1970;
|
|
|
|
return (
|
|
<>
|
|
<button
|
|
ref={fieldRef}
|
|
id={id}
|
|
type="button"
|
|
aria-haspopup="dialog"
|
|
onClick={start}
|
|
className="w-full min-h-[48px] flex items-center justify-between text-left text-base outline-none rounded-xl px-3 py-2.5"
|
|
style={{ ...field, color: cur ? text : isDark ? "rgba(255,255,255,0.35)" : "#9A9A9A" }}
|
|
>
|
|
<span>{cur ? `${cur.d} ${MONTHS[cur.m]} ${cur.y}` : "Select your date of birth"}</span>
|
|
<CalendarDays strokeWidth={1.8} className="w-5 h-5 stroke-tastefullyOrange" aria-hidden="true" />
|
|
</button>
|
|
|
|
<AnimatePresence>
|
|
{open && (
|
|
<motion.div
|
|
className="fixed inset-0 z-[101] flex items-end sm:items-center justify-center bg-black/50"
|
|
initial={{ opacity: 0 }}
|
|
animate={{ opacity: 1 }}
|
|
exit={{ opacity: 0 }}
|
|
transition={{ duration: 0.15 }}
|
|
onClick={close}
|
|
>
|
|
<motion.div
|
|
role="dialog"
|
|
aria-modal="true"
|
|
aria-labelledby="dob-title"
|
|
tabIndex={-1}
|
|
ref={(el) => el?.focus()}
|
|
onClick={(e) => e.stopPropagation()}
|
|
onKeyDown={(e) => e.key === "Escape" && close()}
|
|
initial={{ y: 40 }}
|
|
animate={{ y: 0 }}
|
|
exit={{ y: 40 }}
|
|
transition={{ duration: 0.15 }}
|
|
className="w-full sm:max-w-md max-h-[90vh] flex flex-col rounded-t-2xl sm:rounded-2xl p-4 pb-[calc(1rem_+_env(safe-area-inset-bottom))] outline-none"
|
|
style={{ background: sheetBg, color: text }}
|
|
>
|
|
<h2 id="dob-title" className="text-xl font-bold mb-3">
|
|
Choose your birth {STEP_WORD[step]}
|
|
</h2>
|
|
|
|
<div className="overflow-y-auto">
|
|
{step === 0 && (
|
|
<div className="grid grid-cols-3 gap-2">
|
|
{years.map((y) =>
|
|
choice(y, y === cur?.y, () => { setYear(y); setStep(1); }, false, y === (year || selectedYear))
|
|
)}
|
|
</div>
|
|
)}
|
|
{step === 1 && (
|
|
<div className="grid grid-cols-3 gap-2">
|
|
{MONTHS.map((name, m) =>
|
|
choice(name, cur?.y === year && cur.m === m, () => { setMonth(m); setStep(2); }, year === cutY && m > cutM)
|
|
)}
|
|
</div>
|
|
)}
|
|
{step === 2 && (
|
|
<div className="grid grid-cols-7 gap-1.5">
|
|
{WEEKDAYS.map((w) => (
|
|
<div key={w} className="text-center text-lg font-semibold py-1" style={{ opacity: 0.6 }}>{w}</div>
|
|
))}
|
|
{Array.from({ length: first }, (_, i) => <div key={`b${i}`} />)}
|
|
{Array.from({ length: days }, (_, i) => i + 1).map((d) =>
|
|
choice(
|
|
d,
|
|
cur?.y === year && cur.m === month && cur.d === d,
|
|
() => { onChange(`${year}-${pad(month + 1)}-${pad(d)}`); close(); },
|
|
inCutoffMonth && d > cutD
|
|
)
|
|
)}
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
<div className="flex gap-3 mt-4">
|
|
{step > 0 && (
|
|
<button type="button" onClick={() => setStep(step - 1)} className="flex-1 min-h-[48px] rounded-xl text-lg font-semibold" style={{ border: `1px solid ${border}` }}>
|
|
Back
|
|
</button>
|
|
)}
|
|
<button type="button" onClick={close} className="flex-1 min-h-[48px] rounded-xl text-lg font-semibold" style={{ border: `1px solid ${border}` }}>
|
|
Cancel
|
|
</button>
|
|
</div>
|
|
</motion.div>
|
|
</motion.div>
|
|
)}
|
|
</AnimatePresence>
|
|
</>
|
|
);
|
|
}
|