feat: Add park selection to RideForm

This commit is contained in:
gpt-engineer-app[bot]
2025-11-05 21:18:26 +00:00
parent 34300a89c4
commit 7476fbd5da
2 changed files with 139 additions and 3 deletions

View File

@@ -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 };
}