mirror of
https://github.com/supabase/supabase.git
synced 2026-07-06 09:44:25 +08:00
* chore: make a fake api to avoid showing error page * chore: use redirect to limit access to setting page * chore: revert change
67 lines
1.9 KiB
TypeScript
67 lines
1.9 KiB
TypeScript
import { useIsFeatureEnabled, useSelectedOrganization, useSelectedProject, withAuth } from 'hooks'
|
|
import { useRouter } from 'next/router'
|
|
import { PropsWithChildren, useEffect } from 'react'
|
|
import { generateSettingsMenu } from './SettingsMenu.utils'
|
|
|
|
import { useParams } from 'common'
|
|
import { ProductMenu } from 'components/ui/ProductMenu'
|
|
import { ProjectLayout } from '..'
|
|
import { IS_PLATFORM } from 'lib/constants'
|
|
|
|
interface SettingsLayoutProps {
|
|
title?: string
|
|
}
|
|
|
|
const SettingsLayout = ({ title, children }: PropsWithChildren<SettingsLayoutProps>) => {
|
|
const router = useRouter()
|
|
const { ref } = useParams()
|
|
const project = useSelectedProject()
|
|
const organization = useSelectedOrganization()
|
|
|
|
useEffect(() => {
|
|
if (!IS_PLATFORM) {
|
|
router.push('/project/default')
|
|
}
|
|
}, [router])
|
|
|
|
// billing pages live under /billing/invoices and /billing/subscription, etc
|
|
// so we need to pass the [5]th part of the url to the menu
|
|
const page = router.pathname.includes('billing')
|
|
? router.pathname.split('/')[5]
|
|
: router.pathname.split('/')[4]
|
|
|
|
const {
|
|
projectAuthAll: authEnabled,
|
|
projectEdgeFunctionAll: edgeFunctionsEnabled,
|
|
projectStorageAll: storageEnabled,
|
|
billingInvoices: invoicesEnabled,
|
|
} = useIsFeatureEnabled([
|
|
'project_auth:all',
|
|
'project_edge_function:all',
|
|
'project_storage:all',
|
|
'billing:invoices',
|
|
])
|
|
|
|
const menuRoutes = generateSettingsMenu(ref, project, organization, {
|
|
auth: authEnabled,
|
|
edgeFunctions: edgeFunctionsEnabled,
|
|
storage: storageEnabled,
|
|
invoices: invoicesEnabled,
|
|
})
|
|
|
|
return (
|
|
<ProjectLayout
|
|
isBlocking={false}
|
|
title={title || 'Settings'}
|
|
product="Settings"
|
|
productMenu={<ProductMenu page={page} menu={menuRoutes} />}
|
|
>
|
|
<main style={{ maxHeight: '100vh' }} className="flex-1 overflow-y-auto">
|
|
{children}
|
|
</main>
|
|
</ProjectLayout>
|
|
)
|
|
}
|
|
|
|
export default withAuth(SettingsLayout)
|