feat(manager): Apps, Integrations and License pages on the module catalogue

Platform-v2 step 2.6c:
- Apps (device apps, features, always-included core) and Integrations: module
  cards from GET /api/platform/modules with state (on / off / waiting for a
  dependency / not in your license / always on), dependencies, limits and an
  Open button where the manager has a page; core.modules.manage toggles them
  (PUT /api/platform/modules/{key}), with a confirm listing the modules that
  stop too; bootstrap reloads so the sidebar follows at once
- License page: licensed / free (with the reason) / development, site id,
  validity, last contact, "check the license now" (POST /api/system/sync-license),
  every module's entitlement and limits
- i18n: new `modules` namespace (names, descriptions, limit labels, en + el)
  kept complete against the registry by local_backend/tests/test_module_texts.py
- nav: Integrations and License in the sidebar; old AppsPage removed
- e2e manager.mjs: 43 checks (+ card states, toggle from the card, dependency
  warning, integrations, license page)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-13 22:33:54 +02:00
co-authored by Claude Opus 5.5
parent 49a412d748
commit 0d0b2d78e1
13 changed files with 757 additions and 47 deletions
@@ -0,0 +1,134 @@
// License page (plan step 2.6c, APPS_PLATFORM §5): what this venue's license includes,
// until when, with which limits, and when the site last reached the license server.
// Sources: bootstrap `license` (mode/reason), GET /api/system/status (expiry, last sync,
// site id), GET /api/platform/modules (per-module entitlement and limits).
// "Check the license now" = POST /api/system/sync-license (needs the internet).
import { useCallback, useEffect, useState } from 'react'
import toast from 'react-hot-toast'
import { errorMessage } from '@xenia/api'
import { useAccess } from '@xenia/access'
import { useFormat, useTranslation } from '@xenia/i18n'
import { Button, EmptyState, Spinner } from '@xenia/ui'
import client from '../../api/client'
export default function LicensePage() {
const { t } = useTranslation('manager')
const f = useFormat()
const { license, refresh } = useAccess()
const [status, setStatus] = useState(null)
const [modules, setModules] = useState(null)
const [error, setError] = useState(null)
const [syncing, setSyncing] = useState(false)
const load = useCallback(async () => {
try {
const [s, m] = await Promise.all([client.get('/api/system/status'), client.get('/api/platform/modules')])
setStatus(s.data)
setModules(m.data.modules)
setError(null)
} catch (err) {
setError(errorMessage(err, t))
}
}, [t])
useEffect(() => { load() }, [load])
async function syncNow() {
setSyncing(true)
try {
const { data } = await client.post('/api/system/sync-license')
await Promise.all([load(), refresh()])
if (data?.sync_failed) toast.error(t('licensePage.syncFailed'))
else toast.success(t('licensePage.synced'))
} catch (err) {
toast.error(errorMessage(err, t))
} finally {
setSyncing(false)
}
}
if (error) return <div className="p-8"><EmptyState title={error} action={<Button variant="secondary" onClick={load}>{t('common:actions.retry')}</Button>} /></div>
if (!status || !modules) return <div className="p-8 flex justify-center"><Spinner /></div>
const mode = license?.mode
const statusText = mode === 'dev' ? t('licensePage.statusDev')
: mode === 'licensed' ? t('licensePage.statusLicensed')
: t('licensePage.statusFree')
const statusTone = mode === 'licensed' ? 'bg-success-soft text-success-ink' : mode === 'dev' ? 'bg-info-soft text-info-ink' : 'bg-warning-soft text-warning-ink'
const reason = mode === 'free' && license?.reason ? t(`license.${license.reason}`, { defaultValue: '' }) : ''
const entitlement = m => {
if (!m.entitled) return t('licensePage.notIncluded')
const src = m.entitlement?.source
if (src === 'core') return t('licensePage.included')
if (src === 'dev') return t('licensePage.dev')
if (src === 'free') return t('licensePage.free')
return m.entitlement?.exp ? t('licensePage.inLicenseUntil', { date: f.formatDate(m.entitlement.exp) }) : t('licensePage.inLicense')
}
const sorted = [...modules].sort((a, b) => t(`modules:${a.key}.name`).localeCompare(t(`modules:${b.key}.name`)))
return (
<div className="p-6 lg:p-8 max-w-5xl grid gap-6">
<section className="bg-surface border border-line rounded-card shadow-raised p-6 grid gap-4" data-testid="license-status">
<div className="flex flex-wrap items-center gap-3 justify-between">
<div>
<div className="text-label text-ink-3">{t('licensePage.status')}</div>
<span className={`inline-block mt-1 rounded-full px-3 py-1 text-body font-semibold ${statusTone}`} data-testid="license-mode">{statusText}</span>
</div>
<Button variant="secondary" loading={syncing} onClick={syncNow}>{t('licensePage.syncNow')}</Button>
</div>
{reason && <p className="text-body text-warning-ink">{reason}</p>}
<dl className="grid gap-3 sm:grid-cols-3 text-body">
<div>
<dt className="text-label text-ink-3">{t('licensePage.siteId')}</dt>
<dd className="font-mono text-ink" data-testid="license-site">{status.site_id || '—'}</dd>
</div>
<div>
<dt className="text-label text-ink-3">{t('licensePage.expires')}</dt>
<dd className="text-ink">
{status.expires_at ? f.formatDate(status.expires_at, 'dateMedium') : '—'}
{status.days_until_expiry != null && status.days_until_expiry >= 0 && (
<span className="text-ink-3"> · {t('licensePage.daysLeft', { count: status.days_until_expiry })}</span>
)}
</dd>
</div>
<div>
<dt className="text-label text-ink-3">{t('licensePage.lastSync')}</dt>
<dd className="text-ink">{status.last_sync ? f.formatRelative(status.last_sync) : t('licensePage.never')}</dd>
</div>
</dl>
{status.sync_failed && status.offline_days > 0 && (
<p className="text-label text-warning-ink">{t('licensePage.offline', { count: status.offline_days })}</p>
)}
</section>
<section className="bg-surface border border-line rounded-card shadow-raised overflow-hidden">
<h2 className="px-6 pt-5 pb-3 text-body-lg font-semibold text-ink">{t('licensePage.modules')}</h2>
<table className="w-full text-body" data-testid="license-modules">
<thead>
<tr className="text-left text-label text-ink-3 border-b border-line">
<th className="px-6 py-2 font-medium">{t('licensePage.module')}</th>
<th className="px-6 py-2 font-medium">{t('licensePage.status')}</th>
<th className="px-6 py-2 font-medium">{t('licensePage.limits')}</th>
</tr>
</thead>
<tbody>
{sorted.map(m => (
<tr key={m.key} className="border-b border-line last:border-0" data-testid={`license-row-${m.key}`}>
<td className="px-6 py-2.5 text-ink">{t(`modules:${m.key}.name`)}</td>
<td className={`px-6 py-2.5 ${m.entitled ? 'text-ink-2' : 'text-ink-3'}`}>{entitlement(m)}</td>
<td className="px-6 py-2.5 text-ink-2">
{m.limits.map(l => (
<div key={l.key}>
{t(`modules:${m.key}.limits.${l.key}`)}: <span className="text-ink font-medium">{l.value == null ? t('modules.unlimited') : l.value}</span>
</div>
))}
</td>
</tr>
))}
</tbody>
</table>
</section>
</div>
)
}
@@ -0,0 +1,169 @@
// Apps and Integrations pages (plan step 2.6c, APPS_PLATFORM §4, D-3, D-19): the module
// catalogue from GET /api/platform/modules as cards. A manager with core.modules.manage
// turns modules on/off (PUT /api/platform/modules/{key}); everyone else sees the state.
// Turning one off warns first which modules depending on it stop too. After a change the
// platform bootstrap is reloaded, so the sidebar and every guard follow at once.
import { useCallback, useEffect, useMemo, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import toast from 'react-hot-toast'
import { errorMessage } from '@xenia/api'
import { useAccess, useCan } from '@xenia/access'
import { useTranslation } from '@xenia/i18n'
import { Button, Dialog, EmptyState, Spinner, Switch } from '@xenia/ui'
import client from '../../api/client'
import { moduleState, stoppedBy } from './modulesLogic'
// Modules with a page in the manager: the card gets an "Open" button
const OPEN_PATH = { kds: '/kds', caller_id: '/apps/phone' }
export function AppsPage() {
const { t } = useTranslation('manager')
return <ModulesPage kinds={['app', 'feature', 'core']} intro={t('modules.appsIntro')} />
}
export function IntegrationsPage() {
const { t } = useTranslation('manager')
return <ModulesPage kinds={['integration']} intro={t('modules.integrationsIntro')} />
}
function ModulesPage({ kinds, intro }) {
const { t } = useTranslation('manager')
const { refresh } = useAccess()
const canManage = useCan('core.modules.manage')
const [modules, setModules] = useState(null)
const [error, setError] = useState(null)
const [confirm, setConfirm] = useState(null) // { module, stopped }
const [busy, setBusy] = useState(null) // key being saved
const load = useCallback(async () => {
try {
const { data } = await client.get('/api/platform/modules')
setModules(data.modules)
setError(null)
} catch (err) {
setError(errorMessage(err, t))
}
}, [t])
useEffect(() => { load() }, [load])
async function save(m, enabled) {
setBusy(m.key)
try {
await client.put(`/api/platform/modules/${m.key}`, { enabled })
await Promise.all([load(), refresh()])
toast.success(t('modules.changed', { name: t(`modules:${m.key}.name`), state: enabled ? t('modules.on') : t('modules.off') }))
} catch (err) {
toast.error(errorMessage(err, t))
} finally {
setBusy(null)
}
}
function toggle(m, enabled) {
const stopped = enabled ? [] : stoppedBy(m.key, modules)
if (stopped.length) setConfirm({ module: m, stopped })
else save(m, enabled)
}
const sections = useMemo(() => {
if (!modules) return []
const byName = (a, b) => t(`modules:${a.key}.name`).localeCompare(t(`modules:${b.key}.name`))
return kinds
.map(kind => ({ kind, items: modules.filter(m => m.kind === kind).sort(byName) }))
.filter(s => s.items.length)
}, [modules, kinds, t])
if (error) return <div className="p-8"><EmptyState title={error} action={<Button variant="secondary" onClick={load}>{t('common:actions.retry')}</Button>} /></div>
if (!modules) return <div className="p-8 flex justify-center"><Spinner /></div>
return (
<div className="p-6 lg:p-8 max-w-6xl grid gap-8">
<div>
<p className="text-body text-ink-2 max-w-2xl">{intro}</p>
{!canManage && <p className="text-label text-ink-3 mt-1">{t('modules.readOnly')}</p>}
</div>
{sections.map(({ kind, items }) => (
<section key={kind} className="grid gap-3">
{kinds.length > 1 && <h2 className="text-label font-semibold uppercase tracking-wide text-ink-3">{t(`modules.sections.${kind}`)}</h2>}
<div className="grid gap-4 sm:grid-cols-2 xl:grid-cols-3">
{items.map(m => (
<ModuleCard key={m.key} m={m} modules={modules} canManage={canManage} busy={busy === m.key} onToggle={toggle} />
))}
</div>
</section>
))}
<Dialog
open={!!confirm}
onClose={() => setConfirm(null)}
size="sm"
title={confirm ? t('modules.confirmOffTitle', { name: t(`modules:${confirm.module.key}.name`) }) : ''}
footer={confirm && (
<>
<Button variant="secondary" onClick={() => setConfirm(null)}>{t('common:actions.cancel')}</Button>
<Button variant="danger" onClick={() => { const m = confirm.module; setConfirm(null); save(m, false) }}>{t('modules.turnOff')}</Button>
</>
)}
>
{confirm && (
<span data-testid="confirm-stopped">
{t('modules.confirmOffBody', { list: confirm.stopped.map(s => t(`modules:${s.key}.name`)).join(', ') })}
</span>
)}
</Dialog>
</div>
)
}
function ModuleCard({ m, modules, canManage, busy, onToggle }) {
const { t } = useTranslation('manager')
const navigate = useNavigate()
const name = t(`modules:${m.key}.name`)
const state = moduleState(m)
const label = key => t(`modules:${key}.name`)
const waitingFor = m.depends.filter(d => !modules.find(x => x.key === d)?.effective)
const chip = {
always: ['bg-surface-2 text-ink-2', t('modules.alwaysOn')],
not_licensed: ['bg-warning-soft text-warning-ink', t('modules.notLicensed')],
on: ['bg-success-soft text-success-ink', t('modules.on')],
waiting: ['bg-warning-soft text-warning-ink', t('modules.waiting', { list: waitingFor.map(label).join(', ') })],
off: ['bg-surface-2 text-ink-3', t('modules.off')],
}[state]
return (
<div className="bg-surface border border-line rounded-card shadow-raised p-5 flex flex-col gap-3" data-testid={`module-${m.key}`} data-state={state}>
<div className="flex items-start gap-3">
<div className="flex-1 min-w-0">
<div className="text-body-lg font-semibold text-ink">{name}</div>
<span className={`inline-block mt-1 rounded-full px-2 py-0.5 text-caption font-medium ${chip[0]}`}>{chip[1]}</span>
</div>
{m.can_disable && state !== 'not_licensed' && (
<Switch
checked={m.enabled}
disabled={!canManage || busy}
onChange={on => onToggle(m, on)}
aria-label={t('modules.toggleLabel', { name })}
/>
)}
</div>
<p className="text-label text-ink-2 flex-1">{t(`modules:${m.key}.description`)}</p>
{m.depends.length > 0 && state !== 'waiting' && (
<p className="text-caption text-ink-3">{t('modules.needs', { list: m.depends.map(label).join(', ') })}</p>
)}
{m.limits.length > 0 && (
<dl className="grid gap-1 text-caption">
{m.limits.map(l => (
<div key={l.key} className="flex justify-between gap-3">
<dt className="text-ink-3">{t(`modules:${m.key}.limits.${l.key}`)}</dt>
<dd className="text-ink font-medium">{l.value == null ? t('modules.unlimited') : l.value}</dd>
</div>
))}
</dl>
)}
{OPEN_PATH[m.key] && state === 'on' && (
<div><Button size="sm" variant="secondary" onClick={() => navigate(OPEN_PATH[m.key])}>{t('modules.open')}</Button></div>
)}
</div>
)
}
@@ -0,0 +1,28 @@
// Pure helpers for the Apps/Integrations pages (plan step 2.6c).
/** Modules that stop working if `key` is off (they depend on it, directly or not), currently on. */
export function stoppedBy(key, modules) {
const out = []
const seen = new Set([key])
let frontier = [key]
while (frontier.length) {
const next = []
for (const m of modules) {
if (seen.has(m.key) || !m.depends.some(d => frontier.includes(d))) continue
seen.add(m.key)
next.push(m.key)
if (m.effective) out.push(m)
}
frontier = next
}
return out
}
/** The card's state: always | not_licensed | on | waiting | off */
export function moduleState(m) {
if (!m.can_disable) return 'always'
if (!m.entitled) return 'not_licensed'
if (m.enabled && m.effective) return 'on'
if (m.enabled) return 'waiting'
return 'off'
}