feat(preview): make three-language five-market showcase interactive with explicit sample catalogue
davoodmehraban89 committed
Oct 15, 2026 at 01:25 UTC
2d4e4726cdb531527e7ab2dc666e397ce467cde5
1 file changed
+201
-34
commerce/src/main.tsx
+201
-34
@@ -2,20 +2,69 @@ import React from "react"
2
import { createRoot } from "react-dom/client"
3
import { MARKETS, LOCALES, type MarketCode, type StoreLocale } from "./config/markets"
4
import { fetchCatalog, type CatalogProduct } from "./api/catalog"
5
+import { previewProductsForMarket, type PreviewProduct, type PreviewVisual, type PreviewKind } from "./preview/products"
6
import "./styles.css"
7
8
+type CatalogState = "unconfigured" | "loading" | "ready" | "error"
9
+type Filter = "all" | PreviewKind
10
+
11
+function Artwork({ visual }: { visual: PreviewVisual }) {
12
+ return (
13
+ <div className={"artwork art-" + visual} aria-hidden="true">
14
+ <span className="artwork-orbit" />
15
+ <svg viewBox="0 0 240 180" fill="none" stroke="currentColor" strokeWidth="4" strokeLinecap="round" strokeLinejoin="round">
16
+ {visual === "phone" && <><rect x="84" y="24" width="72" height="132" rx="13" /><path d="M110 33h20" /><circle cx="120" cy="145" r="3" /><path d="M96 65l38-16M99 92l40-15" strokeOpacity=".24" strokeWidth="10" /></>}
17
+ {visual === "laptop" && <><rect x="43" y="42" width="154" height="96" rx="7" /><path d="M25 144h190l-17 12H42z" /><path d="M88 80h64M104 97h32" strokeOpacity=".32" strokeWidth="10" /></>}
18
+ {visual === "headphones" && <><path d="M61 102V83a59 59 0 0 1 118 0v19" /><rect x="48" y="94" width="28" height="52" rx="12" /><rect x="164" y="94" width="28" height="52" rx="12" /><path d="M179 146c-3 20-18 22-37 22h-12" /><rect x="109" y="160" width="24" height="13" rx="6" /></>}
19
+ {visual === "camera" && <><rect x="39" y="66" width="162" height="92" rx="14" /><circle cx="122" cy="110" r="32" /><circle cx="122" cy="110" r="13" /><path d="M77 66l14-19h58l14 19" /><circle cx="180" cy="82" r="4" /></>}
20
+ {visual === "tea" && <><path d="M72 46h90l-9 113H81z" /><path d="M85 64h64M88 143h56" /><path d="M107 16c-13 14 10 18-4 32M137 16c-13 14 10 18-4 32" /><path d="M92 105c26-24 30 22 49 0" strokeOpacity=".55" /></>}
21
+ {visual === "ceramic" && <><path d="M79 38h82M88 38c-3 21 13 28 8 42-6 21-28 24-28 51 0 20 21 28 52 28s52-8 52-28c0-27-22-30-28-51-5-14 11-21 8-42" /><path d="M83 118c26-13 48 15 74 0M92 133c16-7 40 7 56 0" strokeOpacity=".4" /></>}
22
+ {visual === "textile" && <><path d="M50 35h140v110H50z" /><path d="M68 35v110M87 35v110M106 35v110M125 35v110M144 35v110M163 35v110" strokeOpacity=".35" /><path d="M50 63h140M50 88h140M50 113h140" strokeOpacity=".45" /><path d="M50 153v10M68 153v10M87 153v10M106 153v10M125 153v10M144 153v10M163 153v10M190 153v10" /></>}
23
+ {visual === "saffron" && <><path d="M58 96c-16-20-15-39-10-48 20 3 41 23 51 46M182 96c16-20 15-39 10-48-20 3-41 23-51 46" /><path d="M97 92c-20-37-7-67 23-76 30 9 43 39 23 76" /><path d="M89 98h62l-8 55H97z" /><path d="M86 99h68M105 117l30 20M135 117l-30 20" strokeOpacity=".45" /></>}
24
+ </svg>
25
+ </div>
26
+ )
27
+}
28
+
29
function App() {
30
const [market, setMarket] = React.useState<MarketCode>("IR")
31
const [locale, setLocale] = React.useState<StoreLocale>("fa-IR")
32
const [products, setProducts] = React.useState<CatalogProduct[]>([])
11
- const [catalogState, setCatalogState] = React.useState<"unconfigured" | "loading" | "ready" | "error">("unconfigured")
12
- const isFa = locale === "fa-IR"
13
- const isAr = locale === "ar"
14
- const tr = (fa: string, en: string, ar: string) => isFa ? fa : isAr ? ar : en
15
- const marketNames: Record<MarketCode, string> = isFa
33
+ const [catalogState, setCatalogState] = React.useState<CatalogState>("unconfigured")
34
+ const [filter, setFilter] = React.useState<Filter>("all")
35
+ const [search, setSearch] = React.useState("")
36
+ const [selected, setSelected] = React.useState<PreviewProduct | null>(null)
37
+
38
+ const fa = locale === "fa-IR"
39
+ const ar = locale === "ar"
40
+ const tr = (persian: string, english: string, arabic: string) => fa ? persian : ar ? arabic : english
41
+
42
+ const marketNames: Record<MarketCode, string> = fa
43
? { IR: "ایران", AE: "امارات", OM: "عمان", IQ: "عراق", QA: "قطر" }
17
- : isAr ? { IR: "إيران", AE: "الإمارات", OM: "عُمان", IQ: "العراق", QA: "قطر" }
44
+ : ar
45
+ ? { IR: "إيران", AE: "الإمارات", OM: "عُمان", IQ: "العراق", QA: "قطر" }
46
: { IR: "Iran", AE: "UAE", OM: "Oman", IQ: "Iraq", QA: "Qatar" }
47
+
48
+ React.useEffect(() => {
49
+ document.documentElement.dir = LOCALES[locale].direction
50
+ document.documentElement.lang = LOCALES[locale].language
51
+ }, [locale])
52
+
53
+ React.useEffect(() => {
54
+ setSelected(null)
55
+ setFilter("all")
56
+ setSearch("")
57
+ }, [market])
58
+
59
+ React.useEffect(() => {
60
+ if (!selected) return
61
+ const onKeyDown = (event: KeyboardEvent) => {
62
+ if (event.key === "Escape") setSelected(null)
63
+ }
64
+ window.addEventListener("keydown", onKeyDown)
65
+ return () => window.removeEventListener("keydown", onKeyDown)
66
+ }, [selected])
67
+
68
React.useEffect(() => {
69
const backendUrl = import.meta.env.VITE_MEDUSA_BACKEND_URL
70
const publishableKey = import.meta.env.VITE_MEDUSA_PUBLISHABLE_KEY
@@ -28,40 +77,158 @@ function App() {
77
setCatalogState("loading")
78
setProducts([])
79
fetchCatalog(market, { backendUrl, publishableKey, signal: controller.signal })
31
- .then((items) => { if (!controller.signal.aborted) { setProducts(items); setCatalogState("ready") } })
32
- .catch(() => { if (!controller.signal.aborted) setCatalogState("error") })
80
+ .then((items) => {
81
+ if (!controller.signal.aborted) {
82
+ setProducts(items)
83
+ setCatalogState("ready")
84
+ }
85
+ })
86
+ .catch(() => {
87
+ if (!controller.signal.aborted) setCatalogState("error")
88
+ })
89
return () => controller.abort()
90
}, [market])
91
+
92
+ const isDemo = catalogState === "unconfigured" || catalogState === "error"
93
+ const examples = previewProductsForMarket(market).filter((p) => {
94
+ if (filter !== "all" && p.kind !== filter) return false
95
+ if (!search.trim()) return true
96
+ const term = search.trim().toLocaleLowerCase()
97
+ return p.name[locale].toLocaleLowerCase().includes(term) || p.description[locale].toLocaleLowerCase().includes(term)
98
+ })
99
+ const filteredRealProducts = products.filter((p) => p.title.toLocaleLowerCase().includes(search.trim().toLocaleLowerCase()))
100
+ const labelForKind = (kind: PreviewKind) => kind === "electronics"
101
+ ? tr("دیجیتال و الکترونیک", "Electronics", "الإلكترونيات")
102
+ : tr("محصولات منتخب ایران", "Iran-origin collections", "منتجات مختارة من إيران")
103
+
104
return (
36
- <main dir={LOCALES[locale].direction} lang={LOCALES[locale].language}>
105
+ <div className="app-shell">
106
+ <div className="preview-strip">
107
+ <span className="live-dot" />
108
+ {tr("پیشنمایش تعاملی طراحی · بدون خرید یا پرداخت واقعی", "Interactive design preview · no real purchases or payments", "معاينة تصميم تفاعلية · لا شراء أو دفع حقيقي")}
109
+ </div>
110
<header className="header">
38
- <a href="/" className="logo">MEDUSA <span>COMMERCE</span></a>
39
- <nav aria-label={tr("تنظیمات فروشگاه", "Store settings", "إعدادات المتجر")}>
40
- <label>{tr("کشور", "Country", "الدولة")} <select value={market} onChange={(event) => setMarket(event.target.value as MarketCode)}>
41
- {Object.keys(MARKETS).map((code) => <option key={code} value={code}>{marketNames[code as MarketCode]}</option>)}
42
- </select></label>
43
- <label>{tr("زبان", "Language", "اللغة")} <select value={locale} onChange={(event) => setLocale(event.target.value as StoreLocale)}>
44
- <option value="fa-IR">فارسی</option><option value="ar">العربية</option><option value="en">English</option>
45
- </select></label>
111
+ <a href="#top" className="logo" aria-label="Medusa Commerce">
112
+ <span className="logo-mark">M</span>
113
+ <span className="logo-text">MEDUSA <small>COMMERCE</small></span>
114
+ </a>
115
+ <nav className="header-nav" aria-label={tr("تنظیمات فروشگاه", "Store settings", "إعدادات المتجر")}>
116
+ <a href="#catalog" className="nav-catalog">{tr("دستهبندیها", "Collections", "المجموعات")}</a>
117
+ <label className="nav-select">{tr("کشور", "Market", "السوق")}
118
+ <select aria-label={tr("انتخاب کشور", "Select market", "اختر السوق")} value={market} onChange={(e) => setMarket(e.target.value as MarketCode)}>
119
+ {Object.keys(MARKETS).map((code) => <option key={code} value={code}>{marketNames[code as MarketCode]}</option>)}
120
+ </select>
121
+ </label>
122
+ <label className="nav-select">{tr("زبان", "Language", "اللغة")}
123
+ <select aria-label={tr("انتخاب زبان", "Select language", "اختر اللغة")} value={locale} onChange={(e) => setLocale(e.target.value as StoreLocale)}>
124
+ <option value="fa-IR">فارسی</option>
125
+ <option value="ar">العربية</option>
126
+ <option value="en">English</option>
127
+ </select>
128
+ </label>
129
</nav>
130
</header>
48
- <section className="hero">
49
- <p className="eyebrow">{tr("تجربه خرید در پنج بازار", "Shopping across five markets", "تسوّق في خمسة أسواق")}</p>
50
- <h1>{tr("یک فروشگاه، جهانی از انتخابها", "One store. More possibilities.", "متجر واحد، خيارات بلا حدود")}</h1>
51
- <p>{tr("فروشگاه چندکشوری با محصولات دیجیتال و کالاهای منتخب ایران", "A multi-market store for electronics and selected Iran-origin goods.", "متجر متعدد الأسواق للإلكترونيات ومنتجات مختارة من إيران")}</p>
52
- <div className="market">{tr("بازار انتخابشده:", "Selected market:", "السوق المحدد:")} <strong>{marketNames[market]}</strong> · {MARKETS[market].currencyCode.toUpperCase()}</div>
53
- </section>
54
- <section className="content" aria-labelledby="catalog-title">
55
- <h2 id="catalog-title">{tr("محصولات فروشگاه", "Store products", "منتجات المتجر")}</h2>
56
- {catalogState === "unconfigured" && <p>{tr("برای نمایش محصولات، اتصال API فروشگاه را تنظیم کنید.", "Configure the store API to display products.", "يرجى إعداد اتصال واجهة المتجر لعرض المنتجات.")}</p>}
57
- {catalogState === "loading" && <p role="status">{tr("در حال دریافت محصولات…", "Loading products…", "جارٍ تحميل المنتجات…")}</p>}
58
- {catalogState === "error" && <p role="alert">{tr("دریافت محصولات ناموفق بود. اتصال Backend و کلید عمومی را بررسی کنید.", "Could not load products. Check backend connectivity and publishable key.", "تعذر تحميل المنتجات. تحقق من اتصال الخادم والمفتاح العام.")}</p>}
59
- {catalogState === "ready" && products.length === 0 && <p>{tr("در حال حاضر محصولی برای نمایش وجود ندارد.", "No products available to display.", "لا توجد منتجات متاحة للعرض.")}</p>}
60
- {catalogState === "ready" && products.length > 0 && <div className="product-grid">{products.map((product) => <article className="product" key={product.id}>{product.thumbnail && <img loading="lazy" src={product.thumbnail} alt="" />}<h3>{product.title}</h3></article>)}</div>}
61
- <p className="notice">{tr("این نسخه پیشنمایش است؛ قیمتگذاری منطقهای، خرید و پرداخت هنوز فعال نیست.", "This is a preview; regional pricing, checkout and payments are not active.", "هذه معاينة؛ الأسعار الإقليمية والشراء والدفع غير متاحة بعد.")}</p>
62
- </section>
63
- <footer>© Medusa Commerce · {tr("نسخه توسعه", "Development preview", "نسخة تجريبية")}</footer>
64
- </main>
131
+ <main id="top">
132
+ <section className="hero">
133
+ <div className="hero-copy">
134
+ <span className="eyebrow"><span className="eyebrow-line" />{tr("تجربه خرید، بدون مرز", "A new way to explore", "تجربة تسوّق بلا حدود")}</span>
135
+ <h1>{tr("انتخابهای تازه،", "Discover more.", "اكتشف المزيد،")}<br/><em>{tr("در یک نگاه.", "Across borders.", "عبر الحدود.")}</em></h1>
136
+ <p>{tr("یک تجربه فروشگاهی در حال طراحی؛ ویژه محصولات دیجیتال و مجموعهای از کالاهای منتخب ایرانی در پنج بازار.", "A storefront experience in progress, designed for electronics and curated Iran-origin collections across five markets.", "تجربة متجر قيد التطوير للإلكترونيات ومجموعات مختارة من المنتجات الإيرانية في خمسة أسواق.")}</p>
137
+ <div className="hero-actions">
138
+ <a className="primary-action" href="#catalog">{tr("دیدن دستهبندیهای نمونه", "Explore sample collections", "استعرض المجموعات التجريبية")} <span aria-hidden="true">↗</span></a>
139
+ <span className="hero-note">{tr("بدون قیمت و سفارش واقعی", "No real prices or orders", "دون أسعار أو طلبات فعلية")}</span>
140
+ </div>
141
+ <div className="market-pill">
142
+ <span className="market-pill-icon">◎</span>
143
+ <span>{tr("بازار انتخابی", "Selected market", "السوق المحدد")}: <strong>{marketNames[market]}</strong></span>
144
+ <span className="currency">{MARKETS[market].currencyCode.toUpperCase()}</span>
145
+ </div>
146
+ </div>
147
+ <div className="hero-art" aria-hidden="true">
148
+ <div className="hero-ring hero-ring-one" />
149
+ <div className="hero-ring hero-ring-two" />
150
+ <div className="hero-figure">
151
+ <div className="figure-top" />
152
+ <div className="figure-center" />
153
+ <div className="figure-bottom" />
154
+ </div>
155
+ <span className="hero-art-caption">M / CURATED</span>
156
+ <span className="hero-art-index">01—05</span>
157
+ </div>
158
+ </section>
159
+ <section className="feature-band" aria-label={tr("ویژگیهای نسخه نمایشی", "Preview features", "ميزات المعاينة")}>
160
+ <div><strong>05</strong><span>{tr("بازار هدف", "Markets", "أسواق")}</span></div>
161
+ <div><strong>03</strong><span>{tr("زبان مستقل", "Languages", "لغات")}</span></div>
162
+ <div><strong>RTL / LTR</strong><span>{tr("چیدمان هماهنگ", "Adaptive layout", "تصميم متكيف")}</span></div>
163
+ </section>
164
+ <section className="content" id="catalog" aria-labelledby="catalog-title">
165
+ <div className="section-heading">
166
+ <div>
167
+ <span className="section-kicker">{tr("نگاهی به فروشگاه", "A glimpse of the store", "نظرة على المتجر")}</span>
168
+ <h2 id="catalog-title">{tr("مجموعهها را کشف کنید", "Explore the collections", "اكتشف المجموعات")}</h2>
169
+ <p>{isDemo
170
+ ? tr("این کارتها نمونه طراحی هستند؛ نه کالاهای موجود یا قابل سفارش.", "These cards are illustrative design samples, not stocked or orderable products.", "هذه البطاقات أمثلة تصميمية وليست منتجات متوفرة أو قابلة للطلب.")
171
+ : tr("محصولات دریافتی از فروشگاه مدوسا", "Products loaded from Medusa", "المنتجات المحمّلة من مدوسا")}</p>
172
+ </div>
173
+ {isDemo && <span className="demo-badge">{tr("داده نمونه", "DEMO DATA", "بيانات تجريبية")}</span>}
174
+ </div>
175
+ <div className="catalog-toolbar">
176
+ <div className="filters" aria-label={tr("فیلتر دستهبندی", "Category filter", "تصفية الفئات")}>
177
+ <button type="button" aria-pressed={filter === "all"} className={filter === "all" ? "filter active" : "filter"} onClick={() => setFilter("all")}>{tr("همه", "All", "الكل")}</button>
178
+ {market === "IR" && <button type="button" aria-pressed={filter === "electronics"} className={filter === "electronics" ? "filter active" : "filter"} onClick={() => setFilter("electronics")}>{labelForKind("electronics")}</button>}
179
+ <button type="button" aria-pressed={filter === "iranian"} className={filter === "iranian" ? "filter active" : "filter"} onClick={() => setFilter("iranian")}>{labelForKind("iranian")}</button>
180
+ </div>
181
+ <label className="search-field">
182
+ <span aria-hidden="true">⌕</span>
183
+ <input type="search" value={search} onChange={(e) => setSearch(e.target.value)} placeholder={tr("جستوجو در نمونهها…", "Search collections…", "ابحث في المجموعات…")} aria-label={tr("جستوجو", "Search", "بحث")} />
184
+ </label>
185
+ </div>
186
+ {catalogState === "error" && <p role="alert" className="catalog-alert">{tr("اتصال به Backend برقرار نشد؛ نمونه طراحی زیر نمایش داده میشود.", "The backend could not be reached; showing illustrative samples instead.", "تعذر الاتصال بالخادم؛ يتم عرض أمثلة توضيحية بدلاً منها.")}</p>}
187
+ {catalogState === "loading" && <p role="status" className="catalog-alert">{tr("در حال دریافت محصولات…", "Loading products…", "جارٍ تحميل المنتجات…")}</p>}
188
+ {isDemo && <>
189
+ {examples.length ? <div className="product-grid">
190
+ {examples.map((product, index) => <article className="product" key={product.id}>
191
+ <button type="button" className="product-open" onClick={() => setSelected(product)} aria-label={tr("مشاهده نمونه", "View sample", "عرض المثال") + ": " + product.name[locale]}>
192
+ <Artwork visual={product.visual} />
193
+ <div className="product-copy">
194
+ <div className="product-meta"><span>{labelForKind(product.kind)}</span><span>{String(index + 1).padStart(2, "0")}</span></div>
195
+ <h3>{product.name[locale]}</h3>
196
+ <p>{product.description[locale]}</p>
197
+ <span className="product-link">{tr("مشاهده جزئیات نمونه", "View example", "عرض المثال")} <span aria-hidden="true">↗</span></span>
198
+ </div>
199
+ </button>
200
+ </article>)}
201
+ </div> : <p role="status" className="empty-state">{tr("نمونهای مطابق جستوجو پیدا نشد.", "No sample matches your search.", "لا توجد أمثلة تطابق البحث.")}</p>}
202
+ </>}
203
+ {catalogState === "ready" && <>
204
+ {filteredRealProducts.length ? <div className="product-grid">
205
+ {filteredRealProducts.map((product) => <article className="product" key={product.id}>
206
+ <div className="real-product-image">{product.thumbnail ? <img loading="lazy" src={product.thumbnail} alt="" /> : <span aria-hidden="true">◈</span>}</div>
207
+ <div className="product-copy"><h3>{product.title}</h3><p>{tr("اطلاعات قیمت و خرید هنوز فعال نیست.", "Pricing and checkout remain disabled.", "الأسعار والشراء غير متاحين بعد.")}</p></div>
208
+ </article>)}
209
+ </div> : <p role="status" className="empty-state">{tr("محصولی برای نمایش پیدا نشد.", "No matching products found.", "لم يتم العثور على منتجات.")}</p>}
210
+ </>}
211
+ </section>
212
+ <section className="closing">
213
+ <div><span className="section-kicker">{tr("قدم بعدی", "What's next", "الخطوة التالية")}</span><h2>{tr("از نمونه طراحی تا فروشگاه واقعی", "From concept to commerce.", "من التصميم إلى المتجر الحقيقي")}</h2></div>
214
+ <p>{tr("اتصال محصولات واقعی، قیمتگذاری منطقهای، موجودی و پرداخت پس از تکمیل و آزمون زیرساخت اضافه میشوند.", "Live products, region-specific prices, inventory and checkout will follow after backend integration and testing.", "ستُضاف المنتجات الفعلية والأسعار الإقليمية والمخزون والدفع بعد ربط الخادم واختباره.")}</p>
215
+ </section>
216
+ </main>
217
+ <footer><span>MEDUSA COMMERCE <small> / PREVIEW</small></span><span>© 2026 · {tr("نسخه نمایشی غیرعملیاتی", "Non-transactional demonstration", "معاينة غير تجارية")}</span></footer>
218
+ {selected && <div className="modal-backdrop" onClick={() => setSelected(null)}>
219
+ <section className="product-modal" role="dialog" aria-modal="true" aria-labelledby="modal-title" onClick={(e) => e.stopPropagation()}>
220
+ <button type="button" className="modal-close" onClick={() => setSelected(null)} aria-label={tr("بستن", "Close", "إغلاق")}>×</button>
221
+ <Artwork visual={selected.visual} />
222
+ <div className="modal-copy">
223
+ <span className="demo-badge">{tr("نمونه طراحی", "DESIGN SAMPLE", "مثال تصميمي")}</span>
224
+ <h2 id="modal-title">{selected.name[locale]}</h2>
225
+ <p>{selected.description[locale]}</p>
226
+ <p className="modal-note">{tr("این مورد نمایشی است و قیمت، موجودی یا امکان ثبت سفارش ندارد.", "This is an illustration only. No real price, stock or checkout is available.", "هذا مثال توضيحي فقط؛ لا يوجد سعر فعلي أو مخزون أو إمكانية للشراء.")}</p>
227
+ <button type="button" className="modal-done" onClick={() => setSelected(null)}>{tr("بازگشت به مجموعهها", "Back to collections", "العودة إلى المجموعات")}</button>
228
+ </div>
229
+ </section>
230
+ </div>}
231
+ </div>
232
)
233
}
234