fix: orders CSV export, Online Orders live refresh, starter flags and quick messages

Cleanup before platform-v2 phase 3 (owner-approved).
- KI-008: GET /api/reports/orders/export read order_history's dicts as ORM rows and
  always failed with 500; it also ignored business_day_id (the Today page sends it).
  Rebuilt on the dicts, header even when empty. tests/test_reports_export.py.
- KI-010: OnlineOrdersPage listened on /api/stream (never existed: no live refresh,
  a 404 every few seconds). It now refetches on the shared live connection
  (online_order_received / online_order_updated / ready); 20 s polling stays as a
  fallback. manager.mjs checks nothing asks for /api/stream.
- KI-007: the setup wizard seeds the 10 default table flags and 5 quick messages in
  the venue language (services/defaults.py), only when none exist. v1's seed never
  worked (NOT NULL columns missing). Managers edit them in Settings -> Operation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 14:08:54 +02:00
co-authored by Claude Opus 5.5
parent f1f20f7bba
commit 034426f870
7 changed files with 158 additions and 33 deletions
@@ -1,5 +1,5 @@
import { useState, useEffect, useCallback, useRef } from 'react'
import useAuthStore from '../store/authStore'
import { useLiveEvent } from '../live/useLiveEvent'
import {
getIncomingOrders,
getActiveOrders,
@@ -236,7 +236,6 @@ export default function OnlineOrdersPage() {
const [history, setHistory] = useState([])
const [loading, setLoading] = useState(false)
const [error, setError] = useState(null)
const token = useAuthStore(s => s.token)
const pollRef = useRef(null)
const fetchAll = useCallback(async () => {
@@ -265,20 +264,11 @@ export default function OnlineOrdersPage() {
return () => clearInterval(pollRef.current)
}, [fetchAll])
// SSE listener — refetch on online_order_received or online_order_updated
useEffect(() => {
if (!token) return
const es = new EventSource(`/api/stream?token=${encodeURIComponent(token)}`)
es.onmessage = (e) => {
try {
const { type } = JSON.parse(e.data)
if (type === 'online_order_received' || type === 'online_order_updated') {
fetchAll()
}
} catch { /* ignore malformed frames */ }
}
return () => es.close()
}, [token, fetchAll])
// Live: refetch on the WebSocket events (KI-010: this listened on /api/stream, which never
// existed). 'ready' = after a reconnect; the 20 s polling above stays as a fallback.
useLiveEvent('online_order_received', fetchAll)
useLiveEvent('online_order_updated', fetchAll)
useLiveEvent('ready', fetchAll)
async function handleAction(action, orderId, extra) {
try {