import React from 'react'; import { useSelector } from 'react-redux'; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { Button } from '@/components/ui/button'; import { Label } from '@/components/ui/label'; import { Checkbox } from '@/components/ui/checkbox'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { RootState } from '@/store'; interface DDLeadDialogProps { isOpen: boolean; onOpenChange: (open: boolean) => void; editingLeadId: string | null; leadManagerId: string; setLeadManagerId: (id: string) => void; leadStatus: 'active' | 'inactive'; setLeadStatus: (status: 'active' | 'inactive') => void; selectedZones: string[]; setSelectedZones: (zones: string[]) => void; onSave: () => void; userAssignedData: any[]; // All users to pick from } export const DDLeadDialog: React.FC = ({ isOpen, onOpenChange, editingLeadId, leadManagerId, setLeadManagerId, leadStatus, setLeadStatus, selectedZones, setSelectedZones, onSave, userAssignedData }) => { const { zones } = useSelector((state: RootState) => state.master); // Filter users that have DD-related roles or are already DD-Leads const filteredLeadUsers = userAssignedData.filter(u => { const roles = u.allRoles || []; return roles.some((r: string) => { const roleStr = (r || '').toUpperCase(); return ['DD-ZM', 'ZM', 'ZBH', 'ZONE BUSINESS HEAD', 'DD LEAD', 'DD_LEAD'].includes(roleStr) || roleStr.includes('ZONAL') || roleStr.includes('LEAD'); }); }); const toggleZone = (zoneId: string) => { if (selectedZones.includes(zoneId)) { setSelectedZones(selectedZones.filter(id => id !== zoneId)); } else { setSelectedZones([...selectedZones, zoneId]); } }; return ( {editingLeadId ? 'Edit' : 'Add'} DD Lead Assign a user to the DD Lead role and map them to Zones.
{zones.map((zone) => (
toggleZone(zone.id)} />
))}
); };