@fayz-ai/storefront 0.8.3 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"CheckoutPage.d.ts","sourceRoot":"","sources":["../../src/pages/CheckoutPage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAA;AA0GlD,wBAAgB,YAAY,sBAkkB3B"}
1
+ {"version":3,"file":"CheckoutPage.d.ts","sourceRoot":"","sources":["../../src/pages/CheckoutPage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAA;AA0GlD,wBAAgB,YAAY,sBAskB3B"}
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "fayz": {
4
4
  "status": "beta"
5
5
  },
6
- "version": "0.8.3",
6
+ "version": "0.8.4",
7
7
  "description": "Fayz SDK storefront kit — Shopify-style customer-facing ecommerce template components",
8
8
  "type": "module",
9
9
  "main": "./dist/index.cjs",
@@ -43,12 +43,12 @@
43
43
  "@supabase/supabase-js": "^2.45.0",
44
44
  "lucide-react": "^0.400.0",
45
45
  "zustand": "^4.5.0",
46
- "@fayz-ai/auth": "^0.8.3",
47
- "@fayz-ai/core": "^0.8.3",
46
+ "@fayz-ai/auth": "^0.8.4",
47
+ "@fayz-ai/core": "^0.8.4",
48
+ "@fayz-ai/sdk": "^0.8.4",
48
49
  "@fayz-ai/plugin-auth": "^0.8.0",
49
- "@fayz-ai/sdk": "^0.8.3",
50
- "@fayz-ai/shop": "^0.8.3",
51
- "@fayz-ai/ui": "^0.8.3"
50
+ "@fayz-ai/shop": "^0.8.4",
51
+ "@fayz-ai/ui": "^0.8.4"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "react": "^18.0.0 || ^19.0.0",
@@ -1,5 +1,5 @@
1
1
  import React, { useState } from 'react'
2
- import { CreditCard, LogOut, Mail, Package, Phone, Search, ShoppingBag, User, UserCircle, X } from 'lucide-react'
2
+ import { CreditCard, LogOut, Mail, Menu, Package, Phone, Search, ShoppingBag, User, UserCircle, X } from 'lucide-react'
3
3
  import { signOutCustomer } from '../auth'
4
4
  import { useCartStore, selectCount } from '../stores/cart.store'
5
5
  import { useCatalogStore } from '../stores/catalog.store'
@@ -151,7 +151,7 @@ function SearchInput({ className, iconOnly = false }: { className?: string; icon
151
151
  )
152
152
  }
153
153
 
154
- function HeaderActions() {
154
+ function HeaderActions({ onMenuClick }: { onMenuClick?: () => void }) {
155
155
  const config = useStorefrontConfig()
156
156
  const count = useCartStore(selectCount)
157
157
  const openDrawer = useCartStore((s) => s.openDrawer)
@@ -251,6 +251,16 @@ function HeaderActions() {
251
251
  )}
252
252
  </button>
253
253
  )}
254
+ {onMenuClick && (
255
+ <button
256
+ type="button"
257
+ aria-label="Abrir menu"
258
+ onClick={onMenuClick}
259
+ className="relative rounded-full p-2.5 transition-opacity hover:opacity-70 md:hidden"
260
+ >
261
+ <Menu className="h-5 w-5" />
262
+ </button>
263
+ )}
254
264
  </nav>
255
265
  )
256
266
  }
@@ -296,12 +306,99 @@ function NavLinks({ className }: { className?: string }) {
296
306
  )
297
307
  }
298
308
 
309
+ function MobileMenuDrawer({ open, onClose }: { open: boolean; onClose: () => void }) {
310
+ const config = useStorefrontConfig()
311
+ const { categories } = useCategories()
312
+ const setCategoryId = useCatalogStore((s) => s.setCategoryId)
313
+ const showCategories = config.theme?.header?.showCategories !== false
314
+
315
+ const goCategory = (categoryId: string) => {
316
+ useCatalogStore.getState().reset()
317
+ setCategoryId(categoryId)
318
+ navigateTo(config.catalogPath)
319
+ onClose()
320
+ }
321
+
322
+ // a11y: close on Escape
323
+ React.useEffect(() => {
324
+ if (!open) return
325
+ const onKey = (e: KeyboardEvent) => {
326
+ if (e.key === 'Escape') onClose()
327
+ }
328
+ document.addEventListener('keydown', onKey)
329
+ return () => document.removeEventListener('keydown', onKey)
330
+ }, [open, onClose])
331
+
332
+ if (!open) return null
333
+
334
+ return (
335
+ <div className="fixed inset-0 z-50 md:hidden">
336
+ <div
337
+ className="absolute inset-0 animate-fade-in bg-black/40"
338
+ aria-hidden
339
+ onClick={onClose}
340
+ />
341
+ <div
342
+ data-testid="mobile-menu-drawer"
343
+ role="dialog"
344
+ aria-label="Menu Principal"
345
+ className="absolute right-0 top-0 flex h-full w-full max-w-[280px] animate-slide-in-from-right flex-col bg-background shadow-2xl"
346
+ >
347
+ <div className="flex items-center justify-between border-b px-5 py-4">
348
+ <h2 className="text-lg font-semibold">Menu</h2>
349
+ <button
350
+ type="button"
351
+ aria-label="Fechar menu"
352
+ onClick={onClose}
353
+ className="rounded-full p-1.5 hover:bg-muted"
354
+ >
355
+ <X className="h-5 w-5" />
356
+ </button>
357
+ </div>
358
+ <div className="flex-1 overflow-y-auto p-5">
359
+ <nav className="flex flex-col gap-4">
360
+ {config.nav.map((link) => (
361
+ <Link
362
+ key={link.to}
363
+ to={link.to}
364
+ onClick={onClose}
365
+ className="text-base font-semibold transition-opacity hover:opacity-70"
366
+ >
367
+ {link.label}
368
+ </Link>
369
+ ))}
370
+ {showCategories && categories.length > 0 && (
371
+ <>
372
+ <div className="my-2 border-t" />
373
+ <div className="mb-2 text-xs font-bold uppercase tracking-wider text-muted-foreground">
374
+ Categorias
375
+ </div>
376
+ {categories.map((c) => (
377
+ <button
378
+ key={c.id}
379
+ type="button"
380
+ onClick={() => goCategory(c.id)}
381
+ className="text-left text-sm font-medium transition-opacity hover:opacity-80"
382
+ >
383
+ {c.name}
384
+ </button>
385
+ ))}
386
+ </>
387
+ )}
388
+ </nav>
389
+ </div>
390
+ </div>
391
+ </div>
392
+ )
393
+ }
394
+
299
395
  export function StorefrontHeader() {
300
396
  const config = useStorefrontConfig()
301
397
  const variant = config.theme?.header?.variant ?? 'classic'
302
398
  const scrolled = useScrolled()
303
399
  const showSearch = config.theme?.header?.showSearch !== false
304
400
  const iconSearch = config.theme?.header?.searchStyle === 'icon'
401
+ const [mobileMenuOpen, setMobileMenuOpen] = useState(false)
305
402
  const logo = (
306
403
  <Link to="/" className="sf-heading shrink-0 text-xl font-bold tracking-tight">
307
404
  {config.logo ?? config.name}
@@ -359,15 +456,21 @@ export function StorefrontHeader() {
359
456
  </div>
360
457
  </div>
361
458
  ) : (
362
- // classic: logo left, nav, then a right-aligned search + actions cluster
363
- <div className="mx-auto flex h-16 max-w-7xl items-center gap-6 px-4 sm:px-6">
364
- {logo}
365
- <NavLinks className="hidden md:flex" />
366
- <div className="ml-auto flex items-center gap-2 sm:gap-3">
367
- {showSearch && <SearchInput iconOnly={iconSearch} className={iconSearch ? '' : 'hidden w-full max-w-sm sm:block'} />}
368
- <HeaderActions />
459
+ // classic: logo left, nav, then a right-aligned search + actions cluster.
460
+ // NavLinks is hidden below md in the primary row (no room for it there) —
461
+ // below md a hamburger opens MobileMenuDrawer instead, otherwise mobile
462
+ // has no way to reach nav/category links at all.
463
+ <>
464
+ <div className="mx-auto flex h-16 max-w-7xl items-center gap-6 px-4 sm:px-6">
465
+ {logo}
466
+ <NavLinks className="hidden md:flex" />
467
+ <div className="ml-auto flex items-center gap-2 sm:gap-3">
468
+ {showSearch && <SearchInput iconOnly={iconSearch} className={iconSearch ? '' : 'hidden w-full max-w-sm sm:block'} />}
469
+ <HeaderActions onMenuClick={() => setMobileMenuOpen(true)} />
470
+ </div>
369
471
  </div>
370
- </div>
472
+ <MobileMenuDrawer open={mobileMenuOpen} onClose={() => setMobileMenuOpen(false)} />
473
+ </>
371
474
  )}
372
475
  </header>
373
476
  )
@@ -93,6 +93,10 @@ function storefrontDiscountToSeed(discount: StorefrontDiscountConfig): Discount
93
93
  value: discount.percent,
94
94
  usageLimit: null,
95
95
  oncePerCustomer: false,
96
+ minSubtotal: null,
97
+ appliesTo: 'all',
98
+ productIds: [],
99
+ categoryIds: [],
96
100
  startsAt: ts,
97
101
  endsAt: null,
98
102
  status: 'active',
@@ -346,7 +346,7 @@ export function CheckoutPage() {
346
346
  ]
347
347
  const minDuration = sleep(stepMs * 2)
348
348
  try {
349
- const { order } = await placeStorefrontOrder({
349
+ const { order, customerId } = await placeStorefrontOrder({
350
350
  config,
351
351
  cart,
352
352
  session,
@@ -369,6 +369,10 @@ export function CheckoutPage() {
369
369
  // declare it settled. The order is now born `pending` and only the
370
370
  // merchant (or a PSP webhook) can confirm the money arrived.
371
371
  })
372
+ // placeStorefrontOrder resolves/creates the customer record but doesn't persist
373
+ // it — without this, "My purchases" right after checkout queries by email, which
374
+ // anon can't read under RLS, and silently comes back empty.
375
+ if (customerId) session.setSession({ customerId, email: form.email, name: form.name })
372
376
 
373
377
  await minDuration
374
378
  cart.clear()