Files
ds2api/webui/src/features/account/AccountManagerContainer.jsx

150 lines
4.9 KiB
JavaScript

import { useI18n } from '../../i18n'
import { useAccountsData } from './useAccountsData'
import { useAccountActions } from './useAccountActions'
import QueueCards from './QueueCards'
import ApiKeysPanel from './ApiKeysPanel'
import AccountsTable from './AccountsTable'
import AddKeyModal from './AddKeyModal'
import AddAccountModal from './AddAccountModal'
export default function AccountManagerContainer({ config, onRefresh, onMessage, authFetch }) {
const { t } = useI18n()
const apiFetch = authFetch || fetch
const {
queueStatus,
keysExpanded,
setKeysExpanded,
accounts,
page,
pageSize,
totalPages,
totalAccounts,
loadingAccounts,
fetchAccounts,
changePageSize,
resolveAccountIdentifier,
searchQuery,
handleSearchChange,
} = useAccountsData({ apiFetch })
const {
showAddKey,
setShowAddKey,
showAddAccount,
setShowAddAccount,
newKey,
setNewKey,
copiedKey,
setCopiedKey,
newAccount,
setNewAccount,
loading,
testing,
testingAll,
batchProgress,
sessionCounts,
deletingSessions,
addKey,
deleteKey,
addAccount,
deleteAccount,
testAccount,
testAllAccounts,
deleteAllSessions,
} = useAccountActions({
apiFetch,
t,
onMessage,
onRefresh,
config,
fetchAccounts,
resolveAccountIdentifier,
})
return (
<div className="space-y-6">
{Boolean(config?.env_source_present) && (
<div className={`rounded-xl border px-4 py-3 text-sm ${
config?.env_writeback_enabled
? (config?.env_backed ? 'border-amber-500/30 bg-amber-500/10 text-amber-600' : 'border-emerald-500/30 bg-emerald-500/10 text-emerald-600')
: 'border-amber-500/30 bg-amber-500/10 text-amber-600'
}`}>
<p className="font-medium">
{config?.env_writeback_enabled
? (config?.env_backed
? t('accountManager.envModeWritebackPendingTitle')
: t('accountManager.envModeWritebackActiveTitle'))
: t('accountManager.envModeRiskTitle')}
</p>
<p className="mt-1 text-xs opacity-90">
{config?.env_writeback_enabled
? t('accountManager.envModeWritebackDesc', { path: config?.config_path || 'config.json' })
: t('accountManager.envModeRiskDesc')}
</p>
</div>
)}
<QueueCards queueStatus={queueStatus} t={t} />
<ApiKeysPanel
t={t}
config={config}
keysExpanded={keysExpanded}
setKeysExpanded={setKeysExpanded}
setShowAddKey={setShowAddKey}
copiedKey={copiedKey}
setCopiedKey={setCopiedKey}
onDeleteKey={deleteKey}
/>
<AccountsTable
t={t}
accounts={accounts}
loadingAccounts={loadingAccounts}
testing={testing}
testingAll={testingAll}
batchProgress={batchProgress}
sessionCounts={sessionCounts}
deletingSessions={deletingSessions}
totalAccounts={totalAccounts}
page={page}
pageSize={pageSize}
totalPages={totalPages}
resolveAccountIdentifier={resolveAccountIdentifier}
onTestAll={testAllAccounts}
onShowAddAccount={() => setShowAddAccount(true)}
onTestAccount={testAccount}
onDeleteAccount={deleteAccount}
onDeleteAllSessions={deleteAllSessions}
onPrevPage={() => fetchAccounts(page - 1)}
onNextPage={() => fetchAccounts(page + 1)}
onPageSizeChange={changePageSize}
searchQuery={searchQuery}
onSearchChange={handleSearchChange}
envBacked={Boolean(config?.env_backed)}
/>
<AddKeyModal
show={showAddKey}
t={t}
newKey={newKey}
setNewKey={setNewKey}
loading={loading}
onClose={() => setShowAddKey(false)}
onAdd={addKey}
/>
<AddAccountModal
show={showAddAccount}
t={t}
newAccount={newAccount}
setNewAccount={setNewAccount}
loading={loading}
onClose={() => setShowAddAccount(false)}
onAdd={addAccount}
/>
</div>
)
}