9.2 KiB
9.2 KiB
Walkthrough - Authentication & RBAC Implementation (TASK-FE-002)
Goal: Implement robust Authentication UI, Role-Based Access Control (RBAC) helpers, and polish the Login experience.
✅ Changes Implemented
1. State Management (Auth Store)
Created frontend/lib/stores/auth-store.ts using Zustand.
- Manages
user,token, andisAuthenticatedstate. - Provides
hasPermission()andhasRole()helpers. - Uses
persistmiddleware to save state to LocalStorage.
2. RBAC Component (<Can />)
Created frontend/components/common/can.tsx.
- Conditionally renders children based on permissions.
- Usage:
<Can permission="document:create"> <Button>Create Document</Button> </Can>
3. Login Page Polish
Refactored frontend/app/(auth)/login/page.tsx.
- Removed inline error alerts.
- Added
sonnerToasts for success/error messages. - Improved UX with clear loading states and feedback.
4. Global Toaster
- Installed
sonnerandnext-themes. - Created
frontend/components/ui/sonner.tsx(Shadcn/UI wrapper). - Added
<Toaster />tofrontend/app/layout.tsx.
5. Session Sync (AuthSync)
Created frontend/components/auth/auth-sync.tsx.
- Listens to NextAuth session changes.
- Updates Zustand
auth-storeautomatically. - Ensures
useAuthStoreis always in sync with server session.
🧪 Verification Steps
-
Session Sync Test:
- Login to the app.
- Go to
/dashboard/can. - Verify "Current User Info" shows your username and role (NOT "Not logged in").
-
Toast Test:
- On
/dashboard/can, click "Trigger Success Toast". - Verify a green success toast appears.
- Click "Trigger Error Toast".
- Verify a red error toast appears.
- On
-
Permission Test:
- Go to
/login. - Try invalid password -> Expect Toast Error.
- Try valid password -> Expect Toast Success and redirect.
- Go to
-
Permission Test:
- Use the
<Can />component in any page. useAuthStore.getState().setAuth(...)with a user role.- Verify elements show/hide correctly.
- Use the
📸 Screenshots
(No visual artifacts generated in this session, please run locally to verify UI)
Correspondence Module Integration (TASK-FE-004)
Status: ✅ Completed Date: 2025-12-07
🚀 Changes Implemented
1. Service Layer & API
- Removed:
frontend/lib/api/correspondences.ts(Mock API) - Updated:
frontend/lib/services/master-data.service.tsto includegetOrganizations - Verified:
frontend/lib/services/correspondence.service.tsusesapiClientcorrectly.
2. State Management (TanStack Query)
- Created:
frontend/hooks/use-correspondence.tsuseCorrespondences: Fetch list with paginationuseCreateCorrespondence: Mutation for creation
- Created:
frontend/hooks/use-master-data.tsuseOrganizations: Fetch master data for dropdowns
3. UI Components
- List Page: Converted to Client Component using
useCorrespondences. - Create Form: Integrated
useCreateCorrespondenceanduseOrganizationsfor real data submission and dynamic dropdowns.
🧪 Verification Steps (Manual)
1. Verify API Connection
- Ensure Backend is running.
- Go to
/correspondences. - Check Network Tab: Request to
GET /api/correspondencesshould appear.
2. Verify Master Data
- Go to
/correspondences/new. - Check "From/To Organization" dropdowns.
- They should populate from
GET /api/organizations.
3. Verify Create Workflow
- Fill form and Submit.
- Toast success should appear.
- Redirect to list page.
- New item should appear (if
invalidateQueriesworked).
RFA Module Integration (TASK-FE-006)
Status: ✅ Completed Date: 2025-12-07
🚀 Changes Implemented
1. Service Layer & API
- Removed:
frontend/lib/api/rfas.ts(Mock API) - Updated:
frontend/lib/services/master-data.service.tsto includegetDisciplines.
2. State Management (TanStack Query)
- Created:
frontend/hooks/use-rfa.tsuseRFAs,useRFA,useCreateRFA,useProcessRFA.
- Updated:
frontend/hooks/use-master-data.tsto includeuseDisciplines.
3. UI Components
- List Page (
/rfas/page.tsx): Converted to Client Component usinguseRFAs. - Create Form: Uses
useCreateRFAanduseDisciplines. - Detail View: Uses
useRFAanduseProcessRFA(for Approve/Reject). - Hooks: All forms now submit real data via
rfaService.
🧪 Verification Steps (Manual)
1. RFA List
- Go to
/rfas. - Pagination and List should load from Backend.
2. Create RFA
- Go to
/rfas/new. - "Discipline" dropdown should load real data.
- "Contract" defaults to ID 1 (mock/placeholder in code).
- Fill items and Submit. Success Toast should appear.
3. Workflow Action
- Open an RFA Detail (
/rfas/1). - Click "Approve" or "Reject".
- Dialog appears, enter comment, confirm.
- Status badge should update after refresh/invalidation.
Search Module Integration (TASK-FE-008)
Status: ✅ Completed Date: 2025-12-07
🚀 Changes Implemented
1. Service Layer & API
- Removed:
frontend/lib/api/search.ts(Mock API) - Updated:
frontend/lib/services/search.service.tsto includesuggest(viasearchendpoint with limit).
2. Custom Hooks
- Created:
frontend/hooks/use-search.tsuseSearch: For full search results with caching.useSearchSuggestions: For autocomplete in global search.
3. UI Components
- Global Search: Connected to
useSearchSuggestions. Shows real-time results from backend. - Search Page: Connected to
useSearch. Supports filtering (Type, Status) via API parameters.
🧪 Verification Steps (Manual)
1. Global Search
- Type a keyword in the top header search bar (e.g., "test" or "LCBP3").
- Suggestions should dropdown after 300ms debounce.
- Clicking a suggestion should navigate to Detail page.
2. Advanced Search
- Press Enter in Global Search or go to
/search?q=.... - Results list should appear.
- Apply "Document Type" filter (e.g., RFA).
- List should refresh with filtered results.
Drawing Module Integration (TASK-FE-007)
Status: ✅ Completed Date: 2025-12-07
🚀 Changes Implemented
1. Service Layer & API
- Removed:
frontend/lib/api/drawings.ts(Mock API) - Verified:
contract-drawing.service.tsandshop-drawing.service.tsare active.
2. Custom Hooks
- Created:
frontend/hooks/use-drawing.tsuseDrawings(type): Unified hook that switches logic based onCONTRACTorSHOPtype.useCreateDrawing(type): Unified mutation for uploading drawings.
3. UI Components
- Drawing List: Uses
useDrawingsto fetch real data. Supports switching tabs (Contract vs Shop). - Upload Form: Uses
useCreateDrawinganduseDisciplines(from master data). Handles file selection.
🧪 Verification Steps (Manual)
1. Drawing List
- Go to
/drawings. - Switch between "Contract Drawings" and "Shop Drawings" tabs.
- Ensure correct data (or empty state) loads for each.
2. Upload Drawing
- Click "Upload Drawing".
- Select "Contract Drawing".
- Fill in required fields (Discipline must load from API).
- Attach a PDF/DWG file.
- Submit.
- Verify redirection to list and new item appears.
Dashboard & Notifications (TASK-FE-009)
Status: ✅ Completed Date: 2025-12-07
🚀 Changes Implemented
1. Services & Hooks
- Created:
dashboard.service.tsandnotification.service.ts. - Created:
use-dashboard.ts(Stats, Activity, Pending) anduse-notification.ts(Unread, MarkRead).
2. UI Updates
- Dashboard Page: Converted to Client Component to use parallel querying hooks.
- Widgets:
StatsCards,RecentActivity,PendingTasksupdated to acceptisLoadingprops and show skeletons. - Notifications: Dropdown now fetches real unread count and marks as read on click.
🧪 Verification Steps (Manual)
1. Dashboard
- Navigate to
/dashboard(or root/). - Verify Stats, Activity, and Tasks load (skeletons show briefly).
- Check data accuracy against backend state.
2. Notifications
- Check the Bell icon in the top bar.
- Badge should show unread count (if any).
- Click to open dropdown -> list should load.
- Click an item -> should mark as read (decrease count) and navigate.
Admin Panel (TASK-FE-010)
Status: ✅ Completed (90%) Date: 2025-12-07
🚀 Changes Implemented
1. Routes & Layout
- Route Group:
app/(admin)for isolated admin context. - Layout:
AdminLayoutenforces Role Check (server-side). - Sidebar:
AdminSidebarfor navigation (Users, Logs, Settings).
2. User Management
- Page:
/admin/userslists all users with filtering. - Features: Create, Edit, Delete (Soft), Role Assignment.
- Components:
UserDialoghandles form with validation.
3. Audit Logs
- Page:
/admin/audit-logsshows system activity.
🧪 Verification Steps (Manual)
1. Access Control
- Login as non-admin -> Try
/admin/users-> Should redirect to home. - Login as Admin -> Should access.
2. User CRUD
- Go to
/admin/users. - Add User "Test Admin". Assign "ADMIN" role.
- Edit User.
- Delete User.
3. Audit Logs
- Perform actions.
- Go to
/admin/audit-logs. - Verify new logs appear.