The open-source AI receptionist for businesses. Answers every call, books the appointment and hands over to a person when needed. You own the code and the data.
TypeScript ai-receptionistanswering-serviceappointment-bookinglivekitlocal-firstmcpopen-sourceself-hostedsiptelephonytypescriptvoice-agentvoice-ai
Server admin Overview: People, Costs and Funnel as lines (PR 1907)
Janike7a50538fdd7
diff --git a/apps/web/src/admin/AdminMode.tsx b/apps/web/src/admin/AdminMode.tsxindex 26575c48..89e7b870 100644--- a/apps/web/src/admin/AdminMode.tsx+++ b/apps/web/src/admin/AdminMode.tsx@@ -22,7 +22,6 @@ import { ADMIN_HEALTH, type HealthPart, loadHealth, watchAdminSignIn } from './aimport { Billing, billingPartIntro, billingPartTitle, useBillTitle } from './Billing.tsx'import { BrandingSettings } from './Branding.tsx'import { Features } from './Features.tsx'-import { Funnel } from './Funnel.tsx'import { NeedsYou } from './NeedsYou.tsx'import { errorText, type Notify } from './notify.ts'import { AtRisk } from './Onboarding.tsx'@@ -220,7 +219,6 @@ export function AdminMode({ currentUserId, onExit }: Props) {<StatusCard status={status} keys={{ providers, record: status.record, reload, notify }} /><NeedsYou /><Overview onOpen={section => go({ section, id: null })} />- <Funnel /></>)// Workspaces at risk load their own rows.diff --git a/apps/web/src/admin/Funnel.tsx b/apps/web/src/admin/Funnel.tsxindex 0df1c877..7a0d958b 100644--- a/apps/web/src/admin/Funnel.tsx+++ b/apps/web/src/admin/Funnel.tsx@@ -1,12 +1,13 @@// Server admin › Overview › Funnel (LIN-425): the workspaces that signed up each week and how far they got, from-// our own tables (apps/api/src/admin-funnel.ts). The tiles are the whole range, the table one row per sign-up week.+// our own tables (apps/api/src/admin-funnel.ts). One line like the other Overview parts (FeatureLine); Show opens the+// range, the tiles for the whole range and the table with one row per sign-up week.import { useFormat, useT } from '@linedesk/i18n/react'import { useState } from 'react'import { useQuery } from '../cachedQuery.ts'import { Select } from '../ui/controls.tsx'-import { Card } from '../ui/form.tsx'import { Loading, Skeleton, SkeletonRows } from '../ui/LoadStates.tsx'import { type FunnelCounts, loadFunnel } from './api.ts'+import { FeatureLine } from './FeatureLine.tsx'const RANGES = ['4', '8', '12', '26'] as consttype Range = (typeof RANGES)[number]@@ -63,7 +64,7 @@ const tilesSkeleton = (</div>)-export function Funnel() {+export function Funnel({ open, onToggle }: { open: boolean; onToggle: () => void }) {const t = useT()const format = useFormat()const labels = useLabels()@@ -75,12 +76,24 @@ export function Funnel() {index === 0? t('admin.funnel.thisWeek'): format.dateTime(new Date(`${iso}T00:00:00Z`), { month: 'short', day: 'numeric', timeZone: 'UTC' })+ // The line's badge: sign-ups and paid in the chosen range, so the funnel reads without opening it.+ const state = data+ ? {+ text: t('admin.funnel.state', { signedUp: data.total.signed_up, paid: data.total.paid }),+ on: false,+ }+ : nullreturn (- <Card+ <FeatureLinetitle={t('admin.funnel.title')}- description={t('admin.funnel.description')}+ summary={t('admin.funnel.description')}help={t('admin.funnel.help')}- actions={+ state={state}+ open={open}+ onToggle={onToggle}+ view+ >+ <div className="adm-funnel-range"><Selectsize="sm"align="end"@@ -89,8 +102,7 @@ export function Funnel() {onChange={setRange}options={RANGES.map(r => ({ value: r, label: t('admin.funnel.lastWeeks', { weeks: Number(r) }) }))}/>- }- >+ </div><Loadingwhat={t('admin.funnel.title')}loading={!data}@@ -139,6 +151,6 @@ export function Funnel() {</>)}</Loading>- </Card>+ </FeatureLine>)}diff --git a/apps/web/src/admin/Overview.tsx b/apps/web/src/admin/Overview.tsxindex 43c38b2e..98e0eab3 100644--- a/apps/web/src/admin/Overview.tsx+++ b/apps/web/src/admin/Overview.tsx@@ -1,17 +1,19 @@// Server admin › Overview: the first thing an operator sees, under the "Ready for calls" card (StatusCard.tsx, which-// says whether the parts of the install work). Usage (calls, minutes), roughly what it costs per provider, and how many-// workspaces and people there are.+// says whether the parts of the install work). Usage (calls, minutes) as tiles, then People, Costs and Funnel as one+// line each with its number on the badge, like the lines on Features; Show opens the details in place.import { providerCategoryLabel } from '@linedesk/actions'import { T, useT } from '@linedesk/i18n/react'import type { ReactNode } from 'react'import { useQuery } from '../cachedQuery.ts'import { cx } from '../ui/kit.tsx'-import { LoadProblem, Skeleton, SkeletonRows, useLoading } from '../ui/LoadStates.tsx'+import { LoadProblem, Skeleton, useLoading } from '../ui/LoadStates.tsx'import { type AdminOverview, loadOverview } from './api.ts'import { ShopifySetups } from './ShopifySetups.tsx'import { fmt } from '../i18n/format.ts'import { i18n } from '../i18n/index.tsx'import { EMPTY } from './parts.tsx'+import { FeatureLine, useOpenLines } from './FeatureLine.tsx'+import { Funnel } from './Funnel.tsx'const usd = (amount: number) => fmt().currency(amount, 'USD', { minimumFractionDigits: 2, maximumFractionDigits: 2 })const money = (amount: number) =>@@ -38,79 +40,82 @@ function Stat({ label, value, note }: { label: string; value: string; note?: str)}-function Card({- title,- note,- action,- children,-}: {- title: string- note?: string- action?: ReactNode- children: ReactNode-}) {+const costTotals = (overview: AdminOverview) => ({+ week: overview.costs.reduce((sum, c) => sum + c.cost7d, 0),+ month: overview.costs.reduce((sum, c) => sum + c.costMonth, 0),+})++function CostTable({ overview }: { overview: AdminOverview }) {+ const { week: total7d, month: totalMonth } = costTotals(overview)+ const t = useT()return (- <section className="adm-card" aria-label={title}>- <div className="adm-card-head">- <div>- <h2>{title}</h2>- {note && <p className="help">{note}</p>}- </div>- {action}- </div>- {children}- </section>+ <div className="adm-scroll">+ <table className="adm-table">+ <thead>+ <tr>+ <th scope="col">{t('admin.overview.costs.part')}</th>+ <th scope="col">{t('admin.overview.costs.inUse')}</th>+ <th scope="col" className="adm-num">+ {t('admin.overview.costs.minutes7d')}+ </th>+ <th scope="col" className="adm-num">+ {t('admin.overview.costs.cost7d')}+ </th>+ <th scope="col" className="adm-num">+ {t('admin.overview.costs.costMonth')}+ </th>+ </tr>+ </thead>+ <tbody>+ {overview.costs.map(c => (+ <tr key={c.category}>+ <th scope="row">+ {c.category === 'transcript'+ ? t('admin.afterCallTranscript.title')+ : providerCategoryLabel(c.category, i18n())}+ </th>+ <td>{c.label ?? <span className="help">{t('admin.overview.costs.notSetUp')}</span>}</td>+ <td className="adm-num">{count(c.minutes7d)}</td>+ <td className="adm-num">{c.provider ? money(c.cost7d) : EMPTY}</td>+ <td className="adm-num">{c.provider ? money(c.costMonth) : EMPTY}</td>+ </tr>+ ))}+ <tr className="adm-total">+ <th scope="row">{t('admin.overview.costs.total')}</th>+ <td />+ <td />+ <td className="adm-num">{money(total7d)}</td>+ <td className="adm-num">{money(totalMonth)}</td>+ </tr>+ </tbody>+ </table>+ </div>)}-function Costs({ overview }: { overview: AdminOverview }) {- const total7d = overview.costs.reduce((sum, c) => sum + c.cost7d, 0)- const totalMonth = overview.costs.reduce((sum, c) => sum + c.costMonth, 0)+function People({ o, onOpen }: { o: AdminOverview; onOpen: Props['onOpen'] }) {const t = useT()return (- <Card title={t('admin.overview.costs.title')} note={t('admin.overview.costs.note')}>- <div className="adm-scroll">- <table className="adm-table">- <thead>- <tr>- <th scope="col">{t('admin.overview.costs.part')}</th>- <th scope="col">{t('admin.overview.costs.inUse')}</th>- <th scope="col" className="adm-num">- {t('admin.overview.costs.minutes7d')}- </th>- <th scope="col" className="adm-num">- {t('admin.overview.costs.cost7d')}- </th>- <th scope="col" className="adm-num">- {t('admin.overview.costs.costMonth')}- </th>- </tr>- </thead>- <tbody>- {overview.costs.map(c => (- <tr key={c.category}>- <th scope="row">- {c.category === 'transcript'- ? t('admin.afterCallTranscript.title')- : providerCategoryLabel(c.category, i18n())}- </th>- <td>{c.label ?? <span className="help">{t('admin.overview.costs.notSetUp')}</span>}</td>- <td className="adm-num">{count(c.minutes7d)}</td>- <td className="adm-num">{c.provider ? money(c.cost7d) : EMPTY}</td>- <td className="adm-num">{c.provider ? money(c.costMonth) : EMPTY}</td>- </tr>- ))}- <tr className="adm-total">- <th scope="row">{t('admin.overview.costs.total')}</th>- <td />- <td />- <td className="adm-num">{money(total7d)}</td>- <td className="adm-num">{money(totalMonth)}</td>- </tr>- </tbody>- </table>- </div>- </Card>+ <div className="adm-people">+ <button type="button" className="adm-link" onClick={() => onOpen('workspaces')}>+ <T k="admin.overview.people.workspaces" values={{ count: o.workspaces.total, b: bold }} />+ {o.workspaces.disabled > 0 && (+ <span className="help"> {t('admin.overview.people.disabled', { count: o.workspaces.disabled })}</span>+ )}+ {o.workspaces.new7d > 0 && (+ <span className="help"> {t('admin.overview.people.newThisWeek', { count: o.workspaces.new7d })}</span>+ )}+ </button>+ <button type="button" className="adm-link" onClick={() => onOpen('users')}>+ <T k="admin.overview.people.users" values={{ count: o.users.total, b: bold }} />+ {o.users.disabled > 0 && (+ <span className="help"> {t('admin.overview.people.disabled', { count: o.users.disabled })}</span>+ )}+ {o.users.new7d > 0 && (+ <span className="help"> {t('admin.overview.people.newThisWeek', { count: o.users.new7d })}</span>+ )}+ </button>+ </div>)}@@ -120,6 +125,7 @@ const bold = (chunks: ReactNode[]) => <b>{chunks}</b>export function Overview({ onOpen }: Props) {const t = useT()+ const line = useOpenLines<'people' | 'costs' | 'funnel'>()const overview = useLoad('admin.overview', loadOverview)// The numbers wait behind the loading gate (no flash, no blink); the labels and card titles show at once.const view = useLoading(!overview.value)@@ -127,13 +133,16 @@ export function Overview({ onOpen }: Props) {const busy = cx('ld-busy', view.phase === 'reserve' && 'is-reserved')if (overview.error || view.phase === 'slow')return (- <LoadProblem- className="adm-card"- what={t('admin.overview.what')}- message={overview.error ?? undefined}- slow={!overview.error}- onRetry={() => void overview.retry()}- />+ <>+ <LoadProblem+ className="adm-card"+ what={t('admin.overview.what')}+ message={overview.error ?? undefined}+ slow={!overview.error}+ onRetry={() => void overview.retry()}+ />+ <Funnel {...line('funnel')} />+ </>)return (<>@@ -153,7 +162,7 @@ export function Overview({ onOpen }: Props) {/><Statlabel={t('admin.overview.costs.cost7d')}- value={money(o.costs.reduce((sum, c) => sum + c.cost7d, 0))}+ value={money(costTotals(o).week)}note={t('admin.overview.stat.costNote')}/></>@@ -172,39 +181,32 @@ export function Overview({ onOpen }: Props) {)}</div><ShopifySetups />- {o ? (- <Costs overview={o} />- ) : (- <Card title={t('admin.overview.costs.title')} note={t('admin.overview.costs.note')}>- <div className={busy}>- <SkeletonRows rows={4} columns={4} className="adm-sk-rows" />- </div>- </Card>- )}- {o && (- <Card title={t('admin.overview.people.title')}>- <div className="adm-people">- <button type="button" className="adm-link" onClick={() => onOpen('workspaces')}>- <T k="admin.overview.people.workspaces" values={{ count: o.workspaces.total, b: bold }} />- {o.workspaces.disabled > 0 && (- <span className="help"> {t('admin.overview.people.disabled', { count: o.workspaces.disabled })}</span>- )}- {o.workspaces.new7d > 0 && (- <span className="help"> {t('admin.overview.people.newThisWeek', { count: o.workspaces.new7d })}</span>- )}- </button>- <button type="button" className="adm-link" onClick={() => onOpen('users')}>- <T k="admin.overview.people.users" values={{ count: o.users.total, b: bold }} />- {o.users.disabled > 0 && (- <span className="help"> {t('admin.overview.people.disabled', { count: o.users.disabled })}</span>- )}- {o.users.new7d > 0 && (- <span className="help"> {t('admin.overview.people.newThisWeek', { count: o.users.new7d })}</span>- )}- </button>- </div>- </Card>- )}+ <FeatureLine+ title={t('admin.overview.people.title')}+ summary={t('admin.overview.people.summary')}+ state={+ o+ ? {+ text: t('admin.overview.people.state', { workspaces: o.workspaces.total, users: o.users.total }),+ on: false,+ }+ : null+ }+ view+ {...line('people')}+ >+ {o && <People o={o} onOpen={onOpen} />}+ </FeatureLine>+ <FeatureLine+ title={t('admin.overview.costs.title')}+ summary={t('admin.overview.costs.note')}+ state={o ? { text: t('admin.overview.costs.state', { amount: money(costTotals(o).month) }), on: false } : null}+ view+ {...line('costs')}+ >+ {o && <CostTable overview={o} />}+ </FeatureLine>+ <Funnel {...line('funnel')} /></>)}diff --git a/apps/web/src/admin/admin.css b/apps/web/src/admin/admin.cssindex 2b5342a9..866902c8 100644--- a/apps/web/src/admin/admin.css+++ b/apps/web/src/admin/admin.css@@ -2215,6 +2215,10 @@ a.adm-chip {.adm-funnel-stats {margin-bottom: 14px;}+.adm-funnel-range {+ display: flex;+ justify-content: flex-end;+}.adm-funnel-pct {display: inline-block;min-width: 4ch;diff --git a/packages/i18n/locales/en/admin.json b/packages/i18n/locales/en/admin.jsonindex 466be011..1e913c70 100644--- a/packages/i18n/locales/en/admin.json+++ b/packages/i18n/locales/en/admin.json@@ -948,6 +948,7 @@"funnel.lastWeeks": "{weeks, plural, one {Last week} other {Last # weeks}}","funnel.ofSignUps": "{share} of sign-ups","funnel.range": "Range",+ "funnel.state": "{signedUp, plural, one {# sign-up} other {# sign-ups}} · {paid, number} paid","funnel.step.firstCall": "First real call","funnel.step.paid": "Paid","funnel.step.setUp": "Set up",@@ -1118,11 +1119,14 @@"overview.costs.notSetUp": "Not set up","overview.costs.note": "Estimated from list prices.","overview.costs.part": "Part",+ "overview.costs.state": "{amount} this month","overview.costs.title": "Costs","overview.costs.total": "Total","overview.lessThan": "< {amount}","overview.people.disabled": "· {count, number} disabled","overview.people.newThisWeek": "· {count, number} new this week",+ "overview.people.state": "{workspaces, plural, one {# workspace} other {# workspaces}} · {users, plural, one {# user} other {# users}}",+ "overview.people.summary": "Workspaces and users on this server.","overview.people.title": "People","overview.people.users": "{count, plural, one {<b>#</b> user} other {<b>#</b> users}}","overview.people.workspaces": "{count, plural, one {<b>#</b> workspace} other {<b>#</b> workspaces}}",