[CLAUDE] Phase1.2: CRUD Master + Permission Matrix + FE admin pages
Backend:
- Domain/Master: Supplier (+ SupplierType 5 loai), Project, Department (AuditableEntity)
- Domain/Identity: MenuItem, Permission, MenuKeys const (12 menu)
- EF Configurations voi unique Code + query filter IsDeleted
- DbSets + IApplicationDbContext interface update
- Application: PagedResult + PagedRequest generic
- Application/Master CQRS CRUD 3 entity (Create/Update/Delete/Get/List voi paging search sort)
- Application/Permissions: GetMyMenuTree (union OR role, filter tree), ListMenuItems, ListPermissionsByRole, UpsertPermission (guard admin khong tu giam quyen), ListRoles
- Api/Authorization: MenuPermissionRequirement + Handler (Admin bypass, query DB)
- Program.cs: register 48 policy {menu}.{action} tu MenuKeys x Actions
- Api/Controllers: Suppliers, Projects, Departments, Menus, Roles, Permissions
- DbInitializer: seed 12 menu + admin full CRUD permissions
- Migration AddMasterData + AddPermissions
Frontend (fe-admin):
- Types: menuKeys.ts const, menu.ts (MenuNode/Role/Permission), master.ts (Supplier/Project/Department + SupplierType const-object)
- AuthContext: load menu from /menus/me, cache localStorage, refreshMenu()
- usePermission hook + PermissionGuard component (wrap button)
- UI kit them: Dialog (modal overlay), Textarea, Select
- Generic: DataTable (column config, sortable, loading, empty) + Pagination
- PageHeader component
- apiError helper extract message tu ProblemDetails
- Layout rewrite: render menu dong tu AuthContext.menu (MenuGroup collapsible + NavLink + lucide icon map)
- Pages: master/Suppliers, master/Projects, master/Departments (CRUD + search + sort + paging + Dialog form)
- Page system/Permissions: ma tran Role x MenuKey x CRUD checkbox (tick tu dong PUT upsert)
- App.tsx them 4 route moi
Bug fix:
- MenuPermissionHandler: EF expression tree khong support switch expression -> tach switch ra ngoai AnyAsync
- TS erasableSyntaxOnly khong cho enum -> SupplierType const-object pattern (typeof[keyof])
E2E verified via Vite proxy:
- GET /menus/me -> 6 root + 6 child nodes (12 menus)
- GET /roles -> 12 roles
- POST/GET/PUT/DELETE /suppliers -> full CRUD, soft delete OK
- tsc -b fe-admin pass
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
13
fe-admin/src/lib/apiError.ts
Normal file
13
fe-admin/src/lib/apiError.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import axios from 'axios'
|
||||
|
||||
export function getErrorMessage(err: unknown, fallback = 'Lỗi hệ thống'): string {
|
||||
if (axios.isAxiosError(err)) {
|
||||
const data = err.response?.data as { detail?: string; title?: string; errors?: Record<string, string[]> } | undefined
|
||||
if (data?.errors) {
|
||||
const first = Object.values(data.errors).flat()[0]
|
||||
if (first) return first
|
||||
}
|
||||
return data?.detail ?? data?.title ?? err.message
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
18
fe-admin/src/lib/menuKeys.ts
Normal file
18
fe-admin/src/lib/menuKeys.ts
Normal file
@ -0,0 +1,18 @@
|
||||
// Đồng bộ tay với BE SolutionErp.Domain.Identity.MenuKeys
|
||||
export const MenuKeys = {
|
||||
Dashboard: 'Dashboard',
|
||||
Master: 'Master',
|
||||
Suppliers: 'Suppliers',
|
||||
Projects: 'Projects',
|
||||
Departments: 'Departments',
|
||||
Contracts: 'Contracts',
|
||||
Forms: 'Forms',
|
||||
Reports: 'Reports',
|
||||
System: 'System',
|
||||
Users: 'Users',
|
||||
Roles: 'Roles',
|
||||
Permissions: 'Permissions',
|
||||
} as const
|
||||
|
||||
export type MenuKey = typeof MenuKeys[keyof typeof MenuKeys]
|
||||
export type CrudAction = 'Read' | 'Create' | 'Update' | 'Delete'
|
||||
Reference in New Issue
Block a user