diff --git a/src/components/viewPageComponents.tsx b/src/components/viewPageComponents.tsx index ecf8868..49678a8 100644 --- a/src/components/viewPageComponents.tsx +++ b/src/components/viewPageComponents.tsx @@ -102,11 +102,12 @@ export function InfoRow({ label, value, children, isLink, href }: InfoRowProps) export interface MultiLangRowProps { label: string; - value?: { tm?: string; tk?: string; ru?: string; en?: string } | null; + value?: { tm?: string; tk?: string; ru?: string; en?: string } | string | null; } export function MultiLangRow({ label, value }: MultiLangRowProps) { if (!value) return ; + if (typeof value === "string") return ; const langs = [ { code: "TK", val: value.tm ?? value.tk }, diff --git a/src/constants/statusCells.tsx b/src/constants/statusCells.tsx index e826dc4..d8877c5 100644 --- a/src/constants/statusCells.tsx +++ b/src/constants/statusCells.tsx @@ -2,6 +2,12 @@ import { useTranslation } from "react-i18next"; import { CheckCircle2, XCircle } from "lucide-react"; import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge"; import { STATUS_ICONS, STATUS_BADGE_VARIANTS, isStatusValue, getStatusLabel } from "@/constants/statusOptions"; +import { + GATEWAY_STATUS_BADGE_VARIANTS, + GATEWAY_STATUS_ICONS, + getGatewayStatusLabel, + isGatewayStatusValue, +} from "@/constants/paymentStatus"; interface StatusCellProps { status: string; @@ -40,3 +46,24 @@ export function ActiveStatusCell({ active, status, labelActive, labelInactive }: /> ); } + +interface GatewayStatusCellProps { + status?: string | null; +} + +export function GatewayStatusCell({ status }: GatewayStatusCellProps) { + const { t } = useTranslation(); + const normalizedStatus = status || "unknown"; + + if (isGatewayStatusValue(normalizedStatus)) { + return ( + + ); + } + + return ; +} diff --git a/src/features/branches/api/branchesApi.ts b/src/features/branches/api/branchesApi.ts index c4aea81..b280a95 100644 --- a/src/features/branches/api/branchesApi.ts +++ b/src/features/branches/api/branchesApi.ts @@ -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; diff --git a/src/features/branches/components/branchesForm.tsx b/src/features/branches/components/branchesForm.tsx index b4c4250..0331da7 100644 --- a/src/features/branches/components/branchesForm.tsx +++ b/src/features/branches/components/branchesForm.tsx @@ -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 { 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 = 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 }); } } diff --git a/src/features/cardPins/components/cardPinForm.tsx b/src/features/cardPins/components/cardPinForm.tsx index 244430c..508ddb4 100644 --- a/src/features/cardPins/components/cardPinForm.tsx +++ b/src/features/cardPins/components/cardPinForm.tsx @@ -16,8 +16,11 @@ import { useCreateCardPin, useUpdateCardPin } from "@/features/cardPins/hooks/us import { validateStep, DEFAULT_FORM_VALUES, buildPayload } from "@/features/cardPins/schemas/cardPin.schema"; import type { CardPinFormData } from "@/features/cardPins/schemas/cardPin.schema"; import { useCardTypes } from "@/features/cardTypes/hooks/useCardTypes"; +import { resolveCardTypeTitle } from "@/features/cardTypes/api/cardTypesApi"; import { useBranches } from "@/features/branches/hooks/useBranches"; +import { resolveLocalizedName } from "@/features/branches/api/branchesApi"; import { useDistricts } from "@/features/districts/hooks/useDistricts"; +import { resolveDistrictName } from "@/features/districts/api/districtsApi"; import { PASSPORT_SERIES_OPTIONS, getStatusOptions } from "@/constants"; import { DocumentUpload } from "@/components/documentUpload"; import { InfiniteSelect, type InfiniteSelectOption } from "@/components/infiniteSelect"; @@ -396,7 +399,7 @@ export function CardPinForm({ mode, initialData }: CardPinFormProps) { () => (cardTypesData?.paymentCards ?? []).map((ct) => ({ value: String(ct.id), - label: ct.title[lang] || ct.title.tm, + label: resolveCardTypeTitle(ct.title, lang), })), [cardTypesData, lang], ); @@ -405,7 +408,7 @@ export function CardPinForm({ mode, initialData }: CardPinFormProps) { () => (branchesData?.branches ?? []).map((b) => ({ value: String(b.id), - label: b.name[lang] || b.name.tm, + label: resolveLocalizedName(b.name, lang), })), [branchesData, lang], ); @@ -413,8 +416,8 @@ export function CardPinForm({ mode, initialData }: CardPinFormProps) { const districtOptions = useMemo( () => (districtsData?.provinces ?? []).map((d) => ({ - value: d.region?.tm || d.name.tm, - label: d.name[lang] || d.name.tm, + value: resolveDistrictName(d.region, "tm") || resolveDistrictName(d.name, "tm"), + label: resolveDistrictName(d.name, lang), })), [districtsData, lang], ); diff --git a/src/features/cardReasons/api/cardReasonsApi.ts b/src/features/cardReasons/api/cardReasonsApi.ts index f97c3d3..59fd3d7 100644 --- a/src/features/cardReasons/api/cardReasonsApi.ts +++ b/src/features/cardReasons/api/cardReasonsApi.ts @@ -3,14 +3,23 @@ import apiClient from "@/lib/api/client"; // ─── Types ──────────────────────────────────────────────────────────────────── export interface LocalizedTitle { - tm: string; - ru: string; - en: string; + tm?: string; + ru?: string; + en?: string; +} + +export type LocalizedReasonTitle = string | LocalizedTitle; + +export function resolveCardReasonTitle(val: LocalizedReasonTitle | null | undefined, lang = "tm"): string { + if (!val) return ""; + if (typeof val === "string") return val; + const key = (lang === "tk" ? "tm" : lang) as keyof LocalizedTitle; + return val[key] ?? val.tm ?? val.en ?? val.ru ?? ""; } export interface CardReason { id: number; - title: LocalizedTitle; + title: LocalizedReasonTitle; price: string; notes: string; active: boolean; diff --git a/src/features/cardReasons/schemas/cardReason.schema.ts b/src/features/cardReasons/schemas/cardReason.schema.ts index c46cdd5..ae1d20b 100644 --- a/src/features/cardReasons/schemas/cardReason.schema.ts +++ b/src/features/cardReasons/schemas/cardReason.schema.ts @@ -1,5 +1,5 @@ import { z } from "zod"; -import type { CardReason, CreateCardReasonPayload } from "../api/cardReasonsApi"; +import { resolveCardReasonTitle, type CardReason, type CreateCardReasonPayload } from "../api/cardReasonsApi"; export function createCardReasonFormSchema(t: (key: string, fallback?: string) => string) { return z.object({ @@ -36,9 +36,9 @@ export function buildPayload(data: CardReasonFormData): CreateCardReasonPayload export function mapInitial(data: CardReason): CardReasonFormData { return { - nameTk: data.title.tm, - nameRu: data.title.ru, - nameEn: data.title.en, + nameTk: resolveCardReasonTitle(data.title, "tm"), + nameRu: resolveCardReasonTitle(data.title, "ru"), + nameEn: resolveCardReasonTitle(data.title, "en"), price: data.price, notes: data.notes ?? "", active: data.active, diff --git a/src/features/cardRequisites/api/cardRequisitesApi.ts b/src/features/cardRequisites/api/cardRequisitesApi.ts index f69ba51..450e04c 100644 --- a/src/features/cardRequisites/api/cardRequisitesApi.ts +++ b/src/features/cardRequisites/api/cardRequisitesApi.ts @@ -3,15 +3,16 @@ import apiClient from "@/lib/api/client"; // ─── Types ──────────────────────────────────────────────────────────────────── export interface LocalizedText { - tm: string; - ru: string; - en: string; + tm?: string; + ru?: string; + en?: string; } export function resolveLocalizedName(name: LocalizedText | string | null | undefined, lang = "en"): string { if (!name) return ""; if (typeof name === "string") return name; - return name[lang as keyof LocalizedText] ?? name.tm ?? name.en ?? name.ru ?? ""; + const key = (lang === "tk" ? "tm" : lang) as keyof LocalizedText; + return name[key] ?? name.tm ?? name.en ?? name.ru ?? ""; } export type CardRequisiteStatus = "pending" | "approved" | "rejected"; @@ -26,12 +27,12 @@ export interface CardRequisiteUser { export interface CardRequisiteCardType { id: number; - name: LocalizedText; + name: LocalizedText | string; } export interface CardRequisiteBranch { id: number; - name: LocalizedText; + name: LocalizedText | string; } /** Raw backend entity (GET responses mirror this shape). */ diff --git a/src/features/cardTransactions/components/cardTransactionForm.tsx b/src/features/cardTransactions/components/cardTransactionForm.tsx index af39684..3eaf024 100644 --- a/src/features/cardTransactions/components/cardTransactionForm.tsx +++ b/src/features/cardTransactions/components/cardTransactionForm.tsx @@ -11,7 +11,7 @@ import { useCreateCardTransaction, useUpdateCardTransaction } from "../hooks/use import { useInfiniteClients } from "@/features/clients/hooks/useClients"; import { useWebSelfLock } from "@/features/shared/hooks/useWebSelfLock"; import { useCardTypes } from "@/features/cardTypes/hooks/useCardTypes"; -import type { LocalizedTitle } from "@/features/cardTypes/api/cardTypesApi"; +import { resolveCardTypeTitle, type LocalizedTitle } from "@/features/cardTypes/api/cardTypesApi"; import { cardTransactionFormSchema, DEFAULT_FORM_VALUES, buildPayload } from "../schemas/cardTransaction.schema"; import type { CardTransactionFormData } from "../schemas/cardTransaction.schema"; import { MONTH_OPTIONS, CARD_YEAR_OPTIONS } from "@/constants"; @@ -74,7 +74,7 @@ export function CardTransactionForm({ mode, initialData }: CardTransactionFormPr const cardTypeOptions = useMemo(() => { const opts = (cardTypesData?.paymentCards ?? []).map((ct) => ({ value: String(ct.id), - label: ct.title[lang] || ct.title.tm, + label: resolveCardTypeTitle(ct.title, lang), })); if (initialData?.type && !opts.some((o) => o.value === initialData.type)) { diff --git a/src/features/cardTypes/api/cardTypesApi.ts b/src/features/cardTypes/api/cardTypesApi.ts index 0ef2b5b..6d30a91 100644 --- a/src/features/cardTypes/api/cardTypesApi.ts +++ b/src/features/cardTypes/api/cardTypesApi.ts @@ -3,15 +3,24 @@ import apiClient from "@/lib/api/client"; // ─── Types ──────────────────────────────────────────────────────────────────── export interface LocalizedTitle { - tm: string; - ru: string; - en: string; + tm?: string; + ru?: string; + en?: string; +} + +export type LocalizedCardTypeTitle = string | LocalizedTitle; + +export function resolveCardTypeTitle(val: LocalizedCardTypeTitle | null | undefined, lang = "tm"): string { + if (!val) return ""; + if (typeof val === "string") return val; + const key = (lang === "tk" ? "tm" : lang) as keyof LocalizedTitle; + return val[key] ?? val.tm ?? val.en ?? val.ru ?? ""; } export interface CardType { id: number; price: string; - title: LocalizedTitle; + title: LocalizedCardTypeTitle; notes: string; active: boolean; } diff --git a/src/features/cardTypes/schemas/cardType.schema.ts b/src/features/cardTypes/schemas/cardType.schema.ts index 5efff7f..ecbab15 100644 --- a/src/features/cardTypes/schemas/cardType.schema.ts +++ b/src/features/cardTypes/schemas/cardType.schema.ts @@ -1,5 +1,5 @@ import { z } from "zod"; -import type { CardType, CreateCardTypePayload } from "../api/cardTypesApi"; +import { resolveCardTypeTitle, type CardType, type CreateCardTypePayload } from "../api/cardTypesApi"; export function createCardTypeFormSchema(t: (key: string, fallback?: string) => string) { return z.object({ @@ -36,9 +36,9 @@ export function buildPayload(data: CardTypeFormData): CreateCardTypePayload { export function mapInitial(data: CardType): CardTypeFormData { return { - nameTk: data.title.tm, - nameRu: data.title.ru, - nameEn: data.title.en, + nameTk: resolveCardTypeTitle(data.title, "tm"), + nameRu: resolveCardTypeTitle(data.title, "ru"), + nameEn: resolveCardTypeTitle(data.title, "en"), price: data.price, notes: data.notes ?? "", active: data.active, diff --git a/src/features/districts/api/districtsApi.ts b/src/features/districts/api/districtsApi.ts index dd68e18..f7fc81a 100644 --- a/src/features/districts/api/districtsApi.ts +++ b/src/features/districts/api/districtsApi.ts @@ -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 LocalizedDistrictField = string | LocalizedText; + +export function resolveDistrictName(val: LocalizedDistrictField | 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 ?? ""; } // ─── District (Province) ────────────────────────────────────────────────────── export interface District { id: number; - name: LocalizedText; - region: LocalizedText; + name: LocalizedDistrictField; + region: LocalizedDistrictField; active: boolean; } diff --git a/src/features/districts/components/districtsForm.tsx b/src/features/districts/components/districtsForm.tsx index 3f16ea2..94a45c0 100644 --- a/src/features/districts/components/districtsForm.tsx +++ b/src/features/districts/components/districtsForm.tsx @@ -7,7 +7,7 @@ import { Checkbox } from "@/components/ui/checkbox"; import { FormActions } from "@/components/formActions"; import { MultiLangInput } from "@/components/multiLangInput"; import { BentoGrid, BentoCard } from "@/components/bento"; -import type { District } from "../api/districtsApi"; +import { resolveDistrictName, type District } from "../api/districtsApi"; import { useCreateDistrict, useUpdateDistrict } from "../hooks/useDistricts"; import { createDistrictFormSchema, DEFAULT_FORM_VALUES, buildPayload } from "../schemas/district.schema"; import type { DistrictFormData } from "../schemas/district.schema"; @@ -30,12 +30,12 @@ export interface DistrictFormProps { function mapInitial(data: District): DistrictFormData { return { - nameTk: data.name.tm, - nameRu: data.name.ru, - nameEn: data.name.en, - regionTk: data.region.tm, - regionRu: data.region.ru, - regionEn: data.region.en, + nameTk: resolveDistrictName(data.name, "tm"), + nameRu: resolveDistrictName(data.name, "ru"), + nameEn: resolveDistrictName(data.name, "en"), + regionTk: resolveDistrictName(data.region, "tm"), + regionRu: resolveDistrictName(data.region, "ru"), + regionEn: resolveDistrictName(data.region, "en"), isActive: data.active, }; } diff --git a/src/features/loanTypes/api/loanTypesApi.ts b/src/features/loanTypes/api/loanTypesApi.ts index 69b4a77..9d83e5b 100644 --- a/src/features/loanTypes/api/loanTypesApi.ts +++ b/src/features/loanTypes/api/loanTypesApi.ts @@ -3,19 +3,28 @@ 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 LocalizedLoanField = string | LocalizedText; + +export function resolveLoanText(val: LocalizedLoanField | 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 ?? ""; } // ─── Loan Type ──────────────────────────────────────────────────────────────── export interface LoanType { id: number; - title: LocalizedText; + title: LocalizedLoanField; tax: number; loanTerm: string; - content: LocalizedText; + content: LocalizedLoanField; active: boolean; createdAt: string; updatedAt: string; diff --git a/src/features/loanTypes/components/loanTypesForm.tsx b/src/features/loanTypes/components/loanTypesForm.tsx index daf452a..b981417 100644 --- a/src/features/loanTypes/components/loanTypesForm.tsx +++ b/src/features/loanTypes/components/loanTypesForm.tsx @@ -10,7 +10,7 @@ import { MultiLangInput } from "@/components/multiLangInput"; import { Checkbox } from "@/components/ui/checkbox"; import { BentoGrid, BentoCard } from "@/components/bento"; import { useCreateLoanType, useUpdateLoanType } from "../hooks/useLoanTypes"; -import type { LoanType } from "../api/loanTypesApi"; +import { resolveLoanText, type LoanType } from "../api/loanTypesApi"; import { createLoanTypeFormSchema, DEFAULT_FORM_VALUES, buildPayload } from "../schemas/loanType.schema"; import type { LoanTypeFormData } from "../schemas/loanType.schema"; @@ -36,12 +36,12 @@ function flattenErrors(errors: Record) function mapInitial(data: LoanType): LoanTypeFormData { return { - nameTk: data.title.tm, - nameRu: data.title.ru, - nameEn: data.title.en, - notesTk: data.content.tm ?? "", - notesRu: data.content.ru ?? "", - notesEn: data.content.en ?? "", + nameTk: resolveLoanText(data.title, "tm"), + nameRu: resolveLoanText(data.title, "ru"), + nameEn: resolveLoanText(data.title, "en"), + notesTk: resolveLoanText(data.content, "tm"), + notesRu: resolveLoanText(data.content, "ru"), + notesEn: resolveLoanText(data.content, "en"), tax: String(data.tax), loanTerm: data.loanTerm, isActive: data.active, diff --git a/src/features/onlinePaymentHistory/api/onlinePaymentsHistoryApi.ts b/src/features/onlinePaymentHistory/api/onlinePaymentsHistoryApi.ts index facc0bf..fd17335 100644 --- a/src/features/onlinePaymentHistory/api/onlinePaymentsHistoryApi.ts +++ b/src/features/onlinePaymentHistory/api/onlinePaymentsHistoryApi.ts @@ -67,6 +67,32 @@ export interface OnlinePaymentListResponse { export interface GatewayResponse { errorCode?: string; errorMessage?: string; + actionCode?: number; + actionCodeDescription?: string; + orderStatus?: number; + currency?: string; + amount?: number; + date?: number; + ip?: string; + terminalId?: string; + orderNumber?: string; + bankInfo?: { + bankCountryCode?: string; + bankCountryName?: string; + }; + cardAuthInfo?: { + pan?: string; + expiration?: string; + approvalCode?: string; + cardholderName?: string; + }; + paymentAmountInfo?: { + paymentState?: string; + approvedAmount?: number; + refundedAmount?: number; + depositedAmount?: number; + }; + attributes?: Array<{ name?: string; value?: string }>; [key: string]: unknown; } @@ -89,10 +115,18 @@ export interface OnlinePaymentDetail { amountMinor?: number; amountUsd?: number; exchangeRateUsd?: number; + cardholderName?: string; paymentPeriod?: string; gatewayStatus: string; + gatewayReference?: string; apiClient?: string; + apiClientName?: string; description?: string; + maskedPan?: string; + callbackStatus?: string; + callbackAt?: string; + formUrl?: string; + successUrl?: string; createdById?: number; createdByName?: string; createdAt: string; @@ -142,9 +176,13 @@ export async function fetchOnlinePayments(params: OnlinePaymentListParams = {}): * GET /payment-history/:id * Returns the step-by-step history log for a single payment order. */ -export async function fetchOnlinePaymentById(id: number): Promise { - const { data } = await apiClient.get(`/payment-history/${id}`); - return data; +export async function fetchOnlinePaymentById(id: number): Promise { + const { data } = await apiClient.get(`/payment-history/${id}`); + if (Array.isArray(data)) return data; + if (data && Array.isArray(data.data)) return data.data; + if (data && Array.isArray(data.items)) return data.items; + if (data && typeof data === "object") return [data]; + return []; } /** @@ -163,13 +201,14 @@ export async function fetchOnlinePaymentDetail(id: number | string): Promise { - const { page, limit } = params; + const { page, limit, lang } = params; const { data } = await apiClient.get(`/payment-history/${orderId}`, { params: { - page: page ?? 1, - limit: limit ?? 25, + ...(page !== undefined ? { page } : {}), + ...(limit !== undefined ? { limit } : {}), + lang: lang ?? "tm", }, }); @@ -179,6 +218,9 @@ export async function fetchOrderPaymentHistory( if (data && Array.isArray(data.items)) { return { count: data.count ?? data.items.length, items: data.items }; } + if (data && Array.isArray(data.data)) { + return { count: data.data.length, items: data.data }; + } return { count: 0, items: [] }; } diff --git a/src/features/onlinePaymentHistory/hooks/useOnlinePaymentsHistory.ts b/src/features/onlinePaymentHistory/hooks/useOnlinePaymentsHistory.ts index e4fae64..b1f84b4 100644 --- a/src/features/onlinePaymentHistory/hooks/useOnlinePaymentsHistory.ts +++ b/src/features/onlinePaymentHistory/hooks/useOnlinePaymentsHistory.ts @@ -65,7 +65,10 @@ export function useGetOnlinePaymentDetail(id: number | string) { /** * Fetches the paginated payment history for a specific order /payment-history/:id */ -export function useGetOrderPaymentHistory(orderId: number | string | undefined, params: { page?: number; limit?: number } = {}) { +export function useGetOrderPaymentHistory( + orderId: number | string | undefined, + params: { page?: number; limit?: number; lang?: string } = {}, +) { return useQuery({ queryKey: onlinePaymentKeys.orderHistory(orderId ?? "", params), queryFn: () => fetchOrderPaymentHistory(orderId!, params), diff --git a/src/features/orderNewCard/components/orderNewCardForm.tsx b/src/features/orderNewCard/components/orderNewCardForm.tsx index 48c15ac..06bdcb2 100644 --- a/src/features/orderNewCard/components/orderNewCardForm.tsx +++ b/src/features/orderNewCard/components/orderNewCardForm.tsx @@ -18,9 +18,13 @@ import { useCreateCard, useUpdateCard } from "../hooks/useOrderNewCard"; import { validateStep, DEFAULT_FORM_VALUES, buildPayload } from "../schemas/orderNewCard.schema"; import type { OrderNewCardFormData } from "../schemas/orderNewCard.schema"; import { useCardTypes } from "@/features/cardTypes/hooks/useCardTypes"; +import { resolveCardTypeTitle } from "@/features/cardTypes/api/cardTypesApi"; import { useCardReasons } from "@/features/cardReasons/hooks/useCardReasons"; +import { resolveCardReasonTitle } from "@/features/cardReasons/api/cardReasonsApi"; import { useBranches } from "@/features/branches/hooks/useBranches"; +import { resolveLocalizedName } from "@/features/branches/api/branchesApi"; import { useDistricts } from "@/features/districts/hooks/useDistricts"; +import { resolveDistrictName } from "@/features/districts/api/districtsApi"; import { useInfiniteClients } from "@/features/clients/hooks/useClients"; import { useWebSelfLock } from "@/features/shared/hooks/useWebSelfLock"; import { PASSPORT_SERIES_OPTIONS, getStatusOptions } from "@/constants"; @@ -530,7 +534,7 @@ export function CardOrderForm({ mode, initialData }: CardOrderFormProps) { () => (cardTypesData?.paymentCards ?? []).map((ct) => ({ value: String(ct.id), - label: ct.title[lang] || ct.title.tm, + label: resolveCardTypeTitle(ct.title, lang), })), [cardTypesData, lang], ); @@ -539,7 +543,7 @@ export function CardOrderForm({ mode, initialData }: CardOrderFormProps) { () => (cardReasonsData?.reasonCards ?? []).map((cr) => ({ value: String(cr.id), - label: cr.title[lang] || cr.title.tm, + label: resolveCardReasonTitle(cr.title, lang), })), [cardReasonsData, lang], ); @@ -548,7 +552,7 @@ export function CardOrderForm({ mode, initialData }: CardOrderFormProps) { () => (branchesData?.branches ?? []).map((b) => ({ value: String(b.id), - label: b.name[lang] || b.name.tm, + label: resolveLocalizedName(b.name, lang), })), [branchesData, lang], ); @@ -556,8 +560,8 @@ export function CardOrderForm({ mode, initialData }: CardOrderFormProps) { const districtOptions = useMemo( () => (districtsData?.provinces ?? []).map((d) => ({ - value: d.region?.tm || d.name.tm, - label: d.name[lang] || d.name.tm, + value: resolveDistrictName(d.region, "tm") || resolveDistrictName(d.name, "tm"), + label: resolveDistrictName(d.name, lang), })), [districtsData, lang], ); diff --git a/src/features/shared/components/assignDialog.tsx b/src/features/shared/components/assignDialog.tsx index 81636ea..5f298f8 100644 --- a/src/features/shared/components/assignDialog.tsx +++ b/src/features/shared/components/assignDialog.tsx @@ -15,7 +15,7 @@ import { useInfiniteUsers } from "@/features/allUsers/hooks/useAllUsers"; import { useInfiniteRoles } from "@/features/roles/hooks/useRoles"; import { useInfiniteBranches } from "@/features/shared/hooks/useSharedBranchUsers"; import { useAssignRoleToUser, useAssignBranchToUser } from "@/features/shared/hooks/useSharedUserAssignments"; -import type { LocalizedText } from "@/features/branches/api/branchesApi"; +import { resolveLocalizedName } from "@/features/branches/api/branchesApi"; export type AssignDialogKind = "role" | "branch"; @@ -39,7 +39,7 @@ const ASSIGN_DIALOG_FIELD_LABELS: Record = { export function AssignDialog({ kind, onClose, targetUserId, targetUserName, onAssigned }: AssignDialogProps) { const { t, i18n } = useTranslation(); - const lang = (i18n.language === "ru" ? "ru" : i18n.language === "en" ? "en" : "tm") as keyof LocalizedText; + const lang = (i18n.language === "ru" ? "ru" : i18n.language === "en" ? "en" : "tm") as "tm" | "ru" | "en"; const [targetSearch, setTargetSearch] = useState(""); const [targetValue, setTargetValue] = useState(() => (targetUserId ? String(targetUserId) : "")); const [resourceSearch, setResourceSearch] = useState(""); @@ -76,7 +76,7 @@ export function AssignDialog({ kind, onClose, targetUserId, targetUserName, onAs .flatMap((page) => page?.branches ?? []) .map((branch) => ({ value: String(branch.id), - label: branch.name?.[lang] || branch.name?.tm || branch.name?.en || branch.name?.ru || branch.uniqueCode || String(branch.id), + label: resolveLocalizedName(branch.name, lang) || branch.uniqueCode || String(branch.id), })); }, [kind, rolesQuery.data, branchesQuery.data, lang]); diff --git a/src/features/visaMasterPayments/components/PaymentDetailDialog.tsx b/src/features/visaMasterPayments/components/PaymentDetailDialog.tsx index e26a77a..2052613 100644 --- a/src/features/visaMasterPayments/components/PaymentDetailDialog.tsx +++ b/src/features/visaMasterPayments/components/PaymentDetailDialog.tsx @@ -1,6 +1,7 @@ +import type React from "react"; import { Link } from "react-router-dom"; import { useTranslation } from "react-i18next"; -import { Database, AlertTriangle, Eye } from "lucide-react"; +import { Database, AlertTriangle, Eye, ExternalLink } from "lucide-react"; import { Skeleton } from "@/components/ui/skeleton"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription } from "@/components/ui/dialog"; @@ -28,20 +29,18 @@ export function PaymentDetailDialog({ paymentId, open, onOpenChange }: PaymentDe return ( - + -
-
- - - {t("onlinePayments.paymentViewTitle", "Töleg maglumaty")}: #{paymentId} - -
+
+ + + {t("onlinePayments.paymentViewTitle", "Töleg maglumaty")}: #{paymentId} + {data && ( -
+ <> -
+ )}
{data?.orderNumber && ( @@ -52,21 +51,19 @@ export function PaymentDetailDialog({ paymentId, open, onOpenChange }: PaymentDe {isLoading ? ( -
- -
- - -
+
+ + +
) : isError || !data ? (
{t("common.error", "Maglumat ýüklenende ýalňyşlyk ýüze çykdy")}
) : ( -
- {/* Gateway Response Alert if Error */} +
+ {/* Gateway error alert */} {data.gatewayResponse && (data.gatewayResponse.errorCode || data.gatewayResponse.errorMessage) && ( -
+
@@ -77,122 +74,105 @@ export function PaymentDetailDialog({ paymentId, open, onOpenChange }: PaymentDe
)} - {/* Grid 1: General Info */} + {/* Section 1: General */}

{t("onlinePayments.sectionGeneral", "Esasy maglumatlar")}

-
-
- {t("common.id", "ID")} - {data.id} -
-
- {t("onlinePayments.columns.orderId", "Sargyt ID")} +
+ + {data.id} + + #{data.orderId} -
-
- {t("onlinePayments.columns.orderNumber", "Sargyt belgisi")} - {data.orderNumber || "—"} -
-
- {t("onlinePayments.columns.type", "Görnüşi")} - {data.type} -
+ + + {data.orderNumber || "—"} + + + {data.type} + {data.description && ( -
- {t("onlinePayments.columns.description", "Düşündiriş")} - {data.description} -
+ + {data.description} + )} -
- {t("onlinePayments.columns.createdAt", "Döredilen wagty")} - {formatFromApiDate(data.createdAt)} -
-
- {t("onlinePayments.columns.updatedAt", "Täzelenen wagty")} - {formatFromApiDate(data.updatedAt)} -
+ + {formatFromApiDate(data.createdAt)} + + + {formatFromApiDate(data.updatedAt)} +
- {/* Grid 2: Financial Info */} + {/* Section 2: Financial */}

{t("onlinePayments.sectionFinancial", "Maliýe maglumatlary")}

-
-
- {t("onlinePayments.columns.amountTmt", "Töleg möçberi")} - {data.amountTmt?.toLocaleString?.() ?? data.amountTmt} TMT -
-
- {t("onlinePayments.columns.totalAmount", "Jemi töleg möçberi")} +
+ + {data.amountTmt?.toLocaleString?.() ?? data.amountTmt} TMT + + {data.totalAmountTmt?.toLocaleString?.() ?? data.totalAmountTmt} TMT -
-
- {t("onlinePayments.columns.bankFeeTmt", "Bank komissiýasy")} - {data.bankFeeTmt?.toLocaleString?.() ?? data.bankFeeTmt} TMT -
-
- {t("onlinePayments.columns.gbusFeeTmt", "GBUS komissiýasy")} - {data.gbusFeeTmt?.toLocaleString?.() ?? data.gbusFeeTmt} TMT -
+ + + {data.bankFeeTmt?.toLocaleString?.() ?? data.bankFeeTmt} TMT + + + {data.gbusFeeTmt?.toLocaleString?.() ?? data.gbusFeeTmt} TMT + {data.amountUsd != null && ( -
- {t("onlinePayments.columns.amountUsd", "Möçber (USD)")} - {data.amountUsd} $ -
+ + {data.amountUsd} $ + )} {data.exchangeRateUsd != null && ( -
- {t("onlinePayments.columns.exchangeRateUsd", "Hümmet (USD)")} - {data.exchangeRateUsd} TMT -
+ + {data.exchangeRateUsd} TMT + )} {data.paymentPeriod && ( -
- {t("onlinePayments.columns.paymentPeriod", "Töleg döwri")} - {formatFromApiDate(data.paymentPeriod)} -
+ + {formatFromApiDate(data.paymentPeriod)} + )} {data.apiClient && ( -
- {t("onlinePayments.columns.apiClient", "API Client")} - {data.apiClient} -
+ + {data.apiClient} + )}
- {/* Grid 3: Customer & Branch */} + {/* Section 3: Customer & Branch */}

{t("onlinePayments.sectionCustomer", "Müşderi we Şahamça")}

-
-
- {t("onlinePayments.columns.passport", "Müşderi")} - - {[data.passportName, data.passportSurname].filter(Boolean).join(" ") || "—"} - -
-
- {t("onlinePayments.columns.userId", "Ulanyjy ID")} +
+ + {[data.passportName, data.passportSurname].filter(Boolean).join(" ") || "—"} + + #{data.userId} -
-
- {t("onlinePayments.columns.branch", "Şahamça")} - {data.branchName?.[lang] || data.branchName?.tm || data.branchName?.en || "—"} -
-
- {t("onlinePayments.columns.createdByName", "Döreden işgär")} - {data.createdByName || "—"} -
+ + + + {(typeof data.branchName === "string" + ? data.branchName + : data.branchName?.[lang] || data.branchName?.tm || data.branchName?.en) || "—"} + + + + {data.createdByName || "—"} +
@@ -202,57 +182,276 @@ export function PaymentDetailDialog({ paymentId, open, onOpenChange }: PaymentDe ); } +// ─── Shared Row helper ──────────────────────────────────────────────────────── + +function Row({ label, children }: { label: string; children: React.ReactNode }) { + return ( +
+ {label} + {children} +
+ ); +} + // ─── LastStepDialog ─────────────────────────────────────────────────────────── -interface LastStepDialogProps { - /** The order ID (row.original.orderId) used to fetch the step history. */ +export interface LastStepDialogProps { + /** The ID used to fetch the step history from /payment-history/:id. */ orderId: number | null; open: boolean; onOpenChange: (open: boolean) => void; } /** - * Opens a dialog showing only the most recent payment history step + * Opens a dialog showing only the most recent payment history step / operation * for the given order. Used by the Eye icon in PaymentHistoryTable. + * Fetches its own data independently via useGetOnlinePaymentById (/payment-history/:id). */ export function LastStepDialog({ orderId, open, onOpenChange }: LastStepDialogProps) { - const { t } = useTranslation(); - const { data: steps, isLoading } = useGetOnlinePaymentById(orderId ?? 0); + const { t, i18n } = useTranslation(); + const lang = resolveLang(i18n.language); + const { data: rawSteps, isLoading, isError } = useGetOnlinePaymentById(orderId ?? 0); - // The "last" step is the one with the highest createdAt (or last element if already sorted desc). - const lastStep = steps?.length ? [...steps].sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime())[0] : null; + const steps: any[] = Array.isArray(rawSteps) + ? rawSteps + : (rawSteps as any)?.data && Array.isArray((rawSteps as any).data) + ? (rawSteps as any).data + : (rawSteps as any)?.items && Array.isArray((rawSteps as any).items) + ? (rawSteps as any).items + : rawSteps && typeof rawSteps === "object" && (rawSteps as any).id + ? [rawSteps] + : []; + const lastStep = steps.length + ? [...steps].sort((a, b) => new Date(b.createdAt || 0).getTime() - new Date(a.createdAt || 0).getTime())[0] + : null; + + const branchDisplay = + typeof lastStep?.branchName === "string" + ? lastStep.branchName + : lastStep?.branchName?.[lang] || lastStep?.branchName?.tm || lastStep?.branchName?.en || null; + + const fullName = [lastStep?.passportName, lastStep?.passportSurname].filter(Boolean).join(" "); const detailEntries = Object.entries(lastStep?.detail ?? {}); return ( - + -
- +
+ {t("onlinePayments.lastStep.title", "Iň soňky işlem")} + {lastStep && ( + <> + {(lastStep.gatewayStatus || lastStep.step) && } + {typeof lastStep.paid === "boolean" && } + + )}
- {orderId && Order #{orderId}} + {(lastStep?.orderNumber || lastStep?.orderId || orderId) && ( + + {t("onlinePayments.columns.orderNumber", "Sargyt belgisi")}:{" "} + {lastStep?.orderNumber || `Order #${lastStep?.orderId || orderId}`} + + )} {isLoading ? (
- + +
- ) : !lastStep ? ( + ) : isError || !lastStep ? (
{t("onlinePayments.noHistory", "Töleg taryhy tapylmady")}
) : ( -
- {/* Step header: status badge + time + operator */} -
- - {formatFromApiDate(lastStep.createdAt)} - {lastStep.createdByName && {lastStep.createdByName}} +
+ {/* Section 1: General */} +
+

+ {t("onlinePayments.sectionGeneral", "Esasy maglumatlar")} +

+
+ {lastStep.id != null && ( + + {lastStep.id} + + )} + {lastStep.orderId != null && ( + + + #{lastStep.orderId} + + + )} + {lastStep.orderNumber && ( + + {lastStep.orderNumber} + + )} + {lastStep.type && ( + + {lastStep.type} + + )} + {lastStep.description && ( + + {lastStep.description} + + )} + {lastStep.gatewayReference && ( + + {lastStep.gatewayReference} + + )} + {(lastStep.apiClientName || lastStep.apiClient) && ( + + {lastStep.apiClientName || lastStep.apiClient} + + )} + {lastStep.callbackStatus && ( + + {lastStep.callbackStatus} + + )} + {lastStep.createdAt && ( + + {formatFromApiDate(lastStep.createdAt)} + + )} + {lastStep.callbackAt && ( + + {formatFromApiDate(lastStep.callbackAt)} + + )} + {lastStep.updatedAt && ( + + {formatFromApiDate(lastStep.updatedAt)} + + )} +
- {/* Detail key-value grid */} + {/* Section 2: Financial */} + {(lastStep.amountTmt != null || lastStep.totalAmountTmt != null || lastStep.amountUsd != null) && ( +
+

+ {t("onlinePayments.sectionFinancial", "Maliýe maglumatlary")} +

+
+ {lastStep.totalAmountTmt != null && ( + + + {lastStep.totalAmountTmt?.toLocaleString?.() ?? lastStep.totalAmountTmt} TMT + + + )} + {lastStep.amountTmt != null && ( + + {lastStep.amountTmt?.toLocaleString?.() ?? lastStep.amountTmt} TMT + + )} + {lastStep.bankFeeTmt != null && ( + + {lastStep.bankFeeTmt?.toLocaleString?.() ?? lastStep.bankFeeTmt} TMT + + )} + {lastStep.gbusFeeTmt != null && ( + + {lastStep.gbusFeeTmt?.toLocaleString?.() ?? lastStep.gbusFeeTmt} TMT + + )} + {lastStep.amountUsd != null && ( + + {lastStep.amountUsd} $ + + )} + {lastStep.exchangeRateUsd != null && ( + + {lastStep.exchangeRateUsd} TMT + + )} + {lastStep.paymentPeriod && ( + + {formatFromApiDate(lastStep.paymentPeriod)} + + )} +
+
+ )} + + {/* Section 3: Customer & Branch */} + {(fullName || lastStep.branchName || lastStep.createdByName || lastStep.userId) && ( +
+

+ {t("onlinePayments.sectionCustomer", "Müşderi we Şahamça")} +

+
+ {fullName && ( + + {fullName} + + )} + {lastStep.userId != null && ( + + + #{lastStep.userId} + + + )} + {branchDisplay && ( + + {branchDisplay} + + )} + {lastStep.createdByName && ( + + {lastStep.createdByName} + + )} +
+
+ )} + + {/* Section 4: External URLs */} + {(lastStep.formUrl || lastStep.successUrl) && ( +
+

+ {t("onlinePayments.sectionUrls", "Baglanyşyklar")} +

+
+ {lastStep.formUrl && ( + + + + {lastStep.formUrl} + + + )} + {lastStep.successUrl && ( + + + + {lastStep.successUrl} + + + )} +
+
+ )} + + {/* Legacy detail entries if present */} {detailEntries.length > 0 && (

@@ -260,21 +459,13 @@ export function LastStepDialog({ orderId, open, onOpenChange }: LastStepDialogPr

{detailEntries.map(([key, value]) => ( -
- - {t(`onlinePayments.detailKeys.${key}`, rawEnumKey(key))} - - {String(value)} -
+ + {String(value)} + ))}
)} - - {/* Step ID */} -

- Step ID: {lastStep.id} -

)} diff --git a/src/features/visaMasterPayments/components/PaymentHistoryTable.tsx b/src/features/visaMasterPayments/components/PaymentHistoryTable.tsx index e6ddcc4..9c85798 100644 --- a/src/features/visaMasterPayments/components/PaymentHistoryTable.tsx +++ b/src/features/visaMasterPayments/components/PaymentHistoryTable.tsx @@ -1,13 +1,14 @@ import { useState, useMemo } from "react"; import { useTranslation } from "react-i18next"; -import { Eye } from "lucide-react"; +import { ScanLine, Eye } from "lucide-react"; import type { VisibilityState } from "@tanstack/react-table"; import { DataTable, type ColumnDef, type SortingState } from "@/components/dataTable"; import { DataTableToolbar, type ColumnMeta } from "@/components/dataTableToolbar"; import { Button } from "@/components/ui/button"; -import { useGetPaymentGateway } from "@/features/onlinePaymentHistory/hooks/useOnlinePaymentsHistory"; -import { ActiveStatusCell } from "@/constants/statusCells"; +import { useGetOrderPaymentHistory } from "@/features/onlinePaymentHistory/hooks/useOnlinePaymentsHistory"; +import { GatewayStatusCell } from "@/constants/statusCells"; +import { PaidBadge } from "@/features/onlinePaymentHistory/components/PaymentStatusBadge"; import { formatFromApiDate } from "@/lib/utils/dateUtils"; import { PaymentDetailDialog, LastStepDialog } from "./PaymentDetailDialog"; @@ -78,27 +79,15 @@ function isPaid(row: any): boolean { return Boolean(row.paid ?? (row.detail?.paid === "true" || row.detail?.paid === true)); } -function isSynced(row: any): boolean { - if (row.gatewayResponse?.orderStatus === 0 || row.gatewayResponse?.errorMessage === "Успешно") return true; - return Boolean( - row.synced ?? - row.isSynced ?? - row.systemSynced ?? - row.syncedWithSystem ?? - (row.detail?.synced === "true" || row.detail?.synced === true), - ); -} - const PER_PAGE = 25; // ─── Main Component ─────────────────────────────────────────────────────────── interface PaymentHistoryTableProps { orderId?: string | number; - paymentId?: string | number; } -export function PaymentHistoryTable({ orderId, paymentId }: PaymentHistoryTableProps = {}) { +export function PaymentHistoryTable({ orderId }: PaymentHistoryTableProps = {}) { const { t } = useTranslation(); // ─── Dialog State ────────────────────────────────────────────────────────── @@ -117,19 +106,11 @@ export function PaymentHistoryTable({ orderId, paymentId }: PaymentHistoryTableP const [columnVisibility, setColumnVisibility] = useState({}); const [columnOrder, setColumnOrder] = useState([]); - // ─── Query: /payment-history/payments/:id/gateway ────────────────────────── - const effectiveId = paymentId || orderId; - const { data: rawData, isLoading } = useGetPaymentGateway(effectiveId); + // ─── Query: /payment-history/:id?lang=tm ─────────────────────────────────── + const { data: historyData, isLoading } = useGetOrderPaymentHistory(orderId, { lang: "tm" }); const items = useMemo(() => { - let list: any[] = []; - if (Array.isArray(rawData)) { - list = rawData; - } else if (rawData && typeof rawData === "object" && (rawData as any).id) { - list = [rawData]; - } else if (rawData && Array.isArray((rawData as any).items)) { - list = (rawData as any).items; - } + const list = historyData?.items ?? []; if (!search.trim()) return list; const q = search.trim().toLowerCase(); @@ -137,13 +118,11 @@ export function PaymentHistoryTable({ orderId, paymentId }: PaymentHistoryTableP const haystack = [r.id, getPayerFullName(r), getMaskedCard(r), getReference(r), r.orderId].join(" ").toLowerCase(); return haystack.includes(q); }); - }, [rawData, search]); + }, [historyData, search]); const totalCount = useMemo(() => { - if (Array.isArray(rawData)) return rawData.length; - if (rawData && typeof (rawData as any).count === "number") return (rawData as any).count; - return items.length; - }, [rawData, items]); + return historyData?.count ?? items.length; + }, [historyData, items]); const totalPages = Math.ceil(totalCount / perPage) || 1; @@ -234,21 +213,14 @@ export function PaymentHistoryTable({ orderId, paymentId }: PaymentHistoryTableP { id: "isPaid", header: t("intlPayment.historyColumns.isPaid", "Tölenen"), - cell: ({ row }) => ( - - ), + cell: ({ row }) => , size: 110, }, { - id: "isSynced", - header: t("intlPayment.historyColumns.isSynced", "Ulgam bn birikdirilen"), - cell: ({ row }) => ( - - ), + id: "gatewayStatus", + accessorKey: "gatewayStatus", + header: t("onlinePayments.columns.gatewayStatus", "Gateway statusy"), + cell: ({ row }) => , size: 130, }, { @@ -257,7 +229,7 @@ export function PaymentHistoryTable({ orderId, paymentId }: PaymentHistoryTableP cell: ({ row }) => (
{/* Storage (Database) icon: opens payment detail dialog */} - {/* */} + + {/* Eye icon: opens last-step dialog */}
{/* Single history table */} - +
); diff --git a/src/pages/loanDepartment/loanOrderMobile/index.tsx b/src/pages/loanDepartment/loanOrderMobile/index.tsx index 8c2fe36..e6199cc 100644 --- a/src/pages/loanDepartment/loanOrderMobile/index.tsx +++ b/src/pages/loanDepartment/loanOrderMobile/index.tsx @@ -11,6 +11,7 @@ import { TableActions } from "@/components/tableActions"; import { useLoanOrderMobiles, useDeleteLoanOrderMobile } from "@/features/loanOrderMobiles/hooks/useLoanOrderMobiles"; import type { LoanOrderMobile, LoanOrderMobileStatus } from "@/features/loanOrderMobiles/api/loanOrderMobilesApi"; import { useInfiniteBranches } from "@/features/branches/hooks/useBranches"; +import { resolveLocalizedName } from "@/features/branches/api/branchesApi"; import { DeleteDialog } from "@/components/deleteDialog"; import { getStatusOptions, getRegionOptions, StatusCell } from "@/constants"; import { formatFromApiDate } from "@/lib/utils"; @@ -53,7 +54,7 @@ export default function LoanOrderMobilesPage() { (branchesInfiniteData?.pages ?? []).flatMap((page) => (page?.branches ?? []).map((b) => ({ value: String(b.id), - label: b.name[lang] || b.name.tm, + label: resolveLocalizedName(b.name, lang), })), ), [branchesInfiniteData, lang], diff --git a/src/pages/loanDepartment/loanOrders/index.tsx b/src/pages/loanDepartment/loanOrders/index.tsx index 1b6989f..76e7414 100644 --- a/src/pages/loanDepartment/loanOrders/index.tsx +++ b/src/pages/loanDepartment/loanOrders/index.tsx @@ -10,6 +10,7 @@ import { TableActions } from "@/components/tableActions"; import { useLoanOrders, useDeleteLoanOrder } from "@/features/loanOrders/hooks/useLoanOrders"; import type { LoanOrder, LoanOrderStatus } from "@/features/loanOrders/api/loanOrdersApi"; import { useInfiniteBranches } from "@/features/branches/hooks/useBranches"; +import { resolveLocalizedName } from "@/features/branches/api/branchesApi"; import { DeleteDialog } from "@/components/deleteDialog"; import { getStatusOptions, getRegionOptions, StatusCell } from "@/constants"; import { formatFromApiDate } from "@/lib/utils"; @@ -51,7 +52,7 @@ export default function LoanOrdersPage() { (branchesInfiniteData?.pages ?? []).flatMap((page) => (page?.branches ?? []).map((b) => ({ value: String(b.id), - label: b.name[lang] || b.name.tm, + label: resolveLocalizedName(b.name, lang), })), ), [branchesInfiniteData, lang], diff --git a/src/pages/loanDepartment/loanPaidOffLetters/index.tsx b/src/pages/loanDepartment/loanPaidOffLetters/index.tsx index 712b872..77dc088 100644 --- a/src/pages/loanDepartment/loanPaidOffLetters/index.tsx +++ b/src/pages/loanDepartment/loanPaidOffLetters/index.tsx @@ -13,7 +13,9 @@ import { useLoanPaidOffLetters, useDeleteLoanPaidOffLetter } from "@/features/lo import type { LoanPaidOffLetter } from "@/features/loanPaidOffLetters/api/loanPaidOffLettersApi"; import { DeleteDialog } from "@/components/deleteDialog"; import { useInfiniteBranches } from "@/features/branches/hooks/useBranches"; +import { resolveLocalizedName } from "@/features/branches/api/branchesApi"; import { useInfiniteDistricts } from "@/features/districts/hooks/useDistricts"; +import { resolveDistrictName } from "@/features/districts/api/districtsApi"; import { getStatusOptions, StatusCell } from "@/constants"; // ─── Column IDs ──────────────────────────────────────────────────────────────── @@ -120,7 +122,7 @@ export default function LoanPaidOffLettersPage() { (branchesInfiniteData?.pages ?? []).flatMap((page) => (page?.branches ?? []).map((b) => ({ value: String(b.id), - label: b.name[lang] || b.name.tm, + label: resolveLocalizedName(b.name, lang), })), ), [branchesInfiniteData, lang], @@ -130,8 +132,8 @@ export default function LoanPaidOffLettersPage() { () => (districtsInfiniteData?.pages ?? []).flatMap((page) => (page?.provinces ?? []).map((d) => ({ - value: d.region?.tm || d.name.tm, - label: d.name[lang] || d.name.tm, + value: resolveDistrictName(d.region, "tm") || resolveDistrictName(d.name, "tm"), + label: resolveDistrictName(d.name, lang), })), ), [districtsInfiniteData, lang], diff --git a/src/pages/onlinePaymentsHistory/index.tsx b/src/pages/onlinePaymentsHistory/index.tsx index 20e14f5..488a087 100644 --- a/src/pages/onlinePaymentsHistory/index.tsx +++ b/src/pages/onlinePaymentsHistory/index.tsx @@ -13,6 +13,7 @@ import type { OnlinePayment, PaymentSortField, PaymentSortOrder } from "@/featur import { GatewayStatusBadge, PaidBadge } from "../../features/onlinePaymentHistory/components/PaymentStatusBadge"; import { getPaymentHistoryStatusOptions } from "@/constants/paymentStatus"; import { useInfiniteBranches } from "@/features/branches/hooks/useBranches"; +import { resolveLocalizedName } from "@/features/branches/api/branchesApi"; // ─── Helpers ────────────────────────────────────────────────────────────────── @@ -108,7 +109,7 @@ export default function OnlinePaymentHistoryPage() { (branchesInfiniteData?.pages ?? []).flatMap((p) => (p?.branches ?? []).map((b) => ({ value: String(b.id), - label: b.name[lang] || b.name.tm, + label: resolveLocalizedName(b.name, lang), })), ), [branchesInfiniteData, lang], diff --git a/src/pages/onlinePaymentsHistory/onlinePaymentDetailView.tsx b/src/pages/onlinePaymentsHistory/onlinePaymentDetailView.tsx index bf902c4..61f2502 100644 --- a/src/pages/onlinePaymentsHistory/onlinePaymentDetailView.tsx +++ b/src/pages/onlinePaymentsHistory/onlinePaymentDetailView.tsx @@ -6,9 +6,8 @@ import { Button } from "@/components/ui/button"; import { Skeleton } from "@/components/ui/skeleton"; import { BentoGrid, BentoCard, InfoRow } from "@/components/viewPageComponents"; import { GatewayStatusBadge, PaidBadge } from "@/features/onlinePaymentHistory/components/PaymentStatusBadge"; -import { useGetOnlinePaymentDetail, useGetOnlinePaymentById } from "@/features/onlinePaymentHistory/hooks/useOnlinePaymentsHistory"; +import { useGetOnlinePaymentDetail } from "@/features/onlinePaymentHistory/hooks/useOnlinePaymentsHistory"; import { formatFromApiDate } from "@/lib/utils/dateUtils"; -import { rawEnumKey, type TranslateFn } from "@/constants/enumLabels"; function formatDateTime(iso: string | null | undefined): string { if (!iso) return "—"; @@ -21,10 +20,6 @@ function resolveLang(lang: string): "en" | "ru" | "tm" { return "en"; } -function detailKeyLabel(key: string, t: TranslateFn): string { - return t(`onlinePayments.detailKeys.${key}`, rawEnumKey(key)); -} - export default function OnlinePaymentDetailViewPage() { const { id } = useParams<{ id: string }>(); const navigate = useNavigate(); @@ -32,7 +27,6 @@ export default function OnlinePaymentDetailViewPage() { const lang = resolveLang(i18n.language); const { data, isLoading, isError } = useGetOnlinePaymentDetail(id!); - const { data: steps } = useGetOnlinePaymentById(data?.orderId ?? (data?.id || 0)); if (isLoading) { return ( @@ -100,7 +94,10 @@ export default function OnlinePaymentDetailViewPage() {
- Gateway Ýalňyşlygy {data.gatewayResponse.errorCode ? `(Kod: ${data.gatewayResponse.errorCode})` : ""} + {t("onlinePayments.gatewayErrorTitle", "Gateway error")}{" "} + {data.gatewayResponse.errorCode + ? ` (${t("onlinePayments.gateway.errorCode", "Error code")}: ${data.gatewayResponse.errorCode})` + : ""}
{data.gatewayResponse.errorMessage &&
{data.gatewayResponse.errorMessage}
}
@@ -192,39 +189,72 @@ export default function OnlinePaymentDetailViewPage() { - {/* ── Row 3: Last Payment Step ──────────────────────────────────────────── */} - {steps && - steps.length > 0 && - (() => { - const lastStep = [...steps].sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime())[0]; - const detailEntries = Object.entries(lastStep.detail ?? {}); + {/* ── Row 3: Gateway details ──────────────────────────────────────────── */} + {data.gatewayResponse && ( + + + + + + + + + + + + + - return ( - -
- {/* Header: status + time + operator */} -
- - {formatDateTime(lastStep.createdAt)} - {lastStep.createdByName && {lastStep.createdByName}} - Step ID: {lastStep.id} -
+ + + + + + + + + + + + )} - {/* Detail key-value rows */} - {detailEntries.length > 0 && ( -
- {detailEntries.map(([key, value]) => ( -
- {detailKeyLabel(key, t)} - {String(value)} -
- ))} -
- )} -
-
- ); - })()} + +
+ + + + + + +
+
); } diff --git a/src/pages/settings/card/cardTypes/index.tsx b/src/pages/settings/card/cardTypes/index.tsx index 02e2a99..f403a70 100644 --- a/src/pages/settings/card/cardTypes/index.tsx +++ b/src/pages/settings/card/cardTypes/index.tsx @@ -12,7 +12,7 @@ import { Checkbox } from "@/components/ui/checkbox"; import { ActiveStatusCell } from "@/constants"; import type { FilterField, ActiveFilter } from "@/components/dataTableToolbar"; import { useCardTypes, useDeleteCardType, useUpdateCardTypeActive } from "@/features/cardTypes/hooks/useCardTypes"; -import type { CardType } from "@/features/cardTypes/api/cardTypesApi"; +import { type CardType, resolveCardTypeTitle } from "@/features/cardTypes/api/cardTypesApi"; export function CardTypesListPage() { const { t, i18n } = useTranslation(); @@ -70,7 +70,7 @@ export function CardTypesListPage() { accessorKey: "title", id: "name", header: t("cardTypes.fields.name", "ADY").toUpperCase(), - cell: ({ row }) => {row.original.title[lang]}, + cell: ({ row }) => {resolveCardTypeTitle(row.original.title, lang)}, }, { accessorKey: "price", diff --git a/src/pages/settings/card/cardTypesView/index.tsx b/src/pages/settings/card/cardTypesView/index.tsx index ee75861..b3522af 100644 --- a/src/pages/settings/card/cardTypesView/index.tsx +++ b/src/pages/settings/card/cardTypesView/index.tsx @@ -4,23 +4,26 @@ import { Skeleton } from "@/components/ui/skeleton"; import { Section, InfoRow, MultiLangRow, ViewActions } from "@/components/viewPageComponents"; import { ActiveStatusCell } from "@/constants"; import { useCardTypeById, useDeleteCardType } from "@/features/cardTypes/hooks/useCardTypes"; +import { resolveCardTypeTitle } from "@/features/cardTypes/api/cardTypesApi"; export function CardTypeViewPage() { const { id } = useParams<{ id: string }>(); const navigate = useNavigate(); - const { t } = useTranslation(); + const { t, i18n } = useTranslation(); const numericId = Number(id); const { data, isLoading } = useCardTypeById(numericId); const deleteMutation = useDeleteCardType(); + const lang = (i18n.language === "ru" ? "ru" : i18n.language === "en" ? "en" : "tm") as "tm" | "ru" | "en"; + return (

- {isLoading ? "..." : `${t("cardTypes.view.title", "Kart görnüşi giňişleýin")}: ${data?.title.tm ?? ""}`} + {isLoading ? "..." : `${t("cardTypes.view.title", "Kart görnüşi giňişleýin")}: ${resolveCardTypeTitle(data?.title, lang)}`}

diff --git a/src/pages/settings/card/reasons/index.tsx b/src/pages/settings/card/reasons/index.tsx index ca14644..ce4f826 100644 --- a/src/pages/settings/card/reasons/index.tsx +++ b/src/pages/settings/card/reasons/index.tsx @@ -11,7 +11,7 @@ import { CreateButton } from "@/components/createButton"; import { TableActions } from "@/components/tableActions"; import type { FilterField, ActiveFilter } from "@/components/dataTableToolbar"; import { useCardReasons, useDeleteCardReason } from "@/features/cardReasons/hooks/useCardReasons"; -import type { CardReason } from "@/features/cardReasons/api/cardReasonsApi"; +import { type CardReason, resolveCardReasonTitle } from "@/features/cardReasons/api/cardReasonsApi"; // ─── CardReasonsListPage ─────────────────────────────────────────────────────── @@ -68,7 +68,7 @@ export function CardReasonsListPage() { accessorKey: "title", id: "name", header: t("cardReasons.fields.name", "ADY").toUpperCase(), - cell: ({ row }) => {row.original.title[lang]}, + cell: ({ row }) => {resolveCardReasonTitle(row.original.title, lang)}, }, { accessorKey: "price", diff --git a/src/pages/settings/card/reasonsView/index.tsx b/src/pages/settings/card/reasonsView/index.tsx index f2dbfa5..c468c40 100644 --- a/src/pages/settings/card/reasonsView/index.tsx +++ b/src/pages/settings/card/reasonsView/index.tsx @@ -4,6 +4,7 @@ import { ActiveStatusCell } from "@/constants"; import { Skeleton } from "@/components/ui/skeleton"; import { Section, InfoRow, MultiLangRow, ViewActions } from "@/components/viewPageComponents"; import { useCardReasonById, useDeleteCardReason } from "@/features/cardReasons/hooks/useCardReasons"; +import { resolveCardReasonTitle } from "@/features/cardReasons/api/cardReasonsApi"; // ─── CardReasonViewPage ──────────────────────────────────────────────────────── @@ -23,7 +24,9 @@ export function CardReasonViewPage() {

- {isLoading ? "..." : `${t("cardReasons.viewTitle", "Kartyň çykarylmagynyň sebäbi giňişleýin")}: ${data?.title[lang] ?? ""}`} + {isLoading + ? "..." + : `${t("cardReasons.viewTitle", "Kartyň çykarylmagynyň sebäbi giňişleýin")}: ${resolveCardReasonTitle(data?.title, lang)}`}

diff --git a/src/pages/settings/loan/loanTypes/index.tsx b/src/pages/settings/loan/loanTypes/index.tsx index e51646a..e70ab46 100644 --- a/src/pages/settings/loan/loanTypes/index.tsx +++ b/src/pages/settings/loan/loanTypes/index.tsx @@ -10,7 +10,7 @@ import { TableSearchInput } from "@/components/tableSearch"; import { CreateButton } from "@/components/createButton"; import { TableActions } from "@/components/tableActions"; import { useGetLoanTypes, useDeleteLoanType } from "@/features/loanTypes/hooks/useLoanTypes"; -import type { LoanType } from "@/features/loanTypes/api/loanTypesApi"; +import { type LoanType, resolveLoanText } from "@/features/loanTypes/api/loanTypesApi"; import { DeleteDialog } from "@/components/deleteDialog"; // ─── Column definitions ─────────────────────────────────────────────────────── @@ -33,7 +33,7 @@ function useLoanTypeColumns( { accessorKey: "title", header: t("loanTypes.columns.name", "ADY"), - cell: ({ row }) => {row.original.title[lang]}, + cell: ({ row }) => {resolveLoanText(row.original.title, lang)}, }, { accessorKey: "tax", @@ -51,8 +51,8 @@ function useLoanTypeColumns( accessorKey: "content", header: t("loanTypes.columns.notes", "BELLIKLER"), cell: ({ row }) => { - const content = row.original.content; - return {content ? content[lang] || "—" : "—"}; + const content = resolveLoanText(row.original.content, lang); + return {content || "—"}; }, }, { diff --git a/src/pages/settings/loan/loanTypesView/index.tsx b/src/pages/settings/loan/loanTypesView/index.tsx index 8259528..8d42f8f 100644 --- a/src/pages/settings/loan/loanTypesView/index.tsx +++ b/src/pages/settings/loan/loanTypesView/index.tsx @@ -6,6 +6,7 @@ import { ActiveStatusCell } from "@/constants"; import { Skeleton } from "@/components/ui/skeleton"; import { Section, InfoRow, MultiLangRow, ViewActions } from "@/components/viewPageComponents"; import { useGetLoanTypeById, useDeleteLoanType } from "@/features/loanTypes/hooks/useLoanTypes"; +import { resolveLoanText } from "@/features/loanTypes/api/loanTypesApi"; // ─── LoanTypeViewPage ───────────────────────────────────────────────────────── @@ -59,7 +60,7 @@ export default function LoanTypeViewPage() { {/* Page header */}

- {t("loanTypes.viewTitle", "Karz görnüşi giňişleýin")}: {data.title[lang]} + {t("loanTypes.viewTitle", "Karz görnüşi giňişleýin")}: {resolveLoanText(data.title, lang)}

{t("loanTypes.fields.notes", "Bellikler")} - {data.content ? data.content[lang] || "—" : "—"} + {resolveLoanText(data.content, lang) || "—"}
diff --git a/src/pages/settings/location/branches/index.tsx b/src/pages/settings/location/branches/index.tsx index d172050..89ad3ef 100644 --- a/src/pages/settings/location/branches/index.tsx +++ b/src/pages/settings/location/branches/index.tsx @@ -11,7 +11,7 @@ import { CreateButton } from "@/components/createButton"; import { TableActions } from "@/components/tableActions"; import type { FilterField, ActiveFilter } from "@/components/dataTableToolbar"; import { useBranches, useDeleteBranch, useInfiniteProvinces } from "@/features/branches/hooks/useBranches"; -import type { Branch } from "@/features/branches/api/branchesApi"; +import { type Branch, resolveLocalizedName } from "@/features/branches/api/branchesApi"; export function BranchesListPage() { const { t, i18n } = useTranslation(); @@ -70,7 +70,7 @@ export function BranchesListPage() { (provincesInfiniteData?.pages ?? []).flatMap((page) => (page?.provinces ?? []).map((p) => ({ value: String(p.id), - label: p.name[lang], + label: resolveLocalizedName(p.name, lang), })), ), [provincesInfiniteData, lang], @@ -133,13 +133,13 @@ export function BranchesListPage() { accessorKey: "name", id: "name", header: t("branches.fields.name", "ADY").toUpperCase(), - cell: ({ row }) => {row.original.name[lang]}, + cell: ({ row }) => {resolveLocalizedName(row.original.name, lang)}, }, { accessorKey: "provinceName", id: "provinceName", header: t("branches.fields.district", "ETRAP").toUpperCase(), - cell: ({ row }) => {row.original.provinceName[lang]}, + cell: ({ row }) => {resolveLocalizedName(row.original.provinceName, lang)}, }, { accessorKey: "phoneNumbers", diff --git a/src/pages/settings/location/branchesView/index.tsx b/src/pages/settings/location/branchesView/index.tsx index 4f16351..a949517 100644 --- a/src/pages/settings/location/branchesView/index.tsx +++ b/src/pages/settings/location/branchesView/index.tsx @@ -4,6 +4,7 @@ import { ActiveStatusCell } from "@/constants"; import { Skeleton } from "@/components/ui/skeleton"; import { Section, InfoRow, MultiLangRow, ViewActions } from "@/components/viewPageComponents"; import { useBranchById, useDeleteBranch } from "@/features/branches/hooks/useBranches"; +import { resolveLocalizedName } from "@/features/branches/api/branchesApi"; export function BranchViewPage() { const { id } = useParams<{ id: string }>(); @@ -22,7 +23,7 @@ export function BranchViewPage() {

- {isLoading ? "..." : `${t("branches.viewTitle", "Şahamça giňişleýin")}: ${data?.name[lang] ?? ""}`} + {isLoading ? "..." : `${t("branches.viewTitle", "Şahamça giňişleýin")}: ${resolveLocalizedName(data?.name, lang)}`}

diff --git a/src/pages/settings/location/districts/index.tsx b/src/pages/settings/location/districts/index.tsx index f10b73f..bfbe61d 100644 --- a/src/pages/settings/location/districts/index.tsx +++ b/src/pages/settings/location/districts/index.tsx @@ -11,7 +11,7 @@ import { CreateButton } from "@/components/createButton"; import { TableActions } from "@/components/tableActions"; import type { FilterField, ActiveFilter } from "@/components/dataTableToolbar"; import { useDistricts, useDeleteDistrict } from "@/features/districts/hooks/useDistricts"; -import type { District } from "@/features/districts/api/districtsApi"; +import { type District, resolveDistrictName } from "@/features/districts/api/districtsApi"; export function DistrictsListPage() { const { t, i18n } = useTranslation(); @@ -64,13 +64,13 @@ export function DistrictsListPage() { accessorKey: "name", id: "name", header: t("districts.fields.name", "ADY").toUpperCase(), - cell: ({ row }) => {row.original.name[lang]}, + cell: ({ row }) => {resolveDistrictName(row.original.name, lang)}, }, { accessorKey: "region", id: "region", header: t("districts.fields.region", "REGION").toUpperCase(), - cell: ({ row }) => {row.original.region[lang] ?? "—"}, + cell: ({ row }) => {resolveDistrictName(row.original.region, lang) || "—"}, }, { accessorKey: "active", diff --git a/src/pages/settings/location/districtsView/index.tsx b/src/pages/settings/location/districtsView/index.tsx index 59c36c9..5d8c10b 100644 --- a/src/pages/settings/location/districtsView/index.tsx +++ b/src/pages/settings/location/districtsView/index.tsx @@ -4,6 +4,7 @@ import { ActiveStatusCell } from "@/constants"; import { Skeleton } from "@/components/ui/skeleton"; import { Section, InfoRow, MultiLangRow, ViewActions } from "@/components/viewPageComponents"; import { useDistrictById, useDeleteDistrict } from "@/features/districts/hooks/useDistricts"; +import { resolveDistrictName } from "@/features/districts/api/districtsApi"; export function DistrictViewPage() { const { id } = useParams<{ id: string }>(); @@ -22,7 +23,7 @@ export function DistrictViewPage() {

- {isLoading ? "..." : `${t("districts.viewTitle", "Etrap giňişleýin")}: ${data?.name[lang] ?? ""}`} + {isLoading ? "..." : `${t("districts.viewTitle", "Etrap giňişleýin")}: ${resolveDistrictName(data?.name, lang)}`}