(orgSlug: string)
| 49 | } |
| 50 | |
| 51 | export function useOrganizationData(orgSlug: string) { |
| 52 | const { status } = useSession() |
| 53 | |
| 54 | // Query for organization details |
| 55 | const { |
| 56 | data: organization, |
| 57 | isLoading: isLoadingOrg, |
| 58 | error: orgError, |
| 59 | isError: isOrgError, |
| 60 | } = useQuery({ |
| 61 | queryKey: ['organization', orgSlug], |
| 62 | queryFn: () => fetchOrganizationBySlug(orgSlug), |
| 63 | enabled: status === 'authenticated' && !!orgSlug, |
| 64 | }) |
| 65 | |
| 66 | // Query for billing status (depends on organization data) |
| 67 | const { data: billingStatus, isLoading: isLoadingBilling } = useQuery({ |
| 68 | queryKey: ['billing-status', organization?.id], |
| 69 | queryFn: () => fetchBillingStatus(organization!.id), |
| 70 | enabled: !!organization?.id, |
| 71 | }) |
| 72 | |
| 73 | const isLoading = isLoadingOrg || isLoadingBilling |
| 74 | const error = isOrgError ? (orgError as Error)?.message : null |
| 75 | |
| 76 | return { |
| 77 | organization, |
| 78 | billingStatus, |
| 79 | isLoading, |
| 80 | error, |
| 81 | isLoadingOrg, |
| 82 | isLoadingBilling, |
| 83 | } |
| 84 | } |
no test coverage detected