diff --git a/public/sw.js b/public/sw.js index bc8c284..eb18226 100644 --- a/public/sw.js +++ b/public/sw.js @@ -6,7 +6,7 @@ * queued in localStorage by the app itself (see lib/ledgerStore.ts); this worker * only guarantees the shell and its assets are reachable. */ -const CACHE = 'udyamlinc-v1' +const CACHE = 'udyamlinc-v2' const SHELL = ['/', '/app', '/index.html', '/manifest.webmanifest', '/udyamlinc-tile.svg'] self.addEventListener('install', (event) => { diff --git a/src/features/enterprise/AppAlertsPage.tsx b/src/features/enterprise/AppAlertsPage.tsx index 7dd2eb6..41a88e3 100644 --- a/src/features/enterprise/AppAlertsPage.tsx +++ b/src/features/enterprise/AppAlertsPage.tsx @@ -1,4 +1,5 @@ -import { enterpriseSession } from '../../lib/api' +import { useQuery } from '@tanstack/react-query' +import { enterpriseSession, fetchAppAlerts, fetchAppReasons } from '../../lib/api' import { Empty } from '../../components/ui/bits' import { findEnterprise, reasonCodesFor, tripWiresFor } from '../../lib/demo/enterprises' import { alertForEnterprise } from '../../lib/demo/ops' @@ -15,11 +16,28 @@ export function AppAlertsPage() { const { lang, t } = useLang('hi') const hi = lang === 'hi' + // Live alerts for this borrower. The token decides whose they are. + const alertsQ = useQuery({ queryKey: ["app-alerts"], queryFn: fetchAppAlerts, enabled: Boolean(session) }) + // The scored reasons, not a sentence generated from the demo sector table. + const reasonsQ = useQuery({ queryKey: ["app-reasons"], queryFn: fetchAppReasons, enabled: Boolean(session) }) + const e = session ? findEnterprise(session.enterpriseId) : undefined if (!session || !e) return - const alert = alertForEnterprise(e.enterpriseId) - const reasons = reasonCodesFor(e) + const live = alertsQ.data?.[0] + const alert = live + ? { ...live, titleHi: live.titleHi ?? live.title, shortfall: live.shortfall ?? 0, + breachMonth: live.breachMonth ?? "", + reason: { driver: "", driverHi: "", weight: 0, + sentenceEn: live.reasonEn ?? "", sentenceHi: live.reasonHi ?? "" } } + : alertsQ.isSuccess ? null : alertForEnterprise(e.enterpriseId) + // Fall back to the demo sentences only while the request is in flight — once it + // has answered, an empty list means this borrower has no scored reasons, and + // inventing three would be a lie told on the borrower's own screen. + const live_reasons = reasonsQ.data + const reasons = live_reasons + ? live_reasons.slice(0, 3) + : reasonsQ.isSuccess ? [] : reasonCodesFor(e) const fired = tripWiresFor(e).filter((w) => w.fired) if (!alert) { @@ -52,6 +70,11 @@ export function AppAlertsPage() { {hi ? 'ऐसा क्यों लग रहा है' : 'Why this is expected'}