Files
supabase/apps/studio/components/interfaces/UserDropdown.tsx
T
Joshen LimandAlaister Young 37b072aac2 Improve UI for org invites if MFA is enforced (#47067)
## Context

When opening an invite to join an organization that's enforced MFA for
their members, if a member does not have MFA enabled yet, they'll see
this UI which is confusing as there's no clear direction on what to do
<img width="500" alt="image"
src="https://github.com/user-attachments/assets/ca2d1047-20bf-40ca-a9ea-91e81c390e40"
/>

## Changes involved
- Updating the UI to consider this error message and prompt users to set
up MFA
<img width="501" height="317" alt="image"
src="https://github.com/user-attachments/assets/d074ac6d-fd74-4fe0-9078-473fd2401045"
/>
- Small UI nudges to account security page
  - Tight copywriting to explicitly say MFA
- Opt to use Card instead of Collapsible (collapsible seems unnecessary
given that this is the only UI on this page)
  - Before:
<img width="811" height="360" alt="image"
src="https://github.com/user-attachments/assets/1412da3b-3903-4966-85ea-46e0ff443177"
/>
  - After:
<img width="817" height="370" alt="image"
src="https://github.com/user-attachments/assets/02d5a2f5-8c1f-4f78-8a20-10c7a4ff563c"
/>
- Tiny change to the user dropdown, say "account" instead of "account
preferences" + change icon
- This imo aligns better as the account page covers more than just
preferences
  - Before:
<img width="307" height="178" alt="image"
src="https://github.com/user-attachments/assets/fea43cac-9b0c-4fe4-94a3-946ed0925901"
/>
  - After:
<img width="300" height="183" alt="image"
src="https://github.com/user-attachments/assets/800357fe-222f-49b8-b52b-ce4fabff7b95"
/>

## To test
- [ ] Have an organization on paid plan with MFA enforced
- [ ] Invite a user that doesn't have MFA enabled
- [ ] Try to join the organization with that user

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Organization invites now detect and handle MFA requirements with
specific error messaging
* Redesigned Multi-factor authentication section on account security
page

* **Improvements**
  * Updated TOTP authenticator help text for clarity
  * Updated account menu navigation label

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Alaister Young <alaister@users.noreply.github.com>
2026-06-18 18:50:40 +08:00

206 lines
7.2 KiB
TypeScript

import { useFlag } from 'common'
import { FlaskConical, Loader2, ScrollText, User2 } from 'lucide-react'
import { useTheme } from 'next-themes'
import Link from 'next/link'
import { useRouter } from 'next/router'
import { useState } from 'react'
import {
cn,
DropdownMenu,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
singleThemes,
Theme,
} from 'ui'
import { ButtonTooltip } from '../ui/ButtonTooltip'
import { useFeaturePreviewModal } from './App/FeaturePreview/FeaturePreviewContext'
import { TimezoneDropdown } from './UserDropdown/TimezoneDropdown'
import { ProfileImage } from '@/components/ui/ProfileImage'
import { UpgradePlanButton } from '@/components/ui/UpgradePlanButton'
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
import { useUpgradeCtaExperiment } from '@/hooks/misc/useUpgradeCtaExperiment'
import { IS_PLATFORM } from '@/lib/constants'
import { useProfileNameAndPicture } from '@/lib/profile'
import { useTrack } from '@/lib/telemetry/track'
import { useAppStateSnapshot } from '@/state/app-state'
export function UserDropdown({
triggerClassName,
contentClassName,
}: {
triggerClassName?: string
contentClassName?: string
}) {
const router = useRouter()
const { theme, setTheme } = useTheme()
const appStateSnapshot = useAppStateSnapshot()
const profileShowEmailEnabled = useIsFeatureEnabled('profile:show_email')
const timezonePickerEnabled = useFlag('timezonePicker')
const { username, avatarUrl, primaryEmail, isLoading } = useProfileNameAndPicture()
const { toggleFeaturePreviewModal } = useFeaturePreviewModal()
const track = useTrack()
const { variant: upgradeCtaVariant } = useUpgradeCtaExperiment()
// Per Slack feedback (Jonny): the upgrade CTA is org-scoped, so only show it on routes
// where an org is in scope. Excludes /account/*, /organizations, /new, marketing routes, etc.
const isOrgScopedRoute =
router.pathname.startsWith('/project/') || router.pathname.startsWith('/org/')
const showUpgradeCta = upgradeCtaVariant === 'user_dropdown' && isOrgScopedRoute
const [isOpen, setIsOpen] = useState(false)
return (
<DropdownMenu
open={isOpen}
onOpenChange={(open) => {
setIsOpen(open)
if (open) track('header_user_dropdown_opened')
}}
>
<DropdownMenuTrigger asChild className={cn('border shrink-0 px-3', triggerClassName)}>
<ButtonTooltip
variant="default"
className="[&>span]:flex px-0 py-0 rounded-full overflow-hidden h-8 w-8"
tooltip={{ content: { text: 'Account settings' } }}
>
{isLoading ? (
<div className="w-full h-full flex items-center justify-center">
<Loader2 className="animate-spin text-foreground-lighter" size={16} />
</div>
) : (
<ProfileImage alt={username} src={avatarUrl} className="w-8 h-8 rounded-md" />
)}
</ButtonTooltip>
</DropdownMenuTrigger>
<DropdownMenuContent side="bottom" align="end" className={contentClassName}>
{IS_PLATFORM && (
<>
<div className="px-2 py-1 flex flex-col gap-0 text-sm">
{!!username ? (
<>
<span title={username} className="w-full text-left text-foreground truncate">
{username}
</span>
{primaryEmail !== username && profileShowEmailEnabled && (
<span
title={primaryEmail}
className="w-full text-left text-foreground-light text-xs truncate"
>
{primaryEmail}
</span>
)}
</>
) : (
<span title={primaryEmail} className="w-full text-left text-foreground truncate">
{primaryEmail}
</span>
)}
</div>
<DropdownMenuSeparator />
<DropdownMenuGroup>
<DropdownMenuItem className="flex gap-2 cursor-pointer" asChild>
<Link
href="/account/me"
onClick={() => {
if (router.pathname !== '/account/me') {
appStateSnapshot.setLastRouteBeforeVisitingAccountPage(router.asPath)
}
}}
>
<User2 size={14} strokeWidth={1.5} className="text-foreground-lighter" />
Account
</Link>
</DropdownMenuItem>
<DropdownMenuItem
className="flex gap-2 cursor-pointer"
onClick={() => toggleFeaturePreviewModal(true)}
>
<FlaskConical size={14} strokeWidth={1.5} className="text-foreground-lighter" />
Feature previews
</DropdownMenuItem>
<DropdownMenuItem className="flex gap-2 cursor-pointer" asChild>
<Link
href="https://supabase.com/changelog"
target="_blank"
rel="noopener noreferrer"
>
<ScrollText size={14} strokeWidth={1.5} className="text-foreground-lighter" />
Changelog
</Link>
</DropdownMenuItem>
<DropdownMenuSeparator />
</DropdownMenuGroup>
</>
)}
<DropdownMenuGroup>
<DropdownMenuLabel>Theme</DropdownMenuLabel>
<DropdownMenuRadioGroup
value={theme}
onValueChange={(value) => {
setTheme(value)
}}
>
{singleThemes.map((theme: Theme) => (
<DropdownMenuRadioItem
key={theme.value}
value={theme.value}
className="cursor-pointer"
>
{theme.name}
</DropdownMenuRadioItem>
))}
</DropdownMenuRadioGroup>
</DropdownMenuGroup>
{timezonePickerEnabled && (
<>
<DropdownMenuSeparator />
<DropdownMenuGroup>
<TimezoneDropdown />
</DropdownMenuGroup>
</>
)}
{showUpgradeCta && (
<>
<DropdownMenuSeparator />
<div className="p-1">
<UpgradePlanButton
source="user_dropdown"
plan="Pro"
className="w-full justify-center"
onClick={() => {
track('upgrade_cta_clicked', { placement: 'user_dropdown' })
setIsOpen(false)
}}
/>
</div>
</>
)}
{IS_PLATFORM && (
<>
<DropdownMenuSeparator />
<DropdownMenuGroup>
<DropdownMenuItem
className="cursor-pointer"
onSelect={() => {
router.push('/logout')
}}
>
Log out
</DropdownMenuItem>
</DropdownMenuGroup>
</>
)}
</DropdownMenuContent>
</DropdownMenu>
)
}