# 05 — Web UI (apps/web) One React app with two areas: **Admin** (`/admin/*`, admins only) and **My Phone** (`/me/*`, every user, admins included). The browser softphone is part of My Phone and stays docked on every `/me` page. ## 1. Global rules - React 19 + TypeScript strict + Vite + react-router 7 + TanStack Query + Tailwind 4. - A typed API client in `src/api/` generated from the zod schemas in `packages/shared` (write the wrappers by hand; no codegen tool). Every request sends `X-Requested-With: selfphoneng` and `credentials: 'same-origin'`. - Forms validate with the **same zod schemas** as the API (`@hookform/resolvers/zod` + `react-hook-form`; add both to the allowed deps). - Works at 360 px wide. Admin tables become stacked cards on small screens. - Light and dark mode follow `prefers-color-scheme`, with a manual toggle stored in `localStorage` (wrapped in try/catch). - Accessibility: every control has a label, focus is visible, the dialpad works from the keyboard, and the incoming-call dialog traps focus. - Show phone numbers formatted (`(312) 555-1234`). Inputs accept any format and normalize on blur. - Every destructive action uses a confirm dialog. Delete errors of type 409 show the "in use by" list from the API. - Live data comes from the `/api/live` WebSocket (`src/live/`), stored in a small Zustand store (add `zustand` to the allowed deps). The client reconnects with backoff and shows a thin top banner "Reconnecting…" while disconnected. - Never show a secret unless the user clicks "Reveal", which calls the explicit reveal endpoint. ## 2. Admin area Left sidebar navigation, in this order: | Page | Path | Contents | |---|---|---| | Dashboard | `/admin` | Cards: trunks (registered?), extensions online/total, active calls, calls today, missed today, voicemails waiting, disk free. Live call list (from, to, state, duration ticking, recording dot; admin buttons Hang up / Transfer / Listen). Queue tiles (waiting, longest wait, agents available). Warnings banner (restart required, SMTP not set, E911 caller ID not set, trunk down; IPQualityScore out of credits, with Dismiss, 14 §3) | | Users & Extensions | `/admin/users` | Table: number, name, email, role, online (contacts count + state dot), DND, devices. Create/edit drawer with tabs: **General** (name, email, role, number with "next free" button), **Phone** (ring seconds, webrtc on/off, pickup group, BLF numbers multiselect, language, MOH class), **Voicemail** (enabled, PIN, email options), **Calling** (outbound class, outbound caller ID DID, recording mode), **Emergency** (E911 caller ID DID, location text), **Credentials** (SIP username/server/password reveal, regenerate, softphone QR), **Forwarding** (current DND/CFU/CFB/CFNA, editable). As built (owner follow-up to M11-T7, 2026-10-20): the Calling tab's recording mode was missing until then; it is a **Record calls** select (Never, Calls from outside, Calls to outside, All outside calls = `recordMode` never/inbound/outbound/all). Calls inside the company are never recorded, and no recording notice plays for it (only numbers set to record play one) | | Trunks | `/admin/trunks` | List with status pill. Form: provider (voip.ms / generic). Choosing voip.ms pre-fills port, transport, codecs and shows a POP server dropdown (06 §2) plus the voip.ms-side checklist. Test button. API credentials (optional) + "Import DIDs" | | Phone numbers (DIDs) | `/admin/numbers` | Table: number, label, trunk, destination summary ("→ IVR Main menu"), SMS on/off. Form: number, label, trunk, **DestinationPicker**, caller-name prefix, record inbound, SMS enabled + users allowed | | Outbound rules | `/admin/outbound` | Sortable list (drag to reorder). Form: name, patterns (rows of match/strip/prepend with a pattern help popover), required class, trunk order (multi-select with order), caller ID override. **Test box**: pick an extension + type a number → shows the matching route, final dialed number, trunk, caller ID, or the reason it's denied | | Ring groups | `/admin/ring-groups` | Form: number, name, strategy, ring seconds, members (ordered picker), music instead of ring, caller-name prefix, no-answer DestinationPicker | | (Dashboard, Home) | | As built (M8-T2): a "Parked calls" list (slot, caller, parked by, waiting time) on the Dashboard and on Home; Home's has **Pick up 701**, which calls the slot like Call back (softphone, or the desk phone rings first) | | Queues | `/admin/queues` | Form: every column from 02. Detail page shows live waiting callers + agent list with pause/unpause buttons + today's stats. As built (M8-T1): detail at `/admin/queues/:id`; music on hold is a select of `default` and the classes from Sounds & music (M8-T5) | | IVRs (Digital receptionist) | `/admin/ivrs` | Form: number, name, greeting (SoundPicker), keypad grid 0–9 * # where each key gets a DestinationPicker or "unused", timeout, retries, invalid sound, direct dial toggle, timeout and invalid destinations | | Office hours | `/admin/hours` | Time conditions: weekly grid editor (click-drag hours per day) that saves to `open_ranges`; timezone; holidays toggle; open/closed/holiday destinations; override digit; big status chip "Open now / Closed now" with Force open / Force closed / Automatic buttons. Holidays sub-tab: list + "Add US federal holidays for {year}" | | Conferences | `/admin/conferences` | number, name, PIN, admin PIN, max members, record. As built (M8-T3): admins see the PINs in the list (they hand them out); an admin PIN needs a different room PIN | | Paging | `/admin/paging` | number, name, members, duplex. As built (M8-T4): members are checkboxes (no order); the empty state explains `*80` | | Sounds & music | `/admin/sounds` | Prompts list with play buttons, upload (drag-drop), TTS (M12). MOH classes with their files (M8). As built (M8-T5): a **Music on hold** section: make a set (slug name), upload, play and remove its files, delete it. The user drawer's Phone tab and the queue form pick a set from a select. An **Announcements** section (play a sound, then a destination) lives here too: no page of its own (M6-T5) | | Phones (devices) | `/admin/devices` | Table: MAC, vendor, model, user, last provisioned. Form: MAC (any format → normalized), vendor, model, extension. Shows the provisioning URL to type into the phone, and "Preview config". As built (M10-T1): the drawer shows URL, user name (MAC) and password; a generic phone shows the manual settings instead (07 §4); Grandstream gets a note that line keys aren't set | | Contacts | `/admin/contacts` | Company phonebook, CSV import | | Call history | `/admin/calls` | Filters + table + CSV export; a row expands to show the CDR legs and plays the recording | | Recordings | `/admin/recordings` | Searchable list, play, download, delete | | Reports | `/admin/reports` | Summary charts (calls per day stacked by direction, missed per day, busiest hours heatmap), queue report table. As built (M11-T6): From/To dates (the last 30 days by default, a year at most); totals (calls, missed, average talk time); the charts are plain bars, no chart library, each bar labeled for screen readers; the heatmap is a weekday × hour table in the company time zone; the queue table has the same numbers as the queue page. Owner follow-up (2026-10-21, "total minutes, calltime, missed calls"): totals also have answered, talk time and outside minutes (in and out: inbound from arrival, since a receptionist or voicemail answers too; outbound from the answer; roughly what the provider bills), an outside-minutes-per-day chart, and one tile per voip.ms trunk with its account balance (`GET /api/reports/balance`, `getBalance`; a trunk without the API login says what to add) | | SMS | `/admin/sms` | Same UI as the user one, with all DIDs | | Blocked numbers | `/admin/blocked` | Users' Report spam on top (number, reason, who, when; Block or Dismiss); their count is a Dashboard tile | | Settings | `/admin/settings` | Tabs: General, Network (public IP detect, LAN IP, local nets, STUN/TURN), SIP (ports, TCP/TLS), Numbering ranges, Email (SMTP + test), Voicemail, Recording (retention, announcement sound + **legal notice text, 08 §5**), Emergency (default E911 caller ID, notify emails/extensions + a **test notification** button that does NOT dial 911), Backups (schedule, keep, include recordings, list + download + "Back up now"), Webhooks, API tokens. Security: desk phone networks, **outside calls at once** (per extension, whole system; 0 = no limit), phone setup files, SIP TLS. Spam check (14 §7.1) | | System | `/admin/system` | Status JSON pretty-printed, Asterisk version, generator runs list, "Apply config now", "Rollback", "Restart telephony", generated-files viewer (read-only, masked), allowlisted CLI dropdown (04 §7.3) with output panel, audit log. As built (owner follow-ups to M11-T7, 2026-10-20), laid out after 3CX's admin dashboard (not copied): a **System information** panel (version, host name, company, public IP static/dynamic, LAN IPs, ports SIP/SIPS/media/HTTPS, telephony running, restart needed; copy buttons) with how to restart (`docker compose restart asterisk` on the server; no restart button),, a **Diagnostics** panel (08 §2.6: the server's own checks, then a Quick or Complete network test through the probe, each line with how to fix it), and an **Event log** panel (severity, event code, time, source, details; Load more; Download = `/api/system/events.csv`). Events (`system_events`, kept 90 days): `trunk.down`/`trunk.up` (registration changes), `telephony.down`/`telephony.up` (AMI), `telephony.restartNeeded`, `config.failed`, `emergency.call`/`emergency.test`, `network.publicIpChanged`, `backup.done`/`backup.failed`, `disk.low`, `spam.quotaExhausted`/`spam.quotaRestored` (14 §3). Admin edits stay in the audit log (not shown yet). The dashboard's `restart_required` warning links here. Generator runs, generated files and CLI views aren't built; the admin guide's troubleshooting page covers them from the shell | ### 2.1 First-run setup wizard (`/setup`) Shown to admins while `setup.completed` is false. Each step saves when you go to the next one. Steps can be skipped where noted. 1. Change the initial admin password. 2. Company name, timezone (default from the browser), language. 3. Network: "Detect public IP", LAN IP (prefilled from `/api/system/status` if detectable), local nets. A big note about SIP ALG and port forwarding (01 §4.2) with a checkbox "I've done this". 4. Email (SMTP), skippable. Test button. 5. Trunk: voip.ms form (06 §2), with the voip.ms portal checklist next to it. "Test" must show Registered before Next is enabled. Skippable for now ("I'll add it later"). 6. Phone numbers: Import from voip.ms (if API creds were given) or add manually. 7. Users: quick table to add up to 10 users (name, email, extension auto-numbered, temporary password generated and shown once). 8. Main number routing: "When someone calls {DID}, ring:" DestinationPicker (common choices first: a user, everyone (creates a ring group of all users), an IVR (creates a simple one)). 9. Emergency: default E911 caller ID DID (required if a trunk exists), notification emails. Shows the 06 §6 text about registering the address at voip.ms. 10. Done: shows "Dial *43 from any phone for an echo test" and links to the softphone. Implementation notes (M3): - Admins are sent to `/setup` until `setup.completed` is true; "Skip setup" completes it. - Step 1 is already done by the forced password change at first sign-in, so it only confirms. - Step 3 changes the SIP transports; on a fresh install the wizard restarts telephony right away (`POST /api/system/asterisk/restart?now=true`). `restartRequired` clears on the next AMI connect once Asterisk's uptime shows it started after the change. - M3 also ships steps 7 and 8 because "calls work using only the wizard" needs a user and a routed number. Step 8 has the full DestinationPicker plus a **Ring everyone** button (M6-T6), which creates or refreshes a ring group "Everyone" with every extension (unanswered → the lowest-numbered user's voicemail). It does not create an IVR: that needs a recorded greeting, so the step points to Digital receptionist instead. Step 10 does not mention *43 or the softphone until M6/M5 build them. - The first phone number added becomes `routing.defaultCallerIdDidId` when none is set. ## 3. Shared components (`src/components/`) - **DestinationPicker**: a type select (User, Voicemail of user, Ring group, Queue, IVR, Office hours, Conference, Announcement, External number, Hang up), then a searchable target select or a number input. The value is a `Destination` object (02 §1). As built (M6-T6): every type that exists so far (queues joined in M8-T1, conferences in M8-T3); the target is a native select, which is searchable by typing. API summaries include the number where there is one: "Ring group Sales (500)". The read-only display renders "→ Ring group Sales (500)". - **SoundPicker**: select + play button + "upload new" shortcut. - **ExtensionPicker** (single/multi, orderable via drag handle). - **PhoneNumberInput** (normalizes, shows formatted). - **StatusDot**: idle green, ringing amber pulsing, in use red, on hold blue, unavailable gray, DND purple. - **AudioPlayer**: `