Files
co-lite/solvway-admin-portal/app/components/shipping/RegionPicker.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

66 lines
2.6 KiB
TypeScript

"use client";
import { useEffect, useState } from "react";
import { useT } from "@/app/lib/i18n/MessagesProvider";
import { apiGet } from "@/app/lib/clientApi";
import { Checkbox } from "@/app/components/ui/checkbox";
import { Button } from "@/app/components/ui/button";
import type { AdminGeoLocationNode } from "@/app/lib/types";
// Countries, each expandable to its states (add-shipping-rates). A zone holds whole countries and/or states.
export function RegionPicker({ value, onChange }: { value: number[]; onChange: (ids: number[]) => void }) {
const t = useT();
const [countries, setCountries] = useState<AdminGeoLocationNode[]>([]);
const [states, setStates] = useState<Record<number, AdminGeoLocationNode[]>>({});
useEffect(() => {
apiGet<AdminGeoLocationNode[]>("/api/geo-locations").then(setCountries).catch(() => setCountries([]));
}, []);
const toggle = (id: number, on: boolean) =>
onChange(on ? [...value.filter((v) => v !== id), id] : value.filter((v) => v !== id));
const showStates = (countryId: number) =>
apiGet<AdminGeoLocationNode[]>(`/api/geo-locations?parentId=${countryId}`)
.then((list) => setStates((s) => ({ ...s, [countryId]: list })))
.catch(() => setStates((s) => ({ ...s, [countryId]: [] })));
return (
<div className="max-h-72 space-y-2 overflow-y-auto rounded-md border p-3">
{countries.map((c) => (
<div key={c.id} className="space-y-1">
<div className="flex items-center gap-2">
<Checkbox
id={`region-${c.id}`}
checked={value.includes(c.id)}
onCheckedChange={(on) => toggle(c.id, on === true)}
aria-label={c.name}
/>
<label htmlFor={`region-${c.id}`} className="text-sm font-medium">{c.name}</label>
{!states[c.id] && (
<Button type="button" variant="ghost" size="sm" onClick={() => showStates(c.id)}>
{t("ShipZoneShowStates")}
</Button>
)}
</div>
{states[c.id] && (
<div className="ml-6 grid grid-cols-2 gap-1">
{states[c.id].map((s) => (
<div key={s.id} className="flex items-center gap-2">
<Checkbox
id={`region-${s.id}`}
checked={value.includes(s.id)}
onCheckedChange={(on) => toggle(s.id, on === true)}
aria-label={s.name}
/>
<label htmlFor={`region-${s.id}`} className="text-sm">{s.name}</label>
</div>
))}
</div>
)}
</div>
))}
</div>
);
}