Files
co-lite/solvway-customer-portal/app/reset-password/page.tsx
T
ngqileandClaude Opus 5.5 5ee51d1913 chore: copy kept Tastefully modules and portals into Co-Lite
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
2026-11-26 15:55:45 +08:00

166 lines
6.4 KiB
TypeScript

"use client";
import { useState } from "react";
import { motion, AnimatePresence } from "framer-motion";
import { useRouter } from "next/navigation";
import { ArrowRight, Loader2, CheckCircle2 } from "lucide-react";
import PasswordToggle from "@/app/components/ui/PasswordToggle";
import AuthShell from "@/app/components/auth/AuthShell";
import { apiPost, ApiError } from "@/app/lib/clientApi";
import { useMember } from "@/app/lib/MemberContext";
const base =
"w-full rounded-xl px-3.5 py-3 text-sm font-medium outline-none transition-all duration-200 placeholder:text-gray-500 dark:placeholder:text-white/60";
const fieldStyle = (focused: boolean, invalid = false): React.CSSProperties => ({
background: "var(--bg-primary)",
border: `1.5px solid ${invalid ? "rgba(239,68,68,0.7)" : focused ? "rgba(255,107,0,0.65)" : "var(--border-color)"}`,
boxShadow: focused && !invalid ? "0 0 0 3px rgba(255,107,0,0.1)" : "none",
color: "var(--text-primary)",
});
const stagger = { hidden: {}, visible: { transition: { staggerChildren: 0.07 } } };
const fadeUp = {
hidden: { opacity: 0, y: 12 },
visible: { opacity: 1, y: 0, transition: { type: "spring" as const, stiffness: 340, damping: 28 } },
};
const Label = ({ children }: { children: React.ReactNode }) => (
<p className="text-xs font-bold tracking-widest uppercase mb-1.5" style={{ color: "var(--text-muted)" }}>
{children}
</p>
);
export default function ResetPasswordPage() {
const router = useRouter();
const { refresh } = useMember();
const [newPassword, setNewPassword] = useState("");
const [confirm, setConfirm] = useState("");
const [showPw, setShowPw] = useState(false);
const [showConfirm, setShowConfirm] = useState(false);
const [focused, setFocused] = useState<string | null>(null);
const [loading, setLoading] = useState(false);
const [done, setDone] = useState(false);
const [mismatch, setMismatch] = useState(false);
const [error, setError] = useState<string | null>(null);
const valid = newPassword.trim() !== "" && confirm.trim() !== "";
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!valid) return;
if (newPassword !== confirm) {
setMismatch(true);
return;
}
setMismatch(false);
setError(null);
setLoading(true);
try {
await apiPost("/api/member/first-time-password", { newPassword, confirmPassword: confirm });
setDone(true);
await refresh();
setTimeout(() => router.replace("/"), 1000);
} catch (err) {
setLoading(false);
setError(err instanceof ApiError ? err.message : "Couldn't set your password. Please try again.");
}
};
return (
<AuthShell title="Set a New Password" subtitle="Create a password to secure your account">
<motion.form
variants={stagger}
initial="hidden"
animate="visible"
onSubmit={handleSubmit}
className="space-y-4"
>
{/* New password */}
<motion.div variants={fadeUp}>
<Label>New Password</Label>
<div className="relative">
<input
type={showPw ? "text" : "password"}
placeholder="Create a strong password"
value={newPassword}
onChange={(e) => setNewPassword(e.target.value)}
onFocus={() => setFocused("pw")}
onBlur={() => setFocused(null)}
className={`${base} pr-11`}
style={fieldStyle(focused === "pw")}
required
/>
<PasswordToggle shown={showPw} onToggle={() => setShowPw((s) => !s)} label="Password" />
</div>
</motion.div>
{/* Confirm */}
<motion.div variants={fadeUp}>
<Label>Confirm Password</Label>
<div className="relative">
<input
type={showConfirm ? "text" : "password"}
placeholder="Repeat your password"
value={confirm}
onChange={(e) => {
setConfirm(e.target.value);
setMismatch(false);
}}
onFocus={() => setFocused("cf")}
onBlur={() => setFocused(null)}
className={`${base} pr-11`}
style={fieldStyle(focused === "cf", mismatch)}
required
/>
<PasswordToggle shown={showConfirm} onToggle={() => setShowConfirm((s) => !s)} label="Confirm Password" />
</div>
{mismatch && (
<motion.p initial={{ opacity: 0, y: -4 }} animate={{ opacity: 1, y: 0 }} className="text-xs mt-1.5 text-red-400 font-medium">
Passwords don&apos;t match
</motion.p>
)}
</motion.div>
{/* Error */}
{error && (
<motion.p initial={{ opacity: 0, y: -4 }} animate={{ opacity: 1, y: 0 }} className="text-xs text-red-500 text-center font-medium">
{error}
</motion.p>
)}
{/* Submit */}
<motion.button
variants={fadeUp}
type="submit"
disabled={loading || done || !valid}
whileTap={valid ? { scale: 0.97 } : undefined}
transition={{ type: "spring", stiffness: 420, damping: 26 }}
className="w-full flex items-center justify-center gap-2 py-3.5 rounded-xl font-bold text-sm text-white"
style={{
background: done ? "linear-gradient(135deg,#22c55e,#16a34a)" : "linear-gradient(135deg,#C94D00,#A83F00)",
boxShadow: done ? "0 6px 20px rgba(34,197,94,0.4)" : "0 6px 20px rgba(255,107,0,0.45)",
opacity: loading || done || !valid ? 0.9 : 1,
cursor: !valid ? "not-allowed" : "pointer",
}}
>
<AnimatePresence mode="wait">
{loading ? (
<motion.div key="l" animate={{ rotate: 360 }} transition={{ repeat: Infinity, duration: 0.8, ease: "linear" }}>
<Loader2 strokeWidth={2} className="w-4 h-4" />
</motion.div>
) : done ? (
<motion.span key="d" className="flex items-center gap-2">
<CheckCircle2 strokeWidth={2} className="w-4 h-4" /> Password Set
</motion.span>
) : (
<motion.span key="s" className="flex items-center gap-2">
Set Password <ArrowRight strokeWidth={2} className="w-4 h-4" />
</motion.span>
)}
</AnimatePresence>
</motion.button>
</motion.form>
</AuthShell>
);
}