diff --git a/src/App.tsx b/src/App.tsx index 4bce3ae..a7691e0 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -43,7 +43,7 @@ interface AppProps { function RequestsRoute({ onViewRequest }: { onViewRequest: (requestId: string) => void }) { const { user } = useAuth(); const isAdmin = hasManagementAccess(user); - + // Render separate screens based on user role // Admin/Management users see all organization requests // Regular users see only their participant requests (approver/spectator, NOT initiator) @@ -104,7 +104,7 @@ function AppRoutes({ onLogout }: AppProps) { const handleViewRequest = async (requestId: string, requestTitle?: string, status?: string) => { setSelectedRequestId(requestId); setSelectedRequestTitle(requestTitle || 'Unknown Request'); - + // Check if request is a draft - if so, route to edit form instead of detail view const isDraft = status?.toLowerCase() === 'draft' || status === 'DRAFT'; if (isDraft) { @@ -131,11 +131,11 @@ function AppRoutes({ onLogout }: AppProps) { } return; } - + // Regular custom request submission // Generate unique ID for the new custom request const requestId = `RE-REQ-2024-${String(Object.keys(CUSTOM_REQUEST_DATABASE).length + dynamicRequests.length + 1).padStart(3, '0')}`; - + // Create full custom request object const newCustomRequest = { id: requestId, @@ -163,21 +163,21 @@ function AppRoutes({ onLogout }: AppProps) { avatar: 'CU' }, department: requestData.department || 'General', - createdAt: new Date().toLocaleDateString('en-US', { - month: 'short', - day: 'numeric', - year: 'numeric', - hour: 'numeric', + createdAt: new Date().toLocaleDateString('en-US', { + month: 'short', + day: 'numeric', + year: 'numeric', + hour: 'numeric', minute: 'numeric', - hour12: true + hour12: true }), - updatedAt: new Date().toLocaleDateString('en-US', { - month: 'short', - day: 'numeric', - year: 'numeric', - hour: 'numeric', + updatedAt: new Date().toLocaleDateString('en-US', { + month: 'short', + day: 'numeric', + year: 'numeric', + hour: 'numeric', minute: 'numeric', - hour12: true + hour12: true }), dueDate: new Date(Date.now() + 5 * 24 * 60 * 60 * 1000).toISOString(), submittedDate: new Date().toISOString(), @@ -187,7 +187,7 @@ function AppRoutes({ onLogout }: AppProps) { // Extract name from email if name is not available const approverName = approver?.name || approver?.email?.split('@')[0] || `Approver ${index + 1}`; const approverEmail = approver?.email || ''; - + return { step: index + 1, approver: `${approverName}${approverEmail ? ` (${approverEmail})` : ''}`, @@ -212,32 +212,28 @@ function AppRoutes({ onLogout }: AppProps) { }; }), auditTrail: [ - { - type: 'created', - action: 'Request Created', - details: `Custom request "${requestData.title}" created`, - user: 'Current User', + { + type: 'created', + action: 'Request Created', + details: `Custom request "${requestData.title}" created`, + user: 'Current User', timestamp: new Date().toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric', hour: 'numeric', minute: 'numeric', hour12: true }) }, - { - type: 'assignment', - action: 'Assigned to Approver', - details: `Request assigned to ${requestData.approvers?.[0]?.name || requestData.approvers?.[0]?.email || 'first approver'}`, - user: 'System', + { + type: 'assignment', + action: 'Assigned to Approver', + details: `Request assigned to ${requestData.approvers?.[0]?.name || requestData.approvers?.[0]?.email || 'first approver'}`, + user: 'System', timestamp: new Date().toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric', hour: 'numeric', minute: 'numeric', hour12: true }) } ], tags: requestData.tags || ['custom-request'] }; - + // Add to dynamic requests setDynamicRequests([...dynamicRequests, newCustomRequest]); - + navigate('/my-requests'); - toast.success('Request Submitted Successfully!', { - description: `Your request "${requestData.title}" (${requestId}) has been created and sent for approval.`, - duration: 5000, - }); }; const handleApprovalSubmit = (action: 'approve' | 'reject', _comment: string) => { @@ -254,7 +250,7 @@ function AppRoutes({ onLogout }: AppProps) { duration: 5000, }); } - + setApprovalAction(null); resolve(true); }, 1000); @@ -268,7 +264,7 @@ function AppRoutes({ onLogout }: AppProps) { const handleClaimManagementSubmit = (claimData: any) => { // Generate unique ID for the new claim request const requestId = `RE-REQ-2024-CM-${String(dynamicRequests.length + 2).padStart(3, '0')}`; - + // Create full request object const newRequest = { id: requestId, @@ -295,21 +291,21 @@ function AppRoutes({ onLogout }: AppProps) { avatar: 'CU' }, department: 'Marketing', - createdAt: new Date().toLocaleString('en-US', { - month: 'short', - day: 'numeric', - year: 'numeric', - hour: 'numeric', + createdAt: new Date().toLocaleString('en-US', { + month: 'short', + day: 'numeric', + year: 'numeric', + hour: 'numeric', minute: 'numeric', - hour12: true + hour12: true }), - updatedAt: new Date().toLocaleString('en-US', { - month: 'short', - day: 'numeric', - year: 'numeric', - hour: 'numeric', + updatedAt: new Date().toLocaleString('en-US', { + month: 'short', + day: 'numeric', + year: 'numeric', + hour: 'numeric', minute: 'numeric', - hour12: true + hour12: true }), dueDate: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000).toISOString(), conclusionRemark: '', @@ -429,30 +425,30 @@ function AppRoutes({ onLogout }: AppProps) { documents: [], spectators: [], auditTrail: [ - { - type: 'created', - action: 'Request Created', - details: `Claim request for ${claimData.activityName} created`, - user: 'Current User', - timestamp: new Date().toLocaleString('en-US', { - month: 'short', - day: 'numeric', - year: 'numeric', - hour: 'numeric', + { + type: 'created', + action: 'Request Created', + details: `Claim request for ${claimData.activityName} created`, + user: 'Current User', + timestamp: new Date().toLocaleString('en-US', { + month: 'short', + day: 'numeric', + year: 'numeric', + hour: 'numeric', minute: 'numeric', - hour12: true + hour12: true }) } ], tags: ['claim-management', 'new-request', claimData.activityType?.toLowerCase().replace(/\s+/g, '-')] }; - + // Add to dynamic requests setDynamicRequests(prev => [...prev, newRequest]); - + // Also add to REQUEST_DATABASE for immediate viewing (REQUEST_DATABASE as any)[requestId] = newRequest; - + toast.success('Claim Request Submitted', { description: 'Your claim management request has been created successfully.', }); @@ -463,134 +459,134 @@ function AppRoutes({ onLogout }: AppProps) {