connected visa intl payments
This commit is contained in:
@@ -779,4 +779,6 @@ const routes: AppRoute[] = [
|
||||
},
|
||||
];
|
||||
|
||||
export const router = createBrowserRouter(routes as RouteObject[]);
|
||||
export const router = createBrowserRouter(routes as RouteObject[], {
|
||||
basename: "/online",
|
||||
});
|
||||
|
||||
@@ -278,6 +278,8 @@ function DateInput({ value = "", onChange, error, disabled, required, label, cla
|
||||
}
|
||||
|
||||
// ─── SelectInput ──────────────────────────────────────────────────────────────
|
||||
// Panel is absolutely positioned (top-full) so it floats over content below
|
||||
// instead of pushing it down — same pattern as SearchableSelect.
|
||||
|
||||
function SelectInput({
|
||||
value = "",
|
||||
@@ -332,7 +334,9 @@ function SelectInput({
|
||||
</button>
|
||||
</CollapsibleTrigger>
|
||||
|
||||
<CollapsibleContent className="mt-1 rounded-md border border-border bg-card shadow-lg overflow-hidden">
|
||||
<CollapsibleContent
|
||||
className={cn("absolute z-50 top-full left-0 right-0 mt-1", "rounded-md border border-border bg-card shadow-lg overflow-hidden")}
|
||||
>
|
||||
<div className="max-h-52 overflow-y-auto scrollbar-thin py-1">
|
||||
{options.map((opt) => {
|
||||
const isSelected = opt.value === value;
|
||||
@@ -365,9 +369,9 @@ function SelectInput({
|
||||
}
|
||||
|
||||
// ─── SearchableSelect ─────────────────────────────────────────────────────────
|
||||
// Uses Radix Collapsible — no portal, no z-index issues, natural document flow.
|
||||
// onMouseDown (not onClick) on options prevents the trigger's onBlur from
|
||||
// firing before the selection is registered.
|
||||
// Panel is absolutely positioned (top-full) so it floats over content below
|
||||
// instead of pushing it down. onMouseDown (not onClick) on options prevents
|
||||
// the trigger's onBlur from firing before the selection is registered.
|
||||
|
||||
function SearchableSelect({
|
||||
value = "",
|
||||
@@ -462,8 +466,10 @@ function SearchableSelect({
|
||||
</button>
|
||||
</CollapsibleTrigger>
|
||||
|
||||
{/* Panel */}
|
||||
<CollapsibleContent className="mt-1 rounded-md border border-border bg-card shadow-lg overflow-hidden">
|
||||
{/* Panel — absolute so it floats instead of pushing layout down */}
|
||||
<CollapsibleContent
|
||||
className={cn("absolute z-50 top-full left-0 right-0 mt-1", "rounded-md border border-border bg-card shadow-lg overflow-hidden")}
|
||||
>
|
||||
{/* Search */}
|
||||
<div className="flex items-center gap-2 px-3 py-2 border-b border-border bg-muted/20">
|
||||
<Search size={13} className="text-muted-foreground shrink-0" />
|
||||
|
||||
@@ -146,7 +146,7 @@ export function InfiniteSelect({
|
||||
</button>
|
||||
</CollapsibleTrigger>
|
||||
|
||||
<CollapsibleContent className="mt-1 rounded-md border border-border bg-card shadow-lg overflow-hidden">
|
||||
<CollapsibleContent className="absolute z-50 top-full left-0 right-0 mt-1 rounded-md border border-border bg-card shadow-lg overflow-hidden">
|
||||
{onSearchChange && (
|
||||
<div className="flex items-center gap-2 px-3 py-2 border-b border-border bg-muted/20">
|
||||
<Search size={13} className="text-muted-foreground shrink-0" />
|
||||
|
||||
@@ -59,7 +59,7 @@ export function UserForm({ mode, initialData }: UserFormProps) {
|
||||
|
||||
const roleSelect: Omit<InfiniteSelectProps, "label" | "required" | "placeholder"> = useMemo(() => {
|
||||
const opts: InfiniteSelectOption[] = (roleQuery.data?.pages ?? [])
|
||||
.flatMap((p) => p.roles)
|
||||
.flatMap((p) => p?.roles ?? [])
|
||||
.map((r) => ({ value: r.code, label: r.name }));
|
||||
|
||||
// Ensure the currently-selected role is present (edit mode), even if it
|
||||
|
||||
@@ -35,8 +35,9 @@ export function useInfiniteUsers(search = "") {
|
||||
initialPageParam: 1,
|
||||
queryFn: ({ pageParam, signal }) => usersApi.getUsers({ page: pageParam, limit: USER_PAGE_SIZE, search: effectiveSearch }, signal),
|
||||
getNextPageParam: (lastPage, allPages) => {
|
||||
const loaded = allPages.reduce((sum, p) => sum + p.users.length, 0);
|
||||
return loaded < lastPage.count ? allPages.length + 1 : undefined;
|
||||
const loaded = allPages.reduce((sum, p) => sum + (p?.users?.length ?? 0), 0);
|
||||
const count = lastPage?.count ?? 0;
|
||||
return loaded < count ? allPages.length + 1 : undefined;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -307,7 +307,7 @@ export function BranchForm({ mode, initialData }: BranchFormProps) {
|
||||
|
||||
const provinceSelect: Omit<InfiniteSelectProps, "label" | "required" | "placeholder"> = useMemo(() => {
|
||||
const opts: InfiniteSelectOption[] = (provinceQuery.data?.pages ?? [])
|
||||
.flatMap((p) => p.provinces)
|
||||
.flatMap((p) => p?.provinces ?? [])
|
||||
.map((p) => ({ value: String(p.id), label: p.name[lang] }));
|
||||
|
||||
// Ensure the currently-selected province is present (edit mode), even if it
|
||||
|
||||
@@ -48,8 +48,9 @@ export function useInfiniteProvinces(search = "") {
|
||||
initialPageParam: 1,
|
||||
queryFn: ({ pageParam, signal }) => fetchProvinces({ page: pageParam, limit: PROVINCE_PAGE_SIZE, search: effectiveSearch }, signal),
|
||||
getNextPageParam: (lastPage, allPages) => {
|
||||
const loaded = allPages.reduce((sum, p) => sum + p.provinces.length, 0);
|
||||
return loaded < lastPage.count ? allPages.length + 1 : undefined;
|
||||
const loaded = allPages.reduce((sum, p) => sum + (p?.provinces?.length ?? 0), 0);
|
||||
const count = lastPage?.count ?? 0;
|
||||
return loaded < count ? allPages.length + 1 : undefined;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ export function ClientForm({ mode, initialData }: ClientFormProps) {
|
||||
|
||||
const roleSelect: Omit<InfiniteSelectProps, "label" | "required" | "placeholder"> = useMemo(() => {
|
||||
const opts: InfiniteSelectOption[] = (roleQuery.data?.pages ?? [])
|
||||
.flatMap((p) => p.roles)
|
||||
.flatMap((p) => p?.roles ?? [])
|
||||
.map((r) => ({ value: r.code, label: r.name }));
|
||||
|
||||
if (initialData) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useMutation, useInfiniteQuery, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { toast } from "sonner";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useDebouncedValue, normalizeSearch } from "@/hooks/useDebouncedSearch";
|
||||
@@ -12,6 +12,7 @@ export const clientKeys = {
|
||||
list: (params: ClientsListParams) => [...clientKeys.lists(), params] as const,
|
||||
details: () => [...clientKeys.all, "detail"] as const,
|
||||
detail: (id: number) => [...clientKeys.details(), id] as const,
|
||||
infinite: (search: string) => [...clientKeys.all, "infinite", search] as const,
|
||||
};
|
||||
|
||||
// ─── useClients ───────────────────────────────────────────────────────────────
|
||||
@@ -27,6 +28,32 @@ export function useClients(params: ClientsListParams = {}) {
|
||||
});
|
||||
}
|
||||
|
||||
// ─── useInfiniteClients ───────────────────────────────────────────────────────
|
||||
|
||||
const CLIENT_PAGE_SIZE = 25;
|
||||
|
||||
/**
|
||||
* Infinite-scroll client list for searchable selects.
|
||||
* Backed by `clientsApi.getClients` (GET /users/clients).
|
||||
*/
|
||||
export function useInfiniteClients(search = "") {
|
||||
const debouncedSearch = useDebouncedValue(search);
|
||||
const effectiveSearch = normalizeSearch(debouncedSearch);
|
||||
|
||||
return useInfiniteQuery({
|
||||
queryKey: clientKeys.infinite(effectiveSearch),
|
||||
initialPageParam: 1,
|
||||
queryFn: ({ pageParam, signal }) =>
|
||||
clientsApi.getClients({ page: pageParam, limit: CLIENT_PAGE_SIZE, search: effectiveSearch }, signal),
|
||||
getNextPageParam: (lastPage, allPages) => {
|
||||
const loaded = allPages.reduce((sum, p) => sum + (p?.users?.length ?? 0), 0);
|
||||
const count = lastPage?.count ?? 0;
|
||||
return loaded < count ? allPages.length + 1 : undefined;
|
||||
},
|
||||
staleTime: 5 * 60 * 1000, // 5 minutes
|
||||
});
|
||||
}
|
||||
|
||||
// ─── useClient ────────────────────────────────────────────────────────────────
|
||||
|
||||
export function useClient(id: number) {
|
||||
|
||||
@@ -238,7 +238,7 @@ function StepLoan({ form, errors, set, t, initialData }: StepContentProps & { in
|
||||
const loanTypeOptions: InfiniteSelectOption[] = useMemo(() => {
|
||||
const lang = i18n.language ?? "en";
|
||||
const opts: InfiniteSelectOption[] = (loanTypesQuery.data?.pages ?? [])
|
||||
.flatMap((p) => p.loanTypes)
|
||||
.flatMap((p) => p?.loanTypes ?? [])
|
||||
.map((lt) => ({ value: String(lt.id), label: resolveLocalizedName(lt.title, lang) || String(lt.id) }));
|
||||
|
||||
if (initialData?.loanTypeId && !opts.some((o) => o.value === String(initialData.loanTypeId))) {
|
||||
@@ -292,7 +292,7 @@ function StepLocation({ form, errors, set, t, initialData }: StepContentProps &
|
||||
const branchOptions: InfiniteSelectOption[] = useMemo(() => {
|
||||
const lang = i18n.language ?? "en";
|
||||
const opts: InfiniteSelectOption[] = (branchQuery.data?.pages ?? [])
|
||||
.flatMap((p) => p.branches)
|
||||
.flatMap((p) => p?.branches ?? [])
|
||||
.map((b) => ({
|
||||
value: String(b.id),
|
||||
label: resolveLocalizedName(b.name, lang) || b.uniqueCode || String(b.id),
|
||||
@@ -672,7 +672,7 @@ function StepJob({ form, errors, set, t, initialData }: StepContentProps & { ini
|
||||
const provinceOptions: InfiniteSelectOption[] = useMemo(() => {
|
||||
const lang = i18n.language ?? "en";
|
||||
const opts: InfiniteSelectOption[] = (provinceQuery.data?.pages ?? [])
|
||||
.flatMap((p) => p.provinces)
|
||||
.flatMap((p) => p?.provinces ?? [])
|
||||
.map((prov) => ({ value: String(prov.id), label: resolveLocalizedName(prov.name, lang) || String(prov.id) }));
|
||||
|
||||
if (initialData?.workCityId && !opts.some((o) => o.value === String(initialData.workCityId))) {
|
||||
|
||||
@@ -345,7 +345,7 @@ export function LoanPaidOffLetterForm({ mode, initialData }: LoanPaidOffLetterFo
|
||||
const branchSelectProps: Omit<InfiniteSelectProps, "label" | "required" | "placeholder"> = useMemo(() => {
|
||||
const lang = i18n.language ?? "en";
|
||||
const opts: InfiniteSelectOption[] = (branchQuery.data?.pages ?? [])
|
||||
.flatMap((p) => p.branches)
|
||||
.flatMap((p) => p?.branches ?? [])
|
||||
.map((b) => ({
|
||||
value: String(b.id),
|
||||
label: resolveLocalizedName(b.name, lang) || b.uniqueCode || String(b.id),
|
||||
@@ -376,7 +376,7 @@ export function LoanPaidOffLetterForm({ mode, initialData }: LoanPaidOffLetterFo
|
||||
|
||||
const userSelectProps: Omit<InfiniteSelectProps, "label" | "required" | "placeholder"> = useMemo(() => {
|
||||
const opts: InfiniteSelectOption[] = (usersQuery.data?.pages ?? [])
|
||||
.flatMap((p) => p.users)
|
||||
.flatMap((p) => p?.users ?? [])
|
||||
.map((u) => {
|
||||
const displayName = [u.firstName, u.lastName].filter(Boolean).join(" ") || u.name || u.username;
|
||||
return {
|
||||
|
||||
@@ -36,7 +36,7 @@ export function LoanRemainingForm({ mode, initialData }: LoanRemainingFormProps)
|
||||
|
||||
const userSelectProps: Omit<InfiniteSelectProps, "label" | "required" | "placeholder"> = useMemo(() => {
|
||||
const opts: InfiniteSelectOption[] = (usersQuery.data?.pages ?? [])
|
||||
.flatMap((p) => p.users)
|
||||
.flatMap((p) => p?.users ?? [])
|
||||
.map((u) => {
|
||||
const displayName = [u.firstName, u.lastName].filter(Boolean).join(" ") || u.name || u.username;
|
||||
return {
|
||||
|
||||
@@ -51,8 +51,9 @@ export function useInfiniteLoanTypes(search = "") {
|
||||
initialPageParam: 1,
|
||||
queryFn: ({ pageParam, signal }) => fetchLoanTypes({ page: pageParam, limit: LOAN_TYPE_PAGE_SIZE, search: effectiveSearch }, signal),
|
||||
getNextPageParam: (lastPage, allPages) => {
|
||||
const loaded = allPages.reduce((sum, p) => sum + p.loanTypes.length, 0);
|
||||
return loaded < lastPage.count ? allPages.length + 1 : undefined;
|
||||
const loaded = allPages.reduce((sum, p) => sum + (p?.loanTypes?.length ?? 0), 0);
|
||||
const count = lastPage?.count ?? 0;
|
||||
return loaded < count ? allPages.length + 1 : undefined;
|
||||
},
|
||||
staleTime: 5 * 60 * 1000, // 5 minutes
|
||||
});
|
||||
|
||||
@@ -84,7 +84,7 @@ export function OperatorForm({ mode, initialData }: OperatorFormProps) {
|
||||
|
||||
const roleSelect: Omit<InfiniteSelectProps, "label" | "required" | "placeholder"> = useMemo(() => {
|
||||
const opts: InfiniteSelectOption[] = (roleQuery.data?.pages ?? [])
|
||||
.flatMap((p) => p.roles)
|
||||
.flatMap((p) => p?.roles ?? [])
|
||||
.map((r) => ({ value: r.code, label: r.name }));
|
||||
|
||||
if (initialData) {
|
||||
@@ -109,7 +109,7 @@ export function OperatorForm({ mode, initialData }: OperatorFormProps) {
|
||||
const branchSelect: Omit<InfiniteSelectProps, "label" | "required" | "placeholder"> = useMemo(() => {
|
||||
const lang = i18n.language ?? "en";
|
||||
const opts: InfiniteSelectOption[] = (branchQuery.data?.pages ?? [])
|
||||
.flatMap((p) => p.branches)
|
||||
.flatMap((p) => p?.branches ?? [])
|
||||
.map((b) => ({
|
||||
value: String(b.id),
|
||||
label: resolveLocalizedName(b.name, lang) || b.uniqueCode,
|
||||
|
||||
@@ -41,8 +41,9 @@ export function useInfiniteRoles(search = "") {
|
||||
initialPageParam: 1,
|
||||
queryFn: ({ pageParam, signal }) => rolesApi.getAll({ page: pageParam, limit: ROLE_PAGE_SIZE, search: effectiveSearch }, signal),
|
||||
getNextPageParam: (lastPage, allPages) => {
|
||||
const loaded = allPages.reduce((sum, p) => sum + p.roles.length, 0);
|
||||
return loaded < lastPage.count ? allPages.length + 1 : undefined;
|
||||
const loaded = allPages.reduce((sum, p) => sum + (p?.roles?.length ?? 0), 0);
|
||||
const count = lastPage?.count ?? 0;
|
||||
return loaded < count ? allPages.length + 1 : undefined;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -29,8 +29,9 @@ export function useInfiniteBranches(search = "") {
|
||||
initialPageParam: 1,
|
||||
queryFn: ({ pageParam, signal }) => fetchBranches({ page: pageParam, limit: BRANCH_PAGE_SIZE, search: effectiveSearch }, signal),
|
||||
getNextPageParam: (lastPage, allPages) => {
|
||||
const loaded = allPages.reduce((sum, p) => sum + p.branches.length, 0);
|
||||
return loaded < lastPage.count ? allPages.length + 1 : undefined;
|
||||
const loaded = allPages.reduce((sum, p) => sum + (p?.branches?.length ?? 0), 0);
|
||||
const count = lastPage?.count ?? 0;
|
||||
return loaded < count ? allPages.length + 1 : undefined;
|
||||
},
|
||||
staleTime: 5 * 60 * 1000, // 5 minutes
|
||||
});
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import apiClient from "@/lib/api/client";
|
||||
import { formatFromApiPhone, formatToApiPhone } from "@/lib/utils";
|
||||
import { isStatusValue } from "@/constants";
|
||||
import type { LocalizedText } from "@/features/branches/api/branchesApi";
|
||||
import { postFile, buildFileUrl } from "@/features/shared/api/sharedApi";
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
// ─── Types (UI-facing) ────────────────────────────────────────────────────────
|
||||
|
||||
export type IntlPaymentStatus = "pending" | "approved" | "rejected";
|
||||
export type CurrencyType = "visa" | "mastercard";
|
||||
@@ -65,6 +69,10 @@ export interface IntlPaymentListParams {
|
||||
status?: IntlPaymentStatus | "";
|
||||
month?: string;
|
||||
province?: string;
|
||||
region?: string;
|
||||
branch?: string;
|
||||
branch_id?: string;
|
||||
user_id?: string;
|
||||
}
|
||||
|
||||
export interface IntlPaymentListResponse {
|
||||
@@ -79,9 +87,9 @@ export interface IntlPaymentListResponse {
|
||||
|
||||
export type IntlPaymentCreatePayload = {
|
||||
client_id: string;
|
||||
status: IntlPaymentStatus;
|
||||
status: string;
|
||||
note: string;
|
||||
currency_type: CurrencyType;
|
||||
currency_type: string;
|
||||
province: string;
|
||||
branch: string;
|
||||
|
||||
@@ -98,168 +106,268 @@ export type IntlPaymentCreatePayload = {
|
||||
|
||||
receiver_info: string;
|
||||
|
||||
// kabul ediji docs
|
||||
doc_sberbank_account: File | null;
|
||||
doc_school_enrollment: File | null;
|
||||
doc_summons: File | null;
|
||||
doc_passport_tm: File | null;
|
||||
doc_foreign_passport: File | null;
|
||||
doc_foreign_passport_copy: File | null;
|
||||
doc_exit_permission: File | null;
|
||||
doc_school_foreign_info: File | null;
|
||||
doc_school_departure_info: File | null;
|
||||
// kabul ediji docs (uploaded URL strings, same as DocumentUpload in loan orders)
|
||||
doc_sberbank_account: string | null;
|
||||
doc_school_enrollment: string | null;
|
||||
doc_summons: string | null;
|
||||
doc_passport_tm: string | null;
|
||||
doc_foreign_passport: string | null;
|
||||
doc_foreign_passport_copy: string | null;
|
||||
doc_exit_permission: string | null;
|
||||
doc_school_foreign_info: string | null;
|
||||
doc_school_departure_info: string | null;
|
||||
|
||||
// upgradyý docs
|
||||
upd_doc_passport_tm: File | null;
|
||||
upd_doc_foreign_passport: File | null;
|
||||
upd_doc_visa: File | null;
|
||||
upd_doc_acceptance_letter: File | null;
|
||||
upd_doc_passport_biometric: File | null;
|
||||
upd_doc_passport_old: File | null;
|
||||
// upgradyý docs (uploaded URL strings)
|
||||
upd_doc_passport_tm: string | null;
|
||||
upd_doc_foreign_passport: string | null;
|
||||
upd_doc_visa: string | null;
|
||||
upd_doc_acceptance_letter: string | null;
|
||||
upd_doc_passport_biometric: string | null;
|
||||
upd_doc_passport_old: string | null;
|
||||
};
|
||||
|
||||
export type IntlPaymentUpdatePayload = IntlPaymentCreatePayload;
|
||||
export type IntlPaymentUpdatePayload = Partial<IntlPaymentCreatePayload>;
|
||||
|
||||
// ─── API Functions ────────────────────────────────────────────────────────────
|
||||
// ─── Backend types ─────────────────────────────────────────────────────────────
|
||||
|
||||
const MOCK_INTL_PAYMENTS: IntlPaymentItem[] = [
|
||||
{
|
||||
id: "1",
|
||||
client_id: "1",
|
||||
client_label: "Jelaletdin",
|
||||
currency_type: "visa",
|
||||
currency_type_label: "Visa",
|
||||
created_at: "2024-05-07 12:00",
|
||||
province: "ashgabat",
|
||||
province_label: "Aşgabat",
|
||||
branch: "1",
|
||||
branch_label: "Merkezi şahamça",
|
||||
status: "pending",
|
||||
note: "Test sargyt",
|
||||
passport_first_name: "Aman",
|
||||
passport_last_name: "Amanow",
|
||||
phone: "99365123456",
|
||||
email: "aman@example.com",
|
||||
home_address: "Aşgabat ş., Magtymguly şaýoly 1",
|
||||
passport_series: "I-MR",
|
||||
passport_number: "123456",
|
||||
payer_full_name: "Aman Amanow",
|
||||
payer_account_number: "1234567890123456",
|
||||
receiver_info: "Test Receiver",
|
||||
doc_sberbank_account: null,
|
||||
doc_school_enrollment: null,
|
||||
doc_summons: null,
|
||||
doc_passport_tm: null,
|
||||
doc_foreign_passport: null,
|
||||
doc_foreign_passport_copy: null,
|
||||
doc_exit_permission: null,
|
||||
doc_school_foreign_info: null,
|
||||
doc_school_departure_info: null,
|
||||
upd_doc_passport_tm: null,
|
||||
upd_doc_foreign_passport: null,
|
||||
upd_doc_visa: null,
|
||||
upd_doc_acceptance_letter: null,
|
||||
upd_doc_passport_biometric: null,
|
||||
interface BackendIntlPayment {
|
||||
id?: number;
|
||||
uniqueId?: string | null;
|
||||
type?: string | null;
|
||||
passportName?: string | null;
|
||||
passportSurname?: string | null;
|
||||
phone?: string | null;
|
||||
email?: string | null;
|
||||
region?: string | null;
|
||||
regionName?: LocalizedText | string | null;
|
||||
branchId?: number | null;
|
||||
branch?: {
|
||||
id: number;
|
||||
uniqueCode: string;
|
||||
name: LocalizedText;
|
||||
region: string;
|
||||
provinceId: number;
|
||||
provinceName?: LocalizedText;
|
||||
} | null;
|
||||
userId?: number | null;
|
||||
user?: { id: number; name: string; username: string; phone: string; email: string } | null;
|
||||
address?: string | null;
|
||||
senderDatas?: { fullName?: string; passportSerie?: string; passportNumber?: string; depositAccount?: string } | null;
|
||||
paymentReciever?: Array<{ fullName?: string; passportSerie?: string; passportNumber?: string; depositAccount?: string }> | null;
|
||||
documents?: Record<string, string[]>;
|
||||
status?: string | null;
|
||||
notes?: string | null;
|
||||
senderFullName?: string | null;
|
||||
senderPassportSerie?: string | null;
|
||||
senderPassportNumber?: string | null;
|
||||
senderDepositAccount?: string | null;
|
||||
recieverFullName?: string | null;
|
||||
recieverPassportSerie?: string | null;
|
||||
recieverPassportNumber?: string | null;
|
||||
recieverDepositAccount?: string | null;
|
||||
paid?: boolean | null;
|
||||
createdAt?: string | null;
|
||||
updatedAt?: string | null;
|
||||
}
|
||||
|
||||
interface BackendIntlListResponse {
|
||||
count: number;
|
||||
visaMasterPaymentOrders: BackendIntlPayment[];
|
||||
}
|
||||
|
||||
// ─── Mapping helpers ───────────────────────────────────────────────────────────
|
||||
|
||||
function resolveLocalizedName(name: LocalizedText | string | null | undefined): string {
|
||||
if (!name) return "";
|
||||
if (typeof name === "string") return name;
|
||||
return name.tm ?? name.en ?? name.ru ?? "";
|
||||
}
|
||||
|
||||
function toNum(value: string | number | null | undefined): number | null {
|
||||
if (value === null || value === undefined || value === "") return null;
|
||||
const n = Number(value);
|
||||
return Number.isNaN(n) ? null : n;
|
||||
}
|
||||
|
||||
function toFileUrl(nameOrUrl?: string | null): string | null {
|
||||
if (!nameOrUrl) return null;
|
||||
return nameOrUrl.startsWith("http") ? nameOrUrl : buildFileUrl(nameOrUrl);
|
||||
}
|
||||
|
||||
function firstFileUrl(arr?: string[] | null): string | null {
|
||||
if (!arr || arr.length === 0) return null;
|
||||
return toFileUrl(arr[0]);
|
||||
}
|
||||
|
||||
function mapBackendToUI(o: BackendIntlPayment): IntlPaymentItem {
|
||||
const status: IntlPaymentStatus = isStatusValue(o.status ?? "") ? (o.status as IntlPaymentStatus) : "pending";
|
||||
const d = o.documents ?? {};
|
||||
|
||||
return {
|
||||
id: String(o.id ?? o.uniqueId ?? ""),
|
||||
client_id: o.userId != null ? String(o.userId) : (o.uniqueId ?? String(o.id ?? "")),
|
||||
client_label: o.user?.name ?? o.uniqueId ?? String(o.id ?? ""),
|
||||
currency_type: (o.type as CurrencyType) ?? "visa",
|
||||
currency_type_label: o.type ?? "",
|
||||
created_at: o.createdAt ?? "",
|
||||
province: o.region ?? "",
|
||||
province_label: resolveLocalizedName(o.regionName) || o.region || "",
|
||||
branch: o.branchId != null ? String(o.branchId) : "",
|
||||
branch_label: o.branch?.name ? resolveLocalizedName(o.branch.name) : "",
|
||||
status,
|
||||
note: o.notes ?? "",
|
||||
passport_first_name: o.passportName ?? "",
|
||||
passport_last_name: o.passportSurname ?? "",
|
||||
phone: formatFromApiPhone(o.phone),
|
||||
email: o.email ?? "",
|
||||
home_address: o.address ?? "",
|
||||
passport_series: o.senderDatas?.passportSerie ?? o.senderPassportSerie ?? o.paymentReciever?.[0]?.passportSerie ?? "",
|
||||
passport_number: o.senderDatas?.passportNumber ?? o.senderPassportNumber ?? o.paymentReciever?.[0]?.passportNumber ?? "",
|
||||
payer_full_name: o.senderFullName ?? o.senderDatas?.fullName ?? "",
|
||||
payer_account_number: o.senderDepositAccount ?? o.senderDatas?.depositAccount ?? "",
|
||||
receiver_info: o.recieverFullName ?? o.paymentReciever?.[0]?.fullName ?? "",
|
||||
|
||||
doc_sberbank_account: firstFileUrl(d.student_visa_card_details),
|
||||
doc_school_enrollment: firstFileUrl(d.student_enrollment_certificate),
|
||||
doc_summons: firstFileUrl(d.student_ticket_copy),
|
||||
doc_passport_tm: firstFileUrl(d.student_internal_passport),
|
||||
doc_foreign_passport: firstFileUrl(d.student_foreign_passport),
|
||||
doc_foreign_passport_copy: firstFileUrl(d.student_visa_page),
|
||||
doc_exit_permission: firstFileUrl(d.student_stamp_page),
|
||||
doc_school_foreign_info: firstFileUrl(d.student_enrollment_clarification),
|
||||
doc_school_departure_info: firstFileUrl(d.sender_internal_passport),
|
||||
upd_doc_passport_tm: firstFileUrl(d.sender_foreign_passport),
|
||||
upd_doc_foreign_passport: firstFileUrl(d.sender_stamp_page),
|
||||
upd_doc_visa: firstFileUrl(d.kinship_documents),
|
||||
upd_doc_acceptance_letter: firstFileUrl(d.first_passport_series_info),
|
||||
upd_doc_passport_biometric: firstFileUrl(d.police_passport_series_info),
|
||||
upd_doc_passport_old: null,
|
||||
created_by: "1",
|
||||
created_by_label: "Admin",
|
||||
},
|
||||
];
|
||||
|
||||
created_by: o.userId != null ? String(o.userId) : "",
|
||||
created_by_label: o.user?.name ?? "",
|
||||
};
|
||||
}
|
||||
|
||||
// Form doc field -> backend documents key
|
||||
const DOC_FILE_TO_KEY: Record<string, string> = {
|
||||
doc_sberbank_account: "student_visa_card_details",
|
||||
doc_school_enrollment: "student_enrollment_certificate",
|
||||
doc_summons: "student_ticket_copy",
|
||||
doc_passport_tm: "student_internal_passport",
|
||||
doc_foreign_passport: "student_foreign_passport",
|
||||
doc_foreign_passport_copy: "student_visa_page",
|
||||
doc_exit_permission: "student_stamp_page",
|
||||
doc_school_foreign_info: "student_enrollment_clarification",
|
||||
doc_school_departure_info: "sender_internal_passport",
|
||||
upd_doc_passport_tm: "sender_foreign_passport",
|
||||
upd_doc_foreign_passport: "sender_stamp_page",
|
||||
upd_doc_visa: "kinship_documents",
|
||||
upd_doc_acceptance_letter: "first_passport_series_info",
|
||||
upd_doc_passport_biometric: "police_passport_series_info",
|
||||
};
|
||||
|
||||
async function mapPayloadToBackend(
|
||||
payload: IntlPaymentCreatePayload | Partial<IntlPaymentCreatePayload>,
|
||||
): Promise<Record<string, unknown>> {
|
||||
const documents: Record<string, string[]> = {};
|
||||
|
||||
await Promise.all(
|
||||
Object.entries(DOC_FILE_TO_KEY).map(async ([field, key]) => {
|
||||
const value = payload[field as keyof IntlPaymentCreatePayload] as File | string | null | undefined;
|
||||
if (value instanceof File) {
|
||||
const filename = await postFile(value);
|
||||
documents[key] = [filename];
|
||||
} else if (typeof value === "string" && value) {
|
||||
documents[key] = [value];
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
return {
|
||||
address: payload.home_address ?? "",
|
||||
branchId: toNum(payload.branch) ?? 0,
|
||||
documents,
|
||||
email: payload.email ?? "",
|
||||
notes: payload.note ?? "",
|
||||
paid: false,
|
||||
passportName: payload.passport_first_name ?? "",
|
||||
passportSurname: payload.passport_last_name ?? "",
|
||||
paymentReciever: [{ fullName: payload.receiver_info ?? "" }],
|
||||
phone: formatToApiPhone(payload.phone),
|
||||
recieverDepositAccount: payload.payer_account_number ?? "",
|
||||
recieverFullName: payload.receiver_info ?? "",
|
||||
recieverPassportNumber: payload.passport_number ?? "",
|
||||
recieverPassportSerie: payload.passport_series ?? "",
|
||||
region: payload.province ?? "",
|
||||
senderDatas: {
|
||||
fullName: payload.payer_full_name ?? "",
|
||||
passportSerie: payload.passport_series ?? "",
|
||||
passportNumber: payload.passport_number ?? "",
|
||||
depositAccount: payload.payer_account_number ?? "",
|
||||
},
|
||||
senderDepositAccount: payload.payer_account_number ?? "",
|
||||
senderFullName: payload.payer_full_name ?? "",
|
||||
senderPassportNumber: payload.passport_number ?? "",
|
||||
senderPassportSerie: payload.passport_series ?? "",
|
||||
status: payload.status ?? "pending",
|
||||
type: payload.currency_type ?? "visa",
|
||||
uniqueId: "",
|
||||
userId: toNum(payload.client_id) ?? 0,
|
||||
};
|
||||
}
|
||||
|
||||
// ─── API Functions ─────────────────────────────────────────────────────────────
|
||||
|
||||
export const intlPaymentApi = {
|
||||
list: async (params: IntlPaymentListParams): Promise<IntlPaymentListResponse> => {
|
||||
async list(params: IntlPaymentListParams = {}): Promise<IntlPaymentListResponse> {
|
||||
const page = params.page ?? 1;
|
||||
const perPage = params.per_page ?? 25;
|
||||
|
||||
const { data } = await apiClient.get<BackendIntlListResponse>("/visa-master-payment-orders", {
|
||||
params: {
|
||||
page,
|
||||
limit: perPage,
|
||||
name: params.search || undefined,
|
||||
status: params.status || undefined,
|
||||
branch_id: params.branch_id || params.branch || undefined,
|
||||
user_id: params.user_id || undefined,
|
||||
region: params.region || params.province || undefined,
|
||||
month: params.month || undefined,
|
||||
},
|
||||
});
|
||||
|
||||
const orders = (data.visaMasterPaymentOrders ?? []).map(mapBackendToUI);
|
||||
const total = data.count ?? orders.length;
|
||||
|
||||
return {
|
||||
data: MOCK_INTL_PAYMENTS,
|
||||
data: orders,
|
||||
meta: {
|
||||
current_page: params.page || 1,
|
||||
last_page: 1,
|
||||
per_page: params.per_page || 25,
|
||||
total: MOCK_INTL_PAYMENTS.length,
|
||||
current_page: page,
|
||||
last_page: Math.max(1, Math.ceil(total / perPage)),
|
||||
per_page: perPage,
|
||||
total,
|
||||
},
|
||||
};
|
||||
|
||||
const { data } = await apiClient.get("/intl-payments/visa-master", { params });
|
||||
return data;
|
||||
},
|
||||
|
||||
getById: async (id: string): Promise<IntlPaymentItem> => {
|
||||
const mock = MOCK_INTL_PAYMENTS.find((p) => p.id === id);
|
||||
if (mock) return mock;
|
||||
|
||||
const { data } = await apiClient.get(`/intl-payments/visa-master/${id}`);
|
||||
return data;
|
||||
async getById(id: string): Promise<IntlPaymentItem> {
|
||||
const { data } = await apiClient.get<BackendIntlPayment>(`/visa-master-payment-orders/${id}`);
|
||||
return mapBackendToUI(data);
|
||||
},
|
||||
|
||||
create: (payload: IntlPaymentCreatePayload): Promise<IntlPaymentItem> => {
|
||||
const form = buildFormData(payload);
|
||||
return apiClient
|
||||
.post("/intl-payments/visa-master", form, {
|
||||
headers: { "Content-Type": "multipart/form-data" },
|
||||
})
|
||||
.then((r) => r.data);
|
||||
async create(payload: IntlPaymentCreatePayload): Promise<IntlPaymentItem> {
|
||||
const body = await mapPayloadToBackend(payload);
|
||||
const { data } = await apiClient.post<BackendIntlPayment>("/visa-master-payment-orders", body);
|
||||
return mapBackendToUI(data);
|
||||
},
|
||||
|
||||
update: (id: string, payload: IntlPaymentUpdatePayload): Promise<IntlPaymentItem> => {
|
||||
const form = buildFormData(payload);
|
||||
form.append("_method", "PUT");
|
||||
return apiClient
|
||||
.post(`/intl-payments/visa-master/${id}`, form, {
|
||||
headers: { "Content-Type": "multipart/form-data" },
|
||||
})
|
||||
.then((r) => r.data);
|
||||
async update(id: string, payload: IntlPaymentUpdatePayload): Promise<IntlPaymentItem> {
|
||||
const body = await mapPayloadToBackend(payload);
|
||||
const { data } = await apiClient.put<BackendIntlPayment>(`/visa-master-payment-orders/${id}`, body);
|
||||
return mapBackendToUI(data);
|
||||
},
|
||||
|
||||
delete: (id: string): Promise<void> => apiClient.delete(`/intl-payments/visa-master/${id}`).then((r) => r.data),
|
||||
async delete(id: string): Promise<void> {
|
||||
await apiClient.delete(`/visa-master-payment-orders/${id}`);
|
||||
},
|
||||
};
|
||||
|
||||
// ─── Helper ───────────────────────────────────────────────────────────────────
|
||||
|
||||
const TEXT_FIELDS: (keyof IntlPaymentCreatePayload)[] = [
|
||||
"client_id",
|
||||
"status",
|
||||
"note",
|
||||
"currency_type",
|
||||
"province",
|
||||
"branch",
|
||||
"passport_first_name",
|
||||
"passport_last_name",
|
||||
"phone",
|
||||
"email",
|
||||
"home_address",
|
||||
"passport_series",
|
||||
"passport_number",
|
||||
"payer_full_name",
|
||||
"payer_account_number",
|
||||
"receiver_info",
|
||||
];
|
||||
|
||||
const FILE_FIELDS: (keyof IntlPaymentCreatePayload)[] = [
|
||||
"doc_sberbank_account",
|
||||
"doc_school_enrollment",
|
||||
"doc_summons",
|
||||
"doc_passport_tm",
|
||||
"doc_foreign_passport",
|
||||
"doc_foreign_passport_copy",
|
||||
"doc_exit_permission",
|
||||
"doc_school_foreign_info",
|
||||
"doc_school_departure_info",
|
||||
"upd_doc_passport_tm",
|
||||
"upd_doc_foreign_passport",
|
||||
"upd_doc_visa",
|
||||
"upd_doc_acceptance_letter",
|
||||
"upd_doc_passport_biometric",
|
||||
"upd_doc_passport_old",
|
||||
];
|
||||
|
||||
function buildFormData(payload: IntlPaymentCreatePayload): FormData {
|
||||
const form = new FormData();
|
||||
for (const key of TEXT_FIELDS) {
|
||||
const val = payload[key];
|
||||
if (val !== null && val !== undefined) form.append(key, String(val));
|
||||
}
|
||||
for (const key of FILE_FIELDS) {
|
||||
const file = payload[key];
|
||||
if (file instanceof File) form.append(key, file);
|
||||
}
|
||||
return form;
|
||||
}
|
||||
|
||||
@@ -6,14 +6,20 @@ import { useForm } from "react-hook-form";
|
||||
import { toast } from "sonner";
|
||||
import { User, MapPin, IdCard, CreditCard, Files } from "lucide-react";
|
||||
import type { LucideIcon } from "lucide-react";
|
||||
|
||||
import { FormInput } from "@/components/formInput";
|
||||
import { FormActions } from "@/components/formActions";
|
||||
import { DocumentUpload } from "@/components/documentUpload";
|
||||
import { InfiniteSelect, type InfiniteSelectOption } from "@/components/infiniteSelect";
|
||||
import { StepBarCards, type StepCardItem } from "@/components/stepBarV2";
|
||||
import { BentoGrid, BentoCard } from "@/components/bento";
|
||||
import type { IntlPaymentItem, IntlPaymentCreatePayload } from "../api/visaMasterPaymentsApi";
|
||||
import { useCreateIntlPayment, useUpdateIntlPayment } from "../hooks/useVisaMasterPayments";
|
||||
import { validateStep, DEFAULT_FORM_VALUES, buildPayload } from "../schemas/visaMasterPayment.schema";
|
||||
import type { IntlPaymentFormData } from "../schemas/visaMasterPayment.schema";
|
||||
import { useInfiniteBranches } from "@/features/shared/hooks/useSharedBranchUsers";
|
||||
import { useInfiniteClients } from "@/features/clients/hooks/useClients";
|
||||
import type { LocalizedText } from "@/features/branches/api/branchesApi";
|
||||
import { PASSPORT_SERIES_OPTIONS, getStatusOptions } from "@/constants";
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
@@ -32,14 +38,30 @@ const CURRENCY_OPTIONS = [
|
||||
{ value: "mastercard", label: "MasterCard" },
|
||||
];
|
||||
|
||||
const PROVINCE_OPTIONS = [
|
||||
{ value: "ashgabat", label: "Aşgabat" },
|
||||
{ value: "ahal", label: "Ahal" },
|
||||
{ value: "mary", label: "Mary" },
|
||||
{ value: "dasoguz", label: "Daşoguz" },
|
||||
{ value: "lebap", label: "Lebap" },
|
||||
{ value: "balkan", label: "Balkan" },
|
||||
];
|
||||
const REGION_CODES = ["AG", "AH", "BN", "DZ", "LB", "MR"] as const;
|
||||
|
||||
const REGION_LABELS: Record<string, string> = {
|
||||
AG: "Aşgabat",
|
||||
AH: "Ahal",
|
||||
BN: "Balkan",
|
||||
DZ: "Daşoguz",
|
||||
LB: "Lebap",
|
||||
MR: "Mary",
|
||||
};
|
||||
|
||||
function resolveLocalizedName(name: LocalizedText | string | null | undefined, lang = "en"): string {
|
||||
if (!name) return "";
|
||||
if (typeof name === "string") return name;
|
||||
const key = lang === "tk" ? "tm" : lang;
|
||||
return name[key as keyof LocalizedText] ?? name.tm ?? name.en ?? name.ru ?? "";
|
||||
}
|
||||
|
||||
function getRegionOptions(t: TFunction): { value: string; label: string }[] {
|
||||
return REGION_CODES.map((code) => ({
|
||||
value: code,
|
||||
label: t(`intlPayment.regions.${code}`, REGION_LABELS[code] ?? code),
|
||||
}));
|
||||
}
|
||||
|
||||
const KABUL_DOCS: { key: keyof IntlPaymentFormData; label: string }[] = [
|
||||
{ key: "doc_sberbank_account", label: "Talypyň SBERBANK kartynyň rekwizitleri" },
|
||||
@@ -118,7 +140,7 @@ const STEPS: StepDef[] = [
|
||||
titleKey: "intlPaymentForm.steps.docs.title",
|
||||
titleFallback: "Resminamalar",
|
||||
subtitleKey: "intlPaymentForm.steps.docs.subtitle",
|
||||
subtitleFallback: "15 resminama",
|
||||
subtitleFallback: "Resminamalary ýükläň",
|
||||
icon: Files,
|
||||
validate: () => ({}),
|
||||
},
|
||||
@@ -142,23 +164,47 @@ interface StepContentProps {
|
||||
errors: FlatErrors;
|
||||
set: <K extends keyof IntlPaymentFormData>(k: K, v: IntlPaymentFormData[K]) => void;
|
||||
t: TFunction;
|
||||
mode: "create" | "edit";
|
||||
initialData?: IntlPaymentItem;
|
||||
}
|
||||
|
||||
function StepGeneral({ form, errors, set, t }: StepContentProps) {
|
||||
function StepGeneral({ form, errors, set, t, initialData }: StepContentProps) {
|
||||
const [clientSearch, setClientSearch] = useState("");
|
||||
const clientQuery = useInfiniteClients(clientSearch);
|
||||
|
||||
const statusOptions = useMemo(() => getStatusOptions(t, "intlPayment.status"), [t]);
|
||||
|
||||
const clientOptions: InfiniteSelectOption[] = useMemo(() => {
|
||||
const opts: InfiniteSelectOption[] = (clientQuery.data?.pages ?? [])
|
||||
.flatMap((p) => p?.users ?? [])
|
||||
.map((u) => ({
|
||||
value: String(u.id),
|
||||
label: u.name || u.username || String(u.id),
|
||||
}));
|
||||
|
||||
if (initialData?.client_id && !opts.some((o) => o.value === String(initialData.client_id))) {
|
||||
opts.unshift({ value: String(initialData.client_id), label: initialData.client_label || String(initialData.client_id) });
|
||||
}
|
||||
return opts;
|
||||
}, [clientQuery.data, initialData]);
|
||||
|
||||
return (
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
<InfiniteSelect
|
||||
label={t("User") || "Ulanyjy"}
|
||||
required
|
||||
value={form.client_id}
|
||||
onChange={(v) => set("client_id", v)}
|
||||
options={[]}
|
||||
options={clientOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.client_id}
|
||||
required
|
||||
loading={clientQuery.isLoading}
|
||||
isLoadingMore={clientQuery.isFetchingNextPage}
|
||||
hasNextPage={!!clientQuery.hasNextPage}
|
||||
onLoadMore={() => clientQuery.fetchNextPage()}
|
||||
searchValue={clientSearch}
|
||||
onSearchChange={setClientSearch}
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
@@ -200,7 +246,27 @@ function StepGeneral({ form, errors, set, t }: StepContentProps) {
|
||||
);
|
||||
}
|
||||
|
||||
function StepLocation({ form, errors, set, t }: StepContentProps) {
|
||||
function StepLocation({ form, errors, set, t, initialData }: StepContentProps) {
|
||||
const { i18n } = useTranslation();
|
||||
const [branchSearch, setBranchSearch] = useState("");
|
||||
const branchQuery = useInfiniteBranches(branchSearch);
|
||||
|
||||
const regionOptions = useMemo(() => getRegionOptions(t), [t]);
|
||||
|
||||
const branchOptions: InfiniteSelectOption[] = useMemo(() => {
|
||||
const opts: InfiniteSelectOption[] = (branchQuery.data?.pages ?? [])
|
||||
.flatMap((p) => p?.branches ?? [])
|
||||
.map((b) => ({
|
||||
value: String(b.id),
|
||||
label: resolveLocalizedName(b.name, i18n.language) || b.uniqueCode || String(b.id),
|
||||
}));
|
||||
|
||||
if (initialData?.branch && !opts.some((o) => o.value === String(initialData.branch))) {
|
||||
opts.unshift({ value: String(initialData.branch), label: initialData.branch_label || String(initialData.branch) });
|
||||
}
|
||||
return opts;
|
||||
}, [branchQuery.data, i18n.language, initialData]);
|
||||
|
||||
return (
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
@@ -212,22 +278,29 @@ function StepLocation({ form, errors, set, t }: StepContentProps) {
|
||||
set("province", v);
|
||||
set("branch", "");
|
||||
}}
|
||||
options={PROVINCE_OPTIONS}
|
||||
options={regionOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.province}
|
||||
required
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
<InfiniteSelect
|
||||
label={t("Branch") || "Şahamça"}
|
||||
required
|
||||
value={form.branch}
|
||||
onChange={(v) => set("branch", v)}
|
||||
options={[]}
|
||||
options={branchOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
disabled={!form.province}
|
||||
error={errors.branch}
|
||||
required
|
||||
loading={branchQuery.isLoading}
|
||||
isLoadingMore={branchQuery.isFetchingNextPage}
|
||||
hasNextPage={!!branchQuery.hasNextPage}
|
||||
onLoadMore={() => branchQuery.fetchNextPage()}
|
||||
searchValue={branchSearch}
|
||||
onSearchChange={setBranchSearch}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
@@ -350,19 +423,18 @@ function StepPayment({ form, errors, set, t }: StepContentProps) {
|
||||
);
|
||||
}
|
||||
|
||||
function StepDocs({ form, set }: StepContentProps) {
|
||||
function StepDocs({ form, set, errors }: StepContentProps) {
|
||||
return (
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
<div className="space-y-3">
|
||||
{KABUL_DOCS.map(({ key, label }) => (
|
||||
<FormInput
|
||||
<DocumentUpload
|
||||
key={key}
|
||||
type="file"
|
||||
label={label}
|
||||
onFileChange={(f) => set(key, f as IntlPaymentFormData[typeof key])}
|
||||
fileValue={form[key] as File | null}
|
||||
accept="image/*,.pdf"
|
||||
value={(form[key] as string) || ""}
|
||||
onChange={(v) => set(key, v as IntlPaymentFormData[typeof key])}
|
||||
error={errors[key]}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
@@ -371,13 +443,12 @@ function StepDocs({ form, set }: StepContentProps) {
|
||||
<BentoCard>
|
||||
<div className="space-y-3">
|
||||
{UPGRAD_DOCS.map(({ key, label }) => (
|
||||
<FormInput
|
||||
<DocumentUpload
|
||||
key={key}
|
||||
type="file"
|
||||
label={label}
|
||||
onFileChange={(f) => set(key, f as IntlPaymentFormData[typeof key])}
|
||||
fileValue={form[key] as File | null}
|
||||
accept="image/*,.pdf"
|
||||
value={(form[key] as string) || ""}
|
||||
onChange={(v) => set(key, v as IntlPaymentFormData[typeof key])}
|
||||
error={errors[key]}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
@@ -406,6 +477,21 @@ function mapInitial(data: IntlPaymentItem): Partial<IntlPaymentFormData> {
|
||||
payer_full_name: data.payer_full_name,
|
||||
payer_account_number: data.payer_account_number,
|
||||
receiver_info: data.receiver_info,
|
||||
doc_sberbank_account: data.doc_sberbank_account ?? "",
|
||||
doc_school_enrollment: data.doc_school_enrollment ?? "",
|
||||
doc_summons: data.doc_summons ?? "",
|
||||
doc_passport_tm: data.doc_passport_tm ?? "",
|
||||
doc_foreign_passport: data.doc_foreign_passport ?? "",
|
||||
doc_foreign_passport_copy: data.doc_foreign_passport_copy ?? "",
|
||||
doc_exit_permission: data.doc_exit_permission ?? "",
|
||||
doc_school_foreign_info: data.doc_school_foreign_info ?? "",
|
||||
doc_school_departure_info: data.doc_school_departure_info ?? "",
|
||||
upd_doc_passport_tm: data.upd_doc_passport_tm ?? "",
|
||||
upd_doc_foreign_passport: data.upd_doc_foreign_passport ?? "",
|
||||
upd_doc_visa: data.upd_doc_visa ?? "",
|
||||
upd_doc_acceptance_letter: data.upd_doc_acceptance_letter ?? "",
|
||||
upd_doc_passport_biometric: data.upd_doc_passport_biometric ?? "",
|
||||
upd_doc_passport_old: data.upd_doc_passport_old ?? "",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -463,7 +549,7 @@ export function IntlPaymentForm({ mode, initialData }: IntlPaymentFormProps) {
|
||||
return { ...fromRHF, ...allSubmittedErrors };
|
||||
}, [rhfErrors, allSubmittedErrors]);
|
||||
|
||||
const stepProps = useMemo(() => ({ form, errors, set, t }), [form, errors, set, t]);
|
||||
const stepProps = useMemo(() => ({ form, errors, set, t, mode, initialData }), [form, errors, set, t, mode, initialData]);
|
||||
|
||||
// ── Navigation ──────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -529,11 +615,11 @@ export function IntlPaymentForm({ mode, initialData }: IntlPaymentFormProps) {
|
||||
|
||||
if (mode === "create") {
|
||||
createMutation.mutate(payload as IntlPaymentCreatePayload, {
|
||||
onSuccess: (data) => navigate(`/intl-payments/visa-master/${data.id}`),
|
||||
onSuccess: (data) => navigate(`/visa-master/${data.id}`),
|
||||
});
|
||||
} else if (initialData) {
|
||||
updateMutation.mutate(payload as IntlPaymentCreatePayload, {
|
||||
onSuccess: () => navigate(`/intl-payments/visa-master/${initialData.id}`),
|
||||
onSuccess: () => navigate(`/visa-master/${initialData.id}`),
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -580,7 +666,7 @@ export function IntlPaymentForm({ mode, initialData }: IntlPaymentFormProps) {
|
||||
{/* Actions */}
|
||||
<FormActions
|
||||
isPending={isPending}
|
||||
onCancel={() => navigate("/intl-payments/visa-master")}
|
||||
onCancel={() => navigate("/visa-master")}
|
||||
onPrev={currentStep > 0 ? handleBack : undefined}
|
||||
onNext={!isLastStep ? handleNext : undefined}
|
||||
showSubmit={isLastStep}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { z } from "zod";
|
||||
import i18next from "i18next";
|
||||
import type { IntlPaymentCreatePayload, IntlPaymentStatus, CurrencyType } from "../api/visaMasterPaymentsApi";
|
||||
|
||||
const fileField = z.custom<File | null>().nullable();
|
||||
const fileField = z.string().optional().default("");
|
||||
const VALID_PHONE_PREFIXES = ["61", "62", "63", "64", "65", "71"];
|
||||
|
||||
export const visaMasterPaymentFormSchema = z.object({
|
||||
@@ -109,21 +109,21 @@ export const DEFAULT_FORM_VALUES: IntlPaymentFormData = {
|
||||
payer_full_name: "",
|
||||
payer_account_number: "",
|
||||
receiver_info: "",
|
||||
doc_sberbank_account: null,
|
||||
doc_school_enrollment: null,
|
||||
doc_summons: null,
|
||||
doc_passport_tm: null,
|
||||
doc_foreign_passport: null,
|
||||
doc_foreign_passport_copy: null,
|
||||
doc_exit_permission: null,
|
||||
doc_school_foreign_info: null,
|
||||
doc_school_departure_info: null,
|
||||
upd_doc_passport_tm: null,
|
||||
upd_doc_foreign_passport: null,
|
||||
upd_doc_visa: null,
|
||||
upd_doc_acceptance_letter: null,
|
||||
upd_doc_passport_biometric: null,
|
||||
upd_doc_passport_old: null,
|
||||
doc_sberbank_account: "",
|
||||
doc_school_enrollment: "",
|
||||
doc_summons: "",
|
||||
doc_passport_tm: "",
|
||||
doc_foreign_passport: "",
|
||||
doc_foreign_passport_copy: "",
|
||||
doc_exit_permission: "",
|
||||
doc_school_foreign_info: "",
|
||||
doc_school_departure_info: "",
|
||||
upd_doc_passport_tm: "",
|
||||
upd_doc_foreign_passport: "",
|
||||
upd_doc_visa: "",
|
||||
upd_doc_acceptance_letter: "",
|
||||
upd_doc_passport_biometric: "",
|
||||
upd_doc_passport_old: "",
|
||||
};
|
||||
|
||||
export function buildPayload(data: IntlPaymentFormData): IntlPaymentCreatePayload {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState } from "react";
|
||||
import { useState, useMemo } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { ColumnDef, VisibilityState } from "@tanstack/react-table";
|
||||
@@ -9,16 +9,39 @@ import { CreateButton } from "@/components/createButton";
|
||||
import { TableActions } from "@/components/tableActions";
|
||||
import { DeleteDialog } from "@/components/deleteDialog";
|
||||
import { MonthSelect } from "@/components/monthSelect";
|
||||
import { InfiniteSelect } from "@/components/infiniteSelect";
|
||||
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
|
||||
import { AlertCircle, CheckCircle2, XCircle } from "lucide-react";
|
||||
import { useIntlPayments, useDeleteIntlPayment } from "@/features/visaMasterPayments/hooks/useVisaMasterPayments";
|
||||
import type { IntlPaymentStatus, IntlPaymentItem } from "@/features/visaMasterPayments/api/visaMasterPaymentsApi";
|
||||
// ─── Status badge (defined inside component for t() access) ───────────────────
|
||||
import { useInfiniteBranches } from "@/features/shared/hooks/useSharedBranchUsers";
|
||||
import { useInfiniteUsers } from "@/features/allUsers/hooks/useAllUsers";
|
||||
import type { LocalizedText } from "@/features/branches/api/branchesApi";
|
||||
|
||||
// ─── Constants ────────────────────────────────────────────────────────────────
|
||||
|
||||
const REGION_CODES = ["AG", "AH", "BN", "DZ", "LB", "MR"] as const;
|
||||
|
||||
const REGION_LABELS: Record<string, string> = {
|
||||
AG: "Aşgabat",
|
||||
AH: "Ahal",
|
||||
BN: "Balkan",
|
||||
DZ: "Daşoguz",
|
||||
LB: "Lebap",
|
||||
MR: "Mary",
|
||||
};
|
||||
|
||||
function resolveLocalizedName(name: LocalizedText | string | null | undefined, lang: string): string {
|
||||
if (!name) return "";
|
||||
if (typeof name === "string") return name;
|
||||
const key = lang === "tk" ? "tm" : lang;
|
||||
return name[key as keyof LocalizedText] ?? name.tm ?? name.en ?? name.ru ?? "";
|
||||
}
|
||||
|
||||
// ─── Page ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
export default function IntlPaymentsPage() {
|
||||
const { t } = useTranslation();
|
||||
const { t, i18n } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [page, setPage] = useState(1);
|
||||
@@ -26,13 +49,45 @@ export default function IntlPaymentsPage() {
|
||||
const [search, setSearch] = useState("");
|
||||
const [month, setMonth] = useState("");
|
||||
const [statusFilter, setStatusFilter] = useState<IntlPaymentStatus | "">("");
|
||||
const [regionFilter, setRegionFilter] = useState("");
|
||||
const [branchFilter, setBranchFilter] = useState("");
|
||||
const [userFilter, setUserFilter] = useState("");
|
||||
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([]);
|
||||
|
||||
const [deleteTarget, setDeleteTarget] = useState<IntlPaymentItem | null>(null);
|
||||
|
||||
const { data, isLoading } = useIntlPayments({ page, per_page: perPage, search, status: statusFilter, month });
|
||||
const [branchSearch, setBranchSearch] = useState("");
|
||||
const branchQuery = useInfiniteBranches(branchSearch);
|
||||
const branchOptions = useMemo(
|
||||
() =>
|
||||
(branchQuery.data?.pages ?? []).flatMap((p) =>
|
||||
(p?.branches ?? []).map((b) => ({ value: String(b.id), label: resolveLocalizedName(b.name, i18n.language) })),
|
||||
),
|
||||
[branchQuery.data, i18n.language],
|
||||
);
|
||||
|
||||
const [userSearch, setUserSearch] = useState("");
|
||||
const userQuery = useInfiniteUsers(userSearch);
|
||||
const userOptions = useMemo(
|
||||
() =>
|
||||
(userQuery.data?.pages ?? []).flatMap((p) =>
|
||||
(p?.users ?? []).map((u) => ({ value: String(u.id), label: u.name || u.username || String(u.id) })),
|
||||
),
|
||||
[userQuery.data],
|
||||
);
|
||||
|
||||
const { data, isLoading } = useIntlPayments({
|
||||
page,
|
||||
per_page: perPage,
|
||||
search,
|
||||
status: statusFilter,
|
||||
month,
|
||||
region: regionFilter || undefined,
|
||||
branch_id: branchFilter || undefined,
|
||||
user_id: userFilter || undefined,
|
||||
});
|
||||
const { mutate: deletePayment, isPending: isDeleting } = useDeleteIntlPayment();
|
||||
|
||||
function IntlPaymentStatusBadge({ status }: { status: IntlPaymentStatus }) {
|
||||
@@ -111,6 +166,26 @@ export default function IntlPaymentsPage() {
|
||||
return { id, label };
|
||||
});
|
||||
|
||||
const filterFields = useMemo(
|
||||
() => [
|
||||
{
|
||||
id: "status",
|
||||
label: t("intlPayment.status", "Status"),
|
||||
options: [
|
||||
{ value: "pending", label: t("intlPayment.status.pending", "Garaşylýar") },
|
||||
{ value: "approved", label: t("intlPayment.status.approved", "Tassyklandy") },
|
||||
{ value: "rejected", label: t("intlPayment.status.rejected", "Ret edildi") },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "region",
|
||||
label: t("intlPayment.province", "Welaýat"),
|
||||
options: REGION_CODES.map((code) => ({ value: code, label: REGION_LABELS[code] ?? code })),
|
||||
},
|
||||
],
|
||||
[t],
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
@@ -143,24 +218,19 @@ export default function IntlPaymentsPage() {
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
filterFields={[
|
||||
{
|
||||
id: "status",
|
||||
label: t("intlPayment.status", "Status"),
|
||||
options: [
|
||||
{ value: "pending", label: t("intlPayment.status.pending", "Garaşylýar") },
|
||||
{ value: "approved", label: t("intlPayment.status.approved", "Tassyklandy") },
|
||||
{ value: "rejected", label: t("intlPayment.status.rejected", "Ret edildi") },
|
||||
],
|
||||
},
|
||||
filterFields={filterFields}
|
||||
activeFilters={[
|
||||
{ fieldId: "status", value: statusFilter },
|
||||
{ fieldId: "region", value: regionFilter },
|
||||
]}
|
||||
activeFilters={[{ fieldId: "status", value: statusFilter }]}
|
||||
onFilterChange={(fieldId, value) => {
|
||||
if (fieldId === "status") setStatusFilter(value as IntlPaymentStatus | "");
|
||||
if (fieldId === "region") setRegionFilter(value);
|
||||
setPage(1);
|
||||
}}
|
||||
onFilterReset={() => {
|
||||
setStatusFilter("");
|
||||
setRegionFilter("");
|
||||
setPage(1);
|
||||
}}
|
||||
perPage={perPage}
|
||||
@@ -171,13 +241,49 @@ export default function IntlPaymentsPage() {
|
||||
hideSearch
|
||||
hideAction
|
||||
extraActions={
|
||||
<MonthSelect
|
||||
value={month}
|
||||
onChange={(v) => {
|
||||
setMonth(v);
|
||||
setPage(1);
|
||||
}}
|
||||
/>
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="w-44">
|
||||
<InfiniteSelect
|
||||
value={branchFilter}
|
||||
onChange={(v) => {
|
||||
setBranchFilter(v);
|
||||
setPage(1);
|
||||
}}
|
||||
options={branchOptions}
|
||||
loading={branchQuery.isLoading}
|
||||
isLoadingMore={branchQuery.isFetchingNextPage}
|
||||
hasNextPage={!!branchQuery.hasNextPage}
|
||||
onLoadMore={() => branchQuery.fetchNextPage()}
|
||||
searchValue={branchSearch}
|
||||
onSearchChange={setBranchSearch}
|
||||
placeholder={t("intlPayment.branch", "Şahamça")}
|
||||
/>
|
||||
</div>
|
||||
<div className="w-44">
|
||||
<InfiniteSelect
|
||||
value={userFilter}
|
||||
onChange={(v) => {
|
||||
setUserFilter(v);
|
||||
setPage(1);
|
||||
}}
|
||||
options={userOptions}
|
||||
loading={userQuery.isLoading}
|
||||
isLoadingMore={userQuery.isFetchingNextPage}
|
||||
hasNextPage={!!userQuery.hasNextPage}
|
||||
onLoadMore={() => userQuery.fetchNextPage()}
|
||||
searchValue={userSearch}
|
||||
onSearchChange={setUserSearch}
|
||||
placeholder={t("intlPayment.client", "Ulanyjy")}
|
||||
/>
|
||||
</div>
|
||||
<MonthSelect
|
||||
value={month}
|
||||
onChange={(v) => {
|
||||
setMonth(v);
|
||||
setPage(1);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ export default function IntlPaymentViewPage() {
|
||||
const { mutate: deletePayment, isPending: isDeleting } = useDeleteIntlPayment();
|
||||
|
||||
const confirmDelete = () => {
|
||||
deletePayment(data!.id, { onSuccess: () => navigate("/intl-payments/visa-master") });
|
||||
deletePayment(data!.id, { onSuccess: () => navigate("/visa-master") });
|
||||
};
|
||||
|
||||
if (isLoading) return <IntlPaymentViewSkeleton />;
|
||||
@@ -215,7 +215,7 @@ export default function IntlPaymentViewPage() {
|
||||
<BentoCard title={t("intlPayment.personalSection", "Şahsy maglumatlar")}>
|
||||
<InfoRow label={t("intlPayment.passportFirstName", "Pasportdaky ady")} value={data.passport_first_name} />
|
||||
<InfoRow label={t("intlPayment.passportLastName", "Pasportdaky familiýa")} value={data.passport_last_name} />
|
||||
<InfoRow label={t("intlPayment.phone", "Telefon")} value={`+${data.phone}`} />
|
||||
<InfoRow label={t("intlPayment.phone", "Telefon")} value={data.phone} />
|
||||
<InfoRow label={t("intlPayment.email", "E-poçta")} value={data.email} />
|
||||
<InfoRow label={t("intlPayment.homeAddress", "Häzirki ýaşyş ýeri")} value={data.home_address} />
|
||||
</BentoCard>
|
||||
|
||||
@@ -4,6 +4,7 @@ import react from "@vitejs/plugin-react";
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
base: "/online/",
|
||||
plugins: [react()],
|
||||
resolve: {
|
||||
alias: {
|
||||
|
||||
Reference in New Issue
Block a user