mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 18:11:12 -05:00
feat: Add park selection to RideForm
This commit is contained in:
@@ -301,4 +301,46 @@ export function usePropertyOwners() {
|
||||
}, []);
|
||||
|
||||
return { propertyOwners, loading };
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to fetch all parks for autocomplete
|
||||
* Returns parks as combobox options
|
||||
*/
|
||||
export function useParks() {
|
||||
const [parks, setParks] = useState<ComboboxOption[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchParks() {
|
||||
setLoading(true);
|
||||
try {
|
||||
const { data, error } = await supabase
|
||||
.from('parks')
|
||||
.select('id, name, slug')
|
||||
.order('name');
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
setParks(
|
||||
(data || []).map(park => ({
|
||||
label: park.name,
|
||||
value: park.id
|
||||
}))
|
||||
);
|
||||
} catch (error: unknown) {
|
||||
handleNonCriticalError(error, { action: 'Fetch parks' });
|
||||
toast.error('Failed to load parks', {
|
||||
description: 'Please refresh the page and try again.',
|
||||
});
|
||||
setParks([]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
fetchParks();
|
||||
}, []);
|
||||
|
||||
return { parks, loading };
|
||||
}
|
||||
Reference in New Issue
Block a user