fix: useProjectSettings refreshInterval to wait for service_api_keys data

This commit is contained in:
phamhieu committed 2022-04-19 12:19:52 +07:00
1 parent f723d16589
commit 00f88bb69d
1 file changed
+14 -1
+14 -1
View File
@@ -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 {
@@ -15,3 +26,5 @@ export function useProjectSettings(ref?: string) {
isError: !!anyError,
}
}
const DEFAULT_API_SERVICE_ID = 1