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,117 +1,195 @@
|
||||
import { useState } from "react";
|
||||
import { useState, useCallback, useMemo } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { ColumnDef, VisibilityState } from "@tanstack/react-table";
|
||||
import { DataTable } from "@/components/dataTable";
|
||||
import { DataTableToolbar } from "@/components/dataTableToolbar";
|
||||
import { DataTableToolbar, type ColumnMeta, type ActiveFilter, type FilterField } from "@/components/dataTableToolbar";
|
||||
import { TableSearchInput } from "@/components/tableSearch";
|
||||
import { CreateButton } from "@/components/createButton";
|
||||
import { TableActions } from "@/components/tableActions";
|
||||
import { DeleteDialog } from "@/components/deleteDialog";
|
||||
import { AlertCircle, CheckCircle2, XCircle } from "lucide-react";
|
||||
|
||||
import { useCardPins, useDeleteCardPin } from "@/features/cardPins/hooks/useCardPins";
|
||||
import { type CardPinStatus, type CardPinItem } from "@/features/cardPins/api/cardPinApi";
|
||||
|
||||
// ─── Status Badge ─────────────────────────────────────────────────────────────
|
||||
|
||||
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
|
||||
import { AlertCircle, CheckCircle2, XCircle } from "lucide-react";
|
||||
import type { CardPinOrder } from "@/features/cardPins/api/cardPinApi";
|
||||
import { useBranches } from "@/features/branches/hooks/useBranches";
|
||||
import { useDistricts } from "@/features/districts/hooks/useDistricts";
|
||||
import { useCardTypes } from "@/features/cardTypes/hooks/useCardTypes";
|
||||
|
||||
// ─── Filter field IDs ──────────────────────────────────────────────────────────
|
||||
|
||||
const FILTER_IDS = ["status", "branch_id", "user_id", "card_type_id", "region"] as const;
|
||||
type FilterId = (typeof FILTER_IDS)[number];
|
||||
|
||||
const INITIAL_FILTERS: ActiveFilter[] = FILTER_IDS.map((fieldId) => ({ fieldId, value: "" }));
|
||||
|
||||
// ─── Status badge ─────────────────────────────────────────────────────────────
|
||||
|
||||
const STATUS_CONFIG = {
|
||||
pending: {
|
||||
label: "Garaşylýar",
|
||||
variant: "warning" as StatusBadgeVariant,
|
||||
icon: AlertCircle,
|
||||
},
|
||||
approved: {
|
||||
label: "Tassyklandy",
|
||||
variant: "success" as StatusBadgeVariant,
|
||||
icon: CheckCircle2,
|
||||
},
|
||||
rejected: {
|
||||
label: "Ýatyryldy",
|
||||
variant: "error" as StatusBadgeVariant,
|
||||
icon: XCircle,
|
||||
},
|
||||
} satisfies Record<CardPinStatus, { label: string; variant: StatusBadgeVariant; icon: React.ElementType }>;
|
||||
const PENDING_STATUSES = [
|
||||
"pending",
|
||||
"garaşylýar",
|
||||
"garaşilyar",
|
||||
"garasylýar",
|
||||
"garasilyar",
|
||||
"garasylyar",
|
||||
"kutilyor",
|
||||
"kutiliyor",
|
||||
"waiting",
|
||||
"beklemede",
|
||||
];
|
||||
const APPROVED_STATUSES = [
|
||||
"approved",
|
||||
"tassyklandy",
|
||||
"tassyklanan",
|
||||
"tassyklandy",
|
||||
"tassyklanyldy",
|
||||
"accepted",
|
||||
"confirmed",
|
||||
"success",
|
||||
"completed",
|
||||
"approve",
|
||||
];
|
||||
const REJECTED_STATUSES = [
|
||||
"rejected",
|
||||
"reject",
|
||||
"ret",
|
||||
"ýatyryldy",
|
||||
"yatyryldy",
|
||||
"canceled",
|
||||
"cancelled",
|
||||
"cancelled",
|
||||
"declined",
|
||||
"failed",
|
||||
"error",
|
||||
"reject",
|
||||
"red edildi",
|
||||
];
|
||||
|
||||
function CardPinStatusStatusBadge({ status }: { status: CardPinStatus }) {
|
||||
const cfg = STATUS_CONFIG[status];
|
||||
if (!cfg) return <span className="text-xs text-muted-foreground">{String(status)}</span>;
|
||||
function statusConfig(status: string): { label: string; variant: StatusBadgeVariant; icon?: React.ElementType } {
|
||||
const key = status.trim().toLowerCase();
|
||||
if (PENDING_STATUSES.includes(key)) return { label: "Garaşylýar", variant: "warning", icon: AlertCircle };
|
||||
if (APPROVED_STATUSES.includes(key)) return { label: "Tassyklandy", variant: "success", icon: CheckCircle2 };
|
||||
if (REJECTED_STATUSES.includes(key)) return { label: "Ýatyryldy", variant: "error", icon: XCircle };
|
||||
return { label: status, variant: "default" };
|
||||
}
|
||||
|
||||
function StatusCell({ status }: { status: string }) {
|
||||
const cfg = statusConfig(status);
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />;
|
||||
}
|
||||
|
||||
// ─── Page ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
const PER_PAGE = 25;
|
||||
|
||||
export default function CardPinsPage() {
|
||||
const { t } = useTranslation();
|
||||
const { t, i18n } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const lang = (i18n.language === "ru" ? "ru" : i18n.language === "en" ? "en" : "tm") as "tm" | "ru" | "en";
|
||||
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(25);
|
||||
const [perPage, setPerPage] = useState(PER_PAGE);
|
||||
const [search, setSearch] = useState("");
|
||||
const [statusFilter, setStatusFilter] = useState<CardPinStatus | "">("");
|
||||
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([]);
|
||||
|
||||
const [deleteTarget, setDeleteTarget] = useState<CardPinItem | null>(null);
|
||||
const [deleteTarget, setDeleteTarget] = useState<CardPinOrder | null>(null);
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>(INITIAL_FILTERS);
|
||||
|
||||
const { data, isLoading } = useCardPins({
|
||||
page,
|
||||
per_page: perPage,
|
||||
search,
|
||||
status: statusFilter,
|
||||
});
|
||||
// ── Dropdown data ──────────────────────────────────────────────────────────
|
||||
const { data: branchesData } = useBranches({ page, limit: 25 });
|
||||
const { data: districtsData } = useDistricts({ page, limit: 25 });
|
||||
const { data: cardTypesData } = useCardTypes({ page, limit: 25 });
|
||||
|
||||
// ── Query ──────────────────────────────────────────────────────────────────
|
||||
const getFilter = useCallback((id: FilterId) => activeFilters.find((f) => f.fieldId === id)?.value ?? "", [activeFilters]);
|
||||
|
||||
const queryParams = useMemo(
|
||||
() => ({
|
||||
search: search || undefined,
|
||||
page,
|
||||
limit: perPage,
|
||||
status: getFilter("status") || undefined,
|
||||
branch_id: getFilter("branch_id") || undefined,
|
||||
user_id: getFilter("user_id") || undefined,
|
||||
card_type_id: getFilter("card_type_id") || undefined,
|
||||
region: getFilter("region") || undefined,
|
||||
}),
|
||||
[search, page, perPage, getFilter],
|
||||
);
|
||||
|
||||
const { data, isLoading } = useCardPins(queryParams);
|
||||
const { mutate: deletePin, isPending: isDeleting } = useDeleteCardPin();
|
||||
|
||||
const columns: ColumnDef<CardPinItem>[] = [
|
||||
const columns: ColumnDef<CardPinOrder>[] = [
|
||||
{
|
||||
id: "id",
|
||||
accessorKey: "id",
|
||||
header: "ID",
|
||||
cell: ({ row }) => <span className="font-mono text-xs text-muted-foreground">{row.original.id}</span>,
|
||||
header: t("cardPin.col.id", "ID"),
|
||||
cell: ({ row }) => (
|
||||
<button className="text-primary font-medium hover:underline text-left" onClick={() => navigate(`/card-pins/${row.original.id}`)}>
|
||||
{row.original.id}
|
||||
</button>
|
||||
),
|
||||
size: 80,
|
||||
},
|
||||
{
|
||||
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>,
|
||||
id: "uniqueId",
|
||||
accessorKey: "uniqueId",
|
||||
header: t("cardPin.col.uniqueId", "Sargyt belgisi"),
|
||||
cell: ({ row }) => <span className="font-mono text-sm">{row.original.uniqueId}</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>,
|
||||
id: "cardNumber",
|
||||
accessorKey: "cardNumber",
|
||||
header: t("cardPin.col.cardNumber", "Kart belgisi"),
|
||||
cell: ({ row }) => <span className="font-mono text-sm">{row.original.cardNumber}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "province_label",
|
||||
header: t("cardPin.province", "Welaýat"),
|
||||
id: "customerName",
|
||||
accessorKey: "customerName",
|
||||
header: t("cardPin.col.customer", "Müşderi"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">
|
||||
{row.original.customerName} {row.original.customerSurname}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: "branch_label",
|
||||
header: t("cardPin.branch", "Şahamça"),
|
||||
cell: ({ row }) => <span className="text-primary font-medium">{row.original.branch_label}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "first_name",
|
||||
header: t("cardPin.firstName", "Ady"),
|
||||
},
|
||||
{
|
||||
accessorKey: "last_name",
|
||||
header: t("cardPin.lastName", "Familiýasy"),
|
||||
id: "region",
|
||||
accessorKey: "region",
|
||||
header: t("cardPin.col.region", "Sebit"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.region}</span>,
|
||||
},
|
||||
{
|
||||
id: "phone",
|
||||
accessorKey: "phone",
|
||||
header: t("cardPin.phone", "Telefon"),
|
||||
header: t("cardPin.col.phone", "Telefon"),
|
||||
cell: ({ row }) => <span className="font-mono text-sm">{row.original.phone}</span>,
|
||||
},
|
||||
{
|
||||
id: "status",
|
||||
accessorKey: "status",
|
||||
header: t("cardPin.status", "Status"),
|
||||
cell: ({ row }) => <CardPinStatusStatusBadge status={row.original.status} />,
|
||||
header: t("cardPin.col.status", "Statusy"),
|
||||
cell: ({ row }) => <StatusCell status={row.original.status} />,
|
||||
},
|
||||
{
|
||||
id: "createdAt",
|
||||
accessorKey: "createdAt",
|
||||
header: t("cardPin.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",
|
||||
header: "",
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<TableActions
|
||||
@@ -121,16 +199,74 @@ export default function CardPinsPage() {
|
||||
isDeleting={isDeleting}
|
||||
/>
|
||||
),
|
||||
size: 100,
|
||||
},
|
||||
];
|
||||
|
||||
const columnMeta = columns
|
||||
.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;
|
||||
return { id, label };
|
||||
});
|
||||
const columnMeta: ColumnMeta[] = columns
|
||||
.filter((c) => c.id !== "actions")
|
||||
.map((c) => ({
|
||||
id: c.id!,
|
||||
label: typeof c.header === "string" ? c.header : c.id!,
|
||||
}));
|
||||
|
||||
const total = data?.count ?? 0;
|
||||
const totalPages = Math.ceil(total / perPage);
|
||||
|
||||
// ── Filter fields ──────────────────────────────────────────────────────────
|
||||
const filterFields = useMemo<FilterField[]>(
|
||||
() => [
|
||||
{
|
||||
id: "status",
|
||||
label: t("cardPin.filter.status", "Status"),
|
||||
options: [
|
||||
{ value: "pending", label: t("cardPin.status.pending", "Garaşylýar") },
|
||||
{ value: "approved", label: t("cardPin.status.approved", "Tassyklandy") },
|
||||
{ value: "rejected", label: t("cardPin.status.rejected", "Ýatyryldy") },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "branch_id",
|
||||
label: t("cardPin.filter.branch", "Şahamça"),
|
||||
options: (branchesData?.branches ?? []).map((b) => ({
|
||||
value: String(b.id),
|
||||
label: b.name[lang] || b.name.tm,
|
||||
})),
|
||||
},
|
||||
{
|
||||
id: "region",
|
||||
label: t("cardPin.filter.region", "Sebit"),
|
||||
options: (districtsData?.provinces ?? []).map((d) => ({
|
||||
value: d.region?.tm || d.name.tm,
|
||||
label: d.name[lang] || d.name.tm,
|
||||
})),
|
||||
},
|
||||
{
|
||||
id: "user_id",
|
||||
label: t("cardPin.filter.userId", "Ulanyjy ID"),
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
id: "card_type_id",
|
||||
label: t("cardPin.filter.cardTypeId", "Kart görnüşi"),
|
||||
options: (cardTypesData?.paymentCards ?? []).map((ct) => ({
|
||||
value: String(ct.id),
|
||||
label: ct.title[lang] || ct.title.tm,
|
||||
})),
|
||||
},
|
||||
],
|
||||
[t, lang, branchesData, districtsData, cardTypesData],
|
||||
);
|
||||
|
||||
const handleFilterChange = useCallback((fieldId: string, value: string) => {
|
||||
setActiveFilters((prev) => prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f)));
|
||||
setPage(1);
|
||||
}, []);
|
||||
|
||||
const handleFilterReset = useCallback(() => {
|
||||
setActiveFilters(INITIAL_FILTERS);
|
||||
setPage(1);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
@@ -161,47 +297,32 @@ export default function CardPinsPage() {
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
filterFields={[
|
||||
{
|
||||
id: "status",
|
||||
label: t("cardPin.status", "Status"),
|
||||
options: [
|
||||
{ value: "pending", label: "Garaşylýar" },
|
||||
{ value: "approved", label: "Tassyklandy" },
|
||||
{ value: "rejected", label: "Ret edildi" },
|
||||
],
|
||||
},
|
||||
]}
|
||||
activeFilters={[{ fieldId: "status", value: statusFilter }]}
|
||||
onFilterChange={(fieldId, value) => {
|
||||
if (fieldId === "status") setStatusFilter(value as CardPinStatus | "");
|
||||
setPage(1);
|
||||
}}
|
||||
onFilterReset={() => {
|
||||
setStatusFilter("");
|
||||
setPage(1);
|
||||
}}
|
||||
hideSearch
|
||||
hideAction
|
||||
perPage={perPage}
|
||||
onPerPageChange={(v) => {
|
||||
setPerPage(v);
|
||||
setPage(1);
|
||||
}}
|
||||
hideSearch
|
||||
hideAction
|
||||
filterFields={filterFields}
|
||||
activeFilters={activeFilters}
|
||||
onFilterChange={handleFilterChange}
|
||||
onFilterReset={handleFilterReset}
|
||||
/>
|
||||
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
data={data?.cardPinOrders ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
enableRowSelection
|
||||
currentPage={data?.meta?.current_page ?? 1}
|
||||
totalPages={data?.meta?.last_page ?? 1}
|
||||
totalCount={data?.meta?.total}
|
||||
getRowId={(row) => row.id.toString()}
|
||||
currentPage={page}
|
||||
totalPages={totalPages}
|
||||
totalCount={total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
@@ -213,7 +334,7 @@ export default function CardPinsPage() {
|
||||
if (!o) setDeleteTarget(null);
|
||||
}}
|
||||
title={t("cardPin.deleteTitle", "Pozmak isleýärsiňizmi?")}
|
||||
description={`${t("cardPin.deleteDesc", "Bu amal yzyna dolanyp bolmaz.")} ${deleteTarget?.id ?? ""}`}
|
||||
description={t("cardPin.deleteDesc", "Bu amal yzyna dolanyp bolmaz.")}
|
||||
onConfirm={() => {
|
||||
if (deleteTarget) {
|
||||
deletePin(deleteTarget.id, {
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { PageSpinner } from '@/components/pageSpinner'
|
||||
import { PageError } from '@/components/pageError'
|
||||
import { CardPinForm } from '@/features/cardPins/components/cardPinForm'
|
||||
import { useCardPin } from '@/features/cardPins/hooks/useCardPins'
|
||||
import { useParams } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { PageSpinner } from "@/components/pageSpinner";
|
||||
import { PageError } from "@/components/pageError";
|
||||
import { CardPinForm } from "@/features/cardPins/components/cardPinForm";
|
||||
import { useCardPin } from "@/features/cardPins/hooks/useCardPins";
|
||||
|
||||
export default function CardPinEditPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const { t } = useTranslation()
|
||||
const { data, isLoading, isError } = useCardPin(id ?? '')
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const { t } = useTranslation();
|
||||
const numericId = Number(id);
|
||||
const { data, isLoading, isError } = useCardPin(numericId);
|
||||
|
||||
if (isLoading) return <PageSpinner />
|
||||
if (isError || !data) return <PageError message={t('common.notFound', 'Maglumat tapylmady')} />
|
||||
if (isLoading) return <PageSpinner />;
|
||||
if (isError || !data) return <PageError message={t("common.notFound", "Maglumat tapylmady")} />;
|
||||
|
||||
return <CardPinForm mode="edit" initialData={data} />
|
||||
return <CardPinForm mode="edit" initialData={data} />;
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
import { useState } from "react";
|
||||
import { useParams, useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useCardPin, useDeleteCardPin } from "@/features/cardPins/hooks/useCardPins";
|
||||
import type { CardPinStatus } from "@/features/cardPins/api/cardPinApi";
|
||||
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
|
||||
import { AlertCircle, CheckCircle2, XCircle } from "lucide-react";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Pencil, Trash2 } from "lucide-react";
|
||||
@@ -14,31 +16,63 @@ import {
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
AlertDialogTrigger,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
|
||||
import { AlertCircle, CheckCircle2, XCircle } from "lucide-react";
|
||||
import { BentoGrid, BentoCard, InfoRow, PassportImage } from "@/components/viewPageComponents";
|
||||
import { BentoGrid, BentoCard, InfoRow } from "@/components/viewPageComponents";
|
||||
|
||||
// ─── Status config ────────────────────────────────────────────────────────────
|
||||
// ─── Status badge ─────────────────────────────────────────────────────────────
|
||||
|
||||
const STATUS_VARIANT: Record<CardPinStatus, StatusBadgeVariant> = {
|
||||
pending: "warning",
|
||||
approved: "success",
|
||||
rejected: "error",
|
||||
};
|
||||
const PENDING_STATUSES = [
|
||||
"pending",
|
||||
"garaşylýar",
|
||||
"garaşilyar",
|
||||
"garasylýar",
|
||||
"garasilyar",
|
||||
"garasylyar",
|
||||
"kutilyor",
|
||||
"kutiliyor",
|
||||
"waiting",
|
||||
"beklemede",
|
||||
];
|
||||
const APPROVED_STATUSES = [
|
||||
"approved",
|
||||
"tassyklandy",
|
||||
"tassyklanan",
|
||||
"tassyklandy",
|
||||
"tassyklanyldy",
|
||||
"accepted",
|
||||
"confirmed",
|
||||
"success",
|
||||
"completed",
|
||||
"approve",
|
||||
];
|
||||
const REJECTED_STATUSES = [
|
||||
"rejected",
|
||||
"reject",
|
||||
"ret",
|
||||
"ýatyryldy",
|
||||
"yatyryldy",
|
||||
"canceled",
|
||||
"cancelled",
|
||||
"cancelled",
|
||||
"declined",
|
||||
"failed",
|
||||
"error",
|
||||
"reject",
|
||||
"red edildi",
|
||||
];
|
||||
|
||||
const STATUS_ICON: Record<CardPinStatus, React.ElementType> = {
|
||||
pending: AlertCircle,
|
||||
approved: CheckCircle2,
|
||||
rejected: XCircle,
|
||||
};
|
||||
function statusConfig(status: string): { label: string; variant: StatusBadgeVariant; icon?: React.ElementType } {
|
||||
const key = status.trim().toLowerCase();
|
||||
if (PENDING_STATUSES.includes(key)) return { label: "Garaşylýar", variant: "warning", icon: AlertCircle };
|
||||
if (APPROVED_STATUSES.includes(key)) return { label: "Tassyklandy", variant: "success", icon: CheckCircle2 };
|
||||
if (REJECTED_STATUSES.includes(key)) return { label: "Ýatyryldy", variant: "error", icon: XCircle };
|
||||
return { label: status, variant: "default" };
|
||||
}
|
||||
|
||||
function CardPinStatusBadge({ status }: { status: CardPinStatus }) {
|
||||
const { t } = useTranslation();
|
||||
const variant = STATUS_VARIANT[status];
|
||||
const Icon = STATUS_ICON[status];
|
||||
if (!variant) return <span className="text-xs text-muted-foreground">{status}</span>;
|
||||
return <StatusBadge label={t(`cardPin.status.${status}`)} variant={variant} icon={Icon} />;
|
||||
function CardPinStatusBadge({ status }: { status: string }) {
|
||||
const cfg = statusConfig(status);
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />;
|
||||
}
|
||||
|
||||
// ─── Skeleton ─────────────────────────────────────────────────────────────────
|
||||
@@ -68,37 +102,43 @@ export default function CardPinViewPage() {
|
||||
const navigate = useNavigate();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { data, isLoading, isError } = useCardPin(id!);
|
||||
const [deleteOpen, setDeleteOpen] = useState(false);
|
||||
|
||||
const numericId = Number(id);
|
||||
const { data, isLoading, isError } = useCardPin(numericId);
|
||||
const { mutate: deletePin, isPending: isDeleting } = useDeleteCardPin();
|
||||
|
||||
if (isLoading) {
|
||||
return <CardPinViewSkeleton />;
|
||||
}
|
||||
if (isLoading) return <CardPinViewSkeleton />;
|
||||
|
||||
if (isError || !data) {
|
||||
return <div className="flex items-center justify-center py-24 text-muted-foreground">{t("common.notFound", "Maglumat tapylmady")}</div>;
|
||||
}
|
||||
|
||||
const fmtDate = (v?: string | null) => (v ? new Date(v).toLocaleDateString() : "—");
|
||||
|
||||
return (
|
||||
<div className="mx-auto flex flex-col gap-6">
|
||||
{/* ── Page header ──────────────────────────────────────────────────── */}
|
||||
<div className="flex items-start justify-between">
|
||||
<h1 className="text-xl font-bold text-foreground">
|
||||
{t("cardPin.viewTitle", "Kart pin bukja giňişleýin")}: {data.id}
|
||||
{t("cardPin.viewTitle", "Kart pin bukja giňişleýin")}: <span className="text-primary font-mono">{data.uniqueId}</span>
|
||||
</h1>
|
||||
<div className="flex items-center gap-2">
|
||||
<AlertDialog>
|
||||
<AlertDialogTitle asChild>
|
||||
<Button size="icon" variant="ghost" className="h-8 w-8 text-destructive hover:text-destructive hover:bg-destructive/10">
|
||||
<AlertDialog open={deleteOpen} onOpenChange={setDeleteOpen}>
|
||||
<AlertDialogTrigger asChild>
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-8 w-8 text-destructive hover:text-destructive hover:bg-destructive/10"
|
||||
title={t("common.delete", "Poz")}
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
</Button>
|
||||
</AlertDialogTitle>
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t("cardPin.deleteTitle", "Pozmak isleýärsiňizmi?")}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t("cardPin.deleteDesc", "Bu amal yzyna dolanyp bolmaz.")} {data.id}
|
||||
</AlertDialogDescription>
|
||||
<AlertDialogDescription>{t("cardPin.deleteDesc", "Bu amal yzyna dolanyp bolmaz.")}</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={isDeleting}>{t("common.cancel", "Ýatyr")}</AlertDialogCancel>
|
||||
@@ -107,13 +147,19 @@ export default function CardPinViewPage() {
|
||||
className="bg-destructive hover:bg-destructive/90"
|
||||
onClick={() => deletePin(data.id, { onSuccess: () => navigate("/card-pins") })}
|
||||
>
|
||||
{t("common.delete", "Poz")}
|
||||
{isDeleting ? t("common.deleting", "Pozulýar...") : t("common.delete", "Poz")}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
|
||||
<Button size="icon" variant="ghost" className="h-8 w-8" onClick={() => navigate(`/card-pins/${id}/edit`)}>
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-8 w-8"
|
||||
onClick={() => navigate(`/card-pins/${numericId}/edit`)}
|
||||
title={t("common.edit", "Düzet")}
|
||||
>
|
||||
<Pencil size={15} />
|
||||
</Button>
|
||||
</div>
|
||||
@@ -123,53 +169,47 @@ export default function CardPinViewPage() {
|
||||
<BentoGrid cols={3}>
|
||||
<BentoCard title={t("cardPin.metaSection", "Esasy maglumatlar")}>
|
||||
<InfoRow label={t("common.id", "ID")} value={data.id} />
|
||||
<InfoRow label={t("cardPin.createdAt", "Döredilen wagty")} value={data.created_at} />
|
||||
<InfoRow label={t("cardPin.status", "Status")}>
|
||||
<InfoRow label={t("cardPin.field.uniqueId", "Sargyt belgisi")} value={data.uniqueId} />
|
||||
<InfoRow label={t("cardPin.field.status", "Status")}>
|
||||
<CardPinStatusBadge status={data.status} />
|
||||
</InfoRow>
|
||||
<InfoRow label={t("cardPin.note", "Bellik")} value={data.note || undefined} />
|
||||
<InfoRow label={t("cardPin.createdBy", "Sargyt eden")} value={data.created_by_label} isLink />
|
||||
<InfoRow label={t("cardPin.field.notes", "Bellik")} value={data.notes || undefined} />
|
||||
<InfoRow
|
||||
label={t("cardPin.col.createdAt", "Döredilen wagty")}
|
||||
value={data.createdAt ? new Date(data.createdAt).toLocaleString() : "—"}
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title={t("cardPin.cardSection", "Kart")}>
|
||||
<InfoRow label={t("cardPin.cardNumber", "Kart belgisi")} value={data.card_number} />
|
||||
<InfoRow label={t("cardPin.cardExpireMonth", "Kart Möhleti (aý)")} value={null} />
|
||||
<InfoRow label={t("cardPin.cardExpireYear", "Kart Möhleti (ýyl)")} value={null} />
|
||||
<InfoRow label={t("cardPin.field.cardNumber", "Kart belgisi")} value={data.cardNumber} />
|
||||
<InfoRow label={t("cardPin.field.cardTypeId", "Kart görnüşi ID")} value={data.cardTypeId} />
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title={t("cardPin.locationSection", "Lokasiýa")}>
|
||||
<InfoRow label={t("cardPin.province", "Welaýat")} value={data.province_label} />
|
||||
<InfoRow label={t("cardPin.branch", "Şahamça")} value={data.branch_label} isLink />
|
||||
<InfoRow label={t("cardPin.field.region", "Sebit")} value={data.region || undefined} />
|
||||
<InfoRow label={t("cardPin.field.branchId", "Şahamça ID")} value={data.branchId} />
|
||||
<InfoRow label={t("cardPin.field.userId", "Ulanyjy ID")} value={data.userId} />
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
{/* ── Row 2: Şahsy + Pasport maglumatlary ─────────────────────────── */}
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title={t("cardPin.personalSection", "Şahsy maglumatlar")}>
|
||||
<InfoRow label={t("cardPin.fullName", "Doly ady")} value={`${data.last_name} ${data.first_name} ${data.father_name}`} />
|
||||
<InfoRow label={t("cardPin.birthDate", "Doglan güni")} value={data.birth_date} />
|
||||
<InfoRow label={t("cardPin.phone", "Telefon")} value={`+${data.phone}`} />
|
||||
<InfoRow
|
||||
label={t("cardPin.fullName", "Doly ady")}
|
||||
value={`${data.customerSurname} ${data.customerName} ${data.customerPatronicName ?? ""}`.trim()}
|
||||
/>
|
||||
<InfoRow label={t("cardPin.field.bornAt", "Doglan güni")} value={fmtDate(data.bornAt)} />
|
||||
<InfoRow label={t("cardPin.field.phone", "Telefon")} value={data.phone} />
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title={t("cardPin.passportSection", "Pasport")}>
|
||||
<InfoRow label={t("cardPin.passportSeries", "Pasport seriýasy")} value={data.passport_series} />
|
||||
<InfoRow label={t("cardPin.passportNumber", "Pasport belgisi")} value={data.passport_number} />
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
{/* ── Row 3: Passport images ───────────────────────────────────────── */}
|
||||
<BentoGrid cols={4}>
|
||||
<BentoCard title={t("cardPin.passportFile1", "Sahypa 1")}>
|
||||
<PassportImage label={t("cardPin.passportFile1", "Pasport (sahypa 1)")} url={data.passport_file_1} />
|
||||
</BentoCard>
|
||||
<BentoCard title={t("cardPin.passportFile2", "Sahypa 2-3")}>
|
||||
<PassportImage label={t("cardPin.passportFile2", "Pasport (2-3-nji sahypa)")} url={data.passport_file_2} />
|
||||
</BentoCard>
|
||||
<BentoCard title={t("cardPin.passportFile3", "Sahypa 8-9")}>
|
||||
<PassportImage label={t("cardPin.passportFile3", "Pasport (8-9 sahypa)")} url={data.passport_file_3} />
|
||||
</BentoCard>
|
||||
<BentoCard title={t("cardPin.passportFile4", "Sahypa 32")}>
|
||||
<PassportImage label={t("cardPin.passportFile4", "Pasport (32-nji sahypa)")} url={data.passport_file_4} />
|
||||
<InfoRow label={t("cardPin.field.passportSerie", "Pasport seriýasy")} value={data.passportSerie} />
|
||||
<InfoRow label={t("cardPin.field.passportId", "Pasport belgisi")} value={data.passportId} />
|
||||
<InfoRow label={t("cardPin.field.passportOne", "Pasport 1")} value={data.passportOne || "—"} />
|
||||
<InfoRow label={t("cardPin.field.passportTwo", "Pasport 2")} value={data.passportTwo || "—"} />
|
||||
<InfoRow label={t("cardPin.field.passportThree", "Pasport 3")} value={data.passportThree || "—"} />
|
||||
<InfoRow label={t("cardPin.field.passportFour", "Pasport 4")} value={data.passportFour || "—"} />
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
</div>
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useState } from "react";
|
||||
import { useParams, useNavigate, Link } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Download, Trash2, Pencil } from "lucide-react";
|
||||
import { Trash2, Pencil } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import {
|
||||
@@ -14,12 +14,8 @@ import {
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import {
|
||||
useCardTransaction,
|
||||
useDeleteCardTransaction,
|
||||
useDownloadCardTransaction,
|
||||
} from "@/features/cardTransactions/hooks/useCardTransactions";
|
||||
import { InfoRow } from "@/components/viewPageComponents";
|
||||
import { useCardTransaction, useDeleteCardTransaction } from "@/features/cardTransactions/hooks/useCardTransactions";
|
||||
import { BentoGrid, BentoCard, InfoRow } from "@/components/viewPageComponents";
|
||||
|
||||
// ─── Page ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -33,7 +29,6 @@ export default function CardTransactionViewPage() {
|
||||
const numericId = Number(id);
|
||||
const { data, isLoading } = useCardTransaction(numericId);
|
||||
const deleteMutation = useDeleteCardTransaction();
|
||||
const downloadMutation = useDownloadCardTransaction();
|
||||
|
||||
const handleDelete = async () => {
|
||||
await deleteMutation.mutateAsync(numericId);
|
||||
@@ -45,7 +40,7 @@ export default function CardTransactionViewPage() {
|
||||
<div className="space-y-4">
|
||||
<Skeleton className="h-7 w-64" />
|
||||
<div className="rounded-lg border border-border bg-card overflow-hidden">
|
||||
{Array.from({ length: 5 }).map((_, i) => (
|
||||
{Array.from({ length: 7 }).map((_, i) => (
|
||||
<div key={i} className="grid grid-cols-[220px_1fr] items-center py-2.5 px-4 border-b border-border last:border-0">
|
||||
<Skeleton className="h-4 w-24" />
|
||||
<Skeleton className="h-4 w-40" />
|
||||
@@ -57,11 +52,7 @@ export default function CardTransactionViewPage() {
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
return (
|
||||
<div className="text-center py-24 text-muted-foreground">
|
||||
{t("Not found", "Tapylmady")}
|
||||
</div>
|
||||
);
|
||||
return <div className="text-center py-24 text-muted-foreground">{t("Not found", "Tapylmady")}</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -69,18 +60,9 @@ export default function CardTransactionViewPage() {
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t("Card transaction detail", "Kart herekedi giňişleýin")}:
|
||||
{t("Card transaction detail", "Kart giňişleýin")}: <span className="text-primary font-mono">{data.number}</span>
|
||||
</h1>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="gap-1.5"
|
||||
onClick={() => downloadMutation.mutate(numericId)}
|
||||
disabled={downloadMutation.isPending}
|
||||
>
|
||||
<Download size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
@@ -97,54 +79,45 @@ export default function CardTransactionViewPage() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Detail card */}
|
||||
<div className="rounded-lg border border-border bg-card overflow-hidden">
|
||||
<InfoRow label={t("ID", "ID")} value={data.id} />
|
||||
<InfoRow
|
||||
label={t("Passport series", "Pasport seriýasy")}
|
||||
value={data.passport_series}
|
||||
/>
|
||||
<InfoRow
|
||||
label={t("Passport number", "Pasport belgisi")}
|
||||
value={data.passport_number}
|
||||
/>
|
||||
<InfoRow
|
||||
label={t("Card number", "Kart belgisi")}
|
||||
value={data.card_number}
|
||||
/>
|
||||
<InfoRow
|
||||
label={t("Card expiry month", "Kart Möhleti (aý)")}
|
||||
value={data.card_expiry_month}
|
||||
/>
|
||||
<InfoRow
|
||||
label={t("Card expiry year", "Kart Möhleti (ýyl)")}
|
||||
value={data.card_expiry_year}
|
||||
/>
|
||||
</div>
|
||||
{/* Detail cards */}
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title={t("cardTransaction.section.card", "Kart")}>
|
||||
<InfoRow label={t("cardTransaction.col.id", "ID")} value={data.id} />
|
||||
<InfoRow label={t("cardTransaction.col.name", "Ady")} value={data.name} />
|
||||
<InfoRow label={t("cardTransaction.col.type", "Görnüşi")} value={data.type} />
|
||||
<InfoRow label={t("cardTransaction.col.number", "Kart belgisi")} value={data.number} />
|
||||
<InfoRow label={t("cardTransaction.col.expiry", "Möhleti")} value={`${data.month}/${data.year}`} />
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title={t("cardTransaction.section.meta", "Belligi")}>
|
||||
<InfoRow label={t("cardTransaction.col.userId", "Ulanyjy ID")} value={data.userId} />
|
||||
<InfoRow
|
||||
label={t("cardTransaction.col.createdAt", "Döredilen wagty")}
|
||||
value={data.createdAt ? new Date(data.createdAt).toLocaleString() : "—"}
|
||||
/>
|
||||
<InfoRow
|
||||
label={t("cardTransaction.col.updatedAt", "Täzelenen wagty")}
|
||||
value={data.updatedAt ? new Date(data.updatedAt).toLocaleString() : "—"}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
{/* Delete dialog */}
|
||||
<AlertDialog open={deleteOpen} onOpenChange={setDeleteOpen}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>
|
||||
{t("Are you sure?", "Eminsiňizmi?")}
|
||||
</AlertDialogTitle>
|
||||
<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.",
|
||||
"This action cannot be undone. This will permanently delete the card.",
|
||||
"Bu amal yzyna gaýtarylmaz. Kart 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 onClick={handleDelete} className="bg-destructive text-destructive-foreground hover:bg-destructive/90">
|
||||
{deleteMutation.isPending ? t("Deleting...", "Öçürilýär...") : t("Delete", "Öçür")}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
|
||||
@@ -1,229 +1,302 @@
|
||||
import { useState, useMemo, useCallback } from "react";
|
||||
import { useState, useCallback, useMemo } from "react";
|
||||
import { useNavigate, Link } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { CheckCircle2, XCircle, AlertCircle } from "lucide-react";
|
||||
import type { ColumnDef, VisibilityState } from "@tanstack/react-table";
|
||||
|
||||
import { AlertCircle, CheckCircle2, XCircle } from "lucide-react";
|
||||
|
||||
import { DataTable } from "@/components/dataTable";
|
||||
import { DataTableToolbar, type ActiveFilter, type FilterField } from "@/components/dataTableToolbar";
|
||||
import { DataTableToolbar, type ColumnMeta, type ActiveFilter, type FilterField } from "@/components/dataTableToolbar";
|
||||
import { TableSearchInput } from "@/components/tableSearch";
|
||||
import { CreateButton } from "@/components/createButton";
|
||||
import { TableActions } from "@/components/tableActions";
|
||||
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";
|
||||
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
|
||||
import { useCards, useDeleteCard } from "@/features/orderNewCard/hooks/useOrderNewCard";
|
||||
import type { CardOrder } from "@/features/orderNewCard/api/orderNewCardApi";
|
||||
import { useBranches } from "@/features/branches/hooks/useBranches";
|
||||
import { useDistricts } from "@/features/districts/hooks/useDistricts";
|
||||
import { useCardTypes } from "@/features/cardTypes/hooks/useCardTypes";
|
||||
|
||||
const PER_PAGE = 25;
|
||||
|
||||
// ─── Status badge ─────────────────────────────────────────────────────────────
|
||||
|
||||
function OrderNewCardStatusBadge({ status }: { status: CardOrderStatus }) {
|
||||
const PENDING_STATUSES = [
|
||||
"pending",
|
||||
"garaşylýar",
|
||||
"garaşilyar",
|
||||
"garasylýar",
|
||||
"garasilyar",
|
||||
"garasylyar",
|
||||
"kutilyor",
|
||||
"kutiliyor",
|
||||
"waiting",
|
||||
"beklemede",
|
||||
];
|
||||
const APPROVED_STATUSES = [
|
||||
"approved",
|
||||
"tassyklandy",
|
||||
"tassyklanan",
|
||||
"tassyklandy",
|
||||
"tassyklanyldy",
|
||||
"accepted",
|
||||
"confirmed",
|
||||
"success",
|
||||
"completed",
|
||||
"approve",
|
||||
];
|
||||
const REJECTED_STATUSES = [
|
||||
"rejected",
|
||||
"reject",
|
||||
"ret",
|
||||
"ýatyryldy",
|
||||
"yatyryldy",
|
||||
"canceled",
|
||||
"cancelled",
|
||||
"cancelled",
|
||||
"declined",
|
||||
"failed",
|
||||
"error",
|
||||
"reject",
|
||||
"red edildi",
|
||||
];
|
||||
|
||||
function CardOrderStatusBadge({ status }: { status: string }) {
|
||||
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} />;
|
||||
const key = (status || "").trim().toLowerCase();
|
||||
|
||||
let variant: StatusBadgeVariant = "default";
|
||||
let icon: React.ElementType | undefined;
|
||||
let label = status;
|
||||
|
||||
if (PENDING_STATUSES.includes(key)) {
|
||||
variant = "warning";
|
||||
icon = AlertCircle;
|
||||
label = t("cardOrder.status.pending", "Garaşylýar");
|
||||
} else if (APPROVED_STATUSES.includes(key)) {
|
||||
variant = "success";
|
||||
icon = CheckCircle2;
|
||||
label = t("cardOrder.status.approved", "Tassyklandy");
|
||||
} else if (REJECTED_STATUSES.includes(key)) {
|
||||
variant = "error";
|
||||
icon = XCircle;
|
||||
label = t("cardOrder.status.rejected", "Ýatyryldy");
|
||||
} else {
|
||||
label = t(`cardOrder.status.${status}`, status);
|
||||
}
|
||||
|
||||
return <StatusBadge label={label} variant={variant} icon={icon} />;
|
||||
}
|
||||
|
||||
// ─── Coloured text helper ─────────────────────────────────────────────────────
|
||||
// ─── Filter field IDs ──────────────────────────────────────────────────────────
|
||||
|
||||
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>;
|
||||
}
|
||||
const FILTER_IDS = ["status", "branch_id", "user_id", "card_state_id", "card_type_id", "region"] as const;
|
||||
type FilterId = (typeof FILTER_IDS)[number];
|
||||
|
||||
const SPECIAL_BRANCHES = ["Köpetdag", "Türkmenabat", "Türkmenbaşy", "Seýdi", "Çandybil", "Balkan", "Baş bank"];
|
||||
|
||||
// ─── CardOrdersPage ───────────────────────────────────────────────────────────
|
||||
const INITIAL_FILTERS: ActiveFilter[] = FILTER_IDS.map((fieldId) => ({ fieldId, value: "" }));
|
||||
|
||||
export default function CardOrdersPage() {
|
||||
const { t } = useTranslation();
|
||||
const { t, i18n } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const deleteMutation = useDeleteCardOrder();
|
||||
const [deleteId, setDeleteId] = useState<string | null>(null);
|
||||
const deleteMutation = useDeleteCard();
|
||||
|
||||
// ── 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") },
|
||||
],
|
||||
[t],
|
||||
);
|
||||
const DEFAULT_ORDER = useMemo(() => COLUMN_META.map((c) => c.id), [COLUMN_META]);
|
||||
const lang = (i18n.language === "ru" ? "ru" : i18n.language === "en" ? "en" : "tm") as "tm" | "ru" | "en";
|
||||
|
||||
// ── State ──────────────────────────────────────────────────────────────────
|
||||
const [search, setSearch] = useState("");
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
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[]>(DEFAULT_ORDER);
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>([
|
||||
{ fieldId: "status", value: "" },
|
||||
{ fieldId: "provinceId", value: "" },
|
||||
{ fieldId: "branchId", value: "" },
|
||||
]);
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([]);
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>(INITIAL_FILTERS);
|
||||
|
||||
// ── Lookup data ────────────────────────────────────────────────────────────
|
||||
const provinceId = activeFilters.find((f) => f.fieldId === "provinceId")?.value;
|
||||
const { data: provincesData } = useProvinces();
|
||||
const { data: branchesData } = useBranches(provinceId ? Number(provinceId) : undefined);
|
||||
// ── Dropdown data ──────────────────────────────────────────────────────────
|
||||
const { data: branchesData } = useBranches({ page, limit: 25 });
|
||||
const { data: districtsData } = useDistricts({ page, limit: 25 });
|
||||
const { data: cardTypesData } = useCardTypes({ page, limit: 25 });
|
||||
|
||||
// ── Query params ───────────────────────────────────────────────────────────
|
||||
const queryParams = useMemo(() => {
|
||||
const filterMap = Object.fromEntries(activeFilters.map((f) => [f.fieldId, f.value]));
|
||||
return {
|
||||
// ── Query ──────────────────────────────────────────────────────────────────
|
||||
const getFilter = useCallback((id: FilterId) => activeFilters.find((f) => f.fieldId === id)?.value ?? "", [activeFilters]);
|
||||
|
||||
const queryParams = useMemo(
|
||||
() => ({
|
||||
search: search || undefined,
|
||||
status: (filterMap.status as CardOrderStatus) || undefined,
|
||||
provinceId: filterMap.provinceId ? Number(filterMap.provinceId) : undefined,
|
||||
branchId: filterMap.branchId ? Number(filterMap.branchId) : undefined,
|
||||
page,
|
||||
perPage,
|
||||
};
|
||||
}, [search, activeFilters, page, perPage]);
|
||||
|
||||
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));
|
||||
}
|
||||
return updated;
|
||||
});
|
||||
setPage(1);
|
||||
}, []);
|
||||
|
||||
const handleFilterReset = useCallback(() => {
|
||||
setActiveFilters((prev) => prev.map((f) => ({ ...f, value: "" })));
|
||||
setPage(1);
|
||||
}, []);
|
||||
|
||||
const handleDelete = useCallback((id: string) => {
|
||||
setDeleteId(id);
|
||||
}, []);
|
||||
|
||||
const confirmDelete = useCallback(() => {
|
||||
if (!deleteId) return;
|
||||
deleteMutation.mutate(deleteId);
|
||||
setDeleteId(null);
|
||||
}, [deleteId, deleteMutation]);
|
||||
|
||||
// ── Columns ────────────────────────────────────────────────────────────────
|
||||
const columns = useMemo<ColumnDef<CardOrderListItem>[]>(
|
||||
() => [
|
||||
{
|
||||
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">
|
||||
{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: "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"),
|
||||
cell: ({ row }) => (
|
||||
<HighlightText value={row.original.cardTypeName} variant={row.original.cardTypeName === "Altyn Asyr" ? "cyan" : "teal"} />
|
||||
),
|
||||
},
|
||||
{
|
||||
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 }) => (
|
||||
<HighlightText value={row.original.branchName} variant={SPECIAL_BRANCHES.includes(row.original.branchName) ? "cyan" : "muted"} />
|
||||
),
|
||||
},
|
||||
{
|
||||
id: "fullName",
|
||||
header: t("cardOrder.col.name", "Ady"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">
|
||||
{row.original.lastName} {row.original.firstName}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: "status",
|
||||
header: t("cardOrder.col.status", "Status"),
|
||||
cell: ({ row }) => <OrderNewCardStatusBadge status={row.original.status} />,
|
||||
size: 130,
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
header: "",
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<TableActions
|
||||
onView={() => navigate(`/order-new-card/${row.original.id}`)}
|
||||
onEdit={() => navigate(`/order-new-card/${row.original.id}/edit`)}
|
||||
onDelete={() => handleDelete(row.original.id)}
|
||||
isDeleting={deleteMutation.isPending}
|
||||
/>
|
||||
),
|
||||
size: 100,
|
||||
},
|
||||
],
|
||||
[t, navigate, handleDelete, deleteMutation.isPending],
|
||||
limit: perPage,
|
||||
status: getFilter("status") || undefined,
|
||||
branch_id: getFilter("branch_id") || undefined,
|
||||
user_id: getFilter("user_id") || undefined,
|
||||
card_state_id: getFilter("card_state_id") || undefined,
|
||||
card_type_id: getFilter("card_type_id") || undefined,
|
||||
region: getFilter("region") || undefined,
|
||||
}),
|
||||
[search, page, perPage, getFilter],
|
||||
);
|
||||
|
||||
const { data, isLoading } = useCards(queryParams);
|
||||
|
||||
const columns: ColumnDef<CardOrder>[] = [
|
||||
{
|
||||
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">
|
||||
{row.original.id}
|
||||
</Link>
|
||||
),
|
||||
size: 80,
|
||||
},
|
||||
{
|
||||
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>,
|
||||
},
|
||||
{
|
||||
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>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: "phone",
|
||||
accessorKey: "phone",
|
||||
header: t("cardOrder.col.phone", "Telefon"),
|
||||
cell: ({ row }) => <span className="font-mono text-sm">{row.original.phone}</span>,
|
||||
},
|
||||
{
|
||||
id: "region",
|
||||
accessorKey: "region",
|
||||
header: t("cardOrder.col.region", "Sebit"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.region}</span>,
|
||||
},
|
||||
{
|
||||
id: "status",
|
||||
accessorKey: "status",
|
||||
header: t("cardOrder.col.status", "Statusy"),
|
||||
cell: ({ row }) => <CardOrderStatusBadge status={row.original.status} />,
|
||||
},
|
||||
{
|
||||
id: "paid",
|
||||
accessorKey: "paid",
|
||||
header: t("cardOrder.col.paid", "Tölegli"),
|
||||
cell: ({ row }) => (
|
||||
<StatusBadge
|
||||
label={row.original.paid ? t("common.yes", "Hawa") : t("common.no", "Ýok")}
|
||||
variant={row.original.paid ? "success" : "error"}
|
||||
/>
|
||||
),
|
||||
size: 90,
|
||||
},
|
||||
{
|
||||
id: "createdAt",
|
||||
accessorKey: "createdAt",
|
||||
header: t("cardOrder.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",
|
||||
header: "",
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<TableActions
|
||||
onView={() => navigate(`/order-new-card/${row.original.id}`)}
|
||||
onEdit={() => navigate(`/order-new-card/${row.original.id}/edit`)}
|
||||
onDelete={() => setDeleteId(row.original.id)}
|
||||
isDeleting={deleteMutation.isPending}
|
||||
/>
|
||||
),
|
||||
size: 100,
|
||||
},
|
||||
];
|
||||
|
||||
const columnMeta: ColumnMeta[] = columns
|
||||
.filter((c) => c.id !== "actions")
|
||||
.map((c) => ({
|
||||
id: c.id!,
|
||||
label: typeof c.header === "string" ? c.header : c.id!,
|
||||
}));
|
||||
|
||||
const total = data?.count ?? 0;
|
||||
const totalPages = Math.ceil(total / perPage);
|
||||
|
||||
// ── Filter fields ──────────────────────────────────────────────────────────
|
||||
const filterFields = useMemo<FilterField[]>(
|
||||
() => [
|
||||
{
|
||||
id: "status",
|
||||
label: t("cardOrder.col.status", "Status"),
|
||||
label: t("cardOrder.filter.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"),
|
||||
options: provincesData?.map((p) => ({ value: String(p.id), label: p.name })) ?? [],
|
||||
id: "branch_id",
|
||||
label: t("cardOrder.filter.branch", "Şahamça"),
|
||||
options: (branchesData?.branches ?? []).map((b) => ({
|
||||
value: String(b.id),
|
||||
label: b.name[lang] || b.name.tm,
|
||||
})),
|
||||
},
|
||||
{
|
||||
id: "branchId",
|
||||
label: t("cardOrder.col.branch", "Şahamça"),
|
||||
options: branchesData?.map((b) => ({ value: String(b.id), label: b.name })) ?? [],
|
||||
id: "region",
|
||||
label: t("cardOrder.filter.region", "Sebit"),
|
||||
options: (districtsData?.provinces ?? []).map((d) => ({
|
||||
value: d.region?.tm || d.name.tm,
|
||||
label: d.name[lang] || d.name.tm,
|
||||
})),
|
||||
},
|
||||
{
|
||||
id: "user_id",
|
||||
label: t("cardOrder.filter.userId", "Ulanyjy ID"),
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
id: "card_state_id",
|
||||
label: t("cardOrder.filter.cardStateId", "Kart ýagdaýy ID"),
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
id: "card_type_id",
|
||||
label: t("cardOrder.filter.cardTypeId", "Kart görnüşi"),
|
||||
options: (cardTypesData?.paymentCards ?? []).map((ct) => ({
|
||||
value: String(ct.id),
|
||||
label: ct.title[lang] || ct.title.tm,
|
||||
})),
|
||||
},
|
||||
],
|
||||
[t, provincesData, branchesData],
|
||||
[t, lang, branchesData, districtsData, cardTypesData],
|
||||
);
|
||||
|
||||
// ── Render ─────────────────────────────────────────────────────────────────
|
||||
const handleFilterChange = useCallback((fieldId: string, value: string) => {
|
||||
setActiveFilters((prev) => prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f)));
|
||||
setPage(1);
|
||||
}, []);
|
||||
|
||||
const handleFilterReset = useCallback(() => {
|
||||
setActiveFilters(INITIAL_FILTERS);
|
||||
setPage(1);
|
||||
}, []);
|
||||
|
||||
const handleDelete = useCallback(() => {
|
||||
if (deleteId === null) return;
|
||||
deleteMutation.mutate(deleteId);
|
||||
setDeleteId(null);
|
||||
}, [deleteId, deleteMutation]);
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
@@ -239,7 +312,7 @@ export default function CardOrdersPage() {
|
||||
}}
|
||||
placeholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
<CreateButton label={t("cardOrder.create", "Kart sargyt dörediň")} onClick={() => navigate("/order-new-card/create")} />
|
||||
<CreateButton label={t("cardOrder.create", "Kart dörediň")} onClick={() => navigate("/order-new-card/create")} />
|
||||
</div>
|
||||
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
@@ -250,38 +323,38 @@ export default function CardOrdersPage() {
|
||||
setPage(1);
|
||||
}}
|
||||
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||
columns={COLUMN_META}
|
||||
columns={columnMeta}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
filterFields={filterFields}
|
||||
activeFilters={activeFilters}
|
||||
onFilterChange={handleFilterChange}
|
||||
onFilterReset={handleFilterReset}
|
||||
hideSearch
|
||||
hideAction
|
||||
perPageOptions={[10, 25, 50, 100]}
|
||||
perPage={perPage}
|
||||
onPerPageChange={(v) => {
|
||||
setPerPage(v);
|
||||
setPage(1);
|
||||
}}
|
||||
hideSearch
|
||||
hideAction
|
||||
filterFields={filterFields}
|
||||
activeFilters={activeFilters}
|
||||
onFilterChange={handleFilterChange}
|
||||
onFilterReset={handleFilterReset}
|
||||
/>
|
||||
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
data={data?.cardOrders ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
enableRowSelection
|
||||
getRowId={(row) => row.id}
|
||||
getRowId={(row) => String(row.id)}
|
||||
currentPage={page}
|
||||
totalPages={data?.totalPages ?? 1}
|
||||
totalCount={data?.totalCount}
|
||||
totalPages={totalPages}
|
||||
totalCount={total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
@@ -291,8 +364,9 @@ export default function CardOrdersPage() {
|
||||
onOpenChange={(o) => {
|
||||
if (!o) setDeleteId(null);
|
||||
}}
|
||||
title={t("cardOrder.deleteConfirm", "Bu sargyt pozulsynmy?")}
|
||||
onConfirm={confirmDelete}
|
||||
title={t("cardOrder.deleteConfirm", "Bu kart pozulsynmy?")}
|
||||
description={t("cardOrder.deleteDescription", "Bu kart hemişelik pozular. Bu işi yzyna gaýtaryp bolmaz.")}
|
||||
onConfirm={handleDelete}
|
||||
isLoading={deleteMutation.isPending}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { PageSpinner } from '@/components/pageSpinner'
|
||||
import { PageError } from '@/components/pageError'
|
||||
import { CardOrderForm } from '@/features/orderNewCard/components/orderNewCardForm'
|
||||
import { useCardOrderById } from '@/features/orderNewCard/hooks/useOrderNewCard'
|
||||
import { useParams } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { PageSpinner } from "@/components/pageSpinner";
|
||||
import { PageError } from "@/components/pageError";
|
||||
import { CardOrderForm } from "@/features/orderNewCard/components/orderNewCardForm";
|
||||
import { useCardById } from "@/features/orderNewCard/hooks/useOrderNewCard";
|
||||
|
||||
export default function CardOrderEditPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const { t } = useTranslation()
|
||||
const { data: order, isLoading } = useCardOrderById(id ?? '')
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const { t } = useTranslation();
|
||||
const { data: card, isLoading } = useCardById(Number(id));
|
||||
|
||||
if (isLoading) return <PageSpinner />
|
||||
if (!order) return <PageError message={t('common.notFound', 'Tapylmady')} />
|
||||
if (isLoading) return <PageSpinner />;
|
||||
if (!card) return <PageError message={t("common.notFound", "Tapylmady")} />;
|
||||
|
||||
return <CardOrderForm mode="edit" initialData={order} />
|
||||
return <CardOrderForm mode="edit" initialData={card} />;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useState } from "react";
|
||||
import { useParams, useNavigate, Link } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Printer, Download, Trash2, Pencil, AlertCircle, CheckCircle2, XCircle } from "lucide-react";
|
||||
import { Printer, Download, Trash2, Pencil } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
AlertDialog,
|
||||
@@ -14,24 +14,64 @@ import {
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { useCardOrderById, useDeleteCardOrder } from "@/features/orderNewCard/hooks/useOrderNewCard";
|
||||
import type { CardOrderStatus } from "@/features/orderNewCard/api/orderNewCardApi";
|
||||
import { BentoGrid, BentoCard, InfoRow, PassportImage } from "@/components/viewPageComponents";
|
||||
import { useCardById, useDeleteCard } from "@/features/orderNewCard/hooks/useOrderNewCard";
|
||||
import { BentoGrid, BentoCard, InfoRow } from "@/components/viewPageComponents";
|
||||
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
|
||||
import { AlertCircle, CheckCircle2, XCircle } from "lucide-react";
|
||||
|
||||
// ─── Status badge ─────────────────────────────────────────────────────────────
|
||||
|
||||
const STATUS_CONFIG: Record<CardOrderStatus, { label: string; variant: StatusBadgeVariant; icon: React.ElementType }> = {
|
||||
PENDING: { label: "Garaşylýar", variant: "warning", icon: AlertCircle },
|
||||
APPROVED: { label: "Tassyklandy", variant: "success", icon: CheckCircle2 },
|
||||
REJECTED: { label: "Ýatyryldy", variant: "error", icon: XCircle },
|
||||
};
|
||||
const PENDING_STATUSES = [
|
||||
"pending",
|
||||
"garaşylýar",
|
||||
"garaşilyar",
|
||||
"garasylýar",
|
||||
"garasilyar",
|
||||
"garasylyar",
|
||||
"kutilyor",
|
||||
"kutiliyor",
|
||||
"waiting",
|
||||
"beklemede",
|
||||
];
|
||||
const APPROVED_STATUSES = [
|
||||
"approved",
|
||||
"tassyklandy",
|
||||
"tassyklanan",
|
||||
"tassyklandy",
|
||||
"tassyklanyldy",
|
||||
"accepted",
|
||||
"confirmed",
|
||||
"success",
|
||||
"completed",
|
||||
"approve",
|
||||
];
|
||||
const REJECTED_STATUSES = [
|
||||
"rejected",
|
||||
"reject",
|
||||
"ret",
|
||||
"ýatyryldy",
|
||||
"yatyryldy",
|
||||
"canceled",
|
||||
"cancelled",
|
||||
"cancelled",
|
||||
"declined",
|
||||
"failed",
|
||||
"error",
|
||||
"reject",
|
||||
"red edildi",
|
||||
];
|
||||
|
||||
function CardOrderStatusBadge({ status }: { status: CardOrderStatus }) {
|
||||
const { t } = useTranslation();
|
||||
const cfg = STATUS_CONFIG[status];
|
||||
if (!cfg) return <span className="text-xs text-muted-foreground">{status}</span>;
|
||||
return <StatusBadge label={t(`cardOrder.status.${status.toLowerCase()}`)} variant={cfg.variant} icon={cfg.icon} />;
|
||||
function statusConfig(status: string): { label: string; variant: StatusBadgeVariant; icon?: React.ElementType } {
|
||||
const key = status.trim().toLowerCase();
|
||||
if (PENDING_STATUSES.includes(key)) return { label: "Garaşylýar", variant: "warning", icon: AlertCircle };
|
||||
if (APPROVED_STATUSES.includes(key)) return { label: "Tassyklandy", variant: "success", icon: CheckCircle2 };
|
||||
if (REJECTED_STATUSES.includes(key)) return { label: "Ýatyryldy", variant: "error", icon: XCircle };
|
||||
return { label: status, variant: "default" };
|
||||
}
|
||||
|
||||
function CardOrderStatusBadge({ status }: { status: string }) {
|
||||
const cfg = statusConfig(status);
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />;
|
||||
}
|
||||
|
||||
// ─── Skeleton ─────────────────────────────────────────────────────────────────
|
||||
@@ -63,24 +103,26 @@ export default function CardOrderDetailPage() {
|
||||
|
||||
const [deleteOpen, setDeleteOpen] = useState(false);
|
||||
|
||||
const { data: order, isLoading } = useCardOrderById(id ?? "");
|
||||
const deleteMutation = useDeleteCardOrder();
|
||||
const { data: order, isLoading } = useCardById(Number(id));
|
||||
const deleteMutation = useDeleteCard();
|
||||
|
||||
const handleDelete = async () => {
|
||||
if (!id) return;
|
||||
await deleteMutation.mutateAsync(id);
|
||||
await deleteMutation.mutateAsync(Number(id));
|
||||
navigate("/order-new-card");
|
||||
};
|
||||
|
||||
if (isLoading) return <DetailSkeleton />;
|
||||
if (!order) return <p className="text-muted-foreground text-sm">{t("common.notFound", "Tapylmady")}</p>;
|
||||
|
||||
const fmtDate = (v?: string | null) => (v ? new Date(v).toLocaleDateString() : "—");
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-6">
|
||||
{/* ── Page header ──────────────────────────────────────────────────── */}
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t("cardOrder.detailTitle", "Kart sargyt giriş üçin")}: <span className="text-primary font-mono">{order.id}</span>
|
||||
{t("cardOrder.detailTitle", "Kart sargyt giriş üçin")}: <span className="text-primary font-mono">{order.uniqueId}</span>
|
||||
</h1>
|
||||
|
||||
<div className="flex items-center gap-2 shrink-0">
|
||||
@@ -112,65 +154,76 @@ export default function CardOrderDetailPage() {
|
||||
<BentoGrid cols={3}>
|
||||
<BentoCard title={t("cardOrder.section.meta", "Esasy maglumatlar")}>
|
||||
<InfoRow label={t("common.id", "ID")} value={order.id} />
|
||||
<InfoRow label={t("cardOrder.field.createdAt", "Döredilen wagty")} value={order.createdAt} />
|
||||
<InfoRow label={t("cardOrder.field.uniqueId", "Sargyt belgisi")} value={order.uniqueId} />
|
||||
<InfoRow label={t("cardOrder.field.status", "Status")}>
|
||||
<CardOrderStatusBadge status={order.status} />
|
||||
</InfoRow>
|
||||
<InfoRow label={t("cardOrder.field.isPaid", "Tölenen")}>
|
||||
<InfoRow label={t("cardOrder.field.paid", "Tölenen")}>
|
||||
<span
|
||||
className={`inline-flex items-center justify-center w-5 h-5 rounded-full text-xs font-bold ${order.isPaid ? "bg-emerald-500/15 text-emerald-400" : "bg-red-500/15 text-red-400"}`}
|
||||
className={`inline-flex items-center justify-center w-5 h-5 rounded-full text-xs font-bold ${order.paid ? "bg-emerald-500/15 text-emerald-400" : "bg-red-500/15 text-red-400"}`}
|
||||
>
|
||||
{order.isPaid ? "✓" : "✕"}
|
||||
{order.paid ? "✓" : "✕"}
|
||||
</span>
|
||||
</InfoRow>
|
||||
<InfoRow label={t("cardOrder.field.note", "Bellik")} value={order.note ?? undefined} />
|
||||
<InfoRow label={t("cardOrder.field.createdBy", "Sargyt eden")} value={order.createdBy} isLink />
|
||||
<InfoRow label={t("cardOrder.field.notes", "Bellik")} value={order.notes ?? undefined} />
|
||||
<InfoRow
|
||||
label={t("cardOrder.field.createdAt", "Döredilen wagty")}
|
||||
value={order.createdAt ? new Date(order.createdAt).toLocaleString() : "—"}
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title={t("cardOrder.section.card", "Kart")}>
|
||||
<InfoRow label={t("cardOrder.field.issuanceReason", "Kartyň çykarylmagynyň sebäbi")} value={order.issuanceReasonName} isLink />
|
||||
<InfoRow label={t("cardOrder.field.cardType", "Kart görnüşi")} value={order.cardTypeName} />
|
||||
<InfoRow label={t("cardOrder.field.cardTypeId", "Kart görnüşi ID")} value={order.cardTypeId} />
|
||||
<InfoRow label={t("cardOrder.field.cardStateId", "Kart ýagdaýy ID")} value={order.cardStateId} />
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title={t("cardOrder.section.location", "Lokasiýa")}>
|
||||
<InfoRow label={t("cardOrder.field.province", "Welaýat")} value={order.provinceName} />
|
||||
<InfoRow label={t("cardOrder.field.branch", "Şahamça")} value={order.branchName} />
|
||||
<InfoRow label={t("cardOrder.field.region", "Sebit")} value={order.region} />
|
||||
<InfoRow label={t("cardOrder.field.branchId", "Şahamça ID")} value={order.branchId} />
|
||||
<InfoRow label={t("cardOrder.field.userId", "Ulanyjy ID")} value={order.userId} />
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
{/* ── Row 2: Şahsy maglumatlar (full width — many fields) ─────────── */}
|
||||
{/* ── Row 2: Şahsy maglumatlar + Kontakt ──────────────────────────── */}
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title={t("cardOrder.section.personal", "Şahsy maglumatlar")}>
|
||||
<InfoRow
|
||||
label={t("cardOrder.field.fullName", "Doly ady")}
|
||||
value={[order.lastName, order.firstName, order.middleName].filter(Boolean).join(" ")}
|
||||
value={[order.customerSurname, order.customerName, order.customerPatronicName].filter(Boolean).join(" ")}
|
||||
/>
|
||||
<InfoRow label={t("cardOrder.field.birthDate", "Doglan güni")} value={order.birthDate} />
|
||||
<InfoRow label={t("cardOrder.field.bornAt", "Doglan güni")} value={fmtDate(order.bornAt)} />
|
||||
<InfoRow label={t("cardOrder.field.bornPlace", "Doglan ýeri")} value={order.bornPlace ?? undefined} />
|
||||
<InfoRow label={t("cardOrder.field.oldSurname", "Köne familiýa")} value={order.oldSurname ?? undefined} />
|
||||
<InfoRow label={t("cardOrder.field.citizenship", "Raýatlyk")} value={order.citizenship} />
|
||||
<InfoRow label={t("cardOrder.field.registeredAddress", "Ýazgy edilen salgy")} value={order.registeredAddress} />
|
||||
<InfoRow label={t("cardOrder.field.currentAddress", "Häzirki ýaşaýyş ýeri")} value={order.currentAddress} />
|
||||
<InfoRow label={t("cardOrder.field.workplace", "Işleýän ýeri we wezipesi")} value={order.workplace} />
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title={t("cardOrder.section.contacts", "Kontakt")}>
|
||||
<InfoRow label={t("cardOrder.field.phone", "Telefon")} value={order.phone} />
|
||||
<InfoRow label={t("cardOrder.field.phoneExtra", "Telefon goşmaça")} value={order.phoneExtra ?? undefined} />
|
||||
<InfoRow label={t("cardOrder.field.phoneAdditional", "Telefon goşmaça")} value={order.phoneAdditional ?? undefined} />
|
||||
<InfoRow label={t("cardOrder.field.realAddress", "Hakyky ýaşaýyş ýeri")} value={order.realAddress ?? undefined} />
|
||||
<InfoRow label={t("cardOrder.field.jobLocation", "Işleýän ýeri")} value={order.jobLocation ?? undefined} />
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
{/* ── Row 3: Passport images ───────────────────────────────────────── */}
|
||||
<BentoGrid cols={4}>
|
||||
<BentoCard title={t("cardOrder.field.passportPage1", "Sahypa 1")}>
|
||||
<PassportImage label={t("cardOrder.field.passportPage1", "Pasport (sahypa 1)")} url={order.passportFiles.page1} />
|
||||
{/* ── Row 3: Pasport maglumatlary ─────────────────────────────────── */}
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title={t("cardOrder.section.passport", "Pasport")}>
|
||||
<InfoRow label={t("cardOrder.field.passportSerie", "Pasport seriýasy")} value={order.passportSerie} />
|
||||
<InfoRow label={t("cardOrder.field.passportId", "Pasport belgisi")} value={order.passportId} />
|
||||
<InfoRow label={t("cardOrder.field.passportGivenAt", "Berlen senesi")} value={fmtDate(order.passportGivenAt)} />
|
||||
<InfoRow label={t("cardOrder.field.passportGivenBy", "Beren edara")} value={order.passportGivenBy ?? undefined} />
|
||||
<InfoRow label={t("cardOrder.field.passportAddress", "Pasport salgysy")} value={order.passportAddress ?? undefined} />
|
||||
</BentoCard>
|
||||
<BentoCard title={t("cardOrder.field.passportPage23", "Sahypa 2-3")}>
|
||||
<PassportImage label={t("cardOrder.field.passportPage23", "Pasport (2-3-nji sahypa)")} url={order.passportFiles.page23} />
|
||||
</BentoCard>
|
||||
<BentoCard title={t("cardOrder.field.passportPage89", "Sahypa 8-9")}>
|
||||
<PassportImage label={t("cardOrder.field.passportPage89", "Pasport (8-9 sahypa)")} url={order.passportFiles.page89} />
|
||||
</BentoCard>
|
||||
<BentoCard title={t("cardOrder.field.passportPage32", "Sahypa 32")}>
|
||||
<PassportImage label={t("cardOrder.field.passportPage32", "Pasport (32-nji sahypa)")} url={order.passportFiles.page32} />
|
||||
|
||||
<BentoCard title={t("cardOrder.section.passportParts", "Pasport bölekleri")}>
|
||||
<InfoRow label={t("cardOrder.field.passportOne", "Pasport 1")} value={order.passportOne || "—"} />
|
||||
<InfoRow label={t("cardOrder.field.passportTwo", "Pasport 2")} value={order.passportTwo || "—"} />
|
||||
<InfoRow label={t("cardOrder.field.passportThree", "Pasport 3")} value={order.passportThree || "—"} />
|
||||
<InfoRow label={t("cardOrder.field.passportFour", "Pasport 4")} value={order.passportFour || "—"} />
|
||||
<InfoRow
|
||||
label={t("cardOrder.field.updatedAt", "Täzelenen wagty")}
|
||||
value={order.updatedAt ? new Date(order.updatedAt).toLocaleString() : "—"}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
|
||||
Reference in new issue
Block a user