Files
supabase/apps/studio/data/organizations/organization-customer-profile-query.ts
Jordi Enric 25abebc32e a new hope (#38893)
* a new hope

* run tests in ci against cli mode

* summary

* try vercel action to run e2e against studio self hosted preview

* believe

* debug

* gh pages artifact

* test

* rm pages step

* fix automation bypass missing

* continue on error

* only install necessary deps for CI

* fix bypass

* remove

* fail job if test fails

* disable customer query if is_platform false

* vercel check

* fix var name, make comment update instead

* check bypass on runtime

* add env var

* fix tests going to project ref instead of default

* fix

* better dates in comment

* Update E2E test workflow to include flaky test detection and improve summary output

* fix

* fix dumb mistake
2025-09-23 12:02:23 +02:00

61 lines
1.9 KiB
TypeScript

import { PermissionAction } from '@supabase/shared-types/out/constants'
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
import { get, handleError } from 'data/fetchers'
import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
import type { ResponseError } from 'types'
import { organizationKeys } from './keys'
import { IS_PLATFORM } from 'common'
export type OrganizationCustomerProfileVariables = {
slug?: string
}
export async function getOrganizationCustomerProfile(
{ slug }: OrganizationCustomerProfileVariables,
signal?: AbortSignal
) {
if (!slug) throw new Error('slug is required')
const { data, error } = await get(`/platform/organizations/{slug}/customer`, {
params: {
path: {
slug,
},
},
signal,
})
if (error) handleError(error)
return data
}
export type OrganizationCustomerProfileData = Awaited<
ReturnType<typeof getOrganizationCustomerProfile>
>
export type OrganizationCustomerProfileError = ResponseError
export const useOrganizationCustomerProfileQuery = <TData = OrganizationCustomerProfileData>(
{ slug }: OrganizationCustomerProfileVariables,
{
enabled = true,
...options
}: UseQueryOptions<OrganizationCustomerProfileData, OrganizationCustomerProfileError, TData> = {}
) => {
// [Joshen] Thinking it makes sense to add this check at the RQ level - prevent
// unnecessary requests, although this behaviour still needs handling on the UI
const { can: canReadCustomerProfile } = useAsyncCheckPermissions(
PermissionAction.BILLING_READ,
'stripe.customer'
)
return useQuery<OrganizationCustomerProfileData, OrganizationCustomerProfileError, TData>(
organizationKeys.customerProfile(slug),
({ signal }) => getOrganizationCustomerProfile({ slug }, signal),
{
enabled: IS_PLATFORM && enabled && canReadCustomerProfile && typeof slug !== 'undefined',
...options,
}
)
}