mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 02:51:12 -05:00
33 lines
871 B
TypeScript
33 lines
871 B
TypeScript
/**
|
|
* Company Detail Hook
|
|
*
|
|
* Fetches company details with caching for efficient data access.
|
|
*/
|
|
|
|
import { useQuery } from '@tanstack/react-query';
|
|
import { supabase } from '@/integrations/supabase/client';
|
|
import { queryKeys } from '@/lib/queryKeys';
|
|
|
|
export function useCompanyDetail(slug: string | undefined, companyType: string) {
|
|
return useQuery({
|
|
queryKey: queryKeys.companies.detail(slug || '', companyType),
|
|
queryFn: async () => {
|
|
if (!slug) return null;
|
|
|
|
const { data, error } = await supabase
|
|
.from('companies')
|
|
.select('*')
|
|
.eq('slug', slug)
|
|
.eq('company_type', companyType)
|
|
.maybeSingle();
|
|
|
|
if (error) throw error;
|
|
return data;
|
|
},
|
|
enabled: !!slug,
|
|
staleTime: 5 * 60 * 1000, // 5 minutes
|
|
gcTime: 15 * 60 * 1000,
|
|
refetchOnWindowFocus: false,
|
|
});
|
|
}
|