refactord some files
This commit is contained in:
1 parent
3d1dc86cab
commit
caae941346
30 files changed
+2761
-3039
No files matched your search
@@ -3,18 +3,11 @@ import { useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Download, Eye, Pencil, Trash2 } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { DeleteDialog } from "@/components/deleteDialog";
|
||||
import { DataTable, type ColumnDef } from "@/components/dataTable";
|
||||
import { DataTableToolbar, type ColumnMeta } from "@/components/dataTableToolbar";
|
||||
import { TableSearchInput } from "@/components/tableSearch";
|
||||
import { CreateButton } from "@/components/createButton";
|
||||
import type { VisibilityState } from "@tanstack/react-table";
|
||||
import { useCardBalances, useDeleteCardBalance, useDownloadCardBalance } from "@/features/cardBalance/hooks/useCardBalance";
|
||||
import { type CardBalance } from "@/features/cardBalance/api/cardBalanceApi";
|
||||
@@ -147,6 +140,17 @@ export default function CardBalancesPage() {
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold text-foreground">{t("Card balances", "Kart galyndylary")}</h1>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
onChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
<CreateButton label={t("Create card balance", "Kart galyndysy dörediň")} onClick={() => navigate("/card-balances/create")} />
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
@@ -160,8 +164,8 @@ export default function CardBalancesPage() {
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
actionLabel={t("Create card balance", "Kart galyndysy dörediň")}
|
||||
onAction={() => navigate("/card-balances/create")}
|
||||
hideSearch
|
||||
hideAction
|
||||
perPageOptions={[10, 25, 50, 100]}
|
||||
perPage={perPage}
|
||||
onPerPageChange={(v) => {
|
||||
@@ -187,22 +191,16 @@ export default function CardBalancesPage() {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<AlertDialog open={deleteId !== null} onOpenChange={(open) => !open && setDeleteId(null)}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t("Are you sure?", "Eminsiňizmi?")}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t("This action cannot be undone.", "Bu amal yzyna gaýtarylmaz. Kart galyndysy hemişelik öçüriler.")}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t("Cancel", "Ýatyr")}</AlertDialogCancel>
|
||||
<AlertDialogAction onClick={handleDelete} className="bg-destructive text-destructive-foreground hover:bg-destructive/90">
|
||||
{deleteMutation.isPending ? t("Deleting...", "Öçürilýär...") : t("Delete", "Öçür")}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
<DeleteDialog
|
||||
open={deleteId !== null}
|
||||
onOpenChange={(o) => {
|
||||
if (!o) setDeleteId(null);
|
||||
}}
|
||||
title={t("Are you sure?", "Eminsiňizmi?")}
|
||||
description={t("This action cannot be undone.", "Bu amal yzyna gaýtarylmaz. Kart galyndysy hemişelik öçüriler.")}
|
||||
onConfirm={handleDelete}
|
||||
isLoading={deleteMutation.isPending}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -4,38 +4,18 @@ import { useTranslation } from "react-i18next";
|
||||
import type { ColumnDef, VisibilityState } from "@tanstack/react-table";
|
||||
import { DataTable } from "@/components/dataTable";
|
||||
import { DataTableToolbar } from "@/components/dataTableToolbar";
|
||||
import { TableSearchInput } from "@/components/tableSearch";
|
||||
import { CreateButton } from "@/components/createButton";
|
||||
import { useCardPins } from "@/features/cardPins/hooks/useCardPins";
|
||||
import { useDeleteCardPin } from "@/features/cardPins/hooks/useCardPins";
|
||||
import type {
|
||||
CardPinItem,
|
||||
CardPinStatus,
|
||||
} from "@/features/cardPins/api/cardPinApi";
|
||||
import type { CardPinItem, CardPinStatus } from "@/features/cardPins/api/cardPinApi";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Eye,
|
||||
Pencil,
|
||||
Trash2,
|
||||
AlertCircle,
|
||||
CheckCircle2,
|
||||
XCircle,
|
||||
} from "lucide-react";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { DeleteDialog } from "@/components/deleteDialog";
|
||||
import { Eye, Pencil, Trash2, AlertCircle, CheckCircle2, XCircle } from "lucide-react";
|
||||
|
||||
// ─── Status Badge ─────────────────────────────────────────────────────────────
|
||||
|
||||
import {
|
||||
StatusBadge,
|
||||
type StatusBadgeVariant,
|
||||
} from "@/components/ui/statusBadge";
|
||||
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
|
||||
|
||||
// ─── Status badge ─────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -55,20 +35,12 @@ const STATUS_CONFIG = {
|
||||
variant: "error" as StatusBadgeVariant,
|
||||
icon: XCircle,
|
||||
},
|
||||
} satisfies Record<
|
||||
CardPinStatus,
|
||||
{ label: string; variant: StatusBadgeVariant; icon: React.ElementType }
|
||||
>;
|
||||
} satisfies Record<CardPinStatus, { label: string; variant: StatusBadgeVariant; icon: React.ElementType }>;
|
||||
|
||||
function CardPinStatusStatusBadge({ status }: { status: CardPinStatus }) {
|
||||
const cfg = STATUS_CONFIG[status];
|
||||
if (!cfg)
|
||||
return (
|
||||
<span className="text-xs text-muted-foreground">{String(status)}</span>
|
||||
);
|
||||
return (
|
||||
<StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />
|
||||
);
|
||||
if (!cfg) return <span className="text-xs text-muted-foreground">{String(status)}</span>;
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />;
|
||||
}
|
||||
|
||||
// ─── Page ─────────────────────────────────────────────────────────────────────
|
||||
@@ -99,29 +71,17 @@ export default function CardPinsPage() {
|
||||
{
|
||||
accessorKey: "id",
|
||||
header: "ID",
|
||||
cell: ({ row }) => (
|
||||
<span className="font-mono text-xs text-muted-foreground">
|
||||
{row.original.id}
|
||||
</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="font-mono text-xs text-muted-foreground">{row.original.id}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "card_type_label",
|
||||
header: t("cardPin.cardType", "Görnüşi"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm font-medium text-primary">
|
||||
{row.original.card_type_label}
|
||||
</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-sm font-medium text-primary">{row.original.card_type_label}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "created_at",
|
||||
header: t("cardPin.createdAt", "Döredilen wagty"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-muted-foreground whitespace-nowrap">
|
||||
{row.original.created_at}
|
||||
</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-sm text-muted-foreground whitespace-nowrap">{row.original.created_at}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "province_label",
|
||||
@@ -130,11 +90,7 @@ export default function CardPinsPage() {
|
||||
{
|
||||
accessorKey: "branch_label",
|
||||
header: t("cardPin.branch", "Şahamça"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-primary font-medium">
|
||||
{row.original.branch_label}
|
||||
</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-primary font-medium">{row.original.branch_label}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "first_name",
|
||||
@@ -147,36 +103,22 @@ export default function CardPinsPage() {
|
||||
{
|
||||
accessorKey: "phone",
|
||||
header: t("cardPin.phone", "Telefon"),
|
||||
cell: ({ row }) => (
|
||||
<span className="font-mono text-sm">{row.original.phone}</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="font-mono text-sm">{row.original.phone}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "status",
|
||||
header: t("cardPin.status", "Status"),
|
||||
cell: ({ row }) => (
|
||||
<CardPinStatusStatusBadge status={row.original.status} />
|
||||
),
|
||||
cell: ({ row }) => <CardPinStatusStatusBadge status={row.original.status} />,
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-1">
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-7 w-7"
|
||||
onClick={() => navigate(`/card-pins/${row.original.id}`)}
|
||||
>
|
||||
<Button size="icon" variant="ghost" className="h-7 w-7" onClick={() => navigate(`/card-pins/${row.original.id}`)}>
|
||||
<Eye size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-7 w-7"
|
||||
onClick={() => navigate(`/card-pins/${row.original.id}/edit`)}
|
||||
>
|
||||
<Button size="icon" variant="ghost" className="h-7 w-7" onClick={() => navigate(`/card-pins/${row.original.id}/edit`)}>
|
||||
<Pencil size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
@@ -196,21 +138,25 @@ export default function CardPinsPage() {
|
||||
.filter((c) => ("accessorKey" in c || "id" in c) && c.id !== "actions")
|
||||
.map((c) => {
|
||||
const id = ("accessorKey" in c ? String(c.accessorKey) : c.id) as string;
|
||||
const label =
|
||||
typeof c.header === "string"
|
||||
? c.header
|
||||
: "accessorKey" in c
|
||||
? String(c.accessorKey)
|
||||
: id;
|
||||
const label = typeof c.header === "string" ? c.header : "accessorKey" in c ? String(c.accessorKey) : id;
|
||||
return { id, label };
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t("Card pins", "Kart pin bukjalary")}
|
||||
</h1>
|
||||
<h1 className="text-xl font-semibold text-foreground">{t("Card pins", "Kart pin bukjalary")}</h1>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
onChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
<CreateButton label={t("cardPin.createBtn", "Kart pin bukja dörediň")} onClick={() => navigate("/card-pins/create")} />
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<DataTableToolbar
|
||||
@@ -219,7 +165,7 @@ export default function CardPinsPage() {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||
columns={columnMeta}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
@@ -238,8 +184,7 @@ export default function CardPinsPage() {
|
||||
]}
|
||||
activeFilters={[{ fieldId: "status", value: statusFilter }]}
|
||||
onFilterChange={(fieldId, value) => {
|
||||
if (fieldId === "status")
|
||||
setStatusFilter(value as CardPinStatus | "");
|
||||
if (fieldId === "status") setStatusFilter(value as CardPinStatus | "");
|
||||
setPage(1);
|
||||
}}
|
||||
onFilterReset={() => {
|
||||
@@ -251,8 +196,8 @@ export default function CardPinsPage() {
|
||||
setPerPage(v);
|
||||
setPage(1);
|
||||
}}
|
||||
actionLabel={t("cardPin.createBtn", "Kart pin bukja dörediň")}
|
||||
onAction={() => navigate("/card-pins/create")}
|
||||
hideSearch
|
||||
hideAction
|
||||
/>
|
||||
|
||||
<DataTable
|
||||
@@ -272,40 +217,22 @@ export default function CardPinsPage() {
|
||||
</div>
|
||||
|
||||
{/* Delete confirmation */}
|
||||
<AlertDialog
|
||||
<DeleteDialog
|
||||
open={!!deleteTarget}
|
||||
onOpenChange={(o) => !o && setDeleteTarget(null)}
|
||||
>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>
|
||||
{t("cardPin.deleteTitle", "Pozmak isleýärsiňizmi?")}
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t("cardPin.deleteDesc", "Bu amal yzyna dolanyp bolmaz.")}{" "}
|
||||
{deleteTarget?.id}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={isDeleting}>
|
||||
{t("common.cancel", "Ýatyr")}
|
||||
</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
disabled={isDeleting}
|
||||
className="bg-destructive hover:bg-destructive/90"
|
||||
onClick={() => {
|
||||
if (deleteTarget) {
|
||||
deletePin(deleteTarget.id, {
|
||||
onSuccess: () => setDeleteTarget(null),
|
||||
});
|
||||
}
|
||||
}}
|
||||
>
|
||||
{t("common.delete", "Poz")}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
onOpenChange={(o) => {
|
||||
if (!o) setDeleteTarget(null);
|
||||
}}
|
||||
title={t("cardPin.deleteTitle", "Pozmak isleýärsiňizmi?")}
|
||||
description={`${t("cardPin.deleteDesc", "Bu amal yzyna dolanyp bolmaz.")} ${deleteTarget?.id ?? ""}`}
|
||||
onConfirm={() => {
|
||||
if (deleteTarget) {
|
||||
deletePin(deleteTarget.id, {
|
||||
onSuccess: () => setDeleteTarget(null),
|
||||
});
|
||||
}
|
||||
}}
|
||||
isLoading={isDeleting}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -3,38 +3,18 @@ import { useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Download, Eye, Pencil, Trash2 } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { DeleteDialog } from "@/components/deleteDialog";
|
||||
import { DataTable, type ColumnDef } from "@/components/dataTable";
|
||||
import {
|
||||
DataTableToolbar,
|
||||
type ColumnMeta,
|
||||
} from "@/components/dataTableToolbar";
|
||||
import { DataTableToolbar, type ColumnMeta } from "@/components/dataTableToolbar";
|
||||
import { TableSearchInput } from "@/components/tableSearch";
|
||||
import { CreateButton } from "@/components/createButton";
|
||||
import type { VisibilityState } from "@tanstack/react-table";
|
||||
import {
|
||||
useCardRequisites,
|
||||
useDeleteCardRequisite,
|
||||
useDownloadCardRequisite,
|
||||
} from "@/features/cardRequisites/hooks/useCardRequisites";
|
||||
import type {
|
||||
CardRequisite,
|
||||
CardRequisiteStatus,
|
||||
} from "@/features/cardRequisites/api/cardRequisitesApi";
|
||||
import { useCardRequisites, useDeleteCardRequisite, useDownloadCardRequisite } from "@/features/cardRequisites/hooks/useCardRequisites";
|
||||
import type { CardRequisite, CardRequisiteStatus } from "@/features/cardRequisites/api/cardRequisitesApi";
|
||||
|
||||
// ─── Status badge ─────────────────────────────────────────────────────────────
|
||||
|
||||
const STATUS_BADGE: Record<
|
||||
CardRequisiteStatus,
|
||||
{ label: string; className: string }
|
||||
> = {
|
||||
const STATUS_BADGE: Record<CardRequisiteStatus, { label: string; className: string }> = {
|
||||
pending: {
|
||||
label: "Garaşylýar",
|
||||
className: "bg-yellow-500/15 text-yellow-500 border-yellow-500/20",
|
||||
@@ -52,11 +32,7 @@ const STATUS_BADGE: Record<
|
||||
function StatusBadge({ status }: { status: CardRequisiteStatus }) {
|
||||
const cfg = STATUS_BADGE[status] ?? STATUS_BADGE.pending;
|
||||
return (
|
||||
<span
|
||||
className={`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium border ${cfg.className}`}
|
||||
>
|
||||
{cfg.label}
|
||||
</span>
|
||||
<span className={`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium border ${cfg.className}`}>{cfg.label}</span>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -103,39 +79,25 @@ export default function CardRequisitesPage() {
|
||||
id: "card_type",
|
||||
accessorKey: "card_type",
|
||||
header: t("Card type", "GÖRNÜŞI"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-primary font-medium">
|
||||
{row.original.card_type}
|
||||
</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-primary font-medium">{row.original.card_type}</span>,
|
||||
},
|
||||
{
|
||||
id: "created_at",
|
||||
accessorKey: "created_at",
|
||||
header: t("Created at", "DÖREDILEN WAGTY"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-foreground">{row.original.created_at}</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-foreground">{row.original.created_at}</span>,
|
||||
},
|
||||
{
|
||||
id: "province_name",
|
||||
accessorKey: "province_name",
|
||||
header: t("Province", "WELAÝAT"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-foreground">
|
||||
{row.original.province_name ?? "—"}
|
||||
</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-foreground">{row.original.province_name ?? "—"}</span>,
|
||||
},
|
||||
{
|
||||
id: "branch_name",
|
||||
accessorKey: "branch_name",
|
||||
header: t("Branch", "ŞAHAMÇA"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-primary font-medium">
|
||||
{row.original.branch_name ?? "—"}
|
||||
</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-primary font-medium">{row.original.branch_name ?? "—"}</span>,
|
||||
},
|
||||
{
|
||||
id: "first_name",
|
||||
@@ -161,28 +123,13 @@ export default function CardRequisitesPage() {
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-1 justify-end">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
onClick={() => downloadMutation.mutate(row.original.id)}
|
||||
>
|
||||
<Button variant="ghost" size="icon" className="h-7 w-7" onClick={() => downloadMutation.mutate(row.original.id)}>
|
||||
<Download size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
onClick={() => navigate(`/card-requisites/${row.original.id}`)}
|
||||
>
|
||||
<Button variant="ghost" size="icon" className="h-7 w-7" onClick={() => navigate(`/card-requisites/${row.original.id}`)}>
|
||||
<Eye size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
onClick={() => navigate(`/card-requisites/${row.original.id}/edit`)}
|
||||
>
|
||||
<Button variant="ghost" size="icon" className="h-7 w-7" onClick={() => navigate(`/card-requisites/${row.original.id}/edit`)}>
|
||||
<Pencil size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
@@ -222,9 +169,21 @@ export default function CardRequisitesPage() {
|
||||
<div className="space-y-4">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t("Card requisites", "Kart rekwizitler")}
|
||||
</h1>
|
||||
<h1 className="text-xl font-semibold text-foreground">{t("Card requisites", "Kart rekwizitler")}</h1>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
onChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
<CreateButton
|
||||
label={t("cardRequisites.createTitle", "Kart rekwiziti üçin sargyt dörediň")}
|
||||
onClick={() => navigate("/card-requisites/create")}
|
||||
/>
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<DataTableToolbar
|
||||
@@ -233,17 +192,14 @@ export default function CardRequisitesPage() {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||
columns={columnMeta}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
actionLabel={t(
|
||||
"cardRequisites.createTitle",
|
||||
"Kart rekwiziti üçin sargyt dörediň",
|
||||
)}
|
||||
onAction={() => navigate("/card-requisites/create")}
|
||||
hideSearch
|
||||
hideAction
|
||||
perPageOptions={[10, 25, 50, 100]}
|
||||
perPage={perPage}
|
||||
onPerPageChange={(v) => {
|
||||
@@ -270,35 +226,16 @@ export default function CardRequisitesPage() {
|
||||
/>
|
||||
</div>
|
||||
{/* Delete dialog */}
|
||||
<AlertDialog
|
||||
<DeleteDialog
|
||||
open={deleteId !== null}
|
||||
onOpenChange={(open) => !open && setDeleteId(null)}
|
||||
>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>
|
||||
{t("Are you sure?", "Eminsiňizmi?")}
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t(
|
||||
"This action cannot be undone.",
|
||||
"Bu amal yzyna gaýtarylmaz. Kart rekwiziti hemişelik öçüriler.",
|
||||
)}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t("Cancel", "Ýatyr")}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleDelete}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
{deleteMutation.isPending
|
||||
? t("Deleting...", "Öçürilýär...")
|
||||
: t("Delete", "Öçür")}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
onOpenChange={(o) => {
|
||||
if (!o) setDeleteId(null);
|
||||
}}
|
||||
title={t("Are you sure?", "Eminsiňizmi?")}
|
||||
description={t("This action cannot be undone.", "Bu amal yzyna gaýtarylmaz. Kart rekwiziti hemişelik öçüriler.")}
|
||||
onConfirm={handleDelete}
|
||||
isLoading={deleteMutation.isPending}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,54 +1,47 @@
|
||||
import { useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Download, Eye, Pencil, Trash2 } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import { DataTable, type ColumnDef } from '@/components/dataTable'
|
||||
import { DataTableToolbar, type ColumnMeta } from '@/components/dataTableToolbar'
|
||||
import type { VisibilityState } from '@tanstack/react-table'
|
||||
import { useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Download, Eye, Pencil, Trash2 } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { DeleteDialog } from "@/components/deleteDialog";
|
||||
import { DataTable, type ColumnDef } from "@/components/dataTable";
|
||||
import { DataTableToolbar, type ColumnMeta } from "@/components/dataTableToolbar";
|
||||
import { TableSearchInput } from "@/components/tableSearch";
|
||||
import { CreateButton } from "@/components/createButton";
|
||||
import type { VisibilityState } from "@tanstack/react-table";
|
||||
import {
|
||||
useCardTransactions,
|
||||
useDeleteCardTransaction,
|
||||
useDownloadCardTransaction,
|
||||
} from '@/features/cardTransactions/hooks/useCardTransactions'
|
||||
import type { CardTransaction } from '@/features/cardTransactions/api/cardTransactionsApi'
|
||||
} from "@/features/cardTransactions/hooks/useCardTransactions";
|
||||
import type { CardTransaction } from "@/features/cardTransactions/api/cardTransactionsApi";
|
||||
|
||||
// ─── Page ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
const PER_PAGE = 25
|
||||
const PER_PAGE = 25;
|
||||
|
||||
export default function CardTransactionsPage() {
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [page, setPage] = useState(1)
|
||||
const [perPage, setPerPage] = useState(PER_PAGE)
|
||||
const [search, setSearch] = useState('')
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null)
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([])
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(PER_PAGE);
|
||||
const [search, setSearch] = useState("");
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null);
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([]);
|
||||
|
||||
const { data, isLoading } = useCardTransactions({ page, per_page: perPage, search })
|
||||
const deleteMutation = useDeleteCardTransaction()
|
||||
const downloadMutation = useDownloadCardTransaction()
|
||||
const { data, isLoading } = useCardTransactions({ page, per_page: perPage, search });
|
||||
const deleteMutation = useDeleteCardTransaction();
|
||||
const downloadMutation = useDownloadCardTransaction();
|
||||
|
||||
// ── Columns ──────────────────────────────────────────────────────────────────
|
||||
|
||||
const columns: ColumnDef<CardTransaction>[] = [
|
||||
{
|
||||
id: 'id',
|
||||
accessorKey: 'id',
|
||||
header: t('ID', 'ID'),
|
||||
id: "id",
|
||||
accessorKey: "id",
|
||||
header: t("ID", "ID"),
|
||||
cell: ({ row }) => (
|
||||
<button
|
||||
className="text-primary font-medium hover:underline text-left"
|
||||
@@ -59,165 +52,177 @@ export default function CardTransactionsPage() {
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'passport_series',
|
||||
accessorKey: 'passport_series',
|
||||
header: t('Passport series', 'PASPORT SERIYASY'),
|
||||
id: "passport_series",
|
||||
accessorKey: "passport_series",
|
||||
header: t("Passport series", "PASPORT SERIYASY"),
|
||||
cell: ({ row }) => <span>{row.original.passport_series}</span>,
|
||||
},
|
||||
{
|
||||
id: 'passport_number',
|
||||
accessorKey: 'passport_number',
|
||||
header: t('Passport number', 'PASPORT BELGISI'),
|
||||
id: "passport_number",
|
||||
accessorKey: "passport_number",
|
||||
header: t("Passport number", "PASPORT BELGISI"),
|
||||
cell: ({ row }) => <span>{row.original.passport_number}</span>,
|
||||
},
|
||||
{
|
||||
id: 'card_number',
|
||||
accessorKey: 'card_number',
|
||||
header: t('Card number', 'KART BELGISI'),
|
||||
id: "card_number",
|
||||
accessorKey: "card_number",
|
||||
header: t("Card number", "KART BELGISI"),
|
||||
cell: ({ row }) => <span className="font-mono">{row.original.card_number}</span>,
|
||||
},
|
||||
{
|
||||
id: 'card_expiry_month',
|
||||
accessorKey: 'card_expiry_month',
|
||||
header: t('Expiry month', 'KART MÖHLETI (AÝ)'),
|
||||
id: "card_expiry_month",
|
||||
accessorKey: "card_expiry_month",
|
||||
header: t("Expiry month", "KART MÖHLETI (AÝ)"),
|
||||
cell: ({ row }) => <span>{row.original.card_expiry_month}</span>,
|
||||
},
|
||||
{
|
||||
id: 'card_expiry_year',
|
||||
accessorKey: 'card_expiry_year',
|
||||
header: t('Expiry year', 'KART MÖHLETI (ÝYL)'),
|
||||
id: "card_expiry_year",
|
||||
accessorKey: "card_expiry_year",
|
||||
header: t("Expiry year", "KART MÖHLETI (ÝYL)"),
|
||||
cell: ({ row }) => <span>{row.original.card_expiry_year}</span>,
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
id: "actions",
|
||||
header: "",
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-1 justify-end">
|
||||
<Button
|
||||
variant="ghost" size="icon" className="h-7 w-7"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
onClick={() => downloadMutation.mutate(row.original.id)}
|
||||
title={t('Download', 'Ýükle')}
|
||||
title={t("Download", "Ýükle")}
|
||||
>
|
||||
<Download size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost" size="icon" className="h-7 w-7"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
onClick={() => navigate(`/card-transactions/${row.original.id}`)}
|
||||
title={t('View', 'Görmek')}
|
||||
title={t("View", "Görmek")}
|
||||
>
|
||||
<Eye size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost" size="icon" className="h-7 w-7"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
onClick={() => navigate(`/card-transactions/${row.original.id}/edit`)}
|
||||
title={t('Edit', 'Üýtgetmek')}
|
||||
title={t("Edit", "Üýtgetmek")}
|
||||
>
|
||||
<Pencil size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost" size="icon"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7 text-destructive hover:text-destructive hover:bg-destructive/10"
|
||||
onClick={() => setDeleteId(row.original.id)}
|
||||
title={t('Delete', 'Öçürmek')}
|
||||
title={t("Delete", "Öçürmek")}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</Button>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]
|
||||
];
|
||||
|
||||
// ── Column meta for toolbar ───────────────────────────────────────────────────
|
||||
|
||||
const columnMeta: ColumnMeta[] = columns
|
||||
.filter((c) => c.id !== 'actions')
|
||||
.filter((c) => c.id !== "actions")
|
||||
.map((c) => ({
|
||||
id: c.id!,
|
||||
label: typeof c.header === 'string' ? c.header : c.id!,
|
||||
}))
|
||||
label: typeof c.header === "string" ? c.header : c.id!,
|
||||
}));
|
||||
|
||||
// ── Pagination ────────────────────────────────────────────────────────────────
|
||||
|
||||
const total = data?.total ?? 0
|
||||
const totalPages = Math.ceil(total / perPage)
|
||||
const total = data?.total ?? 0;
|
||||
const totalPages = Math.ceil(total / perPage);
|
||||
|
||||
const handleDelete = async () => {
|
||||
if (deleteId === null) return
|
||||
await deleteMutation.mutateAsync(deleteId)
|
||||
setDeleteId(null)
|
||||
}
|
||||
if (deleteId === null) return;
|
||||
await deleteMutation.mutateAsync(deleteId);
|
||||
setDeleteId(null);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t('Card transactions', 'Kart hereketleri')}
|
||||
</h1>
|
||||
<h1 className="text-xl font-semibold text-foreground">{t("Card transactions", "Kart hereketleri")}</h1>
|
||||
</div>
|
||||
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
onChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
<CreateButton label={t("Create card transaction", "Kart herekedi dörediň")} onClick={() => navigate("/card-transactions/create")} />
|
||||
</div>
|
||||
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
{/* Toolbar */}
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||
columns={columnMeta}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
hideSearch
|
||||
hideAction
|
||||
perPageOptions={[10, 25, 50, 100]}
|
||||
perPage={perPage}
|
||||
onPerPageChange={(v) => {
|
||||
setPerPage(v);
|
||||
setPage(1);
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Toolbar */}
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { setSearch(v); setPage(1) }}
|
||||
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||
columns={columnMeta}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
actionLabel={t('Create card transaction', 'Kart herekedi dörediň')}
|
||||
onAction={() => navigate('/card-transactions/create')}
|
||||
perPageOptions={[10, 25, 50, 100]}
|
||||
perPage={perPage}
|
||||
onPerPageChange={(v) => { setPerPage(v); setPage(1) }}
|
||||
/>
|
||||
|
||||
{/* Table */}
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
enableRowSelection
|
||||
getRowId={(row) => row.id.toString()}
|
||||
currentPage={page}
|
||||
totalPages={totalPages}
|
||||
totalCount={total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
{/* Table */}
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
enableRowSelection
|
||||
getRowId={(row) => row.id.toString()}
|
||||
currentPage={page}
|
||||
totalPages={totalPages}
|
||||
totalCount={total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Delete dialog */}
|
||||
<AlertDialog open={deleteId !== null} onOpenChange={(open) => !open && setDeleteId(null)}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t('Are you sure?', 'Eminsiňizmi?')}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t(
|
||||
'This action cannot be undone. This will permanently delete the card transaction.',
|
||||
'Bu amal yzyna gaýtarylmaz. Kart herekedi hemişelik öçüriler.',
|
||||
)}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('Cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleDelete}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
{deleteMutation.isPending ? t('Deleting...', 'Öçürilýär...') : t('Delete', 'Öçür')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
<DeleteDialog
|
||||
open={deleteId !== null}
|
||||
onOpenChange={(o) => {
|
||||
if (!o) setDeleteId(null);
|
||||
}}
|
||||
title={t("Are you sure?", "Eminsiňizmi?")}
|
||||
description={t(
|
||||
"This action cannot be undone. This will permanently delete the card transaction.",
|
||||
"Bu amal yzyna gaýtarylmaz. Kart herekedi hemişelik öçüriler.",
|
||||
)}
|
||||
onConfirm={handleDelete}
|
||||
isLoading={deleteMutation.isPending}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -1,197 +1,171 @@
|
||||
import { useState, useMemo, useCallback } from 'react'
|
||||
import { useNavigate, Link } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Eye, Pencil, Trash2, CheckCircle2, XCircle, AlertCircle } from 'lucide-react'
|
||||
import type { ColumnDef, VisibilityState } from '@tanstack/react-table'
|
||||
|
||||
import { DataTable } from '@/components/dataTable'
|
||||
import { DataTableToolbar, type ActiveFilter, type FilterField } from '@/components/dataTableToolbar'
|
||||
import {
|
||||
useCardOrders,
|
||||
useDeleteCardOrder,
|
||||
useProvinces,
|
||||
useBranches,
|
||||
} from '@/features/orderNewCard/hooks/useOrderNewCard'
|
||||
import type { CardOrderListItem, CardOrderStatus } from '@/features/orderNewCard/api/orderNewCardApi'
|
||||
import { StatusBadge, type StatusBadgeVariant } from '@/components/ui/statusBadge'
|
||||
import { ConfirmDialog } from '@/components/confirmDialog'
|
||||
import { useState, useMemo, useCallback } from "react";
|
||||
import { useNavigate, Link } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Eye, Pencil, Trash2, CheckCircle2, XCircle, AlertCircle } from "lucide-react";
|
||||
import type { ColumnDef, VisibilityState } from "@tanstack/react-table";
|
||||
|
||||
import { DataTable } from "@/components/dataTable";
|
||||
import { DataTableToolbar, type ActiveFilter, type FilterField } from "@/components/dataTableToolbar";
|
||||
import { TableSearchInput } from "@/components/tableSearch";
|
||||
import { CreateButton } from "@/components/createButton";
|
||||
import { useCardOrders, useDeleteCardOrder, useProvinces, useBranches } from "@/features/orderNewCard/hooks/useOrderNewCard";
|
||||
import type { CardOrderListItem, CardOrderStatus } from "@/features/orderNewCard/api/orderNewCardApi";
|
||||
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
|
||||
import { DeleteDialog } from "@/components/deleteDialog";
|
||||
|
||||
// ─── Status badge ─────────────────────────────────────────────────────────────
|
||||
|
||||
function OrderNewCardStatusBadge({ status }: { status: CardOrderStatus }) {
|
||||
const { t } = useTranslation()
|
||||
const { t } = useTranslation();
|
||||
const STATUS_CONFIG = {
|
||||
PENDING: { label: t('cardOrder.status.pending', 'Garaşylýar'), variant: 'warning' as StatusBadgeVariant, icon: AlertCircle },
|
||||
APPROVED: { label: t('cardOrder.status.approved', 'Tassyklandy'), variant: 'success' as StatusBadgeVariant, icon: CheckCircle2 },
|
||||
REJECTED: { label: t('cardOrder.status.rejected', 'Ýatyryldy'), variant: 'error' as StatusBadgeVariant, icon: XCircle },
|
||||
}
|
||||
const cfg = STATUS_CONFIG[status]
|
||||
if (!cfg) return <span className="text-xs text-muted-foreground">{status}</span>
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />
|
||||
PENDING: { label: t("cardOrder.status.pending", "Garaşylýar"), variant: "warning" as StatusBadgeVariant, icon: AlertCircle },
|
||||
APPROVED: { label: t("cardOrder.status.approved", "Tassyklandy"), variant: "success" as StatusBadgeVariant, icon: CheckCircle2 },
|
||||
REJECTED: { label: t("cardOrder.status.rejected", "Ýatyryldy"), variant: "error" as StatusBadgeVariant, icon: XCircle },
|
||||
};
|
||||
const cfg = STATUS_CONFIG[status];
|
||||
if (!cfg) return <span className="text-xs text-muted-foreground">{status}</span>;
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ─── Coloured text helper ─────────────────────────────────────────────────────
|
||||
|
||||
function HighlightText({ value, variant }: { value: string; variant: 'teal' | 'cyan' | 'muted' }) {
|
||||
function HighlightText({ value, variant }: { value: string; variant: "teal" | "cyan" | "muted" }) {
|
||||
const cls =
|
||||
variant === 'teal' ? 'text-teal-400 font-semibold' :
|
||||
variant === 'cyan' ? 'text-cyan-400 font-semibold' :
|
||||
'text-muted-foreground'
|
||||
return <span className={cls}>{value}</span>
|
||||
variant === "teal" ? "text-teal-400 font-semibold" : variant === "cyan" ? "text-cyan-400 font-semibold" : "text-muted-foreground";
|
||||
return <span className={cls}>{value}</span>;
|
||||
}
|
||||
|
||||
const SPECIAL_BRANCHES = [
|
||||
'Köpetdag', 'Türkmenabat', 'Türkmenbaşy',
|
||||
'Seýdi', 'Çandybil', 'Balkan', 'Baş bank',
|
||||
]
|
||||
const SPECIAL_BRANCHES = ["Köpetdag", "Türkmenabat", "Türkmenbaşy", "Seýdi", "Çandybil", "Balkan", "Baş bank"];
|
||||
|
||||
// ─── CardOrdersPage ───────────────────────────────────────────────────────────
|
||||
|
||||
export default function CardOrdersPage() {
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
const deleteMutation = useDeleteCardOrder()
|
||||
const [deleteId, setDeleteId] = useState<string | null>(null)
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const deleteMutation = useDeleteCardOrder();
|
||||
const [deleteId, setDeleteId] = useState<string | null>(null);
|
||||
|
||||
// ── Column meta (toolbar toggle) ──────────────────────────────────────────
|
||||
const COLUMN_META = useMemo(
|
||||
() => [
|
||||
{ id: 'id', label: t('cardOrder.col.id', 'ID') },
|
||||
{ id: 'issuanceReasonName', label: t('cardOrder.col.reason', 'Sebäp') },
|
||||
{ id: 'createdAt', label: t('cardOrder.col.createdAt', 'Döredilen wagty') },
|
||||
{ id: 'cardTypeName', label: t('cardOrder.col.cardType', 'Görnüşi') },
|
||||
{ id: 'provinceName', label: t('cardOrder.col.province', 'Welaýat') },
|
||||
{ id: 'branchName', label: t('cardOrder.col.branch', 'Şahamça') },
|
||||
{ id: 'fullName', label: t('cardOrder.col.name', 'Ady') },
|
||||
{ id: 'status', label: t('cardOrder.col.status', 'Status') },
|
||||
{ id: "id", label: t("cardOrder.col.id", "ID") },
|
||||
{ id: "issuanceReasonName", label: t("cardOrder.col.reason", "Sebäp") },
|
||||
{ id: "createdAt", label: t("cardOrder.col.createdAt", "Döredilen wagty") },
|
||||
{ id: "cardTypeName", label: t("cardOrder.col.cardType", "Görnüşi") },
|
||||
{ id: "provinceName", label: t("cardOrder.col.province", "Welaýat") },
|
||||
{ id: "branchName", label: t("cardOrder.col.branch", "Şahamça") },
|
||||
{ id: "fullName", label: t("cardOrder.col.name", "Ady") },
|
||||
{ id: "status", label: t("cardOrder.col.status", "Status") },
|
||||
],
|
||||
[t]
|
||||
)
|
||||
const DEFAULT_ORDER = useMemo(() => COLUMN_META.map((c) => c.id), [COLUMN_META])
|
||||
[t],
|
||||
);
|
||||
const DEFAULT_ORDER = useMemo(() => COLUMN_META.map((c) => c.id), [COLUMN_META]);
|
||||
|
||||
// ── State ──────────────────────────────────────────────────────────────────
|
||||
const [search, setSearch] = useState('')
|
||||
const [page, setPage] = useState(1)
|
||||
const [perPage, setPerPage] = useState(10)
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>(DEFAULT_ORDER)
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>([
|
||||
{ fieldId: 'status', value: '' },
|
||||
{ fieldId: 'provinceId', value: '' },
|
||||
{ fieldId: 'branchId', value: '' },
|
||||
])
|
||||
const [search, setSearch] = useState("");
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>(DEFAULT_ORDER);
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>([
|
||||
{ fieldId: "status", value: "" },
|
||||
{ fieldId: "provinceId", value: "" },
|
||||
{ fieldId: "branchId", value: "" },
|
||||
]);
|
||||
|
||||
// ── Lookup data ────────────────────────────────────────────────────────────
|
||||
const provinceId = activeFilters.find((f) => f.fieldId === 'provinceId')?.value
|
||||
const { data: provincesData } = useProvinces()
|
||||
const { data: branchesData } = useBranches(provinceId ? Number(provinceId) : undefined)
|
||||
const provinceId = activeFilters.find((f) => f.fieldId === "provinceId")?.value;
|
||||
const { data: provincesData } = useProvinces();
|
||||
const { data: branchesData } = useBranches(provinceId ? Number(provinceId) : undefined);
|
||||
|
||||
// ── Query params ───────────────────────────────────────────────────────────
|
||||
const queryParams = useMemo(() => {
|
||||
const filterMap = Object.fromEntries(activeFilters.map((f) => [f.fieldId, f.value]))
|
||||
const filterMap = Object.fromEntries(activeFilters.map((f) => [f.fieldId, f.value]));
|
||||
return {
|
||||
search: search || undefined,
|
||||
status: (filterMap.status as CardOrderStatus) || undefined,
|
||||
search: search || undefined,
|
||||
status: (filterMap.status as CardOrderStatus) || undefined,
|
||||
provinceId: filterMap.provinceId ? Number(filterMap.provinceId) : undefined,
|
||||
branchId: filterMap.branchId ? Number(filterMap.branchId) : undefined,
|
||||
branchId: filterMap.branchId ? Number(filterMap.branchId) : undefined,
|
||||
page,
|
||||
perPage,
|
||||
}
|
||||
}, [search, activeFilters, page, perPage])
|
||||
};
|
||||
}, [search, activeFilters, page, perPage]);
|
||||
|
||||
const { data, isLoading } = useCardOrders(queryParams)
|
||||
const { data, isLoading } = useCardOrders(queryParams);
|
||||
|
||||
// ── Handlers ───────────────────────────────────────────────────────────────
|
||||
const handleFilterChange = useCallback((fieldId: string, value: string) => {
|
||||
setActiveFilters((prev) => {
|
||||
const updated = prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f))
|
||||
if (fieldId === 'provinceId') {
|
||||
return updated.map((f) => (f.fieldId === 'branchId' ? { ...f, value: '' } : f))
|
||||
const updated = prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f));
|
||||
if (fieldId === "provinceId") {
|
||||
return updated.map((f) => (f.fieldId === "branchId" ? { ...f, value: "" } : f));
|
||||
}
|
||||
return updated
|
||||
})
|
||||
setPage(1)
|
||||
}, [])
|
||||
return updated;
|
||||
});
|
||||
setPage(1);
|
||||
}, []);
|
||||
|
||||
const handleFilterReset = useCallback(() => {
|
||||
setActiveFilters((prev) => prev.map((f) => ({ ...f, value: '' })))
|
||||
setPage(1)
|
||||
}, [])
|
||||
setActiveFilters((prev) => prev.map((f) => ({ ...f, value: "" })));
|
||||
setPage(1);
|
||||
}, []);
|
||||
|
||||
const handleDelete = useCallback((id: string) => {
|
||||
setDeleteId(id)
|
||||
}, [])
|
||||
setDeleteId(id);
|
||||
}, []);
|
||||
|
||||
const confirmDelete = useCallback(() => {
|
||||
if (!deleteId) return
|
||||
deleteMutation.mutate(deleteId)
|
||||
setDeleteId(null)
|
||||
}, [deleteId, deleteMutation])
|
||||
if (!deleteId) return;
|
||||
deleteMutation.mutate(deleteId);
|
||||
setDeleteId(null);
|
||||
}, [deleteId, deleteMutation]);
|
||||
|
||||
// ── Columns ────────────────────────────────────────────────────────────────
|
||||
const columns = useMemo<ColumnDef<CardOrderListItem>[]>(
|
||||
() => [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: t('cardOrder.col.id', 'ID'),
|
||||
accessorKey: "id",
|
||||
header: t("cardOrder.col.id", "ID"),
|
||||
cell: ({ row }) => (
|
||||
<Link
|
||||
to={`/order-new-card/${row.original.id}`}
|
||||
className="font-mono text-xs text-primary hover:underline"
|
||||
>
|
||||
<Link to={`/order-new-card/${row.original.id}`} className="font-mono text-xs text-primary hover:underline">
|
||||
{row.original.id}
|
||||
</Link>
|
||||
),
|
||||
size: 130,
|
||||
},
|
||||
{
|
||||
accessorKey: 'issuanceReasonName',
|
||||
header: t('cardOrder.col.reason', 'Sebäp'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.issuanceReasonName}</span>
|
||||
),
|
||||
accessorKey: "issuanceReasonName",
|
||||
header: t("cardOrder.col.reason", "Sebäp"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.issuanceReasonName}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'createdAt',
|
||||
header: t('cardOrder.col.createdAt', 'Döredilen wagty'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-muted-foreground whitespace-nowrap">{row.original.createdAt}</span>
|
||||
),
|
||||
accessorKey: "createdAt",
|
||||
header: t("cardOrder.col.createdAt", "Döredilen wagty"),
|
||||
cell: ({ row }) => <span className="text-sm text-muted-foreground whitespace-nowrap">{row.original.createdAt}</span>,
|
||||
size: 160,
|
||||
},
|
||||
{
|
||||
accessorKey: 'cardTypeName',
|
||||
header: t('cardOrder.col.cardType', 'Görnüşi'),
|
||||
accessorKey: "cardTypeName",
|
||||
header: t("cardOrder.col.cardType", "Görnüşi"),
|
||||
cell: ({ row }) => (
|
||||
<HighlightText
|
||||
value={row.original.cardTypeName}
|
||||
variant={row.original.cardTypeName === 'Altyn Asyr' ? 'cyan' : 'teal'}
|
||||
/>
|
||||
<HighlightText value={row.original.cardTypeName} variant={row.original.cardTypeName === "Altyn Asyr" ? "cyan" : "teal"} />
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'provinceName',
|
||||
header: t('cardOrder.col.province', 'Welaýat'),
|
||||
accessorKey: "provinceName",
|
||||
header: t("cardOrder.col.province", "Welaýat"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.provinceName}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "branchName",
|
||||
header: t("cardOrder.col.branch", "Şahamça"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.provinceName}</span>
|
||||
<HighlightText value={row.original.branchName} variant={SPECIAL_BRANCHES.includes(row.original.branchName) ? "cyan" : "muted"} />
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'branchName',
|
||||
header: t('cardOrder.col.branch', 'Şahamça'),
|
||||
cell: ({ row }) => (
|
||||
<HighlightText
|
||||
value={row.original.branchName}
|
||||
variant={SPECIAL_BRANCHES.includes(row.original.branchName) ? 'cyan' : 'muted'}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'fullName',
|
||||
header: t('cardOrder.col.name', 'Ady'),
|
||||
id: "fullName",
|
||||
header: t("cardOrder.col.name", "Ady"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">
|
||||
{row.original.lastName} {row.original.firstName}
|
||||
@@ -199,27 +173,27 @@ export default function CardOrdersPage() {
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'status',
|
||||
header: t('cardOrder.col.status', 'Status'),
|
||||
accessorKey: "status",
|
||||
header: t("cardOrder.col.status", "Status"),
|
||||
cell: ({ row }) => <OrderNewCardStatusBadge status={row.original.status} />,
|
||||
size: 130,
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
id: "actions",
|
||||
header: "",
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-1.5 justify-end">
|
||||
<button
|
||||
className="p-1.5 cursor-pointer rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.view', 'Görkez')}
|
||||
title={t("common.view", "Görkez")}
|
||||
onClick={() => navigate(`/order-new-card/${row.original.id}`)}
|
||||
>
|
||||
<Eye size={15} />
|
||||
</button>
|
||||
<button
|
||||
className="p-1.5 cursor-pointer rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.edit', 'Düzet')}
|
||||
title={t("common.edit", "Düzet")}
|
||||
onClick={() => navigate(`/order-new-card/${row.original.id}/edit`)}
|
||||
>
|
||||
<Pencil size={15} />
|
||||
@@ -228,7 +202,7 @@ export default function CardOrdersPage() {
|
||||
onClick={() => handleDelete(row.original.id)}
|
||||
disabled={deleteMutation.isPending}
|
||||
className="p-1.5 cursor-pointer rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50"
|
||||
title={t('common.delete', 'Poz')}
|
||||
title={t("common.delete", "Poz")}
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
</button>
|
||||
@@ -237,49 +211,62 @@ export default function CardOrdersPage() {
|
||||
size: 100,
|
||||
},
|
||||
],
|
||||
[t, navigate, handleDelete, deleteMutation.isPending]
|
||||
)
|
||||
[t, navigate, handleDelete, deleteMutation.isPending],
|
||||
);
|
||||
|
||||
// ── Filter fields ──────────────────────────────────────────────────────────
|
||||
const filterFields = useMemo<FilterField[]>(
|
||||
() => [
|
||||
{
|
||||
id: 'status',
|
||||
label: t('cardOrder.col.status', 'Status'),
|
||||
id: "status",
|
||||
label: t("cardOrder.col.status", "Status"),
|
||||
options: [
|
||||
{ value: 'PENDING', label: t('cardOrder.status.pending', 'Garaşylýar') },
|
||||
{ value: 'APPROVED', label: t('cardOrder.status.approved', 'Tassyklandy') },
|
||||
{ value: 'REJECTED', label: t('cardOrder.status.rejected', 'Ýatyryldy') },
|
||||
{ value: "PENDING", label: t("cardOrder.status.pending", "Garaşylýar") },
|
||||
{ value: "APPROVED", label: t("cardOrder.status.approved", "Tassyklandy") },
|
||||
{ value: "REJECTED", label: t("cardOrder.status.rejected", "Ýatyryldy") },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'provinceId',
|
||||
label: t('cardOrder.col.province', 'Welaýat'),
|
||||
id: "provinceId",
|
||||
label: t("cardOrder.col.province", "Welaýat"),
|
||||
options: provincesData?.map((p) => ({ value: String(p.id), label: p.name })) ?? [],
|
||||
},
|
||||
{
|
||||
id: 'branchId',
|
||||
label: t('cardOrder.col.branch', 'Şahamça'),
|
||||
id: "branchId",
|
||||
label: t("cardOrder.col.branch", "Şahamça"),
|
||||
options: branchesData?.map((b) => ({ value: String(b.id), label: b.name })) ?? [],
|
||||
},
|
||||
],
|
||||
[t, provincesData, branchesData]
|
||||
)
|
||||
[t, provincesData, branchesData],
|
||||
);
|
||||
|
||||
// ── Render ─────────────────────────────────────────────────────────────────
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold text-foreground tracking-tight">
|
||||
{t('cardOrder.title', 'Kart sargytlary')}
|
||||
</h1>
|
||||
<h1 className="text-xl font-semibold text-foreground tracking-tight">{t("cardOrder.title", "Kart sargytlary")}</h1>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
onChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
<CreateButton label={t("cardOrder.create", "Kart sargyt dörediň")} onClick={() => navigate("/order-new-card/create")} />
|
||||
</div>
|
||||
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { setSearch(v); setPage(1) }}
|
||||
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||
onSearchChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||
columns={COLUMN_META}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
@@ -291,9 +278,12 @@ export default function CardOrdersPage() {
|
||||
onFilterReset={handleFilterReset}
|
||||
perPageOptions={[10, 25, 50, 100]}
|
||||
perPage={perPage}
|
||||
onPerPageChange={(v) => { setPerPage(v); setPage(1) }}
|
||||
actionLabel={t('cardOrder.create', 'Kart sargyt dörediň')}
|
||||
onAction={() => navigate('/order-new-card/create')}
|
||||
onPerPageChange={(v) => {
|
||||
setPerPage(v);
|
||||
setPage(1);
|
||||
}}
|
||||
hideSearch
|
||||
hideAction
|
||||
/>
|
||||
|
||||
<DataTable
|
||||
@@ -313,14 +303,15 @@ export default function CardOrdersPage() {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<ConfirmDialog
|
||||
<DeleteDialog
|
||||
open={deleteId !== null}
|
||||
onOpenChange={(o) => { if (!o) setDeleteId(null) }}
|
||||
title={t('cardOrder.deleteConfirm', 'Bu sargyt pozulsynmy?')}
|
||||
confirmLabel={t('common.delete', 'Poz')}
|
||||
onOpenChange={(o) => {
|
||||
if (!o) setDeleteId(null);
|
||||
}}
|
||||
title={t("cardOrder.deleteConfirm", "Bu sargyt pozulsynmy?")}
|
||||
onConfirm={confirmDelete}
|
||||
isLoading={deleteMutation.isPending}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user