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
79 lines
3.0 KiB
TypeScript
79 lines
3.0 KiB
TypeScript
"use client";
|
|
|
|
import { useMemo, useState } from "react";
|
|
import { CheckIcon, ChevronDownIcon } from "lucide-react";
|
|
import { Button } from "@/app/components/ui/button";
|
|
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "@/app/components/ui/command";
|
|
import { Popover, PopoverContent, PopoverTrigger } from "@/app/components/ui/popover";
|
|
import { countryCodeOptions, matchesCountryQuery } from "@/app/lib/countryCallingCodes";
|
|
import { useLocale, useT } from "@/app/lib/i18n/MessagesProvider";
|
|
|
|
/** Searchable phone country-code picker. Value is the bare dial code ("60"); unknown codes are kept. */
|
|
export function CountryCodePicker({
|
|
id,
|
|
value,
|
|
onValueChange,
|
|
disabled,
|
|
}: {
|
|
id?: string;
|
|
value: string;
|
|
onValueChange: (dial: string) => void;
|
|
disabled?: boolean;
|
|
}) {
|
|
const t = useT();
|
|
const [open, setOpen] = useState(false);
|
|
const locale = useLocale();
|
|
const options = useMemo(() => countryCodeOptions(locale), [locale]);
|
|
const byIso = useMemo(() => new Map(options.map((o) => [o.iso2, o])), [options]);
|
|
// Several regions share a code (US/CA "1"); mark only the first as selected.
|
|
const selectedIso = options.find((o) => o.dial === value)?.iso2;
|
|
|
|
return (
|
|
<Popover
|
|
open={open}
|
|
onOpenChange={setOpen}
|
|
>
|
|
<PopoverTrigger asChild>
|
|
<Button
|
|
id={id}
|
|
type="button"
|
|
variant="outline"
|
|
role="combobox"
|
|
aria-expanded={open}
|
|
disabled={disabled}
|
|
className="h-9 w-full justify-between font-normal"
|
|
>
|
|
<span className={value ? undefined : "text-muted-foreground"}>{value ? `+${value}` : t("CountryCodeSelect")}</span>
|
|
<ChevronDownIcon className="size-4 opacity-50" />
|
|
</Button>
|
|
</PopoverTrigger>
|
|
<PopoverContent className="w-72 p-0" align="start">
|
|
{/* cmdk filters (hides rows) with our matcher; filtering outside it unmounts ~240 rows per
|
|
keystroke, which cmdk handles slowly. The search resets because the content unmounts on close. */}
|
|
<Command filter={(iso, search) => (matchesCountryQuery(byIso.get(iso)!, search) ? 1 : 0)}>
|
|
<CommandInput placeholder={t("CountryCodeSearch")} />
|
|
<CommandList>
|
|
<CommandEmpty>{t("CountryCodeNoMatch")}</CommandEmpty>
|
|
<CommandGroup>
|
|
{options.map((o) => (
|
|
<CommandItem
|
|
key={o.iso2}
|
|
value={o.iso2}
|
|
onSelect={() => {
|
|
onValueChange(o.dial);
|
|
setOpen(false);
|
|
}}
|
|
>
|
|
<span>{o.name}</span>
|
|
<span className="ml-auto text-muted-foreground">+{o.dial}</span>
|
|
<CheckIcon data-selected-check={o.iso2 === selectedIso ? "" : undefined} className={o.iso2 === selectedIso ? "size-4" : "size-4 opacity-0"} />
|
|
</CommandItem>
|
|
))}
|
|
</CommandGroup>
|
|
</CommandList>
|
|
</Command>
|
|
</PopoverContent>
|
|
</Popover>
|
|
);
|
|
}
|