Skip to content

Commit

Permalink
fix: users with read access, but without project/read grant will no l…
Browse files Browse the repository at this point in the history
…onger get a missing plan feature dialog
  • Loading branch information
snorrees committed Oct 5, 2023
1 parent 2f00420 commit edcfa36
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/api/isEnabled.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import {useClient, useProjectId} from 'sanity'
import {useProjectId} from 'sanity'
import {createContext, PropsWithChildren, useContext, useEffect, useState} from 'react'
import {Card, Text} from '@sanity/ui'

const featureName = 'embeddingsIndexApi'
import {useApiClient} from './embeddingsApiHooks'

export type FeatureStatus = 'enabled' | 'disabled' | 'loading'
export const FeatureEnabledContext = createContext<FeatureStatus>('loading')

export function useIsFeatureEnabled() {
const client = useClient({apiVersion: '2023-09-01'})
const client = useApiClient()
const [status, setStatus] = useState<FeatureStatus>('loading')

useEffect(() => {
client
.request<string | boolean>({
.request<{enabled: boolean}>({
method: 'GET',
url: `/projects/${client.config().projectId}/features/${featureName}`,
url: `/embeddings-index/status`,
})
.then((isEnabled) => {
setStatus(isEnabled === 'true' || isEnabled === true ? 'enabled' : 'disabled')
.then((response) => {
setStatus(response.enabled ? 'enabled' : 'disabled')
})
.catch((err) => {
console.error(err)
Expand Down

0 comments on commit edcfa36

Please sign in to comment.