From 7d3b6a9da267f2d76fff7ab939c4d235c182d7e6 Mon Sep 17 00:00:00 2001 From: laxmanhalaki Date: Wed, 31 Dec 2025 12:48:09 +0530 Subject: [PATCH] templates disabled for the dealer --- .../modals/TemplateSelectionModal.tsx | 75 ++++++++++++++----- .../ClaimManagementWizard.tsx | 71 ++++++++++++++++-- .../hooks/useCreateRequestHandlers.ts | 24 ++++-- 3 files changed, 143 insertions(+), 27 deletions(-) diff --git a/src/components/modals/TemplateSelectionModal.tsx b/src/components/modals/TemplateSelectionModal.tsx index 53206fd..8ffc419 100644 --- a/src/components/modals/TemplateSelectionModal.tsx +++ b/src/components/modals/TemplateSelectionModal.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import { Dialog, DialogContent, DialogDescription, DialogTitle } from '../ui/dialog'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '../ui/card'; import { Button } from '../ui/button'; @@ -8,14 +8,16 @@ import { Receipt, Package, ArrowRight, + ArrowLeft, Clock, CheckCircle, Target, - X, Sparkles, - Check + Check, + AlertCircle } from 'lucide-react'; import { motion, AnimatePresence } from 'framer-motion'; +import { TokenManager } from '../../utils/tokenManager'; interface TemplateSelectionModalProps { open: boolean; @@ -39,7 +41,8 @@ const AVAILABLE_TEMPLATES = [ 'Document verification', 'E-invoice generation', 'Credit note issuance' - ] + ], + disabled: false }, { id: 'vendor-payment', @@ -55,14 +58,32 @@ const AVAILABLE_TEMPLATES = [ 'Invoice verification', 'Multi-level approvals', 'Payment scheduling' - ] + ], + disabled: true, + comingSoon: true } ]; export function TemplateSelectionModal({ open, onClose, onSelectTemplate }: TemplateSelectionModalProps) { const [selectedTemplate, setSelectedTemplate] = useState(null); + const [isDealer, setIsDealer] = useState(false); + + // Check if user is a Dealer + useEffect(() => { + const userData = TokenManager.getUserData(); + setIsDealer(userData?.jobTitle === 'Dealer'); + }, []); const handleSelect = (templateId: string) => { + // Don't allow selection if user is a dealer + if (isDealer) { + return; + } + // Don't allow selection if template is disabled + const template = AVAILABLE_TEMPLATES.find(t => t.id === templateId); + if (template?.disabled) { + return; + } setSelectedTemplate(templateId); }; @@ -84,12 +105,13 @@ export function TemplateSelectionModal({ open, onClose, onSelectTemplate }: Temp Choose from pre-configured templates with predefined workflows and approval chains for faster processing. - {/* Custom Close button */} + {/* Back arrow button - Top left */} {/* Full Screen Content Container */} @@ -117,6 +139,7 @@ export function TemplateSelectionModal({ open, onClose, onSelectTemplate }: Temp {AVAILABLE_TEMPLATES.map((template, index) => { const Icon = template.icon; const isSelected = selectedTemplate === template.id; + const isDisabled = isDealer || template.disabled; return ( handleSelect(template.id)} > @@ -157,6 +182,22 @@ export function TemplateSelectionModal({ open, onClose, onSelectTemplate }: Temp {template.description} + {isDealer && ( +
+ +

+ Not accessible for Dealers +

+
+ )} + {template.comingSoon && !isDealer && ( +
+ +

+ Coming Soon +

+
+ )} @@ -219,12 +260,12 @@ export function TemplateSelectionModal({ open, onClose, onSelectTemplate }: Temp )} diff --git a/src/pages/CreateRequest/hooks/useCreateRequestHandlers.ts b/src/pages/CreateRequest/hooks/useCreateRequestHandlers.ts index 16df1c9..257bce5 100644 --- a/src/pages/CreateRequest/hooks/useCreateRequestHandlers.ts +++ b/src/pages/CreateRequest/hooks/useCreateRequestHandlers.ts @@ -8,6 +8,7 @@ */ import { useState } from 'react'; +import { useNavigate } from 'react-router-dom'; import { RequestTemplate, FormData } from '@/hooks/useCreateRequestForm'; import { PreviewDocument } from '../types/createRequest.types'; import { getDocumentPreviewUrl } from '@/services/workflowApi'; @@ -44,6 +45,7 @@ export function useCreateRequestHandlers({ openValidationModal, onSubmit, }: UseHandlersOptions) { + const navigate = useNavigate(); const [showTemplateModal, setShowTemplateModal] = useState(false); const [previewDocument, setPreviewDocument] = useState(null); @@ -58,14 +60,19 @@ export function useCreateRequestHandlers({ const suggestedDate = new Date(); suggestedDate.setDate(suggestedDate.getDate() + template.suggestedSLA); updateFormData('slaEndDate', suggestedDate); - - if (template.id === 'existing-template') { - setShowTemplateModal(true); - } + + // Note: For 'existing-template', the modal will open when Next is clicked (handled in nextStep) }; const handleTemplateSelection = (templateId: string) => { - if (onSubmit) { + // Navigate directly to the template-specific route when template is selected from modal + if (templateId === 'claim-management') { + navigate('/claim-management'); + } else if (templateId === 'vendor-payment') { + // Add vendor-payment route if it exists, otherwise fallback to onSubmit + navigate('/vendor-payment'); + } else if (onSubmit) { + // Fallback to onSubmit for other template types onSubmit({ templateType: templateId }); } }; @@ -74,6 +81,12 @@ export function useCreateRequestHandlers({ const nextStep = async () => { if (!isStepValid()) return; + // On step 1, if "existing-template" is selected, open the template selection modal + if (currentStep === 1 && _selectedTemplate?.id === 'existing-template') { + setShowTemplateModal(true); + return; + } + if (window.innerWidth < 640) { window.scrollTo({ top: 0, behavior: 'smooth' }); } @@ -142,6 +155,7 @@ export function useCreateRequestHandlers({ setPreviewDocument(null); }; + return { showTemplateModal, setShowTemplateModal,