'use client' /** * This Source Code is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * Copyright (c) Infonomic Company Limited */ /** * Self-service account container. * * Same drawer pattern as `admin-users/ui/container.tsx` but * narrower: only Profile and Password sections (no Roles, no * Delete) — those are admin-only actions on someone else, not * self-service. Each card surfaces the read-only summary plus an * "Edit" affordance that opens the matching drawer. * * Forms lift the fresh `AccountResponse` back into local state on * success so the container's bumped `vid` is in hand for any * subsequent edit without a refetch. * * Stable override handles: see `container.module.css`. */ import type React from 'react' import { useState } from 'react' import { LocalDateTime } from '@byline/admin/react' import { useTranslation } from '@byline/i18n/react' import { CloseIcon, Drawer, EditIcon, IconButton } from '@byline/ui/react' import cx from 'clsx' import { ChangeAccountPassword } from './change-password.js' import styles from './container.module.css' import { Preferences } from './preferences.js' import { ThemeSwitch } from './theme-switch.js' import { UpdateAccount } from './update.js' import type { AccountResponse } from '../index.js' type ComponentKey = 'update' | 'change_password' | 'preferences' | 'empty' interface PanelProps { account: AccountResponse onClose?: () => void onSuccess?: (account: AccountResponse) => void } const panelComponents: Record> = { update: UpdateAccount, change_password: ChangeAccountPassword, preferences: Preferences, empty: () => null, } function ContainerSection({ title, onEdit, editAriaLabel, children, }: { title: string onEdit?: () => void editAriaLabel?: string children: React.ReactNode }) { return (

{title}

{onEdit ? ( ) : null}
{children}
) } interface AccountSelfContainerProps { account: AccountResponse } export function AccountSelfContainer({ account }: AccountSelfContainerProps) { const { t } = useTranslation('byline-admin') const [currentAccount, setCurrentAccount] = useState(account) const [current, setCurrent] = useState('empty') const [isDrawerOpen, setIsDrawerOpen] = useState(false) const openDrawer = (key: ComponentKey) => () => { setCurrent(key) setIsDrawerOpen(true) } const closeDrawer = () => { setCurrent('empty') setIsDrawerOpen(false) } const handleSuccess = (updated: AccountResponse) => { setCurrentAccount(updated) } const Panel = panelComponents[current] const panelTitles: Record = { update: t('account.sections.profile'), change_password: t('account.sections.password'), preferences: t('account.sections.preferences'), empty: '', } const editAriaFor = (section: string) => t('account.editAriaLabel', { section }) return ( <>

{t('account.profile.emailColon')}{' '} {currentAccount.email}

{t('account.profile.givenName')}{' '} {currentAccount.given_name ?? ( {t('common.notSet')} )}

{t('account.profile.familyName')}{' '} {currentAccount.family_name ?? ( {t('common.notSet')} )}

{t('account.profile.username')}{' '} {currentAccount.username ?? ( {t('common.notSet')} )}

{t('account.profile.created')} 

{t('account.profile.updated')} 

{t('account.profile.lastLogin')} 

{t('account.preferences.interfaceLanguage')}{' '} {currentAccount.preferred_locale ?? ( {t('language.useBrowserDefault')} )}

{t('account.preferences.help')}

{t('account.password.intro')}

{t('account.status.superAdmin')}{' '} {currentAccount.is_super_admin ? t('common.boolean.yes') : t('common.boolean.no')}

{t('account.status.emailVerified')}{' '} {currentAccount.is_email_verified ? t('common.boolean.yes') : t('common.boolean.no')}

{t('account.status.status')}{' '} {currentAccount.is_enabled ? t('account.status.enabled') : t('account.status.disabled')}

{t('account.status.help')}

{panelTitles[current]}

) }