connected visa intl payments
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user