Skip to content

Commit

Permalink
fix: useProjectSettings refreshInterval to wait for service_api_keys …
Browse files Browse the repository at this point in the history
…data
  • Loading branch information
phamhieu committed Apr 19, 2022
1 parent f723d16 commit 00f88bb
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion studio/hooks/queries/useProjectSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@ import useSWR from 'swr'

export function useProjectSettings(ref?: string) {
const url = `${API_URL}/props/project/${ref}/settings`
const { data, error } = useSWR<any>(ref ? url : null, get)
const { data, error } = useSWR<any>(ref ? url : null, get, {
/**
* on project creation, the service_api_keys will be populated with a delay
* check for data.services.service_api_keys, return a valid refresh interval if it's empty
*/
refreshInterval: function (data: any) {
const apiService = (data?.services ?? []).find((x: any) => x.app.id == DEFAULT_API_SERVICE_ID)
const apiKeys = apiService?.service_api_keys ?? []
const interval = apiKeys.length === 0 ? 2000 : 0
return interval
},
})
const anyError = data?.error || error

return {
Expand All @@ -15,3 +26,5 @@ export function useProjectSettings(ref?: string) {
isError: !!anyError,
}
}

const DEFAULT_API_SERVICE_ID = 1

0 comments on commit 00f88bb

Please sign in to comment.