Revert to guest-cart architecture, drop in-site auth/checkout

Per api.meshkee.com/docs/website/AI_PROMPT.md's hard rules (which an
earlier pass on this branch missed): login, register, OTP, the real
cart, addresses, and payment are the customer dashboard's job
(customer.sanihome.ir), not this storefront's. This site should only
ever run a local guest mini-cart and hand off to the dashboard.

- Remove: AuthContext, LoginModal, lib/auth.ts, lib/cart.ts (the real
  /businesses/{id}/cart integration), and the /checkout page entirely.
- Add lib/guestCart.ts: localStorage + shared cookie
  (meshkee-guest-cart, Domain=.sanihome.ir) cart, storeItemVariantId
  keyed, matching the spec's line shape and ~3500-char cookie-size
  cutoff.
- CartContext is now a thin React wrapper over the guest cart (no
  server round-trip, so add/update/remove are synchronous); CartPopup's
  "Continue" builds the exact customer.sanihome.ir/checkout/cart
  (or /login?redirect=...) URL from the spec, base64url-encoding the
  cart and detecting an existing dashboard session via the shared
  meshkee_customer_access_token cookie.
- ProductCard and ProductPurchasePanel add to the guest cart directly;
  no login gate on add-to-cart anymore.
- Comments panel is a plain guest name/email/text form again (the
  comments API never required auth — gating it on the now-removed
  login system was wrong regardless).
- CONTEXT.md rewritten to document the guest-cart contract explicitly
  and flag this exact mistake so it doesn't get reintroduced.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
amirhosein.ashourloo
2026-09-06 15:01:22 +03:30
co-authored by Claude Sonnet 5
parent 053a9ba361
commit 5152b16d61
23 changed files with 351 additions and 1266 deletions
+37 -35
View File
@@ -2,7 +2,6 @@
import { useState } from "react";
import { EmptyState } from "@/components/ui/EmptyState";
import { useAuth } from "@/context/AuthContext";
import { postComment, type EntityComment, type TechnicalInfoField } from "@/lib/meshkee";
type Tab = "specs" | "review" | "comments";
@@ -19,23 +18,23 @@ function formatDate(iso?: string) {
}
function CommentsPanel({ entityId, initialComments }: { entityId: string; initialComments: EntityComment[] }) {
const { user, openLoginModal } = useAuth();
const [comments, setComments] = useState(initialComments);
const [name, setName] = useState("");
const [email, setEmail] = useState("");
const [text, setText] = useState("");
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const handleSubmit = async (event: React.FormEvent) => {
event.preventDefault();
if (!user || !text.trim()) return;
if (!name.trim() || !text.trim()) return;
setBusy(true);
setError(null);
const authorName = [user.firstName, user.lastName].filter(Boolean).join(" ") || "کاربر";
const res = await postComment({
entityType: "product",
entityId,
authorName,
authorEmail: user.email,
authorName: name.trim(),
authorEmail: email.trim() || undefined,
text: text.trim(),
});
setBusy(false);
@@ -43,43 +42,46 @@ function CommentsPanel({ entityId, initialComments }: { entityId: string; initia
setError(res.message ?? "ثبت نظر ناموفق بود.");
return;
}
setComments((prev) => [{ id: `local-${Date.now()}`, authorName, text: text.trim() }, ...prev]);
setComments((prev) => [{ id: `local-${Date.now()}`, authorName: name.trim(), text: text.trim() }, ...prev]);
setText("");
};
return (
<div>
{user ? (
<form onSubmit={handleSubmit} className="mb-6 space-y-3">
<textarea
<form onSubmit={handleSubmit} className="mb-6 space-y-3">
<div className="grid gap-3 sm:grid-cols-2">
<input
required
rows={3}
value={text}
onChange={(e) => setText(e.target.value)}
placeholder="نظر خود را درباره این محصول بنویسید..."
className="w-full rounded-xl border border-border bg-background p-3 text-sm outline-none transition-colors focus:border-red"
placeholder="نام شما"
value={name}
onChange={(e) => setName(e.target.value)}
className="w-full rounded-lg border border-border bg-background px-3 py-2 text-sm outline-none transition-colors focus:border-red"
/>
<input
type="email"
placeholder="ایمیل (اختیاری)"
value={email}
onChange={(e) => setEmail(e.target.value)}
className="w-full rounded-lg border border-border bg-background px-3 py-2 text-sm outline-none transition-colors focus:border-red"
/>
{error && <p className="text-xs text-red-dark">{error}</p>}
<button
type="submit"
disabled={busy || !text.trim()}
className="rounded-lg bg-red px-5 py-2 text-sm font-medium text-white transition-colors hover:bg-red-dark disabled:cursor-not-allowed disabled:opacity-60"
>
{busy ? "در حال ثبت..." : "ثبت نظر"}
</button>
</form>
) : (
<div className="mb-6 flex flex-wrap items-center justify-between gap-3 rounded-xl bg-background p-4 text-sm">
<span className="text-muted">برای ثبت نظر ابتدا وارد حساب کاربری خود شوید.</span>
<button
type="button"
onClick={openLoginModal}
className="rounded-lg bg-red px-4 py-1.5 text-xs font-medium text-white transition-colors hover:bg-red-dark"
>
ورود
</button>
</div>
)}
<textarea
required
rows={3}
value={text}
onChange={(e) => setText(e.target.value)}
placeholder="نظر خود را درباره این محصول بنویسید..."
className="w-full rounded-xl border border-border bg-background p-3 text-sm outline-none transition-colors focus:border-red"
/>
{error && <p className="text-xs text-red-dark">{error}</p>}
<button
type="submit"
disabled={busy || !name.trim() || !text.trim()}
className="rounded-lg bg-red px-5 py-2 text-sm font-medium text-white transition-colors hover:bg-red-dark disabled:cursor-not-allowed disabled:opacity-60"
>
{busy ? "در حال ثبت..." : "ثبت نظر"}
</button>
</form>
{comments.length === 0 ? (
<EmptyState message="هنوز نظری برای این محصول ثبت نشده است." />