import { useState } from 'react'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Alert, AlertDescription } from '@/components/ui/alert'; import { supabase } from '@/lib/supabaseClient'; import { MapPin, AlertCircle, CheckCircle2 } from 'lucide-react'; import { useToast } from '@/hooks/use-toast'; export function ParkLocationBackfill() { const [isRunning, setIsRunning] = useState(false); const [result, setResult] = useState<{ success: boolean; parks_updated: number; locations_created: number; } | null>(null); const [error, setError] = useState(null); const { toast } = useToast(); const handleBackfill = async () => { setIsRunning(true); setError(null); setResult(null); try { const { data, error: invokeError } = await supabase.functions.invoke( 'backfill-park-locations' ); if (invokeError) throw invokeError; setResult(data); toast({ title: 'Backfill Complete', description: `Updated ${data.parks_updated} parks with ${data.locations_created} new locations`, }); } catch (err: any) { const errorMessage = err.message || 'Failed to run backfill'; setError(errorMessage); toast({ title: 'Backfill Failed', description: errorMessage, variant: 'destructive', }); } finally { setIsRunning(false); } }; return ( Park Location Backfill Backfill missing location data for approved parks from their submission data This tool will find parks without location data and populate them using the location information from their approved submissions. This is useful for fixing parks that were approved before the location creation fix was implemented. {result && (
Backfill completed successfully!
Parks updated: {result.parks_updated}
Locations created: {result.locations_created}
)} {error && ( {error} )}
); }