feat(dashboard): Next.js 16 merchant panel with offline POS and PWA
Complete merchant dashboard upgrade:
Next.js 16 compatibility:
- Fix params/searchParams typed as Promise<{}> throughout App Router
- Replace middleware.ts with proxy.ts (Next.js 16 convention)
- Remove unused @ts-expect-error directives caught by stricter TS
- Cast dynamic next-intl t() keys to fix TranslateArgs type errors
Offline POS:
- IndexedDB queue (meezi_pos_offline) for orders created while offline
- Zustand sync store tracking queueCount, isSyncing, isOnline
- useOfflineSync hook: auto-syncs on reconnect/visibility-change
- SyncStatusIndicator chip in topbar (amber=offline, blue=syncing)
- submitOrderToApi falls back to local order on network failure
- Local orders skip payment flow; sync on reconnect
PWA (installable):
- @ducanh2912/next-pwa with Workbox runtime caching rules
- Web App Manifest (manifest.ts) — RTL/Farsi, theme #0F6E56
- PWA icons: 192px, 512px, maskable 512px
- next.config.ts replaces next.config.mjs
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
"use client";
|
||||
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useTranslations, useLocale } from "next-intl";
|
||||
import { Link } from "@/i18n/routing";
|
||||
import { apiGet } from "@/lib/api/client";
|
||||
import type { QueueBoard } from "@/lib/api/types";
|
||||
import { useAuthStore } from "@/lib/stores/auth.store";
|
||||
import { formatNumber } from "@/lib/format";
|
||||
|
||||
export function QueueDisplayScreen() {
|
||||
const t = useTranslations("queue");
|
||||
const locale = useLocale();
|
||||
const numberLocale = locale === "en" ? "en-US" : "fa-IR";
|
||||
const cafeId = useAuthStore((s) => s.user?.cafeId);
|
||||
const searchParams = useSearchParams();
|
||||
const branchId = searchParams.get("branchId");
|
||||
const branchQuery = branchId ? `?branchId=${encodeURIComponent(branchId)}` : "";
|
||||
|
||||
const { data: board } = useQuery({
|
||||
queryKey: ["queue-today", cafeId, branchId, "display"],
|
||||
queryFn: () => apiGet<QueueBoard>(`/api/cafes/${cafeId}/queue/today${branchQuery}`),
|
||||
enabled: !!cafeId,
|
||||
refetchInterval: 5_000,
|
||||
});
|
||||
|
||||
const waiting = board?.tickets.filter((x) => x.status === "Waiting") ?? [];
|
||||
const nowServing = board?.nowServing;
|
||||
|
||||
return (
|
||||
<div className="flex min-h-svh flex-col bg-neutral-950 text-white">
|
||||
<div className="flex items-center justify-between border-b border-white/10 px-6 py-3">
|
||||
<p className="text-sm font-medium uppercase tracking-[0.12em] text-white/60">
|
||||
{t("title")} · {t("displayMode")}
|
||||
</p>
|
||||
<Link
|
||||
href="/queue"
|
||||
className="text-xs text-white/50 underline-offset-2 hover:text-white hover:underline"
|
||||
>
|
||||
{t("exitDisplay")}
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-1 flex-col items-center justify-center gap-10 px-6 py-8">
|
||||
<div className="text-center">
|
||||
<p className="text-lg font-medium uppercase tracking-[0.14em] text-amber-400/90">
|
||||
{t("nowServing")}
|
||||
</p>
|
||||
<p className="mt-2 text-[min(28vw,12rem)] font-bold tabular-nums leading-none text-white">
|
||||
{nowServing != null ? formatNumber(nowServing, numberLocale) : "—"}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="grid w-full max-w-4xl gap-6 sm:grid-cols-2">
|
||||
<div className="rounded-2xl border border-white/10 bg-white/5 px-6 py-5 text-center">
|
||||
<p className="text-xs uppercase tracking-wide text-white/50">{t("lastIssued")}</p>
|
||||
<p className="mt-2 text-4xl font-semibold tabular-nums">
|
||||
{formatNumber(board?.lastIssued ?? 0, numberLocale)}
|
||||
</p>
|
||||
</div>
|
||||
<div className="rounded-2xl border border-white/10 bg-white/5 px-6 py-5 text-center">
|
||||
<p className="text-xs uppercase tracking-wide text-white/50">{t("displayWaitingLabel")}</p>
|
||||
<p className="mt-2 text-4xl font-semibold tabular-nums text-amber-300">
|
||||
{formatNumber(board?.waitingCount ?? 0, numberLocale)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{waiting.length > 0 ? (
|
||||
<div className="w-full max-w-3xl">
|
||||
<p className="mb-3 text-center text-xs uppercase tracking-wide text-white/40">
|
||||
{t("displayUpNext")}
|
||||
</p>
|
||||
<div className="flex flex-wrap justify-center gap-3">
|
||||
{waiting.slice(0, 12).map((ticket) => (
|
||||
<span
|
||||
key={ticket.id}
|
||||
className="rounded-xl border border-amber-500/30 bg-amber-500/10 px-5 py-3 text-2xl font-bold tabular-nums"
|
||||
>
|
||||
{formatNumber(ticket.number, numberLocale)}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user