refactord some files
This commit is contained in:
1 parent
3d1dc86cab
commit
caae941346
30 files changed
+2761
-3039
No files matched your search
@@ -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>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user