draft toast added
This commit is contained in:
parent
164d576ea0
commit
22d3e8a388
@ -181,7 +181,14 @@ function AppRoutes({ onLogout }: AppProps) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Regular custom request submission
|
// If requestData has backendId, it means it came from the API flow (CreateRequest component)
|
||||||
|
// The hook already shows the toast, so we just navigate
|
||||||
|
if (requestData.backendId) {
|
||||||
|
navigate('/my-requests');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Regular custom request submission (old flow without API)
|
||||||
// Generate unique ID for the new custom request
|
// 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')}`;
|
const requestId = `RE-REQ-2024-${String(Object.keys(CUSTOM_REQUEST_DATABASE).length + dynamicRequests.length + 1).padStart(3, '0')}`;
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
import { toast } from 'sonner';
|
||||||
import { FormData, RequestTemplate } from '@/hooks/useCreateRequestForm';
|
import { FormData, RequestTemplate } from '@/hooks/useCreateRequestForm';
|
||||||
import {
|
import {
|
||||||
buildCreatePayload,
|
buildCreatePayload,
|
||||||
@ -72,6 +73,12 @@ export function useCreateRequestSubmission({
|
|||||||
documentsToDelete
|
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?.({
|
onSubmit?.({
|
||||||
...formData,
|
...formData,
|
||||||
backendId: editRequestId,
|
backendId: editRequestId,
|
||||||
@ -87,14 +94,24 @@ export function useCreateRequestSubmission({
|
|||||||
|
|
||||||
const result = await createAndSubmitWorkflow(createPayload, documents);
|
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?.({
|
onSubmit?.({
|
||||||
...formData,
|
...formData,
|
||||||
backendId: result.id,
|
backendId: result.id,
|
||||||
template: selectedTemplate,
|
template: selectedTemplate,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error('Failed to submit workflow:', error);
|
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);
|
setSubmitting(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -130,6 +147,11 @@ export function useCreateRequestSubmission({
|
|||||||
documentsToDelete
|
documentsToDelete
|
||||||
);
|
);
|
||||||
|
|
||||||
|
toast.success('Draft Saved Successfully!', {
|
||||||
|
description: `Your request "${formData.title}" has been saved as draft.`,
|
||||||
|
duration: 5000,
|
||||||
|
});
|
||||||
|
|
||||||
onSubmit?.({
|
onSubmit?.({
|
||||||
...formData,
|
...formData,
|
||||||
backendId: editRequestId,
|
backendId: editRequestId,
|
||||||
@ -145,14 +167,23 @@ export function useCreateRequestSubmission({
|
|||||||
|
|
||||||
const result = await createWorkflow(createPayload, documents);
|
const result = await createWorkflow(createPayload, documents);
|
||||||
|
|
||||||
|
toast.success('Draft Saved Successfully!', {
|
||||||
|
description: `Your request "${formData.title}" has been saved as draft.`,
|
||||||
|
duration: 5000,
|
||||||
|
});
|
||||||
|
|
||||||
onSubmit?.({
|
onSubmit?.({
|
||||||
...formData,
|
...formData,
|
||||||
backendId: result.id,
|
backendId: result.id,
|
||||||
template: selectedTemplate,
|
template: selectedTemplate,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error('Failed to save draft:', error);
|
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);
|
setSavingDraft(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user