96 lines
3.5 KiB
TypeScript
96 lines
3.5 KiB
TypeScript
import { useState } from "react";
|
|
import { useParams, useNavigate } from "react-router-dom";
|
|
import { useTranslation } from "react-i18next";
|
|
import { Pencil, Trash2 } from "lucide-react";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Skeleton } from "@/components/ui/skeleton";
|
|
import { Section, InfoRow } from "@/components/viewPageComponents";
|
|
import { StatusBadge } from "@/components/ui/statusBadge";
|
|
import { useGetRequiredDocumentById, useDeleteRequiredDocument } from "@/features/requiredDocuments/hooks/useRequiredDocuments";
|
|
import { ConfirmDialog } from "@/components/confirmDialog";
|
|
|
|
export default function RequiredDocumentsViewPage() {
|
|
const { id } = useParams<{ id: string }>();
|
|
const navigate = useNavigate();
|
|
const { t } = useTranslation();
|
|
const [deleteOpen, setDeleteOpen] = useState(false);
|
|
|
|
const docId = Number(id);
|
|
const { data, isLoading } = useGetRequiredDocumentById(docId);
|
|
const deleteMutation = useDeleteRequiredDocument();
|
|
|
|
const handleDelete = async () => {
|
|
await deleteMutation.mutateAsync(docId);
|
|
navigate("/settings/loan/required-documents");
|
|
};
|
|
|
|
if (isLoading) {
|
|
return (
|
|
<div className="space-y-2">
|
|
{Array.from({ length: 3 }).map((_, i) => (
|
|
<Skeleton key={i} className="h-12 rounded-lg" />
|
|
))}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (!data) {
|
|
return <div className="text-center py-16 text-muted-foreground">{t("common.notFound", "Maglumat tapylmady")}</div>;
|
|
}
|
|
|
|
return (
|
|
<div>
|
|
{/* Page heading */}
|
|
<div className="flex items-start justify-between mb-4 gap-4">
|
|
<h1 className="text-xl font-semibold text-foreground leading-snug line-clamp-2">
|
|
{t("loanDocuments.viewTitle", "Karz gerekli resminamalary giňişleýin")}: {data.name}
|
|
</h1>
|
|
<div className="flex items-center gap-2 shrink-0">
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
onClick={() => setDeleteOpen(true)}
|
|
disabled={deleteMutation.isPending}
|
|
className="text-muted-foreground hover:text-destructive hover:bg-destructive/10"
|
|
>
|
|
<Trash2 size={16} />
|
|
</Button>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
onClick={() => navigate(`/settings/loan/required-documents/${docId}/edit`)}
|
|
className="text-muted-foreground hover:text-foreground"
|
|
>
|
|
<Pencil size={16} />
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Main info */}
|
|
<Section>
|
|
<InfoRow label={t("common.id", "ID")} value={data.id} />
|
|
<InfoRow label={t("loanDocuments.fields.name", "Ady")} value={data.name} />
|
|
<InfoRow label={t("loanDocuments.fields.value", "Baha")} value={data.value} />
|
|
|
|
<div className="grid grid-cols-[220px_1fr] items-center py-2.5 px-4">
|
|
<span className="text-sm text-muted-foreground">{t("loanDocuments.fields.isActive", "Işjeň")}</span>
|
|
{data.active ? (
|
|
<StatusBadge label={t("common.active", "Işjeň")} variant="success" />
|
|
) : (
|
|
<StatusBadge label={t("common.inactive", "Işjeň däl")} variant="default" />
|
|
)}
|
|
</div>
|
|
</Section>
|
|
|
|
<ConfirmDialog
|
|
open={deleteOpen}
|
|
onOpenChange={setDeleteOpen}
|
|
title={t("loanDocuments.deleteConfirm", "Bu resminamany öçürmek isleýärsiňizmi?")}
|
|
confirmLabel={t("common.delete", "Poz")}
|
|
onConfirm={handleDelete}
|
|
isLoading={deleteMutation.isPending}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|