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
143 lines
5.4 KiB
TypeScript
143 lines
5.4 KiB
TypeScript
"use client";
|
|
|
|
import { useState, type FormEvent } from "react";
|
|
import { UserRound } from "lucide-react";
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
} from "@/app/components/ui/dialog";
|
|
import { Button } from "@/app/components/ui/button";
|
|
import { Input } from "@/app/components/ui/input";
|
|
import { Label } from "@/app/components/ui/label";
|
|
import { MemberSearchCombobox } from "@/app/components/members/MemberSearchCombobox";
|
|
import type { AdminMember } from "@/app/lib/types";
|
|
import type { WalkInDetails } from "@/app/pos/components/CustomerCard";
|
|
import { useT } from "@/app/lib/i18n/MessagesProvider";
|
|
|
|
// Choose the sale's customer (redesign-pos-sale-flow): a member from the search, or a walk-in with
|
|
// optional name, phone and email. noValidate: the form reports every problem at once, itself.
|
|
|
|
interface CustomerDialogProps {
|
|
open: boolean;
|
|
onOpenChange: (open: boolean) => void;
|
|
onMember: (member: AdminMember) => void;
|
|
onWalkIn: (details: WalkInDetails) => void;
|
|
/** The current walk-in details, to start the walk-in form from; null when there are none. */
|
|
walkIn: WalkInDetails | null;
|
|
}
|
|
|
|
const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
|
|
export function CustomerDialog({ open, onOpenChange, onMember, onWalkIn, walkIn }: CustomerDialogProps) {
|
|
const t = useT();
|
|
const [mode, setMode] = useState<"search" | "walkin">("search");
|
|
const [name, setName] = useState("");
|
|
const [phone, setPhone] = useState("");
|
|
const [email, setEmail] = useState("");
|
|
const [errors, setErrors] = useState<string[]>([]);
|
|
|
|
function startWalkIn() {
|
|
setName(walkIn?.name ?? "");
|
|
setPhone(walkIn?.phone ?? "");
|
|
setEmail(walkIn?.email ?? "");
|
|
setErrors([]);
|
|
setMode("walkin");
|
|
}
|
|
|
|
function submit(e: FormEvent<HTMLFormElement>) {
|
|
e.preventDefault();
|
|
const details = { name: name.trim(), phone: phone.trim(), email: email.trim() };
|
|
const problems: string[] = [];
|
|
if (details.phone && details.phone.replace(/\D/g, "").length < 9) {
|
|
problems.push("PosErrPhoneShort");
|
|
}
|
|
if (details.email && !EMAIL.test(details.email)) {
|
|
problems.push("PosErrEmail");
|
|
}
|
|
if (problems.length > 0) {
|
|
setErrors(problems);
|
|
return;
|
|
}
|
|
onWalkIn(details);
|
|
// The next opening (to change the customer) starts on the member search, not this form.
|
|
setMode("search");
|
|
}
|
|
|
|
return (
|
|
<Dialog
|
|
open={open}
|
|
onOpenChange={(next) => {
|
|
if (!next) setMode("search");
|
|
onOpenChange(next);
|
|
}}
|
|
>
|
|
<DialogContent className="sm:max-w-lg">
|
|
<DialogHeader>
|
|
<DialogTitle>{mode === "search" ? t("PosAddCustomer") : t("PosWalkInCustomer")}</DialogTitle>
|
|
<DialogDescription>
|
|
{mode === "search"
|
|
? t("PosCustomerSearchDesc")
|
|
: t("PosWalkInDesc")}
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
{mode === "search" ? (
|
|
<div className="space-y-3">
|
|
{/* The combobox root is h-full; this plain block keeps it from collapsing the dialog's grid
|
|
row, which pushed the walk-in option out of the dialog. */}
|
|
<div>
|
|
<MemberSearchCombobox
|
|
aria-label={t("Member")}
|
|
placeholder={t("PosMemberSearchPlaceholder")}
|
|
autoFocus
|
|
onSelect={(m) => onMember(m)}
|
|
/>
|
|
</div>
|
|
<button
|
|
type="button"
|
|
onClick={startWalkIn}
|
|
className="flex w-full items-center gap-3 rounded-lg border p-3 text-left hover:bg-muted/50"
|
|
>
|
|
<UserRound aria-hidden="true" className="size-8 shrink-0 text-muted-foreground" />
|
|
<span className="flex flex-col">
|
|
<span className="font-semibold">{t("PosWalkInCustomer")}</span>
|
|
<span className="text-xs text-muted-foreground">{t("PosWalkInHint")}</span>
|
|
</span>
|
|
</button>
|
|
</div>
|
|
) : (
|
|
<form onSubmit={submit} noValidate className="space-y-3">
|
|
<div className="space-y-1.5">
|
|
<Label htmlFor="pos-walkin-name">{t("PosNameOptional")}</Label>
|
|
<Input id="pos-walkin-name" value={name} onChange={(e) => setName(e.target.value)} autoFocus />
|
|
</div>
|
|
<div className="grid grid-cols-2 gap-3">
|
|
<div className="space-y-1.5">
|
|
<Label htmlFor="pos-walkin-phone">{t("PosPhoneOptional")}</Label>
|
|
<Input id="pos-walkin-phone" type="tel" inputMode="tel" value={phone} onChange={(e) => setPhone(e.target.value)} />
|
|
</div>
|
|
<div className="space-y-1.5">
|
|
<Label htmlFor="pos-walkin-email">{t("PosEmailOptional")}</Label>
|
|
<Input id="pos-walkin-email" type="email" value={email} onChange={(e) => setEmail(e.target.value)} />
|
|
</div>
|
|
</div>
|
|
{errors.length > 0 && (
|
|
<p role="alert" className="text-sm text-destructive">
|
|
{errors.map((c) => t(c)).join(" ")}
|
|
</p>
|
|
)}
|
|
<div className="flex justify-between gap-2">
|
|
<Button type="button" variant="outline" onClick={() => setMode("search")}>
|
|
{t("Back")}
|
|
</Button>
|
|
<Button type="submit">{t("PosContinueWalkIn")}</Button>
|
|
</div>
|
|
</form>
|
|
)}
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|