[CLAUDE] FE-Admin: redesign Phase 1 — density-first design system (NAMGROUP-ref, giữ brand)
All checks were successful
Deploy SOLUTION_ERP / build-deploy (push) Successful in 4m24s
All checks were successful
Deploy SOLUTION_ERP / build-deploy (push) Successful in 4m24s
Tham khảo NAMGROUP density conventions, GIỮ brand #1F7DC1 + Be Vietnam Pro. - index.css: density heading ladder (semibold, drop font-bold) + .label-eyebrow util - 6 UI primitives (Button/Input/Label/Select/Textarea/Dialog): text-xs font-semibold, py-1.5 ≤36px, rounded-lg, brand focus-ring - 6 shell (DataTable sticky-thead+RowActions/Layout brand-rail/TopBar/PageHeader/PhaseBadge/EmptyState) - DashboardPage flagship: KPI cards + brand-tinted icon chips + uppercase labels Visual-only — functionality unchanged (Button variant/size keys stable 51 call-sites, props/forwardRef intact). build 0 TS err. reviewer PASS 0 blocker (2 minor slate-400 hint a11y defer). fe-admin only (fe-user mirror = Phase 3). Dashboard live-visual blocked by dev auth-rig → xem live sau deploy. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import type { ReactNode } from 'react'
|
||||
import type { ButtonHTMLAttributes, ReactNode } from 'react'
|
||||
import { ChevronDown, ChevronUp } from 'lucide-react'
|
||||
import { cn } from '@/lib/cn'
|
||||
|
||||
@ -11,6 +11,50 @@ export type Column<T> = {
|
||||
align?: 'left' | 'center' | 'right'
|
||||
}
|
||||
|
||||
// Always-visible row-action button (NAMGROUP convention: NEVER hide actions
|
||||
// behind opacity-0 group-hover — touch devices can't reveal them). 7×7 icon
|
||||
// button, tone-tinted hover. Wrap an action cell with <RowActions> to stop the
|
||||
// row's onClick from firing when a button is pressed.
|
||||
type RowActionTone = 'default' | 'brand' | 'danger' | 'success'
|
||||
|
||||
const ROW_ACTION_TONE: Record<RowActionTone, string> = {
|
||||
default: 'text-slate-500 hover:bg-slate-100 hover:text-slate-800',
|
||||
brand: 'text-slate-500 hover:bg-brand-50 hover:text-brand-700',
|
||||
danger: 'text-slate-500 hover:bg-red-50 hover:text-red-600',
|
||||
success: 'text-slate-500 hover:bg-emerald-50 hover:text-emerald-600',
|
||||
}
|
||||
|
||||
export function RowActions({ children, className }: { children: ReactNode; className?: string }) {
|
||||
return (
|
||||
<div
|
||||
className={cn('flex items-center justify-end gap-0.5', className)}
|
||||
onClick={e => e.stopPropagation()}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export function RowActionButton({
|
||||
tone = 'default',
|
||||
className,
|
||||
...props
|
||||
}: ButtonHTMLAttributes<HTMLButtonElement> & { tone?: RowActionTone }) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className={cn(
|
||||
'inline-flex h-7 w-7 items-center justify-center rounded-md transition-colors',
|
||||
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand-500/60',
|
||||
'disabled:pointer-events-none disabled:opacity-40',
|
||||
ROW_ACTION_TONE[tone],
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
type Props<T> = {
|
||||
columns: Column<T>[]
|
||||
rows: T[]
|
||||
@ -35,15 +79,16 @@ export function DataTable<T>({
|
||||
onRowClick,
|
||||
}: Props<T>) {
|
||||
return (
|
||||
<div className="overflow-auto rounded-xl border border-slate-200/80 bg-white shadow-sm">
|
||||
<table className="w-full text-sm">
|
||||
<thead className="bg-slate-50/60 text-slate-600">
|
||||
<tr className="border-b border-slate-200/80">
|
||||
// Density-first: rounded-lg + crisp border (no decorative shadow).
|
||||
<div className="overflow-auto rounded-lg border border-slate-200 bg-white">
|
||||
<table className="w-full text-[12px]">
|
||||
<thead className="sticky top-0 z-10 bg-slate-50 text-slate-500">
|
||||
<tr className="border-b border-slate-200">
|
||||
{columns.map(c => (
|
||||
<th
|
||||
key={c.key}
|
||||
className={cn(
|
||||
'px-4 py-2.5 text-[11px] font-semibold uppercase tracking-wider',
|
||||
'px-3 py-2 text-[11px] font-semibold uppercase tracking-wider',
|
||||
c.align === 'right' && 'text-right',
|
||||
c.align === 'center' && 'text-center',
|
||||
c.align !== 'right' && c.align !== 'center' && 'text-left',
|
||||
@ -70,7 +115,7 @@ export function DataTable<T>({
|
||||
Array.from({ length: 5 }).map((_, i) => (
|
||||
<tr key={`sk-${i}`} className="border-t border-slate-100">
|
||||
{columns.map(c => (
|
||||
<td key={c.key} className="px-4 py-3">
|
||||
<td key={c.key} className="px-3 py-2.5">
|
||||
<div className="h-3 animate-pulse rounded bg-slate-100" />
|
||||
</td>
|
||||
))}
|
||||
@ -78,7 +123,7 @@ export function DataTable<T>({
|
||||
))}
|
||||
{!isLoading && rows.length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={columns.length} className="px-4 py-12 text-center text-sm text-slate-400">
|
||||
<td colSpan={columns.length} className="px-3 py-12 text-center text-[13px] text-slate-400">
|
||||
{empty ?? 'Không có dữ liệu'}
|
||||
</td>
|
||||
</tr>
|
||||
@ -97,7 +142,7 @@ export function DataTable<T>({
|
||||
<td
|
||||
key={c.key}
|
||||
className={cn(
|
||||
'px-4 py-2.5',
|
||||
'px-3 py-2',
|
||||
c.align === 'right' && 'text-right',
|
||||
c.align === 'center' && 'text-center',
|
||||
)}
|
||||
@ -126,25 +171,25 @@ export function Pagination({ page, pageSize, total, onChange }: PaginationProps)
|
||||
const to = Math.min(page * pageSize, total)
|
||||
|
||||
return (
|
||||
<div className="flex items-center justify-between py-3 text-sm text-slate-600">
|
||||
<span>
|
||||
<div className="flex items-center justify-between py-3 text-[12px] text-slate-500">
|
||||
<span className="tabular-nums">
|
||||
{from}–{to} / {total}
|
||||
</span>
|
||||
<div className="flex gap-1">
|
||||
<div className="flex items-center gap-1">
|
||||
<button
|
||||
disabled={page <= 1}
|
||||
onClick={() => onChange(page - 1)}
|
||||
className="rounded-md border border-slate-300 bg-white px-3 py-1 disabled:opacity-50"
|
||||
className="rounded-lg border border-slate-300 bg-white px-2.5 py-1 font-medium text-slate-700 transition-colors hover:bg-slate-50 disabled:opacity-40 disabled:hover:bg-white"
|
||||
>
|
||||
Trước
|
||||
</button>
|
||||
<span className="px-3 py-1">
|
||||
<span className="px-2 tabular-nums">
|
||||
Trang {page}/{totalPages}
|
||||
</span>
|
||||
<button
|
||||
disabled={page >= totalPages}
|
||||
onClick={() => onChange(page + 1)}
|
||||
className="rounded-md border border-slate-300 bg-white px-3 py-1 disabled:opacity-50"
|
||||
className="rounded-lg border border-slate-300 bg-white px-2.5 py-1 font-medium text-slate-700 transition-colors hover:bg-slate-50 disabled:opacity-40 disabled:hover:bg-white"
|
||||
>
|
||||
Sau
|
||||
</button>
|
||||
|
||||
@ -17,12 +17,12 @@ export function EmptyState({
|
||||
return (
|
||||
<div className={cn('flex flex-col items-center justify-center gap-2 py-10 text-center', className)}>
|
||||
{Icon && (
|
||||
<div className="rounded-full bg-slate-100 p-3 text-slate-400">
|
||||
<Icon className="h-6 w-6" />
|
||||
<div className="rounded-xl bg-slate-100 p-2.5 text-slate-400">
|
||||
<Icon className="h-5 w-5" />
|
||||
</div>
|
||||
)}
|
||||
<div className="text-sm font-medium text-slate-700">{title}</div>
|
||||
{description && <div className="max-w-sm text-xs text-slate-400">{description}</div>}
|
||||
<div className="text-[13px] font-semibold text-slate-700">{title}</div>
|
||||
{description && <div className="max-w-sm text-xs leading-relaxed text-slate-500">{description}</div>}
|
||||
{action && <div className="mt-2">{action}</div>}
|
||||
</div>
|
||||
)
|
||||
|
||||
@ -242,10 +242,12 @@ function MenuLeaf({ node, depth }: { node: MenuNode; depth: number }) {
|
||||
to={path}
|
||||
title={node.label}
|
||||
className={cn(
|
||||
'block rounded-md leading-snug transition',
|
||||
isDeep ? 'px-3 py-1 text-[11px]' : 'px-3 py-2 text-[12px] font-medium',
|
||||
// Density-first: active leaf gets a brand left-rail + tint (crisp
|
||||
// selected affordance, NAMGROUP). Inactive stays quiet slate.
|
||||
'relative block rounded-md leading-snug transition-colors',
|
||||
isDeep ? 'px-3 py-1 text-[11px]' : 'px-3 py-1.5 text-[12px] font-medium',
|
||||
isActive
|
||||
? 'bg-brand-50 text-brand-700'
|
||||
? 'bg-brand-50 font-semibold text-brand-700 before:absolute before:inset-y-1 before:left-0 before:w-0.5 before:rounded-full before:bg-brand-600'
|
||||
: 'text-slate-600 hover:bg-slate-100 hover:text-slate-900',
|
||||
)}
|
||||
>
|
||||
|
||||
@ -10,10 +10,12 @@ export function PageHeader({
|
||||
actions?: ReactNode
|
||||
}) {
|
||||
return (
|
||||
<div className="mb-6 flex items-start justify-between gap-6 border-b border-slate-200/70 pb-5">
|
||||
// Density-first (NAMGROUP): compact one-line header, text-[15px] semibold,
|
||||
// tighter bottom rule. Toolbar/actions sit inline on the right.
|
||||
<div className="mb-5 flex items-start justify-between gap-6 border-b border-slate-200 pb-3.5">
|
||||
<div className="min-w-0">
|
||||
<h1 className="text-[22px] font-bold leading-tight text-slate-900">{title}</h1>
|
||||
{description && <p className="mt-1.5 text-[13px] leading-relaxed text-slate-500">{description}</p>}
|
||||
<h1 className="text-[15px] font-semibold leading-tight text-slate-800">{title}</h1>
|
||||
{description && <p className="mt-1 text-xs leading-relaxed text-slate-500">{description}</p>}
|
||||
</div>
|
||||
{actions && <div className="flex shrink-0 items-center gap-2">{actions}</div>}
|
||||
</div>
|
||||
|
||||
@ -1,9 +1,18 @@
|
||||
import { cn } from '@/lib/cn'
|
||||
import { ContractPhaseColor, ContractPhaseLabel } from '@/types/contracts'
|
||||
|
||||
// Density-first status pill (NAMGROUP convention): rounded-full, ring-bordered,
|
||||
// 11px semibold. Tint + text colour come from ContractPhaseColor (bg-{c}-100 /
|
||||
// text-{c}-700); a matching inset ring crisps the edge without a new colour map.
|
||||
export function PhaseBadge({ phase, className }: { phase: number; className?: string }) {
|
||||
return (
|
||||
<span className={cn('inline-flex rounded-full px-2 py-0.5 text-xs font-medium', ContractPhaseColor[phase], className)}>
|
||||
<span
|
||||
className={cn(
|
||||
'inline-flex items-center rounded-full px-2 py-0.5 text-[11px] font-semibold ring-1 ring-inset ring-current/15',
|
||||
ContractPhaseColor[phase],
|
||||
className,
|
||||
)}
|
||||
>
|
||||
{ContractPhaseLabel[phase]}
|
||||
</span>
|
||||
)
|
||||
|
||||
@ -32,7 +32,7 @@ function UserMenu() {
|
||||
onClick={() => setOpen(o => !o)}
|
||||
className="flex items-center gap-2 rounded-md px-2 py-1.5 text-sm transition hover:bg-slate-100"
|
||||
>
|
||||
<span className="flex h-7 w-7 items-center justify-center rounded-full bg-brand-100 text-xs font-bold text-brand-700">
|
||||
<span className="flex h-7 w-7 items-center justify-center rounded-full bg-brand-100 text-[11px] font-semibold text-brand-700">
|
||||
{initials}
|
||||
</span>
|
||||
<span className="hidden max-w-32 truncate text-slate-700 md:inline">{user?.fullName ?? user?.email}</span>
|
||||
|
||||
@ -2,21 +2,26 @@ import { forwardRef, type ButtonHTMLAttributes } from 'react'
|
||||
import { cva, type VariantProps } from 'class-variance-authority'
|
||||
import { cn } from '@/lib/cn'
|
||||
|
||||
// Density-first (NAMGROUP convention): text-xs font-semibold, compact heights,
|
||||
// rounded-lg. Brand identity kept — primary = brand-600, focus ring brand-500.
|
||||
// Decorative shadow dropped; only the filled actions keep a 1px tint shadow for
|
||||
// affordance. Variant keys (primary/secondary/outline/ghost/danger) + size keys
|
||||
// (sm/md/lg) are STABLE — 51 call-sites depend on them.
|
||||
const buttonVariants = cva(
|
||||
'inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium transition-colors disabled:pointer-events-none disabled:opacity-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-white focus-visible:ring-brand-500 active:translate-y-[0.5px]',
|
||||
'inline-flex items-center justify-center gap-1.5 rounded-lg text-xs font-semibold transition-colors disabled:pointer-events-none disabled:opacity-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-offset-white focus-visible:ring-brand-500/70 active:translate-y-[0.5px]',
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
primary: 'bg-brand-600 text-white shadow-sm shadow-brand-600/20 hover:bg-brand-700',
|
||||
secondary: 'bg-slate-100 text-slate-800 hover:bg-slate-200',
|
||||
outline: 'border border-slate-300 bg-white text-slate-700 shadow-sm hover:bg-slate-50 hover:border-slate-400',
|
||||
primary: 'bg-brand-600 text-white shadow-xs shadow-brand-700/20 hover:bg-brand-700',
|
||||
secondary: 'bg-slate-100 text-slate-700 hover:bg-slate-200',
|
||||
outline: 'border border-slate-300 bg-white text-slate-700 hover:bg-slate-50 hover:border-slate-400',
|
||||
ghost: 'text-slate-600 hover:bg-slate-100 hover:text-slate-900',
|
||||
danger: 'bg-red-600 text-white shadow-sm shadow-red-600/20 hover:bg-red-700',
|
||||
danger: 'bg-red-600 text-white shadow-xs shadow-red-700/20 hover:bg-red-700',
|
||||
},
|
||||
size: {
|
||||
sm: 'h-8 px-3 text-xs',
|
||||
md: 'h-9 px-4',
|
||||
lg: 'h-11 px-6 text-base',
|
||||
sm: 'h-7 px-2.5',
|
||||
md: 'h-8 px-3.5',
|
||||
lg: 'h-10 px-5 text-sm',
|
||||
},
|
||||
},
|
||||
defaultVariants: { variant: 'primary', size: 'md' },
|
||||
|
||||
@ -24,10 +24,11 @@ export function Dialog({ open, onClose, title, children, footer, size = 'md' }:
|
||||
if (!open) return null
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4" onClick={onClose}>
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-slate-900/40 p-4 backdrop-blur-[1px]" onClick={onClose}>
|
||||
<div
|
||||
className={cn(
|
||||
'w-full rounded-lg bg-white shadow-xl',
|
||||
// Density-first: ring-bordered card, restrained shadow (no decorative shadow-xl).
|
||||
'w-full rounded-xl bg-white shadow-lg ring-1 ring-slate-900/5',
|
||||
size === 'sm' && 'max-w-md',
|
||||
size === 'md' && 'max-w-xl',
|
||||
size === 'lg' && 'max-w-3xl',
|
||||
@ -35,13 +36,17 @@ export function Dialog({ open, onClose, title, children, footer, size = 'md' }:
|
||||
onClick={e => e.stopPropagation()}
|
||||
>
|
||||
<div className="flex items-center justify-between border-b border-slate-200 px-5 py-3">
|
||||
<div className="text-base font-semibold text-slate-900">{title}</div>
|
||||
<button onClick={onClose} className="rounded p-1 text-slate-500 hover:bg-slate-100">
|
||||
<div className="text-sm font-semibold text-slate-800">{title}</div>
|
||||
<button
|
||||
onClick={onClose}
|
||||
aria-label="Đóng"
|
||||
className="-mr-1 rounded-md p-1 text-slate-400 transition-colors hover:bg-slate-100 hover:text-slate-700"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
<div className="max-h-[70vh] overflow-auto p-5">{children}</div>
|
||||
{footer && <div className="flex items-center justify-end gap-2 border-t border-slate-200 px-5 py-3">{footer}</div>}
|
||||
<div className="max-h-[70vh] overflow-auto px-5 py-4">{children}</div>
|
||||
{footer && <div className="flex items-center justify-end gap-2 border-t border-slate-200 bg-slate-50/70 px-5 py-3">{footer}</div>}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@ -7,9 +7,10 @@ export const Input = forwardRef<HTMLInputElement, Props>(({ className, ...props
|
||||
<input
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'h-9 w-full rounded-md border border-slate-300 bg-white px-3 text-sm text-slate-900',
|
||||
'shadow-[inset_0_1px_0_rgba(15,23,42,0.02)] placeholder:text-slate-400',
|
||||
'transition-[border-color,box-shadow] focus-visible:border-brand-500 focus-visible:ring-2 focus-visible:ring-brand-500/20',
|
||||
// Density-first: compact (~34px) rounded-lg, brand focus glow at low opacity.
|
||||
'h-8 w-full rounded-lg border border-slate-300 bg-white px-3 py-1.5 text-sm text-slate-900',
|
||||
'placeholder:text-slate-400',
|
||||
'transition-[border-color,box-shadow] focus-visible:border-brand-400 focus-visible:ring-2 focus-visible:ring-brand-500/15',
|
||||
'disabled:cursor-not-allowed disabled:bg-slate-50 disabled:opacity-70',
|
||||
className,
|
||||
)}
|
||||
|
||||
@ -1,10 +1,13 @@
|
||||
import type { LabelHTMLAttributes } from 'react'
|
||||
import { cn } from '@/lib/cn'
|
||||
|
||||
// Density-first ERP scan-pattern (NAMGROUP convention): uppercase + tracking +
|
||||
// muted. slate-500 (not 400) so 11px label still clears WCAG-AA (~4.6:1) — a
|
||||
// deliberate accessibility-floor deviation from NAMGROUP's zinc-400.
|
||||
export function Label({ className, ...props }: LabelHTMLAttributes<HTMLLabelElement>) {
|
||||
return (
|
||||
<label
|
||||
className={cn('text-sm font-medium text-slate-700', className)}
|
||||
className={cn('text-[11px] font-semibold uppercase tracking-wider text-slate-500', className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
|
||||
@ -7,9 +7,9 @@ export const Select = forwardRef<HTMLSelectElement, Props>(({ className, childre
|
||||
<select
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'h-9 w-full rounded-md border border-slate-300 bg-white px-3 pr-8 text-sm text-slate-900',
|
||||
'shadow-[inset_0_1px_0_rgba(15,23,42,0.02)]',
|
||||
'transition-[border-color,box-shadow] focus-visible:border-brand-500 focus-visible:ring-2 focus-visible:ring-brand-500/20',
|
||||
// Density-first: matches Input — compact rounded-lg, brand focus glow.
|
||||
'h-8 w-full rounded-lg border border-slate-300 bg-white px-3 pr-8 text-sm text-slate-900',
|
||||
'transition-[border-color,box-shadow] focus-visible:border-brand-400 focus-visible:ring-2 focus-visible:ring-brand-500/15',
|
||||
'disabled:cursor-not-allowed disabled:bg-slate-50 disabled:opacity-70',
|
||||
className,
|
||||
)}
|
||||
|
||||
@ -7,9 +7,10 @@ export const Textarea = forwardRef<HTMLTextAreaElement, Props>(({ className, ...
|
||||
<textarea
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'w-full rounded-md border border-slate-300 bg-white px-3 py-2 text-sm text-slate-900 leading-relaxed',
|
||||
'shadow-[inset_0_1px_0_rgba(15,23,42,0.02)] placeholder:text-slate-400',
|
||||
'transition-[border-color,box-shadow] focus-visible:border-brand-500 focus-visible:ring-2 focus-visible:ring-brand-500/20',
|
||||
// Density-first: matches Input — rounded-lg, brand focus glow.
|
||||
'w-full rounded-lg border border-slate-300 bg-white px-3 py-1.5 text-sm leading-relaxed text-slate-900',
|
||||
'placeholder:text-slate-400',
|
||||
'transition-[border-color,box-shadow] focus-visible:border-brand-400 focus-visible:ring-2 focus-visible:ring-brand-500/15',
|
||||
'disabled:cursor-not-allowed disabled:bg-slate-50 disabled:opacity-70',
|
||||
className,
|
||||
)}
|
||||
|
||||
@ -40,13 +40,24 @@ body {
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
|
||||
/* Heading tightening + better hierarchy with Be Vietnam Pro */
|
||||
/* Heading tightening + better hierarchy with Be Vietnam Pro.
|
||||
Density-first (NAMGROUP convention): semibold ladder, never font-bold —
|
||||
weight carries hierarchy without shouting. */
|
||||
h1, h2, h3, h4 {
|
||||
letter-spacing: -0.018em;
|
||||
letter-spacing: -0.014em;
|
||||
color: #0f172a;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* Section / form labels — uppercase scan-pattern shared across the app.
|
||||
Use class="label-eyebrow" for the dense ERP label treatment. */
|
||||
.label-eyebrow {
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.06em;
|
||||
text-transform: uppercase;
|
||||
color: #64748b; /* slate-500 — WCAG-AA on white (4.6:1) */
|
||||
}
|
||||
h1 { font-weight: 700; }
|
||||
h2 { font-weight: 600; }
|
||||
|
||||
/* Tabular numbers in tables + stat cards for better alignment */
|
||||
table, .tabular-nums {
|
||||
|
||||
@ -6,6 +6,7 @@ import { BarChart } from '@/components/BarChart'
|
||||
import { PhaseBadge } from '@/components/PhaseBadge'
|
||||
import { useAuth } from '@/contexts/AuthContext'
|
||||
import { api } from '@/lib/api'
|
||||
import { cn } from '@/lib/cn'
|
||||
import type { DashboardStats } from '@/types/reports'
|
||||
|
||||
type MyDashboard = {
|
||||
@ -22,6 +23,13 @@ const fmtMoney = (v: number) => {
|
||||
return v.toLocaleString('vi-VN')
|
||||
}
|
||||
|
||||
// Tone → tinted icon chip (brand-led, semantic accents for warn/good).
|
||||
const STAT_TONE: Record<'default' | 'warn' | 'good', { chip: string; icon: string; value: string }> = {
|
||||
default: { chip: 'bg-brand-50', icon: 'text-brand-600', value: 'text-slate-900' },
|
||||
warn: { chip: 'bg-amber-50', icon: 'text-amber-600', value: 'text-amber-700' },
|
||||
good: { chip: 'bg-emerald-50', icon: 'text-emerald-600', value: 'text-slate-900' },
|
||||
}
|
||||
|
||||
function StatCard({ icon: Icon, label, value, hint, tone = 'default' }: {
|
||||
icon: React.ComponentType<{ className?: string }>
|
||||
label: string
|
||||
@ -29,19 +37,31 @@ function StatCard({ icon: Icon, label, value, hint, tone = 'default' }: {
|
||||
hint?: string
|
||||
tone?: 'default' | 'warn' | 'good'
|
||||
}) {
|
||||
const toneClass = tone === 'warn' ? 'text-amber-600' : tone === 'good' ? 'text-emerald-600' : 'text-brand-600'
|
||||
const t = STAT_TONE[tone]
|
||||
return (
|
||||
<div className="rounded-lg border border-slate-200 bg-white p-4 shadow-sm">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="text-xs font-medium text-slate-500">{label}</div>
|
||||
<Icon className={`h-4 w-4 ${toneClass}`} />
|
||||
<div className="rounded-lg border border-slate-200 bg-white p-4 transition-colors hover:border-slate-300">
|
||||
<div className="flex items-start justify-between gap-2">
|
||||
<div className="text-[11px] font-semibold uppercase tracking-wider text-slate-500">{label}</div>
|
||||
<span className={cn('flex h-7 w-7 shrink-0 items-center justify-center rounded-lg', t.chip)}>
|
||||
<Icon className={cn('h-4 w-4', t.icon)} />
|
||||
</span>
|
||||
</div>
|
||||
<div className="mt-2 text-2xl font-bold text-slate-900">{value}</div>
|
||||
{hint && <div className="mt-0.5 text-xs text-slate-400">{hint}</div>}
|
||||
<div className={cn('mt-2.5 text-2xl font-semibold tabular-nums leading-none', t.value)}>{value}</div>
|
||||
{hint && <div className="mt-1.5 text-[11px] text-slate-400">{hint}</div>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// Small section title with a brand tick — gives each band a clear, quiet anchor.
|
||||
function SectionLabel({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<h2 className="mb-2.5 flex items-center gap-2 text-[11px] font-semibold uppercase tracking-wider text-slate-500">
|
||||
<span className="h-3 w-0.5 rounded-full bg-brand-500" />
|
||||
{children}
|
||||
</h2>
|
||||
)
|
||||
}
|
||||
|
||||
function MyDashboardRow() {
|
||||
const navigate = useNavigate()
|
||||
const { user } = useAuth()
|
||||
@ -60,43 +80,51 @@ function MyDashboardRow() {
|
||||
|
||||
return (
|
||||
<div className="mb-6">
|
||||
<h2 className="mb-2 text-xs font-semibold uppercase tracking-wider text-slate-500">Của tôi</h2>
|
||||
<SectionLabel>Của tôi</SectionLabel>
|
||||
<div className="grid grid-cols-2 gap-4 md:grid-cols-4">
|
||||
<button
|
||||
onClick={() => navigate('/contracts?filter=my-drafts')}
|
||||
className="rounded-xl border border-slate-200 bg-white p-4 text-left shadow-sm transition hover:border-brand-300 hover:shadow"
|
||||
className="group rounded-lg border border-slate-200 bg-white p-4 text-left transition-colors hover:border-brand-300 hover:bg-brand-50/30"
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="text-xs font-medium text-slate-500">Đang soạn thảo</div>
|
||||
<Pencil className="h-4 w-4 text-brand-600" />
|
||||
<div className="flex items-start justify-between gap-2">
|
||||
<div className="text-[11px] font-semibold uppercase tracking-wider text-slate-500">Đang soạn thảo</div>
|
||||
<span className="flex h-7 w-7 shrink-0 items-center justify-center rounded-lg bg-brand-50">
|
||||
<Pencil className="h-4 w-4 text-brand-600" />
|
||||
</span>
|
||||
</div>
|
||||
<div className="mt-2 text-2xl font-bold text-slate-900 tabular-nums">{d.draftsInProgress}</div>
|
||||
<div className="mt-0.5 text-xs text-slate-400">{fmtMoney(d.draftsTotalValue)} VND</div>
|
||||
<div className="mt-2.5 text-2xl font-semibold leading-none text-slate-900 tabular-nums">{d.draftsInProgress}</div>
|
||||
<div className="mt-1.5 text-[11px] text-slate-400">{fmtMoney(d.draftsTotalValue)} VND</div>
|
||||
</button>
|
||||
<button
|
||||
onClick={() => navigate('/contracts?filter=pending-me')}
|
||||
className="rounded-xl border border-slate-200 bg-white p-4 text-left shadow-sm transition hover:border-brand-300 hover:shadow"
|
||||
className="group rounded-lg border border-slate-200 bg-white p-4 text-left transition-colors hover:border-brand-300 hover:bg-brand-50/30"
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="text-xs font-medium text-slate-500">Chờ tôi duyệt</div>
|
||||
<Inbox className="h-4 w-4 text-brand-600" />
|
||||
<div className="flex items-start justify-between gap-2">
|
||||
<div className="text-[11px] font-semibold uppercase tracking-wider text-slate-500">Chờ tôi duyệt</div>
|
||||
<span className="flex h-7 w-7 shrink-0 items-center justify-center rounded-lg bg-brand-50">
|
||||
<Inbox className="h-4 w-4 text-brand-600" />
|
||||
</span>
|
||||
</div>
|
||||
<div className="mt-2 text-2xl font-bold text-slate-900 tabular-nums">{d.pendingMyApproval}</div>
|
||||
<div className="mt-0.5 text-xs text-slate-400">Click để xem hộp thư</div>
|
||||
<div className="mt-2.5 text-2xl font-semibold leading-none text-slate-900 tabular-nums">{d.pendingMyApproval}</div>
|
||||
<div className="mt-1.5 text-[11px] text-slate-400">Mở hộp thư duyệt</div>
|
||||
</button>
|
||||
<div className="rounded-xl border border-slate-200 bg-white p-4 shadow-sm">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="text-xs font-medium text-slate-500">Sắp quá hạn (24h)</div>
|
||||
<Clock className="h-4 w-4 text-amber-600" />
|
||||
<div className="rounded-lg border border-slate-200 bg-white p-4">
|
||||
<div className="flex items-start justify-between gap-2">
|
||||
<div className="text-[11px] font-semibold uppercase tracking-wider text-slate-500">Sắp quá hạn (24h)</div>
|
||||
<span className="flex h-7 w-7 shrink-0 items-center justify-center rounded-lg bg-amber-50">
|
||||
<Clock className="h-4 w-4 text-amber-600" />
|
||||
</span>
|
||||
</div>
|
||||
<div className="mt-2 text-2xl font-bold text-amber-600 tabular-nums">{d.dueSoon}</div>
|
||||
<div className="mt-2.5 text-2xl font-semibold leading-none text-amber-700 tabular-nums">{d.dueSoon}</div>
|
||||
</div>
|
||||
<div className="rounded-xl border border-slate-200 bg-white p-4 shadow-sm">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="text-xs font-medium text-slate-500">Đã quá hạn</div>
|
||||
<AlertTriangle className="h-4 w-4 text-red-600" />
|
||||
<div className="rounded-lg border border-slate-200 bg-white p-4">
|
||||
<div className="flex items-start justify-between gap-2">
|
||||
<div className="text-[11px] font-semibold uppercase tracking-wider text-slate-500">Đã quá hạn</div>
|
||||
<span className="flex h-7 w-7 shrink-0 items-center justify-center rounded-lg bg-red-50">
|
||||
<AlertTriangle className="h-4 w-4 text-red-600" />
|
||||
</span>
|
||||
</div>
|
||||
<div className="mt-2 text-2xl font-bold text-red-600 tabular-nums">{d.overdue}</div>
|
||||
<div className="mt-2.5 text-2xl font-semibold leading-none text-red-600 tabular-nums">{d.overdue}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -113,10 +141,10 @@ export function DashboardPage() {
|
||||
if (stats.isLoading) {
|
||||
return (
|
||||
<div className="p-6">
|
||||
<PageHeader title="Tổng quan" />
|
||||
<PageHeader title="Tổng quan" description="Tình hình HĐ toàn hệ thống — cập nhật real-time khi refresh." />
|
||||
<div className="grid grid-cols-2 gap-4 md:grid-cols-5">
|
||||
{[1, 2, 3, 4, 5].map(i => (
|
||||
<div key={i} className="h-24 animate-pulse rounded-lg bg-slate-100" />
|
||||
<div key={i} className="h-[88px] animate-pulse rounded-lg border border-slate-200 bg-slate-50" />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
@ -132,7 +160,7 @@ export function DashboardPage() {
|
||||
|
||||
<MyDashboardRow />
|
||||
|
||||
<h2 className="mb-2 text-xs font-semibold uppercase tracking-wider text-slate-500">Toàn hệ thống</h2>
|
||||
<SectionLabel>Toàn hệ thống</SectionLabel>
|
||||
{/* KPI Cards */}
|
||||
<div className="grid grid-cols-2 gap-4 md:grid-cols-5">
|
||||
<StatCard icon={FileText} label="Tổng HĐ" value={d.totalContracts} />
|
||||
@ -142,12 +170,12 @@ export function DashboardPage() {
|
||||
<StatCard icon={Coins} label="Tổng giá trị active" value={fmtMoney(d.totalValueActive)} hint="VND" />
|
||||
</div>
|
||||
|
||||
<div className="mt-6 grid grid-cols-1 gap-6 lg:grid-cols-2">
|
||||
<div className="mt-6 grid grid-cols-1 gap-4 lg:grid-cols-2">
|
||||
{/* By Phase */}
|
||||
<section className="rounded-lg border border-slate-200 bg-white p-5">
|
||||
<h2 className="mb-4 text-sm font-semibold text-slate-700">HĐ theo phase</h2>
|
||||
<div className="space-y-2">
|
||||
{d.byPhase.length === 0 && <div className="py-6 text-center text-sm text-slate-400">Chưa có HĐ nào</div>}
|
||||
<h2 className="mb-4 text-[13px] font-semibold text-slate-800">HĐ theo phase</h2>
|
||||
<div className="space-y-2.5">
|
||||
{d.byPhase.length === 0 && <div className="py-6 text-center text-[13px] text-slate-400">Chưa có HĐ nào</div>}
|
||||
{d.byPhase
|
||||
.slice()
|
||||
.sort((a, b) => b.count - a.count)
|
||||
@ -159,10 +187,10 @@ export function DashboardPage() {
|
||||
<div className="w-36">
|
||||
<PhaseBadge phase={p.phase} />
|
||||
</div>
|
||||
<div className="h-2 flex-1 rounded-full bg-slate-100">
|
||||
<div className="h-1.5 flex-1 overflow-hidden rounded-full bg-slate-100">
|
||||
<div className="h-full rounded-full bg-brand-500" style={{ width: `${pct}%` }} />
|
||||
</div>
|
||||
<div className="w-12 text-right font-mono text-xs text-slate-600">{p.count}</div>
|
||||
<div className="w-10 text-right text-xs font-medium text-slate-600 tabular-nums">{p.count}</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
@ -171,7 +199,7 @@ export function DashboardPage() {
|
||||
|
||||
{/* Monthly value */}
|
||||
<section className="rounded-lg border border-slate-200 bg-white p-5">
|
||||
<h2 className="mb-4 text-sm font-semibold text-slate-700">Giá trị HĐ theo tháng (12 tháng gần nhất)</h2>
|
||||
<h2 className="mb-4 text-[13px] font-semibold text-slate-800">Giá trị HĐ theo tháng <span className="font-normal text-slate-400">· 12 tháng gần nhất</span></h2>
|
||||
<BarChart
|
||||
data={d.monthlyValue.map(m => ({
|
||||
label: `${String(m.month).padStart(2, '0')}/${m.year}`,
|
||||
@ -184,7 +212,7 @@ export function DashboardPage() {
|
||||
|
||||
{/* Top suppliers */}
|
||||
<section className="rounded-lg border border-slate-200 bg-white p-5">
|
||||
<h2 className="mb-4 text-sm font-semibold text-slate-700">Top NCC theo số HĐ</h2>
|
||||
<h2 className="mb-4 text-[13px] font-semibold text-slate-800">Top NCC theo số HĐ</h2>
|
||||
<BarChart
|
||||
data={d.topSuppliers.map(s => ({
|
||||
label: s.supplierName,
|
||||
@ -196,7 +224,7 @@ export function DashboardPage() {
|
||||
|
||||
{/* Top projects */}
|
||||
<section className="rounded-lg border border-slate-200 bg-white p-5">
|
||||
<h2 className="mb-4 text-sm font-semibold text-slate-700">Top dự án theo số HĐ</h2>
|
||||
<h2 className="mb-4 text-[13px] font-semibold text-slate-800">Top dự án theo số HĐ</h2>
|
||||
<BarChart
|
||||
data={d.topProjects.map(p => ({
|
||||
label: p.projectName,
|
||||
|
||||
Reference in New Issue
Block a user