133 lines
5.3 KiB
TypeScript
133 lines
5.3 KiB
TypeScript
import { useState } from "react";
|
|
import { useParams, useNavigate, Link } from "react-router-dom";
|
|
import { useTranslation } from "react-i18next";
|
|
import { Trash2, Pencil } from "lucide-react";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Skeleton } from "@/components/ui/skeleton";
|
|
import {
|
|
AlertDialog,
|
|
AlertDialogAction,
|
|
AlertDialogCancel,
|
|
AlertDialogContent,
|
|
AlertDialogDescription,
|
|
AlertDialogFooter,
|
|
AlertDialogHeader,
|
|
AlertDialogTitle,
|
|
} from "@/components/ui/alert-dialog";
|
|
import { useCardTransaction, useDeleteCardTransaction } from "@/features/cardTransactions/hooks/useCardTransactions";
|
|
import { BentoGrid, BentoCard, InfoRow } from "@/components/viewPageComponents";
|
|
|
|
// ─── Page ─────────────────────────────────────────────────────────────────────
|
|
|
|
export default function CardTransactionViewPage() {
|
|
const { t } = useTranslation();
|
|
const { id } = useParams<{ id: string }>();
|
|
const navigate = useNavigate();
|
|
|
|
const [deleteOpen, setDeleteOpen] = useState(false);
|
|
|
|
const numericId = Number(id);
|
|
const { data, isLoading } = useCardTransaction(numericId);
|
|
const deleteMutation = useDeleteCardTransaction();
|
|
|
|
const handleDelete = async () => {
|
|
await deleteMutation.mutateAsync(numericId);
|
|
navigate("/card-transactions");
|
|
};
|
|
|
|
if (isLoading) {
|
|
return (
|
|
<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: 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" />
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (!data) {
|
|
return <div className="text-center py-24 text-muted-foreground">{t("Not found", "Tapylmady")}</div>;
|
|
}
|
|
|
|
return (
|
|
<div className="space-y-4">
|
|
{/* Header */}
|
|
<div className="flex items-center justify-between">
|
|
<h1 className="text-xl font-semibold text-foreground">
|
|
{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 text-destructive border-destructive/30 hover:bg-destructive/10"
|
|
onClick={() => setDeleteOpen(true)}
|
|
>
|
|
<Trash2 size={14} />
|
|
</Button>
|
|
<Button variant="outline" size="sm" className="gap-1.5" asChild>
|
|
<Link to={`/card-transactions/${numericId}/edit`}>
|
|
<Pencil size={14} />
|
|
</Link>
|
|
</Button>
|
|
</div>
|
|
</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.user", "Ulanyjy")}
|
|
value={data.user?.name || "—"}
|
|
isLink={Boolean(data.user?.id)}
|
|
href={data.user?.id ? `/all-users/${data.user.id}` : undefined}
|
|
/>
|
|
<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>
|
|
<AlertDialogDescription>
|
|
{t(
|
|
"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>
|
|
</AlertDialogFooter>
|
|
</AlertDialogContent>
|
|
</AlertDialog>
|
|
</div>
|
|
);
|
|
}
|