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
120 lines
4.3 KiB
TypeScript
120 lines
4.3 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useState } from "react";
|
|
import {
|
|
Command,
|
|
CommandEmpty,
|
|
CommandGroup,
|
|
CommandInput,
|
|
CommandItem,
|
|
CommandList,
|
|
} from "@/app/components/ui/command";
|
|
import { Popover, PopoverAnchor, PopoverContent } from "@/app/components/ui/popover";
|
|
import { searchSkuVariations } from "@/app/lib/services/adminCatalogSetup";
|
|
import { variantLabel, type SkuVariationOption } from "@/app/lib/catalogSetup";
|
|
import { useT } from "@/app/lib/i18n/MessagesProvider";
|
|
|
|
// Searches SKU variants by variant code, SKU code or SKU name (restructure-catalogue-setup). Same
|
|
// cmdk-in-popover shape as QianyiSkuPicker: the server filters and caps the list at 20.
|
|
|
|
const SEARCH_DELAY_MS = 250;
|
|
|
|
export interface SkuVariationPickerProps {
|
|
onSelect: (option: SkuVariationOption) => void;
|
|
/** Accessible name of the search box (cmdk wires it through Command's label). */
|
|
label: string;
|
|
placeholder?: string;
|
|
disabled?: boolean;
|
|
}
|
|
|
|
export function SkuVariationPicker({
|
|
onSelect,
|
|
label,
|
|
placeholder: placeholderProp,
|
|
disabled = false,
|
|
}: SkuVariationPickerProps) {
|
|
const t = useT();
|
|
const placeholder = placeholderProp ?? t("SkuSearchVariantsPlaceholder");
|
|
const [query, setQuery] = useState("");
|
|
const [open, setOpen] = useState(false);
|
|
const [options, setOptions] = useState<SkuVariationOption[] | null>(null);
|
|
|
|
useEffect(() => {
|
|
if (!open) return;
|
|
let cancelled = false;
|
|
const timer = setTimeout(() => {
|
|
searchSkuVariations(query.trim())
|
|
.then((rows) => {
|
|
if (!cancelled) setOptions(rows);
|
|
})
|
|
.catch(() => {
|
|
if (!cancelled) setOptions([]);
|
|
});
|
|
}, SEARCH_DELAY_MS);
|
|
return () => {
|
|
cancelled = true;
|
|
clearTimeout(timer);
|
|
};
|
|
}, [open, query]);
|
|
|
|
function handleSelect(option: SkuVariationOption) {
|
|
onSelect(option);
|
|
setOpen(false);
|
|
setQuery("");
|
|
}
|
|
|
|
const trimmed = query.trim();
|
|
|
|
return (
|
|
<Popover open={open} onOpenChange={setOpen}>
|
|
<Command shouldFilter={false} label={label} className="overflow-visible bg-transparent">
|
|
<PopoverAnchor asChild>
|
|
<div className="flex h-9 w-full items-center rounded-md border border-input bg-transparent shadow-sm transition-[color,box-shadow] focus-within:border-ring focus-within:ring-[3px] focus-within:ring-ring/50 dark:bg-input/30 [&_[data-slot=command-input-wrapper]]:h-full [&_[data-slot=command-input-wrapper]]:flex-1 [&_[data-slot=command-input-wrapper]]:border-b-0 [&_[data-slot=command-input]]:h-full [&_[data-slot=command-input]]:py-0 [&_[data-slot=command-input]]:outline-none">
|
|
<CommandInput
|
|
aria-label={label}
|
|
value={query}
|
|
onValueChange={(v) => {
|
|
setQuery(v);
|
|
setOpen(true);
|
|
}}
|
|
onFocus={() => setOpen(true)}
|
|
placeholder={placeholder}
|
|
disabled={disabled}
|
|
/>
|
|
</div>
|
|
</PopoverAnchor>
|
|
<PopoverContent
|
|
className="w-[var(--radix-popover-trigger-width)] p-0"
|
|
align="start"
|
|
onOpenAutoFocus={(event) => event.preventDefault()}
|
|
>
|
|
<CommandList>
|
|
{options === null ? (
|
|
<div className="px-3 py-6 text-center text-sm text-muted-foreground">{t("CatSearching")}</div>
|
|
) : options.length === 0 ? (
|
|
<CommandEmpty>{trimmed ? t("SkuNoVariantsMatch", { query: trimmed }) : t("SkuNoVariantsYet")}</CommandEmpty>
|
|
) : (
|
|
<CommandGroup>
|
|
{options.map((option) => (
|
|
<CommandItem
|
|
key={option.skuVariationId}
|
|
value={String(option.skuVariationId)}
|
|
onSelect={() => handleSelect(option)}
|
|
>
|
|
<div className="flex min-w-0 flex-1 flex-col">
|
|
<span className="truncate text-sm font-medium">{option.code}</span>
|
|
<span className="truncate text-xs text-muted-foreground">
|
|
{option.skuName} · {variantLabel(option.variant, option.variantName, t)}
|
|
</span>
|
|
</div>
|
|
</CommandItem>
|
|
))}
|
|
</CommandGroup>
|
|
)}
|
|
</CommandList>
|
|
</PopoverContent>
|
|
</Command>
|
|
</Popover>
|
|
);
|
|
}
|