Files
meezi/web/dashboard/src/components/settings/settings-screen.tsx
T
soroush.asadi 131ecdbbe6 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>
2026-05-27 21:34:12 +03:30

106 lines
3.6 KiB
TypeScript

"use client";
import { useState } from "react";
import { useTranslations } from "next-intl";
import { useAuthStore } from "@/lib/stores/auth.store";
import { PageHeader } from "@/components/layout/page-header";
import { SettingsNav } from "@/components/settings/settings-nav";
import { SettingsAppearancePanel } from "@/components/settings/settings-appearance-panel";
import { CafeDiscoverProfilePanel } from "@/components/discover/cafe-discover-profile-panel";
import { CafePublicProfilePanel } from "@/components/discover/cafe-public-profile-panel";
import { SettingsShopPanel } from "@/components/settings/settings-shop-panel";
import { SettingsTerminalsPanel } from "@/components/settings/settings-terminals-panel";
import { SettingsPrinterPanel } from "@/components/settings/settings-printer-panel";
import { SettingsPrintTestPanel } from "@/components/settings/settings-print-test-panel";
import {
DEFAULT_SETTINGS_LEAF,
groupForLeaf,
type SettingsGroupId,
type SettingsLeafId,
} from "@/components/settings/settings-types";
const LEAF_PAGE_TITLE: Record<SettingsLeafId, string> = {
"shop-general": "nav.shopGeneral",
"shop-appearance": "nav.shopAppearance",
"shop-discover": "nav.shopDiscover",
"printer-config": "nav.printerSettings",
"print-test": "nav.printTest",
};
export function SettingsScreen() {
const t = useTranslations("settings");
const cafeId = useAuthStore((s) => s.user?.cafeId);
const [activeLeaf, setActiveLeaf] = useState<SettingsLeafId>(DEFAULT_SETTINGS_LEAF);
const [expandedGroup, setExpandedGroup] = useState<SettingsGroupId>("shop");
const selectLeaf = (leaf: SettingsLeafId) => {
setActiveLeaf(leaf);
setExpandedGroup(groupForLeaf(leaf));
};
const toggleGroup = (group: SettingsGroupId) => {
setExpandedGroup((prev) => (prev === group ? prev : group));
const firstChild = group === "shop" ? "shop-general" : "printer-config";
if (groupForLeaf(activeLeaf) !== group) {
selectLeaf(firstChild);
}
};
if (!cafeId) return null;
const pageTitle = t(LEAF_PAGE_TITLE[activeLeaf]);
return (
<div className="space-y-6">
<PageHeader title={t("title")} subtitle={t("subtitle")} />
<div className="flex flex-col gap-6 md:flex-row md:items-start md:gap-8">
<SettingsNav
activeLeaf={activeLeaf}
expandedGroup={expandedGroup}
onSelectLeaf={selectLeaf}
onToggleGroup={toggleGroup}
/>
<div className="min-w-0 flex-1 space-y-4">
<p className="pb-0.5 text-[11px] font-medium uppercase tracking-[0.06em] text-muted-foreground">
{pageTitle}
</p>
{activeLeaf === "shop-general" ? (
<div className="space-y-4">
<SettingsShopPanel cafeId={cafeId} />
<SettingsTerminalsPanel />
</div>
) : null}
{activeLeaf === "shop-appearance" ? (
<SettingsAppearancePanel cafeId={cafeId} />
) : null}
{activeLeaf === "shop-discover" ? (
<div className="space-y-6">
<CafeDiscoverProfilePanel cafeId={cafeId} mode="merchant" />
<CafePublicProfilePanel cafeId={cafeId} />
</div>
) : null}
{activeLeaf === "printer-config" ? (
<SettingsPrinterPanel
cafeId={cafeId}
onOpenPrintTest={() => selectLeaf("print-test")}
/>
) : null}
{activeLeaf === "print-test" ? (
<SettingsPrintTestPanel
cafeId={cafeId}
onOpenPrinterSettings={() => selectLeaf("printer-config")}
/>
) : null}
</div>
</div>
</div>
);
}