fixed some ui, upgrade functionalitym added permission to operator

This commit is contained in:
Jelaletdin12
2026-09-03 20:31:34 +05:00
parent 25c104ad8c
commit 5ed4c9a8ec
46 changed files with 1058 additions and 1401 deletions

View File

@@ -1,7 +1,18 @@
import { useMemo, useState } from "react";
import { Download, Eye, ChevronDown, Inbox } from "lucide-react";
import { Download, Eye, ChevronDown, Inbox, Pencil, Trash2 } from "lucide-react";
import { useTranslation } from "react-i18next";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import { DataTable, type ColumnDef } from "@/components/dataTable";
import { Link } from "react-router-dom";
@@ -320,6 +331,87 @@ export function EmptyState({ label }: EmptyStateProps) {
);
}
// ─── ViewActions ──────────────────────────────────────────────────────────────
// Standard edit (→ `/edit` route) + delete (with confirmation AlertDialog)
// action buttons rendered in a view page header. Delete validation and the
// destructive mutation itself live in the caller's `onDelete`; this component
// only handles the dialog flow (open → confirm → close).
export interface ViewActionsProps {
editTo?: string;
onDelete?: () => void | Promise<void>;
deleteTitle?: string;
deleteDescription?: string;
deleting?: boolean;
deleteConfirmLabel?: string;
editDisabled?: boolean;
deleteDisabled?: boolean;
}
export function ViewActions({
editTo,
onDelete,
deleteTitle,
deleteDescription,
deleting,
deleteConfirmLabel,
editDisabled,
deleteDisabled,
}: ViewActionsProps) {
const { t } = useTranslation();
const [deleteOpen, setDeleteOpen] = useState(false);
const handleConfirm = async () => {
await onDelete?.();
setDeleteOpen(false);
};
return (
<div className="flex items-center gap-2">
{editTo && (
<Button variant="outline" size="sm" asChild disabled={editDisabled}>
<Link to={editTo}>
<Pencil size={14} />
</Link>
</Button>
)}
{onDelete && (
<Button
variant="outline"
size="sm"
disabled={deleteDisabled}
className="text-destructive border-destructive/30 hover:bg-destructive/10"
onClick={() => setDeleteOpen(true)}
>
<Trash2 size={14} />
</Button>
)}
<AlertDialog open={deleteOpen} onOpenChange={setDeleteOpen}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>{deleteTitle ?? t("Are you sure?", "Eminsiňizmi?")}</AlertDialogTitle>
<AlertDialogDescription>
{deleteDescription ?? t("This action cannot be undone.", "Bu amal yzyna gaýtarylmaz.")}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>{t("Cancel", "Ýatyr")}</AlertDialogCancel>
<AlertDialogAction
onClick={handleConfirm}
disabled={deleting}
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
>
{deleting ? t("Deleting...", "Öçürilýär...") : (deleteConfirmLabel ?? t("Delete", "Öçür"))}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
);
}
// ─── AuditLog ─────────────────────────────────────────────────────────────────
export function AuditLog({ logs, currentPage, totalPages, totalCount, onPageChange, isLoading, onView }: AuditLogProps) {