added payment setting page and quota
This commit is contained in:
@@ -12,11 +12,18 @@ import { DeleteDialog } from "@/components/deleteDialog";
|
||||
import { useCards, useDeleteCard } from "@/features/orderNewCard/hooks/useOrderNewCard";
|
||||
import type { CardOrder } from "@/features/orderNewCard/api/orderNewCardApi";
|
||||
import { useInfiniteBranches } from "@/features/branches/hooks/useBranches";
|
||||
import { useInfiniteDistricts } from "@/features/districts/hooks/useDistricts";
|
||||
import { useInfiniteCardTypes } from "@/features/cardTypes/hooks/useCardTypes";
|
||||
import { getStatusOptions, StatusCell, ActiveStatusCell } from "@/constants";
|
||||
import type { LocalizedText } from "@/features/branches/api/branchesApi";
|
||||
import { getStatusOptions, getRegionOptions, StatusCell, ActiveStatusCell } from "@/constants";
|
||||
import { formatFromApiDate } from "@/lib/utils/dateUtils";
|
||||
|
||||
function resolveLocalizedName(name: LocalizedText | string | null | undefined, lang = "tm"): string {
|
||||
if (!name) return "—";
|
||||
if (typeof name === "string") return name;
|
||||
const key = (lang === "ru" ? "ru" : lang === "en" ? "en" : "tm") as keyof LocalizedText;
|
||||
return name[key] ?? name.tm ?? name.en ?? name.ru ?? "—";
|
||||
}
|
||||
|
||||
const PER_PAGE = 25;
|
||||
|
||||
// ─── Filter field IDs ──────────────────────────────────────────────────────────
|
||||
@@ -43,7 +50,6 @@ export default function CardOrdersPage() {
|
||||
|
||||
// ── Dropdown data ──────────────────────────────────────────────────────────
|
||||
const [branchSearch, setBranchSearch] = useState("");
|
||||
const [districtSearch, setDistrictSearch] = useState("");
|
||||
const [cardTypeSearch, setCardTypeSearch] = useState("");
|
||||
|
||||
const {
|
||||
@@ -54,14 +60,6 @@ export default function CardOrdersPage() {
|
||||
isLoading: isBranchesLoading,
|
||||
} = useInfiniteBranches(branchSearch);
|
||||
|
||||
const {
|
||||
data: districtsInfiniteData,
|
||||
fetchNextPage: fetchNextDistricts,
|
||||
hasNextPage: hasNextDistricts,
|
||||
isFetchingNextPage: isFetchingNextDistricts,
|
||||
isLoading: isDistrictsLoading,
|
||||
} = useInfiniteDistricts(districtSearch);
|
||||
|
||||
const {
|
||||
data: cardTypesInfiniteData,
|
||||
fetchNextPage: fetchNextCardTypes,
|
||||
@@ -100,35 +98,80 @@ export default function CardOrdersPage() {
|
||||
{row.original.id}
|
||||
</Link>
|
||||
),
|
||||
size: 80,
|
||||
size: 70,
|
||||
},
|
||||
{
|
||||
id: "uniqueId",
|
||||
accessorKey: "uniqueId",
|
||||
header: t("cardOrder.col.uniqueId", "Sargyt belgisi"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground font-mono">{row.original.uniqueId}</span>,
|
||||
cell: ({ row }) => <span className="text-sm text-foreground font-mono whitespace-nowrap">{row.original.uniqueId}</span>,
|
||||
},
|
||||
{
|
||||
id: "customerName",
|
||||
accessorKey: "customerName",
|
||||
header: t("cardOrder.col.customer", "Müşderi"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">
|
||||
{row.original.customerName} {row.original.customerSurname}
|
||||
</span>
|
||||
),
|
||||
cell: ({ row }) => {
|
||||
const fullName = [row.original.customerSurname, row.original.customerName, row.original.customerPatronicName]
|
||||
.filter(Boolean)
|
||||
.join(" ");
|
||||
return <span className="text-sm text-foreground font-medium whitespace-nowrap">{fullName || "—"}</span>;
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "phone",
|
||||
accessorKey: "phone",
|
||||
header: t("cardOrder.col.phone", "Telefon"),
|
||||
cell: ({ row }) => <span className="font-mono text-sm">{row.original.phone}</span>,
|
||||
cell: ({ row }) => <span className="font-mono text-sm whitespace-nowrap">{row.original.phone || "—"}</span>,
|
||||
},
|
||||
{
|
||||
id: "cardType",
|
||||
header: t("cardOrder.col.cardType", "Kart görnüşi"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground whitespace-nowrap">
|
||||
{resolveLocalizedName(row.original.cardType?.name, i18n.language)}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: "cardState",
|
||||
header: t("cardOrder.col.cardState", "Kart ýagdaýy"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-muted-foreground whitespace-nowrap">
|
||||
{resolveLocalizedName(row.original.cardState?.name, i18n.language)}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: "branch",
|
||||
header: t("cardOrder.col.branch", "Şahamça"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground whitespace-nowrap">{resolveLocalizedName(row.original.branch?.name, i18n.language)}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: "region",
|
||||
accessorKey: "region",
|
||||
header: t("cardOrder.col.region", "Sebit"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.region}</span>,
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground whitespace-nowrap">
|
||||
{row.original.region ? t(`loanOrders.regions.${row.original.region}`, row.original.region) : "—"}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: "passport",
|
||||
header: t("cardOrder.col.passport", "Pasport"),
|
||||
cell: ({ row }) => {
|
||||
const pass = [row.original.passportSerie, row.original.passportId].filter(Boolean).join(" ");
|
||||
return <span className="font-mono text-sm whitespace-nowrap">{pass || "—"}</span>;
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "user",
|
||||
header: t("cardOrder.col.user", "Ulanyjy"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground whitespace-nowrap">{row.original.user?.name || row.original.user?.username || "—"}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: "status",
|
||||
@@ -152,7 +195,7 @@ export default function CardOrdersPage() {
|
||||
{row.original.createdAt ? formatFromApiDate(row.original.createdAt) : "—"}
|
||||
</span>
|
||||
),
|
||||
size: 180,
|
||||
size: 160,
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
@@ -191,16 +234,7 @@ export default function CardOrdersPage() {
|
||||
[branchesInfiniteData, lang],
|
||||
);
|
||||
|
||||
const districtOptions = useMemo(
|
||||
() =>
|
||||
(districtsInfiniteData?.pages ?? []).flatMap((page) =>
|
||||
(page?.provinces ?? []).map((d) => ({
|
||||
value: d.region?.tm || d.name.tm,
|
||||
label: d.name[lang] || d.name.tm,
|
||||
})),
|
||||
),
|
||||
[districtsInfiniteData, lang],
|
||||
);
|
||||
const regionOptions = useMemo(() => getRegionOptions(t), [t]);
|
||||
|
||||
const cardTypeOptions = useMemo(
|
||||
() =>
|
||||
@@ -236,14 +270,7 @@ export default function CardOrdersPage() {
|
||||
{
|
||||
id: "region",
|
||||
label: t("cardOrder.filter.region", "Sebit"),
|
||||
type: "infinite-select",
|
||||
options: districtOptions,
|
||||
loading: isDistrictsLoading,
|
||||
isLoadingMore: isFetchingNextDistricts,
|
||||
hasNextPage: hasNextDistricts,
|
||||
onLoadMore: fetchNextDistricts,
|
||||
searchValue: districtSearch,
|
||||
onSearchChange: setDistrictSearch,
|
||||
options: regionOptions,
|
||||
},
|
||||
{
|
||||
id: "user_id",
|
||||
@@ -275,11 +302,7 @@ export default function CardOrdersPage() {
|
||||
isFetchingNextBranches,
|
||||
hasNextBranches,
|
||||
branchSearch,
|
||||
districtOptions,
|
||||
isDistrictsLoading,
|
||||
isFetchingNextDistricts,
|
||||
hasNextDistricts,
|
||||
districtSearch,
|
||||
regionOptions,
|
||||
cardTypeOptions,
|
||||
isCardTypesLoading,
|
||||
isFetchingNextCardTypes,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useState, useMemo } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { CreditCard } from "lucide-react";
|
||||
import type { ColumnDef, VisibilityState } from "@tanstack/react-table";
|
||||
import { DataTable } from "@/components/dataTable";
|
||||
import { DataTableToolbar } from "@/components/dataTableToolbar";
|
||||
@@ -17,6 +18,7 @@ import { useInfiniteBranches } from "@/features/shared/hooks/useSharedBranchUser
|
||||
import { useInfiniteUsers } from "@/features/allUsers/hooks/useAllUsers";
|
||||
import type { LocalizedText } from "@/features/branches/api/branchesApi";
|
||||
import { formatFromApiDate } from "@/lib/utils/dateUtils";
|
||||
import { PayDialog } from "@/features/visaMasterPayments/components/PayDialog";
|
||||
|
||||
// ─── Constants ────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -46,6 +48,7 @@ export default function IntlPaymentsPage() {
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([]);
|
||||
|
||||
const [deleteTarget, setDeleteTarget] = useState<IntlPaymentItem | null>(null);
|
||||
const [payTarget, setPayTarget] = useState<IntlPaymentItem | null>(null);
|
||||
|
||||
const [branchSearch, setBranchSearch] = useState("");
|
||||
const branchQuery = useInfiniteBranches(branchSearch);
|
||||
@@ -140,6 +143,17 @@ export default function IntlPaymentsPage() {
|
||||
onEdit={() => navigate(`/visa-master/${row.original.id}/edit`)}
|
||||
onDelete={() => setDeleteTarget(row.original)}
|
||||
isDeleting={isDeleting}
|
||||
extraActions={
|
||||
row.original.status === "approved"
|
||||
? [
|
||||
{
|
||||
icon: CreditCard,
|
||||
title: t("intlPayment.pay.action", "Töleg et"),
|
||||
onClick: () => setPayTarget(row.original),
|
||||
},
|
||||
]
|
||||
: []
|
||||
}
|
||||
/>
|
||||
),
|
||||
},
|
||||
@@ -303,6 +317,14 @@ export default function IntlPaymentsPage() {
|
||||
}}
|
||||
isLoading={isDeleting}
|
||||
/>
|
||||
|
||||
<PayDialog
|
||||
id={payTarget?.id ?? ""}
|
||||
open={payTarget !== null}
|
||||
onOpenChange={(o) => {
|
||||
if (!o) setPayTarget(null);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -269,7 +269,7 @@ export default function ProfilePage() {
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" className="gap-1.5" onClick={() => setAssignDialog("permission")}>
|
||||
<KeyRound size={14} />
|
||||
{t("profile.actions.assignPermission", "Rugsat birikdiriň")}
|
||||
{t("profile.actions.assignPermissionRole", "Rola rugsat birikdiriň")}
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" className="gap-1.5" onClick={() => setAssignDialog("branch")}>
|
||||
<Building2 size={14} />
|
||||
@@ -340,7 +340,7 @@ export default function ProfilePage() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ── Assign dialog (staff user + role/permission/branch) ─────────────── */}
|
||||
{/* ── Assign dialog (role/permission/branch) ─────────────── */}
|
||||
{assignDialog && <AssignDialog kind={assignDialog} onClose={() => setAssignDialog(null)} />}
|
||||
</div>
|
||||
);
|
||||
|
||||
173
src/pages/settings/payment/index.tsx
Normal file
173
src/pages/settings/payment/index.tsx
Normal file
@@ -0,0 +1,173 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Pencil, Loader2, Settings2 } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { usePaymentSettings, useUpdatePaymentSettings } from "@/features/paymentSettings/hooks/usePaymentSettings";
|
||||
import type { PaymentSettingsPayload } from "@/features/paymentSettings/api/paymentSettingsApi";
|
||||
import { formatFromApiDate } from "@/lib/utils/dateUtils";
|
||||
|
||||
// ─── Field row ────────────────────────────────────────────────────────────────
|
||||
|
||||
function InfoRow({ label, value, unit }: { label: string; value?: number | string | null; unit?: string }) {
|
||||
return (
|
||||
<div className="flex items-center justify-between py-3.5 border-b border-border last:border-0">
|
||||
<span className="text-sm text-muted-foreground">{label}</span>
|
||||
<span className="text-sm font-semibold text-foreground tabular-nums">
|
||||
{value ?? "—"}
|
||||
{unit ? ` ${unit}` : ""}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Edit dialog ──────────────────────────────────────────────────────────────
|
||||
|
||||
interface EditDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (v: boolean) => void;
|
||||
initial: PaymentSettingsPayload;
|
||||
}
|
||||
|
||||
function EditDialog({ open, onOpenChange, initial }: EditDialogProps) {
|
||||
const { t } = useTranslation();
|
||||
const { mutate, isPending } = useUpdatePaymentSettings();
|
||||
|
||||
const [form, setForm] = useState<PaymentSettingsPayload>(initial);
|
||||
|
||||
// sync when initial changes (e.g. dialog re-opened)
|
||||
useEffect(() => {
|
||||
if (open) setForm(initial);
|
||||
}, [open, initial]);
|
||||
|
||||
function set(key: keyof PaymentSettingsPayload, raw: string) {
|
||||
const n = parseFloat(raw);
|
||||
setForm((prev) => ({ ...prev, [key]: isNaN(n) ? 0 : n }));
|
||||
}
|
||||
|
||||
function handleSave() {
|
||||
mutate(form, { onSuccess: () => onOpenChange(false) });
|
||||
}
|
||||
|
||||
if (!open) return null;
|
||||
|
||||
const fields: { key: keyof PaymentSettingsPayload; label: string; unit: string }[] = [
|
||||
{ key: "bankFeeTmt", label: t("paymentSettings.bankFeeTmt", "Bankyň tutumy"), unit: "TMT" },
|
||||
{ key: "gbusFeeTmt", label: t("paymentSettings.gbusFeeTmt", "GBÜS tutumy"), unit: "TMT" },
|
||||
{ key: "sberBankFeeTmt", label: t("paymentSettings.sberBankFeeTmt", "Sber bank tutumy"), unit: "TMT" },
|
||||
{ key: "tvebFeeUsd", label: t("paymentSettings.tvebFeeUsd", "TVEB tutumy"), unit: "USD" },
|
||||
{ key: "maxAmountUsd", label: t("paymentSettings.maxAmountUsd", "Iň ýokary möçber"), unit: "USD" },
|
||||
];
|
||||
|
||||
return (
|
||||
<div
|
||||
className="fixed inset-0 z-50 flex items-center justify-center"
|
||||
onClick={(e) => {
|
||||
if (e.target === e.currentTarget) onOpenChange(false);
|
||||
}}
|
||||
>
|
||||
<div className="absolute inset-0 bg-black/40 backdrop-blur-sm" />
|
||||
<div className="relative z-10 w-full max-w-md mx-4 bg-card rounded-2xl shadow-2xl overflow-hidden border border-border">
|
||||
{/* Header */}
|
||||
<div className="px-6 pt-6 pb-4 border-b border-border flex items-center gap-2">
|
||||
<Settings2 size={16} className="text-primary" />
|
||||
<h2 className="text-sm font-bold uppercase tracking-widest text-foreground">
|
||||
{t("paymentSettings.editTitle", "Sazlamalary üýtget")}
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
{/* Body */}
|
||||
<div className="px-6 py-5 space-y-4">
|
||||
{fields.map(({ key, label, unit }) => (
|
||||
<div key={key} className="flex items-center gap-4">
|
||||
<label className="min-w-40 text-sm text-muted-foreground">{label}</label>
|
||||
<div className="flex-1 relative">
|
||||
<input
|
||||
type="number"
|
||||
min={0}
|
||||
value={form[key]}
|
||||
onChange={(e) => set(key, e.target.value)}
|
||||
className="w-full h-9 px-3 pr-12 border border-border rounded-lg text-sm outline-none bg-background focus:border-primary focus:ring-1 focus:ring-primary/30 transition-colors"
|
||||
/>
|
||||
<span className="absolute right-3 top-1/2 -translate-y-1/2 text-xs text-muted-foreground font-medium">{unit}</span>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Footer */}
|
||||
<div className="px-6 pb-6 flex items-center justify-end gap-3">
|
||||
<Button type="button" variant="outline" onClick={() => onOpenChange(false)} disabled={isPending}>
|
||||
{t("common.cancel", "Ýatyr")}
|
||||
</Button>
|
||||
<Button type="button" onClick={handleSave} disabled={isPending}>
|
||||
{isPending ? (
|
||||
<span className="flex items-center gap-2">
|
||||
<Loader2 size={14} className="animate-spin" />
|
||||
{t("common.saving", "Saklanýar...")}
|
||||
</span>
|
||||
) : (
|
||||
t("common.save", "Sakla")
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Page ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
export default function PaymentSettingsPage() {
|
||||
const { t } = useTranslation();
|
||||
const { data, isLoading } = usePaymentSettings();
|
||||
const [editOpen, setEditOpen] = useState(false);
|
||||
|
||||
const initial: PaymentSettingsPayload = {
|
||||
bankFeeTmt: data?.bankFeeTmt ?? 0,
|
||||
gbusFeeTmt: data?.gbusFeeTmt ?? 0,
|
||||
sberBankFeeTmt: data?.sberBankFeeTmt ?? 0,
|
||||
tvebFeeUsd: data?.tvebFeeUsd ?? 0,
|
||||
maxAmountUsd: data?.maxAmountUsd ?? 0,
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-foreground">{t("paymentSettings.title", "Töleg sazlamalary")}</h1>
|
||||
{data?.updatedAt && (
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
{t("paymentSettings.lastUpdated", "Soňky üýtgeşme")}: {formatFromApiDate(data.updatedAt)}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<Button type="button" onClick={() => setEditOpen(true)} disabled={isLoading}>
|
||||
<Pencil size={14} />
|
||||
{t("paymentSettings.edit", "Üýtget")}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Info card */}
|
||||
<div className="bg-card border border-border rounded-xl px-5 py-1">
|
||||
{isLoading ? (
|
||||
<div className="flex items-center justify-center py-10 text-muted-foreground gap-2">
|
||||
<Loader2 size={16} className="animate-spin" />
|
||||
<span className="text-sm">{t("common.loading", "Ýüklenýär...")}</span>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<InfoRow label={t("paymentSettings.bankFeeTmt", "Bankyň tutumy")} value={data?.bankFeeTmt} unit="TMT" />
|
||||
<InfoRow label={t("paymentSettings.gbusFeeTmt", "GBÜS tutumy")} value={data?.gbusFeeTmt} unit="TMT" />
|
||||
<InfoRow label={t("paymentSettings.sberBankFeeTmt", "Sber bank tutumy")} value={data?.sberBankFeeTmt} unit="TMT" />
|
||||
<InfoRow label={t("paymentSettings.tvebFeeUsd", "TVEB tutumy")} value={data?.tvebFeeUsd} unit="USD" />
|
||||
<InfoRow label={t("paymentSettings.maxAmountUsd", "Iň ýokary möçber")} value={data?.maxAmountUsd} unit="USD" />
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Edit dialog */}
|
||||
<EditDialog open={editOpen} onOpenChange={setEditOpen} initial={initial} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user