Files
supabase/apps/studio/components/layouts/ProjectLayout/OrganizationSettingsLayout.tsx
T
6d09404779 feat: add mfa enforcement toggle (#34307)
* feat: add mfa enforcement toggle

Allows toggling MFA enforcement on an organization level.

Depends on API change #22088

* fix: toggle and disable action for non-owner

* chore: disable for free plans

* chore: disable toggle for org MFA if current user doesn't have MFA enabled

* set initial state

* move org mfa to security page

* use zod resolver

* fix initial values

* useQueryClient in the organization-mfa-mutation

* chore: warn about losing access to mfa orgs

* Some refactors, fixes and improvements

* chore: feature flag mfa enforce page

* Tiny fix

* Leave comment

---------

Co-authored-by: Saxon Fletcher <saxonafletcher@gmail.com>
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2025-05-09 16:56:49 +02:00

99 lines
2.8 KiB
TypeScript

import Link from 'next/link'
import { PropsWithChildren } from 'react'
import { useParams } from 'common'
import { useIsNewLayoutEnabled } from 'components/interfaces/App/FeaturePreview/FeaturePreviewContext'
import { useCurrentPath } from 'hooks/misc/useCurrentPath'
import { useFlag } from 'hooks/ui/useFlag'
import { NavMenu, NavMenuItem } from 'ui'
import { ScaffoldContainerLegacy, ScaffoldTitle } from '../Scaffold'
function OrganizationSettingsLayout({ children }: PropsWithChildren) {
const { slug } = useParams()
const newLayoutPreview = useIsNewLayoutEnabled()
// [Joshen] RE Organization Settings - need to figure out how to enforce MFA across users before this goes live
const newSecurityPage = useFlag('showOrganizationSecuritySettings')
// Get the path without any hash values
const fullCurrentPath = useCurrentPath()
const [currentPath] = fullCurrentPath.split('#')
// hide these settings in the new layout
// when path equals `/org/${slug}/team`
// or `/org/${slug}/integrations`
// or `/org/${slug}/usage`
// make the function
const isHidden = (path: string) => {
return (
newLayoutPreview &&
(path === `/org/${slug}/team` ||
path === `/org/${slug}/integrations` ||
path === `/org/${slug}/usage` ||
path === `/org/${slug}/billing`)
)
}
if (isHidden(currentPath)) {
return children
}
const navMenuItems = [
{
label: 'General',
href: `/org/${slug}/general`,
},
newSecurityPage && {
label: 'Security',
href: `/org/${slug}/security`,
},
!newLayoutPreview && {
label: 'Team',
href: `/org/${slug}/team`,
},
!newLayoutPreview && {
label: 'Integrations',
href: `/org/${slug}/integrations`,
},
!newLayoutPreview && {
label: 'Billing',
href: `/org/${slug}/billing`,
},
!newLayoutPreview && {
label: 'Usage',
href: `/org/${slug}/usage`,
},
{
label: 'OAuth Apps',
href: `/org/${slug}/apps`,
},
{
label: 'Audit Logs',
href: `/org/${slug}/audit`,
},
{
label: 'Legal Documents',
href: `/org/${slug}/documents`,
},
]
return (
<>
<ScaffoldContainerLegacy className="mb-0">
<ScaffoldTitle>Organization Settings</ScaffoldTitle>
<NavMenu className="overflow-x-auto" aria-label="Organization menu navigation">
{(navMenuItems.filter(Boolean) as { label: string; href: string }[]).map((item) => (
<NavMenuItem key={item.label} active={currentPath === item.href}>
<Link href={item.href}>{item.label}</Link>
</NavMenuItem>
))}
</NavMenu>
</ScaffoldContainerLegacy>
<main className="h-full w-full overflow-y-auto">{children}</main>
</>
)
}
export default OrganizationSettingsLayout