[CLAUDE] Phase3: Workflow MVP — 9-phase state machine + code gen + FE Inbox/Detail
Backend Contracts domain (5 entities):
- Contract aggregate: Phase (9 enum), SlaDeadline, MaHopDong, BypassProcurementAndCCM, DraftData, SlaWarningSent
- ContractApproval: FromPhase → ToPhase, ApproverUserId (null = system auto-approve), Decision, Comment
- ContractComment: thread theo Phase current
- ContractAttachment: FileName + StoragePath + Purpose (DraftExport/ScannedSigned/SealedCopy)
- ContractCodeSequence: Prefix PK + LastSeq — atomic gen
EF configs:
- Unique MaHopDong filtered [MaHopDong] IS NOT NULL
- Indexes: Phase+IsDeleted, SupplierId, ProjectId, SlaDeadline, ContractId+ApprovedAt, ContractId+CreatedAt
- Cascade delete Approvals/Comments/Attachments khi Contract xoa
- Query filter IsDeleted
- Migration AddContractsWorkflow (DB 19 tables)
Workflow service:
- IContractWorkflowService.TransitionAsync:
- Adjacency check qua Transitions Dict<(from,to), roles[]> (12 transitions)
- Role guard: user phai co role ∈ allowed
- Admin bypass (role Admin pass moi check)
- System bypass (userId=null + Decision=AutoApprove → cho SLA job sau nay)
- Bypass CCM: BypassProcurementAndCCM=true cho phep DangInKy → DangTrinhKy skip phase 6
- Gen ma HD khi chuyen DangDongDau (idempotent — khong gen lai neu da co)
- Reset SlaDeadline = UtcNow + PhaseSla
- Insert ContractApproval row
Code generator (RG-001):
- 7 format theo ContractType: HDTP / HDGK / NCC / HDDV / MB + 2 framework (year prefix)
- BeginTransactionAsync(Serializable) + ContractCodeSequences UPSERT → atomic
- Idempotent: neu MaHopDong da co thi skip
CQRS (8 feature, ContractFeatures.cs):
- CreateContractCommand + Validator + Handler (set SlaDeadline = +7d)
- UpdateContractDraftCommand (chi khi Phase=DangSoanThao)
- TransitionContractCommand (delegate → WorkflowService)
- AddCommentCommand (phase = hien tai)
- ListContractsQuery (PagedResult + filter phase/supplier/project/search)
- GetMyInboxQuery (map Phase → actor roles, filter theo role user)
- GetContractQuery (detail + approvals + comments + attachments + resolve user names)
- DeleteContractCommand (soft, block > DangInKy)
Controller:
- ContractsController 8 endpoint: GET list/inbox/detail, POST create/transition/comment, PUT update, DELETE
Frontend fe-admin (2 page moi):
- types/contracts.ts: ContractPhase const + Label + Color maps + types
- components/PhaseBadge.tsx
- pages/contracts/ContractsListPage.tsx: filter phase + search + click → detail
- pages/contracts/ContractDetailPage.tsx: 2-col layout (info+comments | timeline), action dialog select target phase + comment
Frontend fe-user (4 page moi + 14 file shared):
- cp 14 file shared tu fe-admin (menuKeys, types/*, DataTable, PhaseBadge, Dialog, Textarea, Select, apiError, usePermission, PermissionGuard)
- AuthContext update: load menu tu /menus/me + cache
- Layout: menu fixed 3 muc + user info + roles display
- InboxPage: list HD cho role user xu ly (sort theo SLA)
- ContractCreatePage: form chon loai + template + NCC + du an + gia tri + bypass CDT
- ContractDetailPage: duplicate fe-admin pattern (convention)
- MyContractsPage: list HD cua toi
- App.tsx: 4 route moi
E2E verified:
- Setup Supplier + Project
- POST /contracts → 201 + phase=2
- POST /contracts/{id}/transitions x7 → di het 9 phase
- Final: MaHopDong = "FLOCK 01/HĐGK/SOL&PVL2026/01" dung format RG-001
- Approvals: 7 rows audit day du
Docs:
- .claude/skills/contract-workflow/SKILL.md: placeholder → full spec voi state machine, SLA table, role matrix, 7 code format, code pointers, API, E2E workflow, pitfalls
- docs/changelog/sessions/2026-04-21-1330-phase3-workflow.md: session log
- docs/STATUS.md: Phase 3 MVP done, next Phase 4
- docs/HANDOFF.md: update phase status + file tree + commit log + testing points
- docs/changelog/migration-todos.md: tick Phase 3 MVP items + add iteration 2 list
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
151
fe-user/src/components/DataTable.tsx
Normal file
151
fe-user/src/components/DataTable.tsx
Normal file
@ -0,0 +1,151 @@
|
||||
import type { ReactNode } from 'react'
|
||||
import { ChevronDown, ChevronUp } from 'lucide-react'
|
||||
import { cn } from '@/lib/cn'
|
||||
|
||||
export type Column<T> = {
|
||||
key: string
|
||||
header: ReactNode
|
||||
render: (row: T) => ReactNode
|
||||
sortable?: boolean
|
||||
width?: string
|
||||
align?: 'left' | 'center' | 'right'
|
||||
}
|
||||
|
||||
type Props<T> = {
|
||||
columns: Column<T>[]
|
||||
rows: T[]
|
||||
getRowKey: (row: T) => string
|
||||
isLoading?: boolean
|
||||
empty?: ReactNode
|
||||
sortBy?: string
|
||||
sortDesc?: boolean
|
||||
onSortChange?: (sortBy: string, sortDesc: boolean) => void
|
||||
onRowClick?: (row: T) => void
|
||||
}
|
||||
|
||||
export function DataTable<T>({
|
||||
columns,
|
||||
rows,
|
||||
getRowKey,
|
||||
isLoading,
|
||||
empty,
|
||||
sortBy,
|
||||
sortDesc,
|
||||
onSortChange,
|
||||
onRowClick,
|
||||
}: Props<T>) {
|
||||
return (
|
||||
<div className="overflow-auto rounded-md border border-slate-200 bg-white">
|
||||
<table className="w-full text-sm">
|
||||
<thead className="bg-slate-50 text-slate-700">
|
||||
<tr>
|
||||
{columns.map(c => (
|
||||
<th
|
||||
key={c.key}
|
||||
className={cn(
|
||||
'px-3 py-2 font-medium',
|
||||
c.align === 'right' && 'text-right',
|
||||
c.align === 'center' && 'text-center',
|
||||
c.align !== 'right' && c.align !== 'center' && 'text-left',
|
||||
c.width,
|
||||
)}
|
||||
>
|
||||
{c.sortable && onSortChange ? (
|
||||
<button
|
||||
onClick={() => onSortChange(c.key, sortBy === c.key ? !sortDesc : false)}
|
||||
className="inline-flex items-center gap-1 hover:text-slate-900"
|
||||
>
|
||||
{c.header}
|
||||
{sortBy === c.key && (sortDesc ? <ChevronDown className="h-3.5 w-3.5" /> : <ChevronUp className="h-3.5 w-3.5" />)}
|
||||
</button>
|
||||
) : (
|
||||
c.header
|
||||
)}
|
||||
</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{isLoading && (
|
||||
<tr>
|
||||
<td colSpan={columns.length} className="px-3 py-8 text-center text-slate-500">
|
||||
Đang tải…
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
{!isLoading && rows.length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={columns.length} className="px-3 py-8 text-center text-slate-500">
|
||||
{empty ?? 'Không có dữ liệu'}
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
{!isLoading &&
|
||||
rows.map(row => (
|
||||
<tr
|
||||
key={getRowKey(row)}
|
||||
className={cn(
|
||||
'border-t border-slate-100 transition',
|
||||
onRowClick && 'cursor-pointer hover:bg-slate-50',
|
||||
)}
|
||||
onClick={() => onRowClick?.(row)}
|
||||
>
|
||||
{columns.map(c => (
|
||||
<td
|
||||
key={c.key}
|
||||
className={cn(
|
||||
'px-3 py-2',
|
||||
c.align === 'right' && 'text-right',
|
||||
c.align === 'center' && 'text-center',
|
||||
)}
|
||||
>
|
||||
{c.render(row)}
|
||||
</td>
|
||||
))}
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
type PaginationProps = {
|
||||
page: number
|
||||
pageSize: number
|
||||
total: number
|
||||
onChange: (page: number) => void
|
||||
}
|
||||
|
||||
export function Pagination({ page, pageSize, total, onChange }: PaginationProps) {
|
||||
const totalPages = Math.max(1, Math.ceil(total / pageSize))
|
||||
const from = total === 0 ? 0 : (page - 1) * pageSize + 1
|
||||
const to = Math.min(page * pageSize, total)
|
||||
|
||||
return (
|
||||
<div className="flex items-center justify-between py-3 text-sm text-slate-600">
|
||||
<span>
|
||||
{from}–{to} / {total}
|
||||
</span>
|
||||
<div className="flex 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"
|
||||
>
|
||||
Trước
|
||||
</button>
|
||||
<span className="px-3 py-1">
|
||||
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"
|
||||
>
|
||||
Sau
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user