security.tsx 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { Smartphone } from 'lucide-react'
  2. import { Badge, cn, Collapsible, CollapsibleContent, CollapsibleTrigger } from 'ui'
  3. import { PageContainer } from 'ui-patterns/PageContainer'
  4. import {
  5. PageHeader,
  6. PageHeaderDescription,
  7. PageHeaderMeta,
  8. PageHeaderSummary,
  9. PageHeaderTitle,
  10. } from 'ui-patterns/PageHeader'
  11. import { TOTPFactors } from '@/components/interfaces/Account/TOTPFactors'
  12. import AccountLayout from '@/components/layouts/AccountLayout/AccountLayout'
  13. import { AppLayout } from '@/components/layouts/AppLayout/AppLayout'
  14. import { DefaultLayout } from '@/components/layouts/DefaultLayout'
  15. import { UnknownInterface } from '@/components/ui/UnknownInterface'
  16. import { useMfaListFactorsQuery } from '@/data/profile/mfa-list-factors-query'
  17. import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
  18. import type { NextPageWithLayout } from '@/types'
  19. const collapsibleClasses = [
  20. 'bg-surface-100',
  21. 'hover:bg-surface-200',
  22. 'data-open:bg-surface-200',
  23. 'border-default',
  24. 'hover:border-strong data-open:border-strong',
  25. 'data-open:pb-px col-span-12 rounded-sm',
  26. '-space-y-px overflow-hidden',
  27. 'border shadow-sm',
  28. 'transition',
  29. 'hover:z-50',
  30. ]
  31. const Security: NextPageWithLayout = () => {
  32. const showSecuritySettings = useIsFeatureEnabled('account:show_security_settings')
  33. const { data } = useMfaListFactorsQuery({ enabled: showSecuritySettings })
  34. if (!showSecuritySettings) {
  35. return <UnknownInterface urlBack={`/account/me`} />
  36. }
  37. return (
  38. <>
  39. <PageHeader size="small">
  40. <PageHeaderMeta>
  41. <PageHeaderSummary>
  42. <PageHeaderTitle>Security</PageHeaderTitle>
  43. <PageHeaderDescription>
  44. Manage your account security settings and authentication methods.
  45. </PageHeaderDescription>
  46. </PageHeaderSummary>
  47. </PageHeaderMeta>
  48. </PageHeader>
  49. <PageContainer size="small">
  50. <Collapsible className={cn('mt-8', collapsibleClasses)}>
  51. <CollapsibleTrigger asChild>
  52. <button
  53. type="button"
  54. className="group flex w-full items-center justify-between rounded-sm py-3 px-4 md:px-6 text-foreground"
  55. >
  56. <div className="flex flex-row gap-4 items-center py-1">
  57. <Smartphone strokeWidth={1.5} />
  58. <span className="text-sm">Authenticator app</span>
  59. </div>
  60. {data ? (
  61. <Badge variant={data.totp.length === 0 ? 'default' : 'success'}>
  62. {data.totp.length} app{data.totp.length === 1 ? '' : 's'} configured
  63. </Badge>
  64. ) : null}
  65. </button>
  66. </CollapsibleTrigger>
  67. <CollapsibleContent className="group border-t border-default bg-surface-100 py-6 px-4 md:px-6 text-foreground">
  68. <TOTPFactors />
  69. </CollapsibleContent>
  70. </Collapsible>
  71. </PageContainer>
  72. </>
  73. )
  74. }
  75. Security.getLayout = (page) => (
  76. <AppLayout>
  77. <DefaultLayout headerTitle="Account">
  78. <AccountLayout title="Security">{page}</AccountLayout>
  79. </DefaultLayout>
  80. </AppLayout>
  81. )
  82. export default Security