131ecdbbe6
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>
59 lines
1.5 KiB
TypeScript
59 lines
1.5 KiB
TypeScript
/** Localized menu label: primary name for locale + English line for international guests. */
|
|
|
|
export type MenuNameFields = {
|
|
name: string;
|
|
nameEn?: string | null;
|
|
nameAr?: string | null;
|
|
};
|
|
|
|
export function getMenuPrimaryName(
|
|
item: MenuNameFields,
|
|
locale: string
|
|
): string {
|
|
const en = item.nameEn?.trim();
|
|
const ar = item.nameAr?.trim();
|
|
const fa = item.name.trim();
|
|
|
|
if (locale === "en") return en || fa;
|
|
if (locale === "ar") return ar || fa;
|
|
return fa;
|
|
}
|
|
|
|
/** English subtitle when primary is fa/ar (helps staff and international customers). */
|
|
export function getMenuEnglishSubtitle(
|
|
item: MenuNameFields,
|
|
locale: string
|
|
): string | undefined {
|
|
const en = item.nameEn?.trim();
|
|
if (!en) return undefined;
|
|
|
|
const primary = getMenuPrimaryName(item, locale);
|
|
if (primary === en) return undefined;
|
|
|
|
if (locale === "en") return undefined;
|
|
|
|
return en;
|
|
}
|
|
|
|
/** Case-insensitive match for POS / menu search (fa, en, ar, description). */
|
|
export function menuItemMatchesSearch(
|
|
item: MenuNameFields & { description?: string | null },
|
|
query: string,
|
|
locale: string
|
|
): boolean {
|
|
const q = query.trim().toLowerCase();
|
|
if (!q) return true;
|
|
const haystack = [
|
|
item.name,
|
|
item.nameEn,
|
|
item.nameAr,
|
|
item.description,
|
|
getMenuPrimaryName(item, locale),
|
|
getMenuEnglishSubtitle(item, locale),
|
|
]
|
|
.filter((s): s is string => typeof s === "string" && s.length > 0)
|
|
.join(" ")
|
|
.toLowerCase();
|
|
return haystack.includes(q);
|
|
}
|