Files
co-lite/solvway-admin-portal/app/components/product-page/CodeMatchNotice.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

62 lines
2.2 KiB
TypeScript

"use client";
import { useEffect, useState } from "react";
import { Button } from "@/app/components/ui/button";
import { getSku, listSkus } from "@/app/lib/services/adminCatalogSetup";
import type { SkuView } from "@/app/lib/catalogSetup";
import { useT } from "@/app/lib/i18n/MessagesProvider";
// Shown under a new Product's code when a SKU with the same code (any case) already exists: sell that stock
// item (Use it) or keep the code and make a new one (Create new code, which hides the notice for that code).
const SEARCH_DELAY_MS = 250;
export function CodeMatchNotice({ code, onUse }: { code: string; onUse: (view: SkuView) => void }) {
const t = useT();
const wanted = code.trim();
const [match, setMatch] = useState<{ id: number; code: string } | null>(null);
const [dismissed, setDismissed] = useState("");
const [failed, setFailed] = useState(false);
useEffect(() => {
// eslint-disable-next-line react-hooks/set-state-in-effect -- a changed code drops the previous code's match.
setMatch(null);
setFailed(false);
if (!wanted) return;
let cancelled = false;
const timer = setTimeout(() => {
listSkus({ q: wanted, pageSize: 5 })
.then((page) => {
if (!cancelled) setMatch(page.items.find((s) => s.code.toLowerCase() === wanted.toLowerCase()) ?? null);
})
// ponytail: a failed search shows no notice, like no match; the page still works without it.
.catch(() => {});
}, SEARCH_DELAY_MS);
return () => {
cancelled = true;
clearTimeout(timer);
};
}, [wanted]);
if (!match || dismissed === wanted.toLowerCase()) return null;
return (
<div role="status" className="flex flex-wrap items-center gap-2 rounded-lg border bg-muted/30 p-3 text-sm">
<span className="flex-1">{failed ? t("SkuLoadFailed") : t("PageStockItemExists", { code: match.code })}</span>
<Button
type="button"
size="sm"
onClick={() =>
getSku(match.id)
.then(onUse)
.catch(() => setFailed(true))
}
>
{t("PageUseIt")}
</Button>
<Button type="button" size="sm" variant="outline" onClick={() => setDismissed(wanted.toLowerCase())}>
{t("PageCreateNewCode")}
</Button>
</div>
);
}