refactored badge

This commit is contained in:
@jcarymuhammedow committed 2026-06-04 16:43:36 +05:00
1 parent 26057e1fac
commit 2ba061b76c
5 files changed
+247 -501

No files matched your search

@@ -1,7 +1,7 @@
import { useState } from "react";
import { useNavigate } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { Download } from "lucide-react";
import { Download, AlertCircle, CheckCircle2, XCircle } from "lucide-react";
import { DeleteDialog } from "@/components/deleteDialog";
import { DataTable, type ColumnDef } from "@/components/dataTable";
import { DataTableToolbar, type ColumnMeta } from "@/components/dataTableToolbar";
@@ -11,29 +11,20 @@ import { TableActions } from "@/components/tableActions";
import type { VisibilityState } from "@tanstack/react-table";
import { useCardRequisites, useDeleteCardRequisite, useDownloadCardRequisite } from "@/features/cardRequisites/hooks/useCardRequisites";
import type { CardRequisite, CardRequisiteStatus } from "@/features/cardRequisites/api/cardRequisitesApi";
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
// ─── Status badge ─────────────────────────────────────────────────────────────
const STATUS_BADGE: Record<CardRequisiteStatus, { label: string; className: string }> = {
pending: {
label: "Garaşylýar",
className: "bg-yellow-500/15 text-yellow-500 border-yellow-500/20",
},
approved: {
label: "Tassyklanan",
className: "bg-emerald-500/15 text-emerald-500 border-emerald-500/20",
},
rejected: {
label: "Ret edilen",
className: "bg-red-500/15 text-red-500 border-red-500/20",
},
const STATUS_CONFIG: Record<CardRequisiteStatus, { label: string; variant: StatusBadgeVariant; icon: React.ElementType }> = {
pending: { label: "Garaşylýar", variant: "warning", icon: AlertCircle },
approved: { label: "Tassyklanan", variant: "success", icon: CheckCircle2 },
rejected: { label: "Ret edilen", variant: "error", icon: XCircle },
};
function StatusBadge({ status }: { status: CardRequisiteStatus }) {
const cfg = STATUS_BADGE[status] ?? STATUS_BADGE.pending;
return (
<span className={`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium border ${cfg.className}`}>{cfg.label}</span>
);
function CardRequisiteStatusBadge({ status }: { status: CardRequisiteStatus }) {
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} />;
}
// ─── Page ─────────────────────────────────────────────────────────────────────
@@ -115,7 +106,7 @@ export default function CardRequisitesPage() {
id: "status",
accessorKey: "status",
header: t("Status", "STATUS"),
cell: ({ row }) => <StatusBadge status={row.original.status} />,
cell: ({ row }) => <CardRequisiteStatusBadge status={row.original.status} />,
},
{
id: "actions",
@@ -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 } from "lucide-react";
import { Printer, Download, Trash2, Pencil, AlertCircle, CheckCircle2, XCircle } from "lucide-react";
import { Button } from "@/components/ui/button";
import {
AlertDialog,
@@ -14,30 +14,24 @@ import {
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import { Skeleton } from "@/components/ui/skeleton";
import {
useCardOrderById,
useDeleteCardOrder,
} from "@/features/orderNewCard/hooks/useOrderNewCard";
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 { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
// ─── Status badge ─────────────────────────────────────────────────────────────
const STATUS_STYLE: Record<CardOrderStatus, { className: string; icon: string }> = {
PENDING: { icon: "⏳", className: "bg-amber-500/10 text-amber-400 border border-amber-500/20" },
APPROVED: { icon: "✓", className: "bg-emerald-500/10 text-emerald-400 border border-emerald-500/20" },
REJECTED: { icon: "✕", className: "bg-red-500/10 text-red-400 border border-red-500/20" },
}
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 },
};
function StatusBadge({ status }: { status: CardOrderStatus }) {
const { t } = useTranslation()
const cfg = STATUS_STYLE[status]
return (
<span className={`inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-[11px] font-bold tracking-wide ${cfg.className}`}>
<span className="text-[10px]">{cfg.icon}</span>
{t(`cardOrder.status.${status.toLowerCase()}`)}
</span>
)
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} />;
}
// ─── Skeleton ─────────────────────────────────────────────────────────────────
@@ -57,43 +51,36 @@ function DetailSkeleton() {
))}
</div>
</div>
)
);
}
// ─── Page ─────────────────────────────────────────────────────────────────────
export default function CardOrderDetailPage() {
const { id } = useParams<{ id: string }>()
const navigate = useNavigate()
const { t } = useTranslation()
const { id } = useParams<{ id: string }>();
const navigate = useNavigate();
const { t } = useTranslation();
const [deleteOpen, setDeleteOpen] = useState(false)
const [deleteOpen, setDeleteOpen] = useState(false);
const { data: order, isLoading } = useCardOrderById(id ?? "")
const deleteMutation = useDeleteCardOrder()
const { data: order, isLoading } = useCardOrderById(id ?? "");
const deleteMutation = useDeleteCardOrder();
const handleDelete = async () => {
if (!id) return
await deleteMutation.mutateAsync(id)
navigate("/order-new-card")
}
if (!id) return;
await deleteMutation.mutateAsync(id);
navigate("/order-new-card");
};
if (isLoading) return <DetailSkeleton />
if (!order)
return (
<p className="text-muted-foreground text-sm">
{t("common.notFound", "Tapylmady")}
</p>
)
if (isLoading) return <DetailSkeleton />;
if (!order) return <p className="text-muted-foreground text-sm">{t("common.notFound", "Tapylmady")}</p>;
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.id}</span>
</h1>
<div className="flex items-center gap-2 shrink-0">
@@ -125,20 +112,18 @@ export default function CardOrderDetailPage() {
<BentoGrid cols={3}>
<BentoCard title={t("cardOrder.section.meta", "Esasy maglumatlar")}>
<InfoRow label={t("common.id", "ID")}>{order.id}</InfoRow>
<InfoRow label={t("cardOrder.field.createdAt", "Döredilen wagty")}>
{order.createdAt}
</InfoRow>
<InfoRow label={t("cardOrder.field.createdAt", "Döredilen wagty")}>{order.createdAt}</InfoRow>
<InfoRow label={t("cardOrder.field.status", "Status")}>
<StatusBadge status={order.status} />
<CardOrderStatusBadge status={order.status} />
</InfoRow>
<InfoRow label={t("cardOrder.field.isPaid", "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"}`}>
<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"}`}
>
{order.isPaid ? "✓" : "✕"}
</span>
</InfoRow>
<InfoRow label={t("cardOrder.field.note", "Bellik")}>
{order.note ?? "—"}
</InfoRow>
<InfoRow label={t("cardOrder.field.note", "Bellik")}>{order.note ?? "—"}</InfoRow>
<InfoRow label={t("cardOrder.field.createdBy", "Sargyt eden")}>
<span className="text-primary font-medium">{order.createdBy}</span>
</InfoRow>
@@ -154,9 +139,7 @@ export default function CardOrderDetailPage() {
</BentoCard>
<BentoCard title={t("cardOrder.section.location", "Lokasiýa")}>
<InfoRow label={t("cardOrder.field.province", "Welaýat")}>
{order.provinceName}
</InfoRow>
<InfoRow label={t("cardOrder.field.province", "Welaýat")}>{order.provinceName}</InfoRow>
<InfoRow label={t("cardOrder.field.branch", "Şahamça")}>
<span className="text-cyan-400 font-medium">{order.branchName}</span>
</InfoRow>
@@ -169,58 +152,32 @@ export default function CardOrderDetailPage() {
<InfoRow label={t("cardOrder.field.fullName", "Doly ady")}>
{[order.lastName, order.firstName, order.middleName].filter(Boolean).join(" ")}
</InfoRow>
<InfoRow label={t("cardOrder.field.birthDate", "Doglan güni")}>
{order.birthDate}
</InfoRow>
<InfoRow label={t("cardOrder.field.citizenship", "Raýatlyk")}>
{order.citizenship}
</InfoRow>
<InfoRow label={t("cardOrder.field.registeredAddress", "Ýazgy edilen salgy")}>
{order.registeredAddress}
</InfoRow>
<InfoRow label={t("cardOrder.field.currentAddress", "Häzirki ýaşaýyş ýeri")}>
{order.currentAddress}
</InfoRow>
<InfoRow label={t("cardOrder.field.workplace", "Işleýän ýeri we wezipesi")}>
{order.workplace}
</InfoRow>
<InfoRow label={t("cardOrder.field.birthDate", "Doglan güni")}>{order.birthDate}</InfoRow>
<InfoRow label={t("cardOrder.field.citizenship", "Raýatlyk")}>{order.citizenship}</InfoRow>
<InfoRow label={t("cardOrder.field.registeredAddress", "Ýazgy edilen salgy")}>{order.registeredAddress}</InfoRow>
<InfoRow label={t("cardOrder.field.currentAddress", "Häzirki ýaşaýyş ýeri")}>{order.currentAddress}</InfoRow>
<InfoRow label={t("cardOrder.field.workplace", "Işleýän ýeri we wezipesi")}>{order.workplace}</InfoRow>
</BentoCard>
<BentoCard title={t("cardOrder.section.contacts", "Kontakt")}>
<InfoRow label={t("cardOrder.field.phone", "Telefon")}>
{order.phone}
</InfoRow>
<InfoRow label={t("cardOrder.field.phoneExtra", "Telefon goşmaça")}>
{order.phoneExtra ?? "—"}
</InfoRow>
<InfoRow label={t("cardOrder.field.phone", "Telefon")}>{order.phone}</InfoRow>
<InfoRow label={t("cardOrder.field.phoneExtra", "Telefon goşmaça")}>{order.phoneExtra ?? "—"}</InfoRow>
</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}
/>
<PassportImage label={t("cardOrder.field.passportPage1", "Pasport (sahypa 1)")} url={order.passportFiles.page1} />
</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}
/>
<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}
/>
<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}
/>
<PassportImage label={t("cardOrder.field.passportPage32", "Pasport (32-nji sahypa)")} url={order.passportFiles.page32} />
</BentoCard>
</BentoGrid>
@@ -228,27 +185,19 @@ export default function CardOrderDetailPage() {
<AlertDialog open={deleteOpen} onOpenChange={setDeleteOpen}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>
{t("cardOrder.deleteTitle", "Pozmak isleýärsiňizmi?")}
</AlertDialogTitle>
<AlertDialogTitle>{t("cardOrder.deleteTitle", "Pozmak isleýärsiňizmi?")}</AlertDialogTitle>
<AlertDialogDescription>
{t("cardOrder.deleteDescription", "Bu kart sargyt hemişelik pozular. Bu işi yzyna gaýtaryp bolmaz.")}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>{t("common.cancel", "Ýatyr")}</AlertDialogCancel>
<AlertDialogAction
onClick={handleDelete}
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
>
{deleteMutation.isPending
? t("common.deleting", "Pozulýar...")
: t("common.delete", "Pozmak")}
<AlertDialogAction onClick={handleDelete} className="bg-destructive text-destructive-foreground hover:bg-destructive/90">
{deleteMutation.isPending ? t("common.deleting", "Pozulýar...") : t("common.delete", "Pozmak")}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
)
}
);
}