diff --git a/src/api/API.ts b/src/api/API.ts index 2674529..994021e 100644 --- a/src/api/API.ts +++ b/src/api/API.ts @@ -69,7 +69,7 @@ export const API = { removeParticipant: (id: string) => client.delete(`/collaboration/participants/${id}`), // User management routes - getUsers: () => client.get('/admin/users'), + getUsers: (params?: any) => client.get('/admin/users', { params }), createUser: (data: any) => client.post('/admin/users', data), updateUser: (id: string, data: any) => client.put(`/admin/users/${id}`, data), updateUserStatus: (id: string, data: any) => client.patch(`/admin/users/${id}/status`, data), diff --git a/src/components/applications/ApplicationDetails.tsx b/src/components/applications/ApplicationDetails.tsx index 65c6097..f62dffe 100644 --- a/src/components/applications/ApplicationDetails.tsx +++ b/src/components/applications/ApplicationDetails.tsx @@ -310,6 +310,9 @@ export function ApplicationDetails() { inaugurationDate: getStageDate('Inauguration'), participants: data.participants || [], dealerCode: data.dealerCode, + zoneId: data.zoneId, + regionId: data.regionId, + areaId: data.areaId, }; setApplication(mappedApp); } catch (error) { @@ -693,31 +696,51 @@ export function ApplicationDetails() { } }, [activeTab, applicationId]); - useEffect(() => { - const fetchUsers = async () => { - // Only fetch users if user has admin/DD roles to avoid 403s - if (!currentUser || !['DD Admin', 'Super Admin'].includes(currentUser.role)) { - return; - } - try { - const response = await onboardingService.getUsers(); - if (Array.isArray(response)) { - setUsers(response); - } else if (response && Array.isArray(response.data)) { - setUsers(response.data); - } else if (response && Array.isArray(response.users)) { - setUsers(response.users); - } else { - console.warn('Unexpected users response:', response); - setUsers([]); + const fetchUsers = async (type?: string) => { + // Only fetch users if user has admin/DD roles to avoid 403s + if (!currentUser || !['DD Admin', 'Super Admin'].includes(currentUser.role)) { + return; + } + try { + const params: any = {}; + if (type) { + const roleMapping: any = { + 'level1': ['DD-ZM', 'RBM'], + 'level2': ['DD Lead', 'ZBH'], + 'level3': ['NBH', 'DD Head'] + }; + params.roleCode = roleMapping[type]; + + // Include location from the application + if (application) { + params.locationId = application.locationId || application.areaId || application.regionId || application.zoneId; } - } catch (error) { - console.error('Failed to fetch users', error); + } + + const response = await onboardingService.getUsers(params); + if (Array.isArray(response)) { + setUsers(response); + } else if (response && Array.isArray(response.data)) { + setUsers(response.data); + } else if (response && Array.isArray(response.users)) { + setUsers(response.users); + } else { + console.warn('Unexpected users response:', response); setUsers([]); } - }; - fetchUsers(); - }, []); + } catch (error) { + console.error('Failed to fetch users', error); + setUsers([]); + } + }; + + useEffect(() => { + if (showScheduleModal) { + fetchUsers(interviewType); + } else { + fetchUsers(); // Default fetch for other modals like Assign + } + }, [showScheduleModal, interviewType]); const handleScheduleInterview = async () => { if (!interviewDate) { @@ -847,8 +870,8 @@ export function ApplicationDetails() { name: '3rd Level Interview', status: ['Level 3 Approved', 'FDD Verification', 'LOI In Progress', 'Payment Pending', 'LOI Issued', 'Statutory LOI Ack', 'Dealer Code Generation', 'Architecture Team Assigned', 'Architecture Document Upload', 'Architecture Team Completion', 'LOA Pending', 'EOR In Progress', 'EOR Complete', 'Inauguration', 'Approved'].includes(application.status) ? 'completed' : ['Level 3 Interview Pending'].includes(application.status) ? 'active' : 'pending', date: application.level3InterviewDate, - description: 'NBH + DD-Head evaluation', - evaluators: ['NBH', 'DD-Head'], + description: 'NBH + DD Head evaluation', + evaluators: ['NBH', 'DD Head'], documentsUploaded: 2 }, { @@ -2321,7 +2344,7 @@ export function ApplicationDetails() { Work Note - {currentUser && ['DD Admin', 'Super Admin'].includes(currentUser.role) && ( + {currentUser && ['DD Admin', 'Super Admin', 'DD AM', 'ASM'].includes(currentUser.role) && (