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
68 lines
2.2 KiB
TypeScript
68 lines
2.2 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useState } from "react";
|
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/app/components/ui/select";
|
|
import { listCatalogRows } from "@/app/lib/services/adminCatalog";
|
|
import type { CatalogRow } from "@/app/lib/types";
|
|
import { useT } from "@/app/lib/i18n/MessagesProvider";
|
|
import type { Translate } from "@/app/lib/i18n/t";
|
|
|
|
const NONE = "none";
|
|
|
|
function label(row: CatalogRow, t: Translate): string {
|
|
return row.status === "Y" ? `${row.code} · ${row.name}` : t("SupplierOptionInactive", { code: String(row.code), name: String(row.name) });
|
|
}
|
|
|
|
// The SKU's supplier (add-sku-supplier). Loads the supplier list itself because the SKU editor is used from three
|
|
// places. Lists active suppliers, plus the current one even when it has since been deactivated.
|
|
export function SupplierSelect({
|
|
value,
|
|
onChange,
|
|
disabled,
|
|
invalid,
|
|
}: {
|
|
value: number | null;
|
|
onChange: (id: number | null) => void;
|
|
disabled?: boolean;
|
|
invalid?: boolean;
|
|
}) {
|
|
const t = useT();
|
|
const [rows, setRows] = useState<CatalogRow[]>([]);
|
|
const [failed, setFailed] = useState(false);
|
|
|
|
useEffect(() => {
|
|
let cancelled = false;
|
|
listCatalogRows("supplier")
|
|
.then((list) => !cancelled && setRows(list))
|
|
.catch(() => !cancelled && setFailed(true));
|
|
return () => {
|
|
cancelled = true;
|
|
};
|
|
}, []);
|
|
|
|
const shown = rows.filter((r) => r.status === "Y" || Number(r.id) === value);
|
|
|
|
return (
|
|
<>
|
|
<Select
|
|
value={value == null ? NONE : String(value)}
|
|
onValueChange={(v) => onChange(v === NONE ? null : Number(v))}
|
|
disabled={disabled}
|
|
>
|
|
<SelectTrigger id="sku-supplier" aria-label={t("SkuSupplier")} aria-invalid={invalid} className="w-full">
|
|
<SelectValue placeholder={t("SupplierNone")} />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
<SelectItem value={NONE}>{t("SupplierNone")}</SelectItem>
|
|
{shown.map((r) => (
|
|
<SelectItem key={r.id} value={String(r.id)}>
|
|
{label(r, t)}
|
|
</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
{failed && <p className="text-sm text-destructive">{t("SupplierLoadFailed")}</p>}
|
|
</>
|
|
);
|
|
}
|