Files
supabase/apps/studio/components/layouts/StorageLayout/StorageLayout.tsx
Joshen Lim 6b741bc964 Replace ui setnotification with toast midway (#21867)
Replace ui setnotification with toast
2024-03-08 15:46:52 +08:00

57 lines
1.7 KiB
TypeScript

import { useParams } from 'common'
import { ReactNode, useEffect } from 'react'
import toast from 'react-hot-toast'
import { AutoApiService, useProjectApiQuery } from 'data/config/project-api-query'
import { useSelectedProject, withAuth } from 'hooks'
import { PROJECT_STATUS } from 'lib/constants'
import { useStorageStore } from 'localStores/storageExplorer/StorageExplorerStore'
import { ProjectLayout } from '../'
import StorageMenu from './StorageMenu'
export interface StorageLayoutProps {
title: string
children: ReactNode
}
const StorageLayout = ({ title, children }: StorageLayoutProps) => {
const { ref: projectRef } = useParams()
const project = useSelectedProject()
const storageExplorerStore = useStorageStore()
const { data: settings, isLoading } = useProjectApiQuery({ projectRef })
const apiService = settings?.autoApiService
const isPaused = project?.status === PROJECT_STATUS.INACTIVE
useEffect(() => {
if (!isLoading && apiService) initializeStorageStore(apiService)
}, [isLoading, projectRef])
const initializeStorageStore = async (apiService: AutoApiService) => {
if (isPaused) return
if (apiService.endpoint) {
storageExplorerStore.initStore(
projectRef,
apiService.endpoint,
apiService.serviceApiKey,
apiService.protocol
)
} else {
toast.error(
'Failed to fetch project configuration. Try refreshing your browser, or reach out to us at support@supabase.io'
)
}
storageExplorerStore.setLoaded(true)
}
return (
<ProjectLayout title={title || 'Storage'} product="Storage" productMenu={<StorageMenu />}>
{children}
</ProjectLayout>
)
}
export default withAuth(StorageLayout)