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,115 @@
|
||||
"use client";
|
||||
|
||||
import { useRef } from "react";
|
||||
import { ImagePlus, Video } from "lucide-react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { apiUpload, resolveMediaUrl } from "@/lib/api/client";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
type MediaKind = "menu" | "table";
|
||||
|
||||
type MediaPairUploadProps = {
|
||||
cafeId: string;
|
||||
kind: MediaKind;
|
||||
imageUrl?: string | null;
|
||||
videoUrl?: string | null;
|
||||
onImageChange: (url: string | null) => void;
|
||||
onVideoChange: (url: string | null) => void;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
export function MediaPairUpload({
|
||||
cafeId,
|
||||
kind,
|
||||
imageUrl,
|
||||
videoUrl,
|
||||
onImageChange,
|
||||
onVideoChange,
|
||||
className,
|
||||
}: MediaPairUploadProps) {
|
||||
const t = useTranslations("media");
|
||||
const imageRef = useRef<HTMLInputElement>(null);
|
||||
const videoRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
const imageEndpoint =
|
||||
kind === "menu"
|
||||
? `/api/cafes/${cafeId}/media/menu-image`
|
||||
: `/api/cafes/${cafeId}/media/table-image`;
|
||||
const videoEndpoint =
|
||||
kind === "menu"
|
||||
? `/api/cafes/${cafeId}/media/menu-video`
|
||||
: `/api/cafes/${cafeId}/media/table-video`;
|
||||
|
||||
const imgSrc = resolveMediaUrl(imageUrl);
|
||||
const vidSrc = resolveMediaUrl(videoUrl);
|
||||
|
||||
const upload = async (file: File, endpoint: string, onDone: (url: string) => void) => {
|
||||
const data = await apiUpload<{ url: string }>(endpoint, file);
|
||||
onDone(data.url);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={cn("space-y-2", className)}>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<input
|
||||
ref={imageRef}
|
||||
type="file"
|
||||
accept="image/jpeg,image/png,image/webp"
|
||||
className="hidden"
|
||||
onChange={(e) => {
|
||||
const f = e.target.files?.[0];
|
||||
if (f) void upload(f, imageEndpoint, onImageChange);
|
||||
}}
|
||||
/>
|
||||
<input
|
||||
ref={videoRef}
|
||||
type="file"
|
||||
accept="video/mp4,video/webm,video/quicktime"
|
||||
className="hidden"
|
||||
onChange={(e) => {
|
||||
const f = e.target.files?.[0];
|
||||
if (f) void upload(f, videoEndpoint, onVideoChange);
|
||||
}}
|
||||
/>
|
||||
<Button type="button" size="sm" variant="outline" onClick={() => imageRef.current?.click()}>
|
||||
<ImagePlus className="me-1 h-3.5 w-3.5" />
|
||||
{t("uploadImage")}
|
||||
</Button>
|
||||
<Button type="button" size="sm" variant="outline" onClick={() => videoRef.current?.click()}>
|
||||
<Video className="me-1 h-3.5 w-3.5" />
|
||||
{t("uploadVideo")}
|
||||
</Button>
|
||||
{imageUrl ? (
|
||||
<Button type="button" size="sm" variant="ghost" onClick={() => onImageChange(null)}>
|
||||
{t("removeImage")}
|
||||
</Button>
|
||||
) : null}
|
||||
{videoUrl ? (
|
||||
<Button type="button" size="sm" variant="ghost" onClick={() => onVideoChange(null)}>
|
||||
{t("removeVideo")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-3">
|
||||
{imgSrc ? (
|
||||
// eslint-disable-next-line @next/next/no-img-element
|
||||
<img
|
||||
src={imgSrc}
|
||||
alt=""
|
||||
className="h-20 w-20 rounded-lg border object-cover"
|
||||
/>
|
||||
) : null}
|
||||
{vidSrc ? (
|
||||
<video
|
||||
src={vidSrc}
|
||||
className="h-20 max-w-[140px] rounded-lg border object-cover"
|
||||
muted
|
||||
playsInline
|
||||
controls
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
"use client";
|
||||
|
||||
import { useRef } from "react";
|
||||
import { Box } from "lucide-react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { apiGet, apiUpload, ApiClientError } from "@/lib/api/client";
|
||||
import { MENU_3D_GLB_MAX_MB, MENU_360_PHOTO_COUNT } from "@/lib/menu-3d";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
type Menu3dUploadProps = {
|
||||
cafeId: string;
|
||||
model3dUrl?: string | null;
|
||||
onChange: (url: string | null) => void;
|
||||
};
|
||||
|
||||
export function Menu3dUpload({ cafeId, model3dUrl, onChange }: Menu3dUploadProps) {
|
||||
const t = useTranslations("media");
|
||||
const tSub = useTranslations("subscription");
|
||||
const ref = useRef<HTMLInputElement>(null);
|
||||
const { data: billing } = useQuery({
|
||||
queryKey: ["billing-status", cafeId],
|
||||
queryFn: () => apiGet<{ menu3dEnabled: boolean }>("/api/billing/status"),
|
||||
enabled: !!cafeId,
|
||||
});
|
||||
const enabled = billing?.menu3dEnabled ?? false;
|
||||
|
||||
return (
|
||||
<div className="space-y-2 rounded-lg border border-dashed border-border/80 bg-muted/20 p-3">
|
||||
<p className="text-xs font-medium text-foreground">{t("upload3dTitle")}</p>
|
||||
<p className="text-xs text-muted-foreground">{t("upload3dHint", { maxMb: MENU_3D_GLB_MAX_MB })}</p>
|
||||
{!enabled ? (
|
||||
<p className="text-xs text-amber-700">{tSub("featureMenu3dUpgrade")}</p>
|
||||
) : null}
|
||||
<p className="text-[11px] text-muted-foreground">
|
||||
{t("upload3dPhotoCount", {
|
||||
min: MENU_360_PHOTO_COUNT.min,
|
||||
ideal: MENU_360_PHOTO_COUNT.ideal,
|
||||
})}
|
||||
</p>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<input
|
||||
ref={ref}
|
||||
type="file"
|
||||
accept=".glb,model/gltf-binary"
|
||||
className="hidden"
|
||||
onChange={(e) => {
|
||||
const f = e.target.files?.[0];
|
||||
if (!f) return;
|
||||
void apiUpload<{ url: string }>(`/api/cafes/${cafeId}/media/menu-model3d`, f)
|
||||
.then((d) => onChange(d.url))
|
||||
.catch((err) => {
|
||||
if (err instanceof ApiClientError && err.code === "PLAN_FEATURE_DISABLED") {
|
||||
alert(tSub("featureMenu3dUpgrade"));
|
||||
}
|
||||
});
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="outline"
|
||||
disabled={!enabled}
|
||||
onClick={() => ref.current?.click()}
|
||||
>
|
||||
<Box className="me-1 h-3.5 w-3.5" />
|
||||
{t("upload3d")}
|
||||
</Button>
|
||||
{model3dUrl ? (
|
||||
<Button type="button" size="sm" variant="ghost" onClick={() => onChange(null)}>
|
||||
{t("remove3d")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
{model3dUrl ? (
|
||||
<p className="text-[11px] text-[#0F6E56]">{t("upload3dReady")}</p>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Sparkles } from "lucide-react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { apiGet, apiPost, ApiClientError } from "@/lib/api/client";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { notify } from "@/lib/notify";
|
||||
|
||||
type MenuAi3dGenerateProps = {
|
||||
cafeId: string;
|
||||
itemId: string;
|
||||
imageUrl?: string | null;
|
||||
onGenerated: (model3dUrl: string) => void;
|
||||
};
|
||||
|
||||
type BillingStatus = {
|
||||
menu3dEnabled: boolean;
|
||||
menuAi3dEnabled: boolean;
|
||||
menuAi3dUsedThisMonth: number;
|
||||
menuAi3dMonthlyLimit: number;
|
||||
};
|
||||
|
||||
type Ai3dUsage = {
|
||||
used: number;
|
||||
limit: number;
|
||||
period: string;
|
||||
};
|
||||
|
||||
export function MenuAi3dGenerate({
|
||||
cafeId,
|
||||
itemId,
|
||||
imageUrl,
|
||||
onGenerated,
|
||||
}: MenuAi3dGenerateProps) {
|
||||
const t = useTranslations("media");
|
||||
const tSub = useTranslations("subscription");
|
||||
const queryClient = useQueryClient();
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
const { data: billing } = useQuery({
|
||||
queryKey: ["billing-status", cafeId],
|
||||
queryFn: () => apiGet<BillingStatus>("/api/billing/status"),
|
||||
enabled: !!cafeId,
|
||||
});
|
||||
|
||||
const { data: usage } = useQuery({
|
||||
queryKey: ["menu-ai-3d-usage", cafeId],
|
||||
queryFn: () => apiGet<Ai3dUsage>(`/api/cafes/${cafeId}/menu/ai-3d/usage`),
|
||||
enabled: !!cafeId && (billing?.menuAi3dEnabled ?? false),
|
||||
});
|
||||
|
||||
const aiEnabled = billing?.menuAi3dEnabled ?? false;
|
||||
const used = usage?.used ?? billing?.menuAi3dUsedThisMonth ?? 0;
|
||||
const limit = usage?.limit ?? billing?.menuAi3dMonthlyLimit ?? 100;
|
||||
const atLimit = limit > 0 && used >= limit;
|
||||
|
||||
const generate = useMutation({
|
||||
mutationFn: () =>
|
||||
apiPost<{ model3dUrl: string; used: number; limit: number }>(
|
||||
`/api/cafes/${cafeId}/menu/items/${itemId}/ai-3d`,
|
||||
{}
|
||||
),
|
||||
onSuccess: (data) => {
|
||||
onGenerated(data.model3dUrl);
|
||||
void queryClient.invalidateQueries({ queryKey: ["billing-status", cafeId] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["menu-ai-3d-usage", cafeId] });
|
||||
notify.success(t("ai3dSuccess"));
|
||||
},
|
||||
onError: (err) => {
|
||||
if (err instanceof ApiClientError) {
|
||||
if (err.code === "PLAN_FEATURE_DISABLED") {
|
||||
notify.error(tSub("featureMenuAi3dUpgrade"));
|
||||
return;
|
||||
}
|
||||
if (err.code === "PLAN_LIMIT_REACHED") {
|
||||
notify.error(t("ai3dLimitReached"));
|
||||
return;
|
||||
}
|
||||
if (err.code === "NO_IMAGE") {
|
||||
notify.error(t("ai3dNoImage"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
notify.error(t("ai3dFailed"));
|
||||
},
|
||||
});
|
||||
|
||||
const handleClick = async () => {
|
||||
setBusy(true);
|
||||
try {
|
||||
await generate.mutateAsync();
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (!billing?.menu3dEnabled) return null;
|
||||
|
||||
return (
|
||||
<div className="space-y-2 rounded-lg border border-border/80 bg-card p-3">
|
||||
<p className="text-xs font-medium text-foreground">{t("ai3dTitle")}</p>
|
||||
<p className="text-xs text-muted-foreground">{t("ai3dHint")}</p>
|
||||
{!aiEnabled ? (
|
||||
<p className="text-xs text-amber-700">{tSub("featureMenuAi3dUpgrade")}</p>
|
||||
) : (
|
||||
<p className="text-[11px] text-muted-foreground">
|
||||
{t("ai3dUsage", { used: used.toLocaleString("fa-IR"), limit: limit.toLocaleString("fa-IR") })}
|
||||
</p>
|
||||
)}
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="default"
|
||||
className="bg-primary text-primary-foreground hover:opacity-90"
|
||||
disabled={!aiEnabled || !imageUrl || atLimit || busy || generate.isPending}
|
||||
onClick={() => void handleClick()}
|
||||
>
|
||||
<Sparkles className="me-1 h-3.5 w-3.5" />
|
||||
{busy || generate.isPending ? t("ai3dGenerating") : t("ai3dGenerate")}
|
||||
</Button>
|
||||
{!imageUrl ? (
|
||||
<p className="text-[11px] text-amber-700">{t("ai3dNoImage")}</p>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user