From 1391e2d2f58dd1016171209e03f2e88c2cccd3de Mon Sep 17 00:00:00 2001 From: laxmanhalaki Date: Wed, 21 Jan 2026 18:44:38 +0530 Subject: [PATCH] draft toast modification done for production --- src/App.tsx | 250 +++++++++--------- .../hooks/useCreateRequestSubmission.ts | 35 ++- 2 files changed, 156 insertions(+), 129 deletions(-) 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) {
{/* Auth Callback - Must be before other routes */} - } + } /> - + {/* Dashboard */} - - } + } /> - - - } + } /> {/* Open Requests */} - - } + } /> {/* Closed Requests */} - - } + } /> {/* Shared Summaries */} - - } + } /> {/* Shared Summary Detail */} - - } + } /> {/* My Requests */} - - } + } /> {/* Requests - Separate screens for Admin and Regular Users */} - - } + } /> {/* Approver Performance - Detailed Performance Analysis */} - - } + } /> {/* Request Detail - requestId will be read from URL params */} - - - } + } /> {/* Work Notes - Dedicated Full-Screen Page */} - } + } /> {/* New Request (Custom) */} - - } + } /> {/* Edit Draft Request */} - - } + } /> {/* Claim Management Wizard */} - - } + } /> {/* Profile */} - - } + } /> {/* Settings */} - - } + } /> {/* Notifications */} - - } + } /> {/* Detailed Reports */} - - } + } /> {/* Admin Control Panel */} - - } + } /> - diff --git a/src/pages/CreateRequest/hooks/useCreateRequestSubmission.ts b/src/pages/CreateRequest/hooks/useCreateRequestSubmission.ts index b227330..e4bcb9a 100644 --- a/src/pages/CreateRequest/hooks/useCreateRequestSubmission.ts +++ b/src/pages/CreateRequest/hooks/useCreateRequestSubmission.ts @@ -3,6 +3,7 @@ */ import { useState } from 'react'; +import { toast } from 'sonner'; import { FormData, RequestTemplate } from '@/hooks/useCreateRequestForm'; import { buildCreatePayload, @@ -72,6 +73,12 @@ export function useCreateRequestSubmission({ documentsToDelete ); + // Show toast after backend confirmation + toast.success('Request Submitted Successfully!', { + description: `Your request "${formData.title}" has been submitted and sent for approval.`, + duration: 5000, + }); + onSubmit?.({ ...formData, backendId: editRequestId, @@ -87,14 +94,24 @@ export function useCreateRequestSubmission({ const result = await createAndSubmitWorkflow(createPayload, documents); + // Show toast after backend confirmation + toast.success('Request Submitted Successfully!', { + description: `Your request "${formData.title}" has been created and sent for approval.`, + duration: 5000, + }); + onSubmit?.({ ...formData, backendId: result.id, template: selectedTemplate, }); } - } catch (error) { + } catch (error: any) { console.error('Failed to submit workflow:', error); + toast.error('Failed to Submit Request', { + description: error?.response?.data?.message || error?.message || 'An error occurred while submitting the request.', + duration: 5000, + }); setSubmitting(false); } }; @@ -130,6 +147,11 @@ export function useCreateRequestSubmission({ documentsToDelete ); + toast.success('Draft Saved Successfully!', { + description: `Your request "${formData.title}" has been saved as draft.`, + duration: 5000, + }); + onSubmit?.({ ...formData, backendId: editRequestId, @@ -145,14 +167,23 @@ export function useCreateRequestSubmission({ const result = await createWorkflow(createPayload, documents); + toast.success('Draft Saved Successfully!', { + description: `Your request "${formData.title}" has been saved as draft.`, + duration: 5000, + }); + onSubmit?.({ ...formData, backendId: result.id, template: selectedTemplate, }); } - } catch (error) { + } catch (error: any) { console.error('Failed to save draft:', error); + toast.error('Failed to Save Draft', { + description: error?.response?.data?.message || error?.message || 'An error occurred while saving the draft.', + duration: 5000, + }); setSavingDraft(false); } };