mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 20:51:12 -05:00
feat: Add park operators and owners to form
This commit is contained in:
@@ -200,4 +200,76 @@ export function useCompanyHeadquarters() {
|
||||
}, []);
|
||||
|
||||
return { headquarters, loading };
|
||||
}
|
||||
|
||||
export function useOperators() {
|
||||
const [operators, setOperators] = useState<ComboboxOption[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchOperators() {
|
||||
setLoading(true);
|
||||
try {
|
||||
const { data, error } = await supabase
|
||||
.from('companies')
|
||||
.select('id, name')
|
||||
.eq('company_type', 'operator')
|
||||
.order('name');
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
setOperators(
|
||||
(data || []).map(company => ({
|
||||
label: company.name,
|
||||
value: company.id
|
||||
}))
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('Error fetching operators:', error);
|
||||
setOperators([]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
fetchOperators();
|
||||
}, []);
|
||||
|
||||
return { operators, loading };
|
||||
}
|
||||
|
||||
export function usePropertyOwners() {
|
||||
const [propertyOwners, setPropertyOwners] = useState<ComboboxOption[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchPropertyOwners() {
|
||||
setLoading(true);
|
||||
try {
|
||||
const { data, error } = await supabase
|
||||
.from('companies')
|
||||
.select('id, name')
|
||||
.eq('company_type', 'property_owner')
|
||||
.order('name');
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
setPropertyOwners(
|
||||
(data || []).map(company => ({
|
||||
label: company.name,
|
||||
value: company.id
|
||||
}))
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('Error fetching property owners:', error);
|
||||
setPropertyOwners([]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
fetchPropertyOwners();
|
||||
}, []);
|
||||
|
||||
return { propertyOwners, loading };
|
||||
}
|
||||
Reference in New Issue
Block a user