import { InboxOutlined, ReloadOutlined, SettingOutlined } from '@ant-design/icons'; import { Alert, Button, Card, Descriptions, List, Skeleton, Space, Table, Tag, Typography } from 'antd'; import type { ColumnsType } from 'antd/es/table'; import { useCallback, useEffect, useMemo, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { EmptyState } from '../components/common/EmptyState'; import { PageHeader } from '../components/common/PageHeader'; import { SectionCard } from '../components/common/SectionCard'; import { MailboxPermissionTags } from '../components/mailbox/MailboxPermissionTags'; import { useAppContext } from '../frontend/app-context'; import { useI18n } from '../frontend/i18n/react'; import { api } from '../frontend/services/api'; import type { InboundMailbox, MailboxAccess } from '../frontend/types'; import { useMediaQuery } from '../frontend/use-media-query'; export default function Account() { const { user } = useAppContext(); const { t } = useI18n(); const navigate = useNavigate(); const isTableView = useMediaQuery('(min-width: 768px)'); const [mailboxes, setMailboxes] = useState([]); const [loading, setLoading] = useState(true); const [loadError, setLoadError] = useState(''); const loadMailboxes = useCallback(async () => { setLoading(true); setLoadError(''); try { const result = await api.inboundMailboxes('effective'); setMailboxes(result.mailboxes || []); } catch (error) { setLoadError(error instanceof Error ? error.message : t('common.error')); } finally { setLoading(false); } }, [t]); useEffect(() => { void loadMailboxes(); }, [loadMailboxes]); const counts = useMemo(() => ({ owned: mailboxes.filter((mailbox) => mailboxAccess(mailbox).type === 'owner').length, assigned: mailboxes.filter((mailbox) => mailboxAccess(mailbox).type === 'assigned').length }), [mailboxes]); function openInbox(mailbox: InboundMailbox) { navigate(`/inbox?mailboxId=${mailbox.id}&folder=INBOX`); } function manageMailbox(mailbox: InboundMailbox) { navigate(`/inbox?workspace=routing&mailboxId=${mailbox.id}`); } const columns: ColumnsType = [ { title: t('inbox.mailboxAddress'), render: (_, mailbox) => ( {mailbox.address} {mailbox.displayName ? {mailbox.displayName} : null} ) }, { title: t('account.accessSource'), width: 160, render: (_, mailbox) => }, { title: t('account.permissions'), width: 280, render: (_, mailbox) => }, { title: t('common.actions'), width: 250, render: (_, mailbox) => ( {mailboxAccess(mailbox).permissions.receive ? ( ) : null} {mailboxAccess(mailbox).type === 'owner' ? ( ) : null} ) } ]; return ( {user?.username || '—'} {user?.email || '—'} {user?.role || '—'} {user?.status || '—'} {loadError ? ( } onClick={() => void loadMailboxes()}>{t('common.refresh')}} /> ) : null} {t('account.owned')} {counts.owned}{t('account.assigned')} {counts.assigned}} > {loading && !mailboxes.length ? : mailboxes.length ? ( isTableView ? ( ) : ( ( {mailboxAccess(mailbox).permissions.receive ? ( ) : null} {mailboxAccess(mailbox).type === 'owner' ? ( ) : null} )} /> ) ) : navigate('/inbox?workspace=routing')}>{t('inbox.createMailbox')}} />} ); } function AccessSource({ mailbox }: { mailbox: InboundMailbox }) { const { t } = useI18n(); const access = mailboxAccess(mailbox); if (access.type === 'owner') return {t('account.ownedMailbox')}; if (access.type === 'admin') return {t('account.adminAccess')}; return {t('account.adminAssigned')}; } function mailboxAccess(mailbox: InboundMailbox): MailboxAccess { return mailbox.access || { type: 'owner', permissions: { view: true, receive: true, send: true } }; }