Files
supabase/apps/studio/data/organizations/organization-customer-profile-query.ts
Alaister YoungandKevin Grüneberg 70da0f1d1d chore: cleanup packages (#27770)
* chore: cleanup packages

- Avoid circular imports
- Export API-types as types
- pg-format without depending on Node internal Buffer (not browser-compatible)
- Avoid importing from barrel files in ui dir

* chore: avoid barrel file imports in studio (#27771)

* chore: avoid barrel file imports

- Removes some unused imports
- Avoids barrel file import for faster builds + less memory

* add eslint rule

* type fixes

* delete layouts barrel

* delete components/grid barrel file

* delete components/grid/utils barrel file

* delete components/grid/components/common barrel file

* delete components/grid/components/editor barrel file

* delete components/grid/components/formatter barrel file

* delete components/grid/components/grid barrel file

* delete components/grid/components/header/filter barrel file

* remote components/grid/store barrel file

* remove components/interfaces/Auth/Policies barrel file

* delete components/interfaces/Settings/Logs barrel file

* delete components/ui/CodeEditor barrel file

* delete components/ui/Forms barrel file

* delete components/ui/Shimmers barrel file

* delete data/analytics barrel file

* delete hooks barrel file

* cleanup lib/common/fetch barrel file

* final * barral files cleanup

* global react-data-grid styles

* remove console.log

---------

Co-authored-by: Kevin Grüneberg <k.grueneberg1994@gmail.com>

* fix build

---------

Co-authored-by: Kevin Grüneberg <k.grueneberg1994@gmail.com>
2024-07-04 14:48:10 +08:00

60 lines
1.8 KiB
TypeScript

import { PermissionAction } from '@supabase/shared-types/out/constants'
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
import { get, handleError } from 'data/fetchers'
import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
import type { ResponseError } from 'types'
import { organizationKeys } from './keys'
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 canReadCustomerProfile = useCheckPermissions(
PermissionAction.BILLING_READ,
'stripe.customer'
)
return useQuery<OrganizationCustomerProfileData, OrganizationCustomerProfileError, TData>(
organizationKeys.customerProfile(slug),
({ signal }) => getOrganizationCustomerProfile({ slug }, signal),
{
enabled: enabled && canReadCustomerProfile && typeof slug !== 'undefined',
...options,
}
)
}