added lang param to api
This commit is contained in:
1 parent
11903e23bf
commit
524733ad9f
50 files changed
+798
-361
No files matched your search
@@ -3,17 +3,26 @@ import apiClient from "@/lib/api/client";
|
||||
// ─── Localized text (backend keys: tm | ru | en) ──────────────────────────────
|
||||
|
||||
export interface LocalizedText {
|
||||
tm: string;
|
||||
ru: string;
|
||||
en: string;
|
||||
tm?: string;
|
||||
ru?: string;
|
||||
en?: string;
|
||||
}
|
||||
|
||||
export type LocalizedField = string | LocalizedText;
|
||||
|
||||
export function resolveLocalizedName(val: LocalizedField | null | undefined, lang = "tm"): string {
|
||||
if (!val) return "";
|
||||
if (typeof val === "string") return val;
|
||||
const key = (lang === "tk" ? "tm" : lang) as keyof LocalizedText;
|
||||
return val[key] ?? val.tm ?? val.en ?? val.ru ?? "";
|
||||
}
|
||||
|
||||
// ─── Province (for the provinceId select) ─────────────────────────────────────
|
||||
|
||||
export interface Province {
|
||||
id: number;
|
||||
name: LocalizedText;
|
||||
region: LocalizedText;
|
||||
name: LocalizedField;
|
||||
region: LocalizedField;
|
||||
active: boolean;
|
||||
}
|
||||
|
||||
@@ -22,11 +31,11 @@ export interface Province {
|
||||
export interface Branch {
|
||||
id: number;
|
||||
uniqueCode: string;
|
||||
name: LocalizedText;
|
||||
address: LocalizedText;
|
||||
name: LocalizedField;
|
||||
address: LocalizedField;
|
||||
region: string;
|
||||
provinceId: number;
|
||||
provinceName: LocalizedText;
|
||||
provinceName: LocalizedField;
|
||||
phoneNumbers: string;
|
||||
billingUsername: string;
|
||||
billingPassword: string;
|
||||
|
||||
@@ -13,7 +13,7 @@ import { InfiniteSelect, type InfiniteSelectOption, type InfiniteSelectProps } f
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { StepBarCards, type StepCardItem } from "@/components/stepBarV2";
|
||||
import { useCreateBranch, useUpdateBranch, useInfiniteProvinces } from "@/features/branches/hooks/useBranches";
|
||||
import type { Branch } from "@/features/branches/api/branchesApi";
|
||||
import { resolveLocalizedName, type Branch } from "@/features/branches/api/branchesApi";
|
||||
import { createBranchFormSchema, validateStep, DEFAULT_FORM_VALUES, buildPayload } from "@/features/branches/schemas/branch.schema";
|
||||
import type { BranchFormData } from "@/features/branches/schemas/branch.schema";
|
||||
|
||||
@@ -278,15 +278,15 @@ export interface BranchFormProps {
|
||||
|
||||
function mapInitial(data: Branch): Partial<BranchFormData> {
|
||||
return {
|
||||
nameTk: data.name.tm,
|
||||
nameRu: data.name.ru,
|
||||
nameEn: data.name.en,
|
||||
nameTk: resolveLocalizedName(data.name, "tm"),
|
||||
nameRu: resolveLocalizedName(data.name, "ru"),
|
||||
nameEn: resolveLocalizedName(data.name, "en"),
|
||||
uniqueCode: data.uniqueCode,
|
||||
provinceId: String(data.provinceId),
|
||||
region: data.region,
|
||||
addressTk: data.address.tm,
|
||||
addressRu: data.address.ru,
|
||||
addressEn: data.address.en,
|
||||
addressTk: resolveLocalizedName(data.address, "tm"),
|
||||
addressRu: resolveLocalizedName(data.address, "ru"),
|
||||
addressEn: resolveLocalizedName(data.address, "en"),
|
||||
phoneNumbers: data.phoneNumbers,
|
||||
billingUsername: data.billingUsername,
|
||||
billingPassword: data.billingPassword,
|
||||
@@ -316,14 +316,14 @@ export function BranchForm({ mode, initialData }: BranchFormProps) {
|
||||
const provinceSelect: Omit<InfiniteSelectProps, "label" | "required" | "placeholder"> = useMemo(() => {
|
||||
const opts: InfiniteSelectOption[] = (provinceQuery.data?.pages ?? [])
|
||||
.flatMap((p) => p?.provinces ?? [])
|
||||
.map((p) => ({ value: String(p.id), label: p.name[lang] }));
|
||||
.map((p) => ({ value: String(p.id), label: resolveLocalizedName(p.name, lang) }));
|
||||
|
||||
// Ensure the currently-selected province is present (edit mode), even if it
|
||||
// lives beyond the pages loaded so far.
|
||||
if (initialData) {
|
||||
const current = String(initialData.provinceId);
|
||||
if (!opts.some((o) => o.value === current)) {
|
||||
opts.unshift({ value: current, label: initialData.provinceName?.[lang] ?? current });
|
||||
opts.unshift({ value: current, label: resolveLocalizedName(initialData.provinceName, lang) || current });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user