feat: reset password shares the login frame

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-12-01 22:38:22 +08:00
1 parent a9e40280ee
commit d4ae94fcc9
4 files changed
+195 -170

No files matched your search

@@ -0,0 +1,67 @@
"use client";
import type { ReactNode } from "react";
import { CalendarDays, ListChecks, UserPlus } from "lucide-react";
import { useT } from "@/app/lib/i18n/MessagesProvider";
import PoweredBy from "@/app/components/app/PoweredBy";
/** What the back office is for, on the brand panel. */
const PANEL_POINTS = [
{ icon: CalendarDays, code: "BackOfficePanelEvents" },
{ icon: UserPlus, code: "BackOfficePanelLeads" },
{ icon: ListChecks, code: "BackOfficePanelFollowUps" },
] as const;
// Two-column frame shared by the signed-out pages (login, forced password change): an accent panel
// with the giraffe-spot coat on the left from lg, the page's own content on the right. Below lg the
// panel folds into a compact brand row above the content.
export default function AuthFrame({ children }: { children: ReactNode }) {
const t = useT();
return (
<div className="grid min-h-svh bg-background lg:grid-cols-[minmax(0,5fr)_minmax(0,6fr)]">
<aside className="relative isolate hidden flex-col justify-between gap-10 overflow-hidden bg-accent p-12 text-accent-foreground lg:flex">
{/* Light accent ground with the giraffe-spot coat at 14%. In dark mode the coat and the chips
switch to --accent-foreground so they stay legible on the dark accent. */}
<span aria-hidden="true" className="giraffe-spots absolute inset-0 -z-10 opacity-[0.14] [--giraffe-patch:var(--primary)] dark:[--giraffe-patch:var(--accent-foreground)]" />
<div className="flex items-center gap-4">
<span className="rounded-full bg-primary px-3 py-1 text-sm font-semibold text-primary-foreground dark:bg-accent-foreground dark:text-accent">
{t("BackOfficeLabel")}
</span>
</div>
<div className="max-w-md space-y-8">
<p className="font-heading text-4xl leading-tight font-semibold tracking-tight text-balance">
{t("BackOfficePanelTitle")}
</p>
<ul className="space-y-4">
{PANEL_POINTS.map(({ icon: PointIcon, code }) => (
<li key={code} className="flex items-center gap-3 text-base font-medium">
<span className="flex size-10 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground dark:bg-accent-foreground dark:text-accent">
<PointIcon aria-hidden="true" className="size-5" />
</span>
{t(code)}
</li>
))}
</ul>
</div>
<span aria-hidden="true" />
</aside>
<main className="flex flex-col items-center justify-center gap-8 p-6 sm:p-10">
<div className="w-full max-w-sm space-y-8">
{/* Below lg a short brand band stands in for the panel: same accent ground and giraffe-spot coat. */}
<div className="relative isolate flex items-center gap-3 overflow-hidden rounded-2xl bg-accent p-4 lg:hidden">
<span aria-hidden="true" className="giraffe-spots absolute inset-0 -z-10 opacity-[0.14] [--giraffe-patch:var(--primary)] dark:[--giraffe-patch:var(--accent-foreground)]" />
<span className="rounded-full bg-primary px-3 py-1 text-xs font-semibold text-primary-foreground dark:bg-accent-foreground dark:text-accent">
{t("BackOfficeLabel")}
</span>
</div>
{children}
</div>
<PoweredBy />
</main>
</div>
);
}
+71 -125
View File
@@ -1,7 +1,7 @@
"use client";
import { useState, useSyncExternalStore } from "react";
import { CalendarDays, Eye, EyeOff, ListChecks, Loader2, UserPlus } from "lucide-react";
import { Eye, EyeOff, Loader2 } from "lucide-react";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { Button } from "@/app/components/ui/button";
@@ -11,20 +11,13 @@ import { ErrorState } from "@/app/components/ui/states";
import { ApiError, apiPost } from "@/app/lib/clientApi";
import { useAdminAuth } from "@/app/lib/AdminAuthContext";
import { useT } from "@/app/lib/i18n/MessagesProvider";
import PoweredBy from "@/app/components/app/PoweredBy";
import AuthFrame from "@/app/components/app/AuthFrame";
import { signedInElsewhere } from "@/app/lib/signedInElsewhere";
import { safeReturnTo } from "@/app/lib/returnTo";
/** The marker is read once per render; nothing in the page changes it. */
const noSubscription = () => () => {};
/** What the back office is for, on the brand panel. */
const PANEL_POINTS = [
{ icon: CalendarDays, code: "BackOfficePanelEvents" },
{ icon: UserPlus, code: "BackOfficePanelLeads" },
{ icon: ListChecks, code: "BackOfficePanelFollowUps" },
] as const;
// Ported from src/legacy-pages/login/LoginPage.tsx. The hardcoded
// services/auth.ts credential check and localStorage session are gone (spec:
// "The hardcoded SPA auth is gone"); submit now calls the same-origin
@@ -74,127 +67,80 @@ export default function LoginPage() {
}
return (
// Brand split (feedback 2026-10-23, "make it impactful"): a brand-gold panel with the brown giraffe
// coat and the logo on the left from lg, the form on the cream page on the right. Below lg the
// panel folds into a compact brand row above the form.
<div className="grid min-h-svh bg-background lg:grid-cols-[minmax(0,5fr)_minmax(0,6fr)]">
<aside className="relative isolate hidden flex-col justify-between gap-10 overflow-hidden bg-accent p-12 text-accent-foreground lg:flex">
{/* Gold ground, brown coat at 14% (owner request: lighter, colours reversed). Dark text still
clears AA on a patch: --accent-foreground ≈ 7.0:1 (8.4:1 on plain gold). In dark mode
--primary turns light gold, so the coat and the chips switch to --accent-foreground, which
stays dark brown; the logo inverts to white on its dark plate. */}
<span aria-hidden="true" className="giraffe-spots absolute inset-0 -z-10 opacity-[0.14] [--giraffe-patch:var(--primary)] dark:[--giraffe-patch:var(--accent-foreground)]" />
<div className="flex items-center gap-4">
<span className="rounded-full bg-primary px-3 py-1 text-sm font-semibold text-primary-foreground dark:bg-accent-foreground dark:text-accent">
{t("BackOfficeLabel")}
</span>
<AuthFrame>
<div className="space-y-2">
<h1 className="font-heading text-3xl font-semibold tracking-tight">{t("BackOfficeTitle")}</h1>
<p className="text-muted-foreground">{t("BackOfficeSubtitle")}</p>
</div>
{error ? <ErrorState message={t(error)} /> : elsewhere && <ErrorState message={t("SignedInElsewhere")} />}
<form onSubmit={handleSubmit} className="space-y-5" noValidate>
<div className="space-y-1.5">
<Label htmlFor="company">{t("Company")}</Label>
<Input
id="company"
type="text"
autoComplete="organization"
placeholder={t("CompanyBlankForSuper")}
value={company}
onChange={(e) => setCompany(e.target.value)}
disabled={submitting}
className="h-11 bg-card"
/>
</div>
<div className="max-w-md space-y-8">
<p className="font-heading text-4xl leading-tight font-semibold tracking-tight text-balance">
{t("BackOfficePanelTitle")}
</p>
<ul className="space-y-4">
{PANEL_POINTS.map(({ icon: PointIcon, code }) => (
<li key={code} className="flex items-center gap-3 text-base font-medium">
<span className="flex size-10 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground dark:bg-accent-foreground dark:text-accent">
<PointIcon aria-hidden="true" className="size-5" />
</span>
{t(code)}
</li>
))}
</ul>
<div className="space-y-1.5">
<Label htmlFor="username">{t("Username")}</Label>
<Input
id="username"
type="text"
autoComplete="username"
required
value={username}
onChange={(e) => setUsername(e.target.value)}
disabled={submitting}
className="h-11 bg-card"
/>
</div>
<span aria-hidden="true" />
</aside>
<main className="flex flex-col items-center justify-center gap-8 p-6 sm:p-10">
<div className="w-full max-w-sm space-y-8">
{/* Below lg a short brand band stands in for the panel: same brown, coat and logo. */}
<div className="relative isolate flex items-center gap-3 overflow-hidden rounded-2xl bg-accent p-4 lg:hidden">
<span aria-hidden="true" className="giraffe-spots absolute inset-0 -z-10 opacity-[0.14] [--giraffe-patch:var(--primary)] dark:[--giraffe-patch:var(--accent-foreground)]" />
<span className="rounded-full bg-primary px-3 py-1 text-xs font-semibold text-primary-foreground dark:bg-accent-foreground dark:text-accent">
{t("BackOfficeLabel")}
</span>
<div className="space-y-1.5">
<Label htmlFor="password">{t("Password")}</Label>
<div className="relative">
<Input
id="password"
type={showPassword ? "text" : "password"}
autoComplete="current-password"
required
value={password}
onChange={(e) => setPassword(e.target.value)}
disabled={submitting}
className="h-11 bg-card pr-11"
/>
<button
type="button"
onClick={() => setShowPassword((v) => !v)}
aria-label={showPassword ? t("LoginHidePassword") : t("LoginShowPassword")}
className="absolute top-1/2 right-1 flex size-9 -translate-y-1/2 cursor-pointer items-center justify-center rounded-full text-muted-foreground transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none"
>
{showPassword ? (
<EyeOff aria-hidden="true" className="size-4" />
) : (
<Eye aria-hidden="true" className="size-4" />
)}
</button>
</div>
<div className="space-y-2">
<h1 className="font-heading text-3xl font-semibold tracking-tight">{t("BackOfficeTitle")}</h1>
<p className="text-muted-foreground">{t("BackOfficeSubtitle")}</p>
</div>
{error ? <ErrorState message={t(error)} /> : elsewhere && <ErrorState message={t("SignedInElsewhere")} />}
<form onSubmit={handleSubmit} className="space-y-5" noValidate>
<div className="space-y-1.5">
<Label htmlFor="company">{t("Company")}</Label>
<Input
id="company"
type="text"
autoComplete="organization"
placeholder={t("CompanyBlankForSuper")}
value={company}
onChange={(e) => setCompany(e.target.value)}
disabled={submitting}
className="h-11 bg-card"
/>
</div>
<div className="space-y-1.5">
<Label htmlFor="username">{t("Username")}</Label>
<Input
id="username"
type="text"
autoComplete="username"
required
value={username}
onChange={(e) => setUsername(e.target.value)}
disabled={submitting}
className="h-11 bg-card"
/>
</div>
<div className="space-y-1.5">
<Label htmlFor="password">{t("Password")}</Label>
<div className="relative">
<Input
id="password"
type={showPassword ? "text" : "password"}
autoComplete="current-password"
required
value={password}
onChange={(e) => setPassword(e.target.value)}
disabled={submitting}
className="h-11 bg-card pr-11"
/>
<button
type="button"
onClick={() => setShowPassword((v) => !v)}
aria-label={showPassword ? t("LoginHidePassword") : t("LoginShowPassword")}
className="absolute top-1/2 right-1 flex size-9 -translate-y-1/2 cursor-pointer items-center justify-center rounded-full text-muted-foreground transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none"
>
{showPassword ? (
<EyeOff aria-hidden="true" className="size-4" />
) : (
<Eye aria-hidden="true" className="size-4" />
)}
</button>
</div>
</div>
<Link href="/forgot-password" className="block text-sm text-muted-foreground underline-offset-4 hover:underline">
{t("ForgotLink")}
</Link>
<Button type="submit" className="h-11 w-full text-base shadow-md" disabled={submitting}>
{submitting && <Loader2 aria-hidden="true" className="size-4 animate-spin" />}
{t("LogIn")}
</Button>
</form>
</div>
<PoweredBy />
</main>
</div>
<Link href="/forgot-password" className="block text-sm text-muted-foreground underline-offset-4 hover:underline">
{t("ForgotLink")}
</Link>
<Button type="submit" className="h-11 w-full text-base shadow-md" disabled={submitting}>
{submitting && <Loader2 aria-hidden="true" className="size-4 animate-spin" />}
{t("LogIn")}
</Button>
</form>
</AuthFrame>
);
}
@@ -0,0 +1,18 @@
import { render, screen } from "@testing-library/react";
import { describe, it, expect, vi } from "vitest";
vi.mock("next/navigation", () => ({ useRouter: () => ({ push: vi.fn() }) }));
vi.mock("@/app/lib/clientApi", () => ({ apiPost: vi.fn(), ApiError: class ApiError extends Error {} }));
vi.mock("@/app/lib/AdminAuthContext", () => ({ useAdminAuth: () => ({ refresh: vi.fn() }) }));
import ResetPasswordPage from "./page";
describe("ResetPasswordPage frame", () => {
it("uses the login two-column frame", () => {
const { container } = render(<ResetPasswordPage />);
expect(screen.getByText("Everything behind Co-Lite, in one place.")).toBeInTheDocument();
expect(container.querySelector(".giraffe-spots")).not.toBeNull();
expect(screen.getByRole("link", { name: "Containerverse Sdn. Bhd." })).toBeInTheDocument();
expect(screen.getByRole("heading", { name: "Set your password" })).toBeInTheDocument();
});
});
@@ -4,14 +4,13 @@ import { useState } from "react";
import { Loader2 } from "lucide-react";
import { useRouter } from "next/navigation";
import { Button } from "@/app/components/ui/button";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/app/components/ui/card";
import { Input } from "@/app/components/ui/input";
import { Label } from "@/app/components/ui/label";
import { ErrorState } from "@/app/components/ui/states";
import { apiPost } from "@/app/lib/clientApi";
import { useAdminAuth } from "@/app/lib/AdminAuthContext";
import { useT } from "@/app/lib/i18n/MessagesProvider";
import PoweredBy from "@/app/components/app/PoweredBy";
import AuthFrame from "@/app/components/app/AuthFrame";
// First sign-in: login answered resetPasswordRequired (the account is still on the temporary
// password an admin set), so the user must choose their own before reaching the portal.
@@ -48,49 +47,44 @@ export default function ResetPasswordPage() {
}
return (
<div className="flex min-h-svh flex-col items-center justify-center gap-4 bg-background p-4">
<Card className="w-full max-w-sm">
<CardHeader className="gap-2">
<CardTitle className="text-lg">{t("ResetTitle")}</CardTitle>
<CardDescription>{t("ResetChooseIntro")}</CardDescription>
</CardHeader>
<CardContent>
{error && <ErrorState message={t(error)} className="mb-4" />}
<form onSubmit={handleSubmit} className="space-y-4" noValidate>
<div className="space-y-1.5">
<Label htmlFor="newPassword">{t("ResetNewPassword")}</Label>
<Input
id="newPassword"
type="password"
autoComplete="new-password"
value={newPassword}
onChange={(e) => setNewPassword(e.target.value)}
disabled={submitting}
aria-describedby="newPasswordRules"
/>
<p id="newPasswordRules" className="text-sm text-muted-foreground">{t("AdminPasswordHint")}</p>
</div>
<div className="space-y-1.5">
<Label htmlFor="confirmPassword">{t("ResetConfirmPassword")}</Label>
<Input
id="confirmPassword"
type="password"
autoComplete="new-password"
value={confirmPassword}
onChange={(e) => setConfirmPassword(e.target.value)}
disabled={submitting}
/>
</div>
<Button type="submit" className="w-full" disabled={submitting}>
{submitting && <Loader2 aria-hidden="true" className="size-4 animate-spin" />}
{t("ResetSubmit")}
</Button>
</form>
</CardContent>
</Card>
<div className="text-center">
<PoweredBy />
<AuthFrame>
<div className="space-y-2">
<h1 className="font-heading text-3xl font-semibold tracking-tight">{t("ResetTitle")}</h1>
<p className="text-muted-foreground">{t("ResetChooseIntro")}</p>
</div>
</div>
{error && <ErrorState message={t(error)} />}
<form onSubmit={handleSubmit} className="space-y-5" noValidate>
<div className="space-y-1.5">
<Label htmlFor="newPassword">{t("ResetNewPassword")}</Label>
<Input
id="newPassword"
type="password"
autoComplete="new-password"
value={newPassword}
onChange={(e) => setNewPassword(e.target.value)}
disabled={submitting}
aria-describedby="newPasswordRules"
className="h-11 bg-card"
/>
<p id="newPasswordRules" className="text-sm text-muted-foreground">{t("AdminPasswordHint")}</p>
</div>
<div className="space-y-1.5">
<Label htmlFor="confirmPassword">{t("ResetConfirmPassword")}</Label>
<Input
id="confirmPassword"
type="password"
autoComplete="new-password"
value={confirmPassword}
onChange={(e) => setConfirmPassword(e.target.value)}
disabled={submitting}
className="h-11 bg-card"
/>
</div>
<Button type="submit" className="h-11 w-full text-base shadow-md" disabled={submitting}>
{submitting && <Loader2 aria-hidden="true" className="size-4 animate-spin" />}
{t("ResetSubmit")}
</Button>
</form>
</AuthFrame>
);
}