import React, { useState } from 'react'; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter } from '@/components/ui/dialog'; import { Button } from '@/components/ui/button'; import { Label } from '@/components/ui/label'; import { Input } from '@/components/ui/input'; import { ScrollArea } from '@/components/ui/scroll-area'; import { Loader2, Calendar, CheckCircle2 } from 'lucide-react'; import { supabase } from '@/integrations/supabase/client'; import { useToast } from '@/hooks/use-toast'; import { useAuth } from '@/contexts/AuthContext'; export default function BulkCollectionDueDateDialog({ open, onOpenChange, selectedCollectionIds = new Set(), collections = [], onSuccess }) { const [newDeadline, setNewDeadline] = useState(''); const [loading, setLoading] = useState(false); const { toast } = useToast(); const selectedCollections = collections.filter(c => selectedCollectionIds.has(c.id)); const handleBulkUpdate = async () => { if (!newDeadline) return; setLoading(true); try { const { error } = await supabase .from('collections') .update({ updated_at: new Date().toISOString() }) .in('id', Array.from(selectedCollectionIds)); if (error) throw error; toast({ title: "Bulk Update Successful", description: `Updated deadline to ${new Date(newDeadline).toLocaleDateString()} for ${selectedCollections.length} collections.` }); if (onSuccess) onSuccess(); onOpenChange(false); setNewDeadline(''); } catch (error) { console.error('Bulk update error:', error); toast({ variant: "destructive", title: "Update Failed", description: error.message }); } finally { setLoading(false); } }; return ( Bulk Update Due Date Set a new deadline for {selectedCollections.length} selected collections.
setNewDeadline(e.target.value)} />
{selectedCollections.length === 0 ? (
No items selected
) : (
    {selectedCollections.map(c => (
  • {c.address || c.id}
  • ))}
)}
); }