import React, { useId } from 'react' import { User, Save, Lock, KeyRound, AlertTriangle, Shield, Camera, Trash2, Copy, Download, Printer, ShieldCheck, Smartphone } from 'lucide-react' import { useTranslation } from '../../i18n' import Section from './Section' import PasskeysSection from './PasskeysSection' import NativeServerSection from './NativeServerSection' import PasswordChecklist from '../shared/PasswordChecklist' import ConfirmDialog from '../shared/ConfirmDialog' import { Tooltip } from '../shared/Tooltip' import { DialogButton, DialogFooter, DialogHeader, DialogShell, DialogTile, FooterSpacer, NEUTRAL_TINT, fs } from '../shared/DialogShell' import { EditorField, GRID_2, INPUT, PANEL } from '../shared/dialogParts' import { SETTINGS_BUTTON, SETTINGS_BUTTON_DANGER, SETTINGS_BUTTON_PRIMARY, SettingRow, SettingRows, SettingsHint, StatusPill, SettingsColumns } from './settingsKit' import { stripTrailingSlashes, useAccountSettings } from './useAccountSettings' import AccountDemoLock from './AccountDemoLock' import AppStoreCards from '../shared/AppStoreCards' import { isNativeApp } from '../../native/platform' /** The small turning ring a button shows while its request is on the way. */ const SPINNER = 'h-3.5 w-3.5 flex-none animate-spin rounded-full border-2 border-current border-t-transparent' /** The eyebrow over a block inside a card body. */ const EYEBROW = 'm-0 font-geist font-bold uppercase tracking-[.08em] text-content-faint' export default function AccountTab(): React.ReactElement { const { t } = useTranslation() const blockedLabelId = useId() const { user, demoMode, avatarInputRef, saving, showDeleteConfirm, setShowDeleteConfirm, username, setUsername, email, setEmail, currentPassword, setCurrentPassword, newPassword, setNewPassword, confirmPassword, setConfirmPassword, oidcOnlyMode, mfaQr, mfaSecret, mfaSetupCode, setMfaSetupCode, mfaDisablePwd, setMfaDisablePwd, mfaDisableCode, setMfaDisableCode, mfaLoading, backupCodes, backupCodesText, mfaRequiredByPolicy, oidcIssuer, dismissBackupCodes, copyBackupCodes, downloadBackupCodes, printBackupCodes, handleAvatarUpload, handleAvatarRemove, saveProfile, changePassword, startMfaSetup, cancelMfaSetup, enableMfa, disableMfa, requestDelete, deleteAccount, } = useAccountSettings({ avatarRemoveErrorKey: 'settings.avatarError', ignoreEmptyBackupCodes: true }) return ( <> {/* The shared demo account: everything here is shown, nothing can be changed. */} {/* Two columns by length: who you are and the second factor on the left, the password and passkeys on the right. */}
{/* Who is signed in: the picture with its two actions, the role and the SSO link. */}
{user?.avatar_url ? ( ) : (
{user?.username?.charAt(0).toUpperCase()}
)} {user?.avatar_url && ( )}
{user?.username}
{user?.role === 'admin' ? }>{t('settings.roleAdmin')} : {t('settings.roleUser')}} {oidcIssuer && SSO}
{oidcIssuer && (

{t('settings.oidcLinked')} {stripTrailingSlashes(oidcIssuer.replace('https://', ''))}

)}
setUsername(e.target.value)} className={INPUT} /> setEmail(e.target.value)} className={INPUT} />
{/* The card's foot: the way out on the left, the save on the right, like a dialog's bar. */}
{/* MFA */}
{mfaRequiredByPolicy && (

{t('settings.mfa.requiredByPolicy')}

)} {t('settings.mfa.description')} <> {mfaLoading ? : } {t('settings.mfa.setup')} ) : user?.mfa_enabled ? ( ) : undefined} /> {!user?.mfa_enabled && mfaQr && (
{t('settings.mfa.scanQr')}
{/* A QR code needs its light quiet zone in either theme to scan. */}
{mfaSecret} setMfaSetupCode(e.target.value.replace(/\D/g, '').slice(0, 8))} placeholder={t('settings.mfa.codePlaceholder')} className={`${INPUT} font-geist tabular-nums tracking-[.2em]`} />
)} {user?.mfa_enabled && (

{t('settings.mfa.disableTitle')}

{t('settings.mfa.disableHint')}
setMfaDisablePwd(e.target.value)} placeholder={t('settings.currentPassword')} aria-label={t('settings.currentPassword')} className={INPUT} /> setMfaDisableCode(e.target.value.replace(/[^a-zA-Z0-9-]/g, '').slice(0, 12))} placeholder={t('settings.mfa.codePlaceholder')} aria-label={t('settings.mfa.codePlaceholder')} className={`${INPUT} font-geist tabular-nums`} />
)} {backupCodes && backupCodes.length > 0 && (

{t('settings.mfa.backupTitle')}

{t('settings.mfa.backupDescription')}
{backupCodesText}

{t('settings.mfa.backupWarning')}

)}
} end={<> {/* Change Password */} {!oidcOnlyMode && (
setCurrentPassword(e.target.value)} placeholder={t('settings.currentPassword')} className={INPUT} />
setNewPassword(e.target.value)} placeholder={t('settings.newPassword')} className={INPUT} /> setConfirmPassword(e.target.value)} placeholder={t('settings.confirmPassword')} className={INPUT} />
)} {/* Passkeys */} {/* Where to get the phone app; inside the app itself there is nothing to fetch. */} {!isNativeApp() && (
)} } />
{/* Delete Account Blocked */} setShowDeleteConfirm(false)} labelledBy={blockedLabelId} width="narrow" header={( } tint={NEUTRAL_TINT} labelId={blockedLabelId} onClose={() => setShowDeleteConfirm(false)} title={t('settings.deleteBlockedTitle')} /> )} footer={( setShowDeleteConfirm(false)}> {t('common.ok') || 'OK'} )} >

{t('settings.deleteBlockedMessage')}

{/* Delete Account Confirm */} setShowDeleteConfirm(false)} onConfirm={deleteAccount} title={t('settings.deleteAccountTitle')} message={t('settings.deleteAccountWarning')} confirmLabel={t('settings.deleteAccountConfirm')} danger /> ) }