started connect with api
This commit is contained in:
1 parent
0ca218505d
commit
6da59f42d9
112 files changed
+7091
-6989
No files matched your search
@@ -1,7 +1,6 @@
|
||||
import { useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Download } from "lucide-react";
|
||||
import { DeleteDialog } from "@/components/deleteDialog";
|
||||
import { DataTable, type ColumnDef } from "@/components/dataTable";
|
||||
import { DataTableToolbar, type ColumnMeta } from "@/components/dataTableToolbar";
|
||||
@@ -9,12 +8,8 @@ import { TableSearchInput } from "@/components/tableSearch";
|
||||
import { CreateButton } from "@/components/createButton";
|
||||
import { TableActions } from "@/components/tableActions";
|
||||
import type { VisibilityState } from "@tanstack/react-table";
|
||||
import {
|
||||
useCardTransactions,
|
||||
useDeleteCardTransaction,
|
||||
useDownloadCardTransaction,
|
||||
} from "@/features/cardTransactions/hooks/useCardTransactions";
|
||||
import type { CardTransaction } from "@/features/cardTransactions/api/cardTransactionsApi";
|
||||
import { useCardTransactions, useDeleteCardTransaction } from "@/features/cardTransactions/hooks/useCardTransactions";
|
||||
import type { Card } from "@/features/cardTransactions/api/cardTransactionsApi";
|
||||
|
||||
// ─── Page ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -31,17 +26,16 @@ export default function CardTransactionsPage() {
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([]);
|
||||
|
||||
const { data, isLoading } = useCardTransactions({ page, per_page: perPage, search });
|
||||
const { data, isLoading } = useCardTransactions({ page, limit: perPage, search });
|
||||
const deleteMutation = useDeleteCardTransaction();
|
||||
const downloadMutation = useDownloadCardTransaction();
|
||||
|
||||
// ── Columns ──────────────────────────────────────────────────────────────────
|
||||
|
||||
const columns: ColumnDef<CardTransaction>[] = [
|
||||
const columns: ColumnDef<Card>[] = [
|
||||
{
|
||||
id: "id",
|
||||
accessorKey: "id",
|
||||
header: t("ID", "ID"),
|
||||
header: t("cardTransaction.col.id", "ID"),
|
||||
cell: ({ row }) => (
|
||||
<button
|
||||
className="text-primary font-medium hover:underline text-left"
|
||||
@@ -50,36 +44,54 @@ export default function CardTransactionsPage() {
|
||||
{row.original.id}
|
||||
</button>
|
||||
),
|
||||
size: 80,
|
||||
},
|
||||
{
|
||||
id: "passport_series",
|
||||
accessorKey: "passport_series",
|
||||
header: t("Passport series", "PASPORT SERIYASY"),
|
||||
cell: ({ row }) => <span>{row.original.passport_series}</span>,
|
||||
id: "name",
|
||||
accessorKey: "name",
|
||||
header: t("cardTransaction.col.name", "Ady"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.name}</span>,
|
||||
},
|
||||
{
|
||||
id: "passport_number",
|
||||
accessorKey: "passport_number",
|
||||
header: t("Passport number", "PASPORT BELGISI"),
|
||||
cell: ({ row }) => <span>{row.original.passport_number}</span>,
|
||||
id: "number",
|
||||
accessorKey: "number",
|
||||
header: t("cardTransaction.col.number", "Kart belgisi"),
|
||||
cell: ({ row }) => <span className="font-mono text-sm">{row.original.number}</span>,
|
||||
},
|
||||
{
|
||||
id: "card_number",
|
||||
accessorKey: "card_number",
|
||||
header: t("Card number", "KART BELGISI"),
|
||||
cell: ({ row }) => <span className="font-mono">{row.original.card_number}</span>,
|
||||
id: "type",
|
||||
accessorKey: "type",
|
||||
header: t("cardTransaction.col.type", "Görnüşi"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.type}</span>,
|
||||
},
|
||||
{
|
||||
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: "expiry",
|
||||
accessorKey: "year",
|
||||
header: t("cardTransaction.col.expiry", "Möhleti"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-muted-foreground whitespace-nowrap">
|
||||
{row.original.month}/{row.original.year}
|
||||
</span>
|
||||
),
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
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: "userId",
|
||||
accessorKey: "userId",
|
||||
header: t("cardTransaction.col.userId", "Ulanyjy ID"),
|
||||
cell: ({ row }) => <span className="text-sm text-muted-foreground">{row.original.userId}</span>,
|
||||
size: 110,
|
||||
},
|
||||
{
|
||||
id: "createdAt",
|
||||
accessorKey: "createdAt",
|
||||
header: t("cardTransaction.col.createdAt", "Döredilen wagty"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-muted-foreground whitespace-nowrap">
|
||||
{row.original.createdAt ? new Date(row.original.createdAt).toLocaleString() : "—"}
|
||||
</span>
|
||||
),
|
||||
size: 180,
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
@@ -87,13 +99,13 @@ export default function CardTransactionsPage() {
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<TableActions
|
||||
extraActions={[{ icon: Download, title: t("Download", "Ýükle"), onClick: () => downloadMutation.mutate(row.original.id) }]}
|
||||
onView={() => navigate(`/card-transactions/${row.original.id}`)}
|
||||
onEdit={() => navigate(`/card-transactions/${row.original.id}/edit`)}
|
||||
onDelete={() => setDeleteId(row.original.id)}
|
||||
isDeleting={deleteMutation.isPending}
|
||||
/>
|
||||
),
|
||||
size: 100,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -108,7 +120,7 @@ export default function CardTransactionsPage() {
|
||||
|
||||
// ── Pagination ────────────────────────────────────────────────────────────────
|
||||
|
||||
const total = data?.total ?? 0;
|
||||
const total = data?.count ?? 0;
|
||||
const totalPages = Math.ceil(total / perPage);
|
||||
|
||||
const handleDelete = async () => {
|
||||
@@ -121,7 +133,7 @@ export default function CardTransactionsPage() {
|
||||
<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", "Kartlar")}</h1>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-3 justify-between">
|
||||
@@ -133,7 +145,7 @@ export default function CardTransactionsPage() {
|
||||
}}
|
||||
placeholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
<CreateButton label={t("Create card transaction", "Kart herekedi dörediň")} onClick={() => navigate("/card-transactions/create")} />
|
||||
<CreateButton label={t("Create card", "Kart dörediň")} onClick={() => navigate("/card-transactions/create")} />
|
||||
</div>
|
||||
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
@@ -163,7 +175,7 @@ export default function CardTransactionsPage() {
|
||||
{/* Table */}
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
data={data?.cards ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
@@ -186,8 +198,8 @@ export default function CardTransactionsPage() {
|
||||
}}
|
||||
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.",
|
||||
"This action cannot be undone. This will permanently delete the card.",
|
||||
"Bu amal yzyna gaýtarylmaz. Kart hemişelik öçüriler.",
|
||||
)}
|
||||
onConfirm={handleDelete}
|
||||
isLoading={deleteMutation.isPending}
|
||||
|
||||
Reference in new issue
Block a user