import React, { useState } from 'react'; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '../ui/dialog'; import { Button } from '../ui/button'; import { Input } from '../ui/input'; import { Label } from '../ui/label'; import { Textarea } from '../ui/textarea'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select'; import { Badge } from '../ui/badge'; import { Avatar, AvatarFallback } from '../ui/avatar'; import { Progress } from '../ui/progress'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '../ui/card'; import { Switch } from '../ui/switch'; import { Calendar } from '../ui/calendar'; import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover'; import { ArrowLeft, ArrowRight, Calendar as CalendarIcon, Upload, X, User, Clock, FileText, Check, Users } from 'lucide-react'; import { format } from 'date-fns'; interface NewRequestModalProps { open: boolean; onClose: () => void; onSubmit?: (requestData: any) => void; } export function NewRequestModal({ open, onClose, onSubmit }: NewRequestModalProps) { const [currentStep, setCurrentStep] = useState(1); const [formData, setFormData] = useState({ title: '', description: '', priority: '', slaEndDate: undefined as Date | undefined, approvers: [] as any[], workflowType: 'sequential', spectators: [] as any[], documents: [] as File[] }); const totalSteps = 5; // Mock users for selection const availableUsers = [ { id: '1', name: 'Mike Johnson', role: 'Team Lead', avatar: 'MJ' }, { id: '2', name: 'Lisa Wong', role: 'Finance Manager', avatar: 'LW' }, { id: '3', name: 'David Kumar', role: 'Department Head', avatar: 'DK' }, { id: '4', name: 'Anna Smith', role: 'Marketing Coordinator', avatar: 'AS' }, { id: '5', name: 'John Doe', role: 'Budget Analyst', avatar: 'JD' } ]; const updateFormData = (field: string, value: any) => { setFormData(prev => ({ ...prev, [field]: value })); }; const addApprover = (user: any) => { if (!formData.approvers.find(a => a.id === user.id)) { updateFormData('approvers', [...formData.approvers, user]); } }; const removeApprover = (userId: string) => { updateFormData('approvers', formData.approvers.filter(a => a.id !== userId)); }; const addSpectator = (user: any) => { if (!formData.spectators.find(s => s.id === user.id)) { updateFormData('spectators', [...formData.spectators, user]); } }; const removeSpectator = (userId: string) => { updateFormData('spectators', formData.spectators.filter(s => s.id !== userId)); }; const handleFileUpload = (event: React.ChangeEvent) => { const files = Array.from(event.target.files || []); updateFormData('documents', [...formData.documents, ...files]); }; const removeDocument = (index: number) => { const newDocs = formData.documents.filter((_, i) => i !== index); updateFormData('documents', newDocs); }; const isStepValid = () => { switch (currentStep) { case 1: return formData.title && formData.description && formData.priority && formData.slaEndDate; case 2: return formData.approvers.length > 0; case 3: return true; // Spectators are optional case 4: return true; // Documents are optional case 5: return true; // Review step default: return false; } }; const nextStep = () => { if (currentStep < totalSteps && isStepValid()) { setCurrentStep(currentStep + 1); } }; const prevStep = () => { if (currentStep > 1) { setCurrentStep(currentStep - 1); } }; const handleSubmit = () => { if (isStepValid()) { onSubmit?.(formData); onClose(); // Reset form setCurrentStep(1); setFormData({ title: '', description: '', priority: '', slaEndDate: undefined, approvers: [], workflowType: 'sequential', spectators: [], documents: [] }); } }; const renderStepContent = () => { switch (currentStep) { case 1: return (
updateFormData('title', e.target.value)} />