refactored badge
This commit is contained in:
@@ -3,16 +3,11 @@ import { Download, Eye, ChevronDown, Inbox } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { DataTable, type ColumnDef } from "@/components/dataTable";
|
||||
import { Link } from "react-router-dom";
|
||||
|
||||
// ─── BentoGrid ────────────────────────────────────────────────────────────────
|
||||
|
||||
export function BentoGrid({
|
||||
cols = 2,
|
||||
children,
|
||||
}: {
|
||||
cols?: 1 | 2 | 3 | 4;
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
export function BentoGrid({ cols = 2, children }: { cols?: 1 | 2 | 3 | 4; children: React.ReactNode }) {
|
||||
const colClass = {
|
||||
1: "grid-cols-1",
|
||||
2: "grid-cols-1 sm:grid-cols-2",
|
||||
@@ -31,30 +26,14 @@ interface BentoCardProps {
|
||||
noPadding?: boolean;
|
||||
}
|
||||
|
||||
export function BentoCard({
|
||||
title,
|
||||
span,
|
||||
children,
|
||||
noPadding,
|
||||
}: BentoCardProps) {
|
||||
const spanClass =
|
||||
span === "full"
|
||||
? "sm:col-span-full"
|
||||
: span === 2
|
||||
? "sm:col-span-2"
|
||||
: span === 3
|
||||
? "sm:col-span-3"
|
||||
: "";
|
||||
export function BentoCard({ title, span, children, noPadding }: BentoCardProps) {
|
||||
const spanClass = span === "full" ? "sm:col-span-full" : span === 2 ? "sm:col-span-2" : span === 3 ? "sm:col-span-3" : "";
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`bg-card border border-border rounded-xl overflow-hidden min-w-0 ${spanClass}`}
|
||||
>
|
||||
<div className={`bg-card border border-border rounded-xl overflow-hidden min-w-0 ${spanClass}`}>
|
||||
{title && (
|
||||
<div className="px-4 py-2.5 border-b border-border">
|
||||
<p className="text-xs font-semibold text-muted-foreground uppercase tracking-wide truncate">
|
||||
{title}
|
||||
</p>
|
||||
<p className="text-xs font-semibold text-muted-foreground uppercase tracking-wide truncate">{title}</p>
|
||||
</div>
|
||||
)}
|
||||
{noPadding ? <div>{children}</div> : children}
|
||||
@@ -69,23 +48,24 @@ export interface InfoRowProps {
|
||||
value?: string | number | null;
|
||||
children?: React.ReactNode;
|
||||
isLink?: boolean;
|
||||
href?: string;
|
||||
}
|
||||
|
||||
export function InfoRow({ label, value, children, isLink }: InfoRowProps) {
|
||||
export function InfoRow({ label, value, children, isLink, href }: InfoRowProps) {
|
||||
const content = children ?? (value != null ? String(value) : null);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col sm:grid sm:grid-cols-[minmax(0,42%)_minmax(0,58%)] items-start sm:items-center py-2.5 px-4 border-b border-border last:border-0 gap-0.5 sm:gap-0">
|
||||
<span className="text-xs sm:text-sm text-muted-foreground leading-snug">
|
||||
{label}
|
||||
</span>
|
||||
<span className="text-xs sm:text-sm text-muted-foreground leading-snug">{label}</span>
|
||||
{content != null && content !== "" ? (
|
||||
typeof content === "string" ? (
|
||||
<span
|
||||
className={`text-sm break-words min-w-0 ${isLink ? "text-primary font-medium" : "text-foreground"}`}
|
||||
>
|
||||
{content}
|
||||
</span>
|
||||
isLink && href ? (
|
||||
<Link to={href} className="text-sm break-words min-w-0 text-[#2bbae6] font-medium cursor-pointer hover:underline">
|
||||
{content}
|
||||
</Link>
|
||||
) : (
|
||||
<span className={`text-sm break-words min-w-0 ${isLink ? "text-primary font-medium" : "text-foreground"}`}>{content}</span>
|
||||
)
|
||||
) : (
|
||||
<div className="text-sm min-w-0">{content}</div>
|
||||
)
|
||||
@@ -116,9 +96,7 @@ export function MultiLangRow({ label, value }: MultiLangRowProps) {
|
||||
|
||||
return (
|
||||
<div className="flex flex-col sm:grid sm:grid-cols-[minmax(0,42%)_minmax(0,58%)] items-start py-2.5 px-4 border-b border-border last:border-0 gap-1 sm:gap-0">
|
||||
<span className="text-xs sm:text-sm text-muted-foreground leading-snug pt-1">
|
||||
{label}
|
||||
</span>
|
||||
<span className="text-xs sm:text-sm text-muted-foreground leading-snug pt-1">{label}</span>
|
||||
<div className="w-full min-w-0 flex flex-col gap-1.5 py-0.5">
|
||||
{langs.map((l) =>
|
||||
l.val ? (
|
||||
@@ -126,9 +104,7 @@ export function MultiLangRow({ label, value }: MultiLangRowProps) {
|
||||
<span className="inline-flex items-center justify-center border border-border bg-muted/50 text-muted-foreground text-[9px] font-bold px-1.5 py-0.5 rounded min-w-[22px] mt-0.5 select-none">
|
||||
{l.code}
|
||||
</span>
|
||||
<span className="text-sm text-foreground break-words flex-1 min-w-0">
|
||||
{l.val}
|
||||
</span>
|
||||
<span className="text-sm text-foreground break-words flex-1 min-w-0">{l.val}</span>
|
||||
</div>
|
||||
) : null,
|
||||
)}
|
||||
@@ -148,14 +124,8 @@ export interface SectionProps {
|
||||
export function Section({ title, children }: SectionProps) {
|
||||
return (
|
||||
<div className="mb-6">
|
||||
{title ? (
|
||||
<h2 className="text-base font-semibold text-foreground mb-2">
|
||||
{title}
|
||||
</h2>
|
||||
) : null}
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
{children}
|
||||
</div>
|
||||
{title ? <h2 className="text-base font-semibold text-foreground mb-2">{title}</h2> : null}
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">{children}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -172,21 +142,11 @@ export function CollapsibleSection({ title, children }: CollapsibleSectionProps)
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div
|
||||
className="flex items-center gap-2 mb-2 cursor-pointer select-none w-fit"
|
||||
onClick={() => setOpen((v) => !v)}
|
||||
>
|
||||
<div className="flex items-center gap-2 mb-2 cursor-pointer select-none w-fit" onClick={() => setOpen((v) => !v)}>
|
||||
<h2 className="text-base font-semibold text-foreground">{title}</h2>
|
||||
<ChevronDown
|
||||
size={15}
|
||||
className={`text-muted-foreground transition-transform duration-200 ${open ? "" : "-rotate-90"}`}
|
||||
/>
|
||||
<ChevronDown size={15} className={`text-muted-foreground transition-transform duration-200 ${open ? "" : "-rotate-90"}`} />
|
||||
</div>
|
||||
{open && (
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden p-4 space-y-3">
|
||||
{children}
|
||||
</div>
|
||||
)}
|
||||
{open && <div className="bg-card border border-border rounded-xl overflow-hidden p-4 space-y-3">{children}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -208,11 +168,7 @@ export function PassportImage({ label, src, url }: PassportImageProps) {
|
||||
<span className="text-xs sm:text-sm text-muted-foreground">{label}</span>
|
||||
<div className="flex flex-col gap-2">
|
||||
{imageSrc ? (
|
||||
<img
|
||||
src={imageSrc}
|
||||
alt={label}
|
||||
className="w-28 h-20 object-cover rounded-md border border-border"
|
||||
/>
|
||||
<img src={imageSrc} alt={label} className="w-28 h-20 object-cover rounded-md border border-border" />
|
||||
) : (
|
||||
<div className="w-28 h-20 bg-muted rounded-md border border-border flex items-center justify-center">
|
||||
<span className="text-xs text-muted-foreground">—</span>
|
||||
@@ -264,9 +220,7 @@ export function StatusBadge({ status }: { status: string }) {
|
||||
|
||||
// ─── useAuditColumns ──────────────────────────────────────────────────────────
|
||||
|
||||
export function useAuditColumns(
|
||||
onView?: (log: AuditRowProps) => void,
|
||||
): ColumnDef<AuditRowProps>[] {
|
||||
export function useAuditColumns(onView?: (log: AuditRowProps) => void): ColumnDef<AuditRowProps>[] {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return useMemo(
|
||||
@@ -274,35 +228,23 @@ export function useAuditColumns(
|
||||
{
|
||||
accessorKey: "id",
|
||||
header: t("audit.columns.id", "ID"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-xs font-mono text-muted-foreground">
|
||||
{row.original.id}
|
||||
</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-xs font-mono text-muted-foreground">{row.original.id}</span>,
|
||||
size: 130,
|
||||
},
|
||||
{
|
||||
accessorKey: "action",
|
||||
header: t("audit.columns.action", "AMALYŇ ADY"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm font-medium text-primary">
|
||||
{row.original.action}
|
||||
</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-sm font-medium text-primary">{row.original.action}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "by",
|
||||
header: t("audit.columns.by", "KIM TARAPYNDAN"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.by}</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.by}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "target",
|
||||
header: t("audit.columns.target", "AMALYŇ NYŞANY"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.target}</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.target}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "status",
|
||||
@@ -313,11 +255,7 @@ export function useAuditColumns(
|
||||
{
|
||||
accessorKey: "date",
|
||||
header: t("audit.columns.date", "SENE"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground whitespace-nowrap">
|
||||
{row.original.date}
|
||||
</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground whitespace-nowrap">{row.original.date}</span>,
|
||||
size: 160,
|
||||
},
|
||||
{
|
||||
@@ -374,15 +312,7 @@ export function EmptyState({ label }: EmptyStateProps) {
|
||||
|
||||
// ─── AuditLog ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export function AuditLog({
|
||||
logs,
|
||||
currentPage,
|
||||
totalPages,
|
||||
totalCount,
|
||||
onPageChange,
|
||||
isLoading,
|
||||
onView,
|
||||
}: AuditLogProps) {
|
||||
export function AuditLog({ logs, currentPage, totalPages, totalCount, onPageChange, isLoading, onView }: AuditLogProps) {
|
||||
const columns = useAuditColumns(onView);
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user