@fayz-ai/storefront 0.9.0 → 0.10.0
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.
- package/README.md +3 -3
- package/dist/app/createStorefrontApp.d.ts +65 -0
- package/dist/app/createStorefrontApp.d.ts.map +1 -0
- package/dist/{define.d.ts → app/define.d.ts} +3 -3
- package/dist/app/define.d.ts.map +1 -0
- package/dist/app/hydration.d.ts +37 -0
- package/dist/app/hydration.d.ts.map +1 -0
- package/dist/app/prerender.d.ts +57 -0
- package/dist/app/prerender.d.ts.map +1 -0
- package/dist/{router.d.ts → app/router.d.ts} +140 -113
- package/dist/app/router.d.ts.map +1 -0
- package/dist/{scaffold.d.ts → app/scaffold.d.ts} +2 -2
- package/dist/app/scaffold.d.ts.map +1 -0
- package/dist/app/serving.d.ts +70 -0
- package/dist/app/serving.d.ts.map +1 -0
- package/dist/app/static-render.d.ts +46 -0
- package/dist/app/static-render.d.ts.map +1 -0
- package/dist/blocks/block-at-path.d.ts +59 -0
- package/dist/blocks/block-at-path.d.ts.map +1 -0
- package/dist/blocks/page-blocks.d.ts +163 -0
- package/dist/blocks/page-blocks.d.ts.map +1 -0
- package/dist/blocks/page-data.d.ts +105 -0
- package/dist/blocks/page-data.d.ts.map +1 -0
- package/dist/{blocks.d.ts → blocks/registry.d.ts} +1 -1
- package/dist/blocks/registry.d.ts.map +1 -0
- package/dist/{sections.d.ts → blocks/sections.d.ts} +40 -2
- package/dist/blocks/sections.d.ts.map +1 -0
- package/dist/chunk-6B7H3IZ6.js +10232 -0
- package/dist/chunk-6B7H3IZ6.js.map +1 -0
- package/dist/chunk-6IXTENLB.js +162 -0
- package/dist/chunk-6IXTENLB.js.map +1 -0
- package/dist/components/PaymentTerms.d.ts +34 -0
- package/dist/components/PaymentTerms.d.ts.map +1 -0
- package/dist/components/SmoothImage.d.ts +1 -1
- package/dist/components/SmoothImage.d.ts.map +1 -1
- package/dist/components/account/CustomerAccountShell.d.ts.map +1 -0
- package/dist/components/account/SignInModal.d.ts.map +1 -0
- package/dist/components/cart/CartDrawer.d.ts.map +1 -0
- package/dist/components/cart/QuantityInput.d.ts.map +1 -0
- package/dist/components/checkout/DeliveryEstimator.d.ts.map +1 -0
- package/dist/components/collection/CategoryShowcase.d.ts +44 -0
- package/dist/components/collection/CategoryShowcase.d.ts.map +1 -0
- package/dist/components/collection/FiltersPanel.d.ts +19 -0
- package/dist/components/collection/FiltersPanel.d.ts.map +1 -0
- package/dist/components/collection/ProductGrid.d.ts.map +1 -0
- package/dist/components/layout/PageBodyBlocks.d.ts +40 -0
- package/dist/components/layout/PageBodyBlocks.d.ts.map +1 -0
- package/dist/components/layout/SearchOverlay.d.ts +13 -0
- package/dist/components/layout/SearchOverlay.d.ts.map +1 -0
- package/dist/components/layout/StorefrontErrorBoundary.d.ts.map +1 -0
- package/dist/components/layout/StorefrontFooter.d.ts.map +1 -0
- package/dist/components/layout/StorefrontHeader.d.ts.map +1 -0
- package/dist/components/layout/Toaster.d.ts.map +1 -0
- package/dist/components/marketing/CollectionSections.d.ts +463 -0
- package/dist/components/marketing/CollectionSections.d.ts.map +1 -0
- package/dist/components/marketing/ConversionSections.d.ts +221 -0
- package/dist/components/marketing/ConversionSections.d.ts.map +1 -0
- package/dist/components/marketing/EditorialSections.d.ts +248 -0
- package/dist/components/marketing/EditorialSections.d.ts.map +1 -0
- package/dist/components/marketing/EntityList.d.ts +97 -0
- package/dist/components/marketing/EntityList.d.ts.map +1 -0
- package/dist/components/marketing/FormBlock.d.ts +167 -0
- package/dist/components/marketing/FormBlock.d.ts.map +1 -0
- package/dist/components/marketing/HeroSection.d.ts +125 -0
- package/dist/components/marketing/HeroSection.d.ts.map +1 -0
- package/dist/components/marketing/MediaCarousel.d.ts +135 -0
- package/dist/components/marketing/MediaCarousel.d.ts.map +1 -0
- package/dist/components/marketing/MiscSections.d.ts +252 -0
- package/dist/components/marketing/MiscSections.d.ts.map +1 -0
- package/dist/components/order/OrderTrackingTimeline.d.ts.map +1 -0
- package/dist/components/product/ProductCard.d.ts +14 -0
- package/dist/components/product/ProductCard.d.ts.map +1 -0
- package/dist/components/product/ProductEnquiryForm.d.ts.map +1 -0
- package/dist/components/product/ProductGallery.d.ts +36 -0
- package/dist/components/product/ProductGallery.d.ts.map +1 -0
- package/dist/components/{ProductOptionSelector.d.ts → product/ProductOptionSelector.d.ts} +1 -1
- package/dist/components/product/ProductOptionSelector.d.ts.map +1 -0
- package/dist/components/product/ProductRail.d.ts +93 -0
- package/dist/components/product/ProductRail.d.ts.map +1 -0
- package/dist/components/product/ProductReviews.d.ts +39 -0
- package/dist/components/product/ProductReviews.d.ts.map +1 -0
- package/dist/components/product/ProductSlider.d.ts +169 -0
- package/dist/components/product/ProductSlider.d.ts.map +1 -0
- package/dist/components/product/ProductSpecs.d.ts.map +1 -0
- package/dist/components/product/RelatedProducts.d.ts.map +1 -0
- package/dist/{auth.d.ts → data/auth.d.ts} +9 -0
- package/dist/data/auth.d.ts.map +1 -0
- package/dist/data/facets.d.ts +39 -0
- package/dist/data/facets.d.ts.map +1 -0
- package/dist/data/loaders.d.ts +56 -0
- package/dist/data/loaders.d.ts.map +1 -0
- package/dist/data/order-status.d.ts.map +1 -0
- package/dist/data/product-options.d.ts +36 -0
- package/dist/data/product-options.d.ts.map +1 -0
- package/dist/diagnostics/seo-audit.d.ts +54 -0
- package/dist/diagnostics/seo-audit.d.ts.map +1 -0
- package/dist/diagnostics/seo-audit.js +3 -0
- package/dist/diagnostics/seo-audit.js.map +1 -0
- package/dist/document/change.d.ts +100 -0
- package/dist/document/change.d.ts.map +1 -0
- package/dist/{config.d.ts → document/config.d.ts} +126 -7
- package/dist/document/config.d.ts.map +1 -0
- package/dist/document/describe.d.ts +135 -0
- package/dist/document/describe.d.ts.map +1 -0
- package/dist/document/overlay.d.ts +58 -0
- package/dist/document/overlay.d.ts.map +1 -0
- package/dist/{presets.d.ts → document/presets.d.ts} +2 -2
- package/dist/document/presets.d.ts.map +1 -0
- package/dist/document/render.d.ts +171 -0
- package/dist/document/render.d.ts.map +1 -0
- package/dist/document/round-trip.d.ts +46 -0
- package/dist/document/round-trip.d.ts.map +1 -0
- package/dist/document/sections.d.ts +194 -0
- package/dist/document/sections.d.ts.map +1 -0
- package/dist/document/upgrade.d.ts +112 -0
- package/dist/document/upgrade.d.ts.map +1 -0
- package/dist/document/validate.d.ts +24 -0
- package/dist/document/validate.d.ts.map +1 -0
- package/dist/{component-contracts.d.ts → extend/component-contracts.d.ts} +74 -22
- package/dist/extend/component-contracts.d.ts.map +1 -0
- package/dist/extend/component-override.d.ts +38 -0
- package/dist/extend/component-override.d.ts.map +1 -0
- package/dist/extend/component-selectors.d.ts.map +1 -0
- package/dist/extend/editor-bridge.d.ts +59 -0
- package/dist/extend/editor-bridge.d.ts.map +1 -0
- package/dist/extend/extension-points.d.ts +103 -0
- package/dist/extend/extension-points.d.ts.map +1 -0
- package/dist/extend/slots.d.ts +216 -0
- package/dist/extend/slots.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +25 -6
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/use-address.d.ts +26 -0
- package/dist/hooks/use-address.d.ts.map +1 -0
- package/dist/hooks/use-cart.d.ts +3 -0
- package/dist/hooks/use-cart.d.ts.map +1 -0
- package/dist/hooks/use-catalog.d.ts +24 -0
- package/dist/hooks/use-catalog.d.ts.map +1 -0
- package/dist/hooks/use-categories.d.ts +19 -0
- package/dist/hooks/use-categories.d.ts.map +1 -0
- package/dist/hooks/use-checkout.d.ts +41 -0
- package/dist/hooks/use-checkout.d.ts.map +1 -0
- package/dist/hooks/use-discount-validator.d.ts +20 -0
- package/dist/hooks/use-discount-validator.d.ts.map +1 -0
- package/dist/hooks/use-enquiry.d.ts +7 -0
- package/dist/hooks/use-enquiry.d.ts.map +1 -0
- package/dist/hooks/{useMyOrders.d.ts → use-my-orders.d.ts} +1 -1
- package/dist/hooks/use-my-orders.d.ts.map +1 -0
- package/dist/hooks/use-order.d.ts +17 -0
- package/dist/hooks/use-order.d.ts.map +1 -0
- package/dist/hooks/use-payment-methods.d.ts +19 -0
- package/dist/hooks/use-payment-methods.d.ts.map +1 -0
- package/dist/hooks/use-policies.d.ts +25 -0
- package/dist/hooks/use-policies.d.ts.map +1 -0
- package/dist/hooks/use-product.d.ts +15 -0
- package/dist/hooks/use-product.d.ts.map +1 -0
- package/dist/hooks/{useProducts.d.ts → use-products.d.ts} +1 -1
- package/dist/hooks/use-products.d.ts.map +1 -0
- package/dist/hooks/use-region.d.ts +15 -0
- package/dist/hooks/use-region.d.ts.map +1 -0
- package/dist/hooks/use-shipping.d.ts +29 -0
- package/dist/hooks/use-shipping.d.ts.map +1 -0
- package/dist/hooks/use-storefront-actions.d.ts +12 -0
- package/dist/hooks/use-storefront-actions.d.ts.map +1 -0
- package/dist/hooks/use-storefront-head.d.ts +19 -0
- package/dist/hooks/use-storefront-head.d.ts.map +1 -0
- package/dist/hooks/use-storefront.d.ts +3 -0
- package/dist/hooks/use-storefront.d.ts.map +1 -0
- package/dist/index.d.ts +123 -54
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1311 -5012
- package/dist/index.js.map +1 -1
- package/dist/lib/format.d.ts.map +1 -0
- package/dist/lib/motion.d.ts.map +1 -0
- package/dist/lib/seo.d.ts +26 -0
- package/dist/lib/seo.d.ts.map +1 -0
- package/dist/{testids.d.ts → lib/testids.d.ts} +21 -0
- package/dist/lib/testids.d.ts.map +1 -0
- package/dist/{theme.d.ts → lib/theme.d.ts} +41 -3
- package/dist/lib/theme.d.ts.map +1 -0
- package/dist/render.d.ts +5 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +359 -0
- package/dist/render.js.map +1 -0
- package/dist/stores/cart.store.d.ts +6 -2
- package/dist/stores/cart.store.d.ts.map +1 -1
- package/dist/stores/catalog.store.d.ts +11 -0
- package/dist/stores/catalog.store.d.ts.map +1 -1
- package/dist/views/CatalogPage.d.ts.map +1 -0
- package/dist/views/CheckoutPage.d.ts.map +1 -0
- package/dist/views/ContentPage.d.ts +11 -0
- package/dist/views/ContentPage.d.ts.map +1 -0
- package/dist/views/HomePage.d.ts +9 -0
- package/dist/views/HomePage.d.ts.map +1 -0
- package/dist/views/MyPurchasesPage.d.ts.map +1 -0
- package/dist/views/NotFoundPage.d.ts.map +1 -0
- package/dist/{pages → views}/OrderConfirmationPage.d.ts.map +1 -1
- package/dist/{pages → views}/PolicyPage.d.ts.map +1 -1
- package/dist/views/ProductDetailPage.d.ts.map +1 -0
- package/dist/views/StorefrontPage.d.ts +35 -0
- package/dist/views/StorefrontPage.d.ts.map +1 -0
- package/dist/workflows/checkout.d.ts +1 -1
- package/dist/workflows/checkout.d.ts.map +1 -1
- package/package.json +21 -14
- package/dist/auth.d.ts.map +0 -1
- package/dist/blocks.d.ts.map +0 -1
- package/dist/component-contracts.d.ts.map +0 -1
- package/dist/component-selectors.d.ts.map +0 -1
- package/dist/components/CartDrawer.d.ts.map +0 -1
- package/dist/components/CustomerAccountShell.d.ts.map +0 -1
- package/dist/components/DeliveryEstimator.d.ts.map +0 -1
- package/dist/components/FiltersPanel.d.ts +0 -3
- package/dist/components/FiltersPanel.d.ts.map +0 -1
- package/dist/components/OrderTrackingTimeline.d.ts.map +0 -1
- package/dist/components/ProductCard.d.ts +0 -4
- package/dist/components/ProductCard.d.ts.map +0 -1
- package/dist/components/ProductEnquiryForm.d.ts.map +0 -1
- package/dist/components/ProductGallery.d.ts +0 -22
- package/dist/components/ProductGallery.d.ts.map +0 -1
- package/dist/components/ProductGrid.d.ts.map +0 -1
- package/dist/components/ProductOptionSelector.d.ts.map +0 -1
- package/dist/components/ProductSpecs.d.ts.map +0 -1
- package/dist/components/QuantityInput.d.ts.map +0 -1
- package/dist/components/RelatedProducts.d.ts.map +0 -1
- package/dist/components/SignInModal.d.ts.map +0 -1
- package/dist/components/StorefrontErrorBoundary.d.ts.map +0 -1
- package/dist/components/StorefrontFooter.d.ts.map +0 -1
- package/dist/components/StorefrontHeader.d.ts.map +0 -1
- package/dist/components/Toaster.d.ts.map +0 -1
- package/dist/components/sections/CategoryShowcase.d.ts +0 -6
- package/dist/components/sections/CategoryShowcase.d.ts.map +0 -1
- package/dist/components/sections/HeroSection.d.ts +0 -9
- package/dist/components/sections/HeroSection.d.ts.map +0 -1
- package/dist/components/sections/MediaCarousel.d.ts +0 -11
- package/dist/components/sections/MediaCarousel.d.ts.map +0 -1
- package/dist/components/sections/MiscSections.d.ts +0 -33
- package/dist/components/sections/MiscSections.d.ts.map +0 -1
- package/dist/components/sections/ProductRail.d.ts +0 -9
- package/dist/components/sections/ProductRail.d.ts.map +0 -1
- package/dist/components/sections/ProductSlider.d.ts +0 -15
- package/dist/components/sections/ProductSlider.d.ts.map +0 -1
- package/dist/config.d.ts.map +0 -1
- package/dist/createStorefrontApp.d.ts +0 -28
- package/dist/createStorefrontApp.d.ts.map +0 -1
- package/dist/define.d.ts.map +0 -1
- package/dist/format.d.ts.map +0 -1
- package/dist/hooks/useCategories.d.ts +0 -6
- package/dist/hooks/useCategories.d.ts.map +0 -1
- package/dist/hooks/useDiscountValidator.d.ts +0 -14
- package/dist/hooks/useDiscountValidator.d.ts.map +0 -1
- package/dist/hooks/useMyOrders.d.ts.map +0 -1
- package/dist/hooks/useProduct.d.ts +0 -7
- package/dist/hooks/useProduct.d.ts.map +0 -1
- package/dist/hooks/useProducts.d.ts.map +0 -1
- package/dist/hooks/useStorefront.d.ts +0 -35
- package/dist/hooks/useStorefront.d.ts.map +0 -1
- package/dist/hooks/useStorefrontHead.d.ts +0 -11
- package/dist/hooks/useStorefrontHead.d.ts.map +0 -1
- package/dist/motion.d.ts.map +0 -1
- package/dist/order-status.d.ts.map +0 -1
- package/dist/pages/CatalogPage.d.ts.map +0 -1
- package/dist/pages/CheckoutPage.d.ts.map +0 -1
- package/dist/pages/HomePage.d.ts +0 -9
- package/dist/pages/HomePage.d.ts.map +0 -1
- package/dist/pages/MyPurchasesPage.d.ts.map +0 -1
- package/dist/pages/NotFoundPage.d.ts.map +0 -1
- package/dist/pages/ProductDetailPage.d.ts.map +0 -1
- package/dist/presets.d.ts.map +0 -1
- package/dist/product-options.d.ts +0 -12
- package/dist/product-options.d.ts.map +0 -1
- package/dist/router.d.ts.map +0 -1
- package/dist/scaffold.d.ts.map +0 -1
- package/dist/sections.d.ts.map +0 -1
- package/dist/testids.d.ts.map +0 -1
- package/dist/theme.d.ts.map +0 -1
- package/src/auth.ts +0 -227
- package/src/blocks.tsx +0 -51
- package/src/catalog.ts +0 -3
- package/src/component-contracts.ts +0 -154
- package/src/component-selectors.ts +0 -31
- package/src/components/CartDrawer.tsx +0 -279
- package/src/components/CustomerAccountShell.tsx +0 -102
- package/src/components/DeliveryEstimator.tsx +0 -157
- package/src/components/FiltersPanel.tsx +0 -109
- package/src/components/OrderTrackingTimeline.tsx +0 -135
- package/src/components/Price.tsx +0 -32
- package/src/components/ProductCard.tsx +0 -120
- package/src/components/ProductEnquiryForm.tsx +0 -175
- package/src/components/ProductGallery.tsx +0 -174
- package/src/components/ProductGrid.tsx +0 -43
- package/src/components/ProductOptionSelector.tsx +0 -50
- package/src/components/ProductSpecs.tsx +0 -75
- package/src/components/QuantityInput.tsx +0 -52
- package/src/components/RelatedProducts.tsx +0 -40
- package/src/components/SignInModal.tsx +0 -120
- package/src/components/SmoothImage.tsx +0 -59
- package/src/components/StorefrontErrorBoundary.tsx +0 -51
- package/src/components/StorefrontFooter.tsx +0 -110
- package/src/components/StorefrontHeader.tsx +0 -477
- package/src/components/Toaster.tsx +0 -60
- package/src/components/sections/CategoryShowcase.tsx +0 -80
- package/src/components/sections/HeroSection.tsx +0 -193
- package/src/components/sections/MediaCarousel.tsx +0 -141
- package/src/components/sections/MiscSections.tsx +0 -158
- package/src/components/sections/ProductRail.tsx +0 -81
- package/src/components/sections/ProductSlider.tsx +0 -119
- package/src/config.ts +0 -229
- package/src/createStorefrontApp.tsx +0 -247
- package/src/define.ts +0 -34
- package/src/format.ts +0 -7
- package/src/hooks/index.ts +0 -6
- package/src/hooks/useCategories.ts +0 -26
- package/src/hooks/useDiscountValidator.ts +0 -43
- package/src/hooks/useMyOrders.ts +0 -41
- package/src/hooks/useProduct.ts +0 -36
- package/src/hooks/useProducts.ts +0 -39
- package/src/hooks/useStorefront.ts +0 -58
- package/src/hooks/useStorefrontHead.ts +0 -25
- package/src/index.ts +0 -202
- package/src/motion.tsx +0 -94
- package/src/order-status.ts +0 -33
- package/src/pages/CatalogPage.tsx +0 -118
- package/src/pages/CheckoutPage.tsx +0 -689
- package/src/pages/HomePage.tsx +0 -16
- package/src/pages/MyPurchasesPage.tsx +0 -311
- package/src/pages/NotFoundPage.tsx +0 -25
- package/src/pages/OrderConfirmationPage.tsx +0 -190
- package/src/pages/PolicyPage.tsx +0 -47
- package/src/pages/ProductDetailPage.tsx +0 -264
- package/src/presets.ts +0 -324
- package/src/product-options.ts +0 -63
- package/src/router.ts +0 -49
- package/src/scaffold.tsx +0 -115
- package/src/sections.ts +0 -116
- package/src/shop.ts +0 -4
- package/src/stores/cart.store.ts +0 -185
- package/src/stores/catalog.store.ts +0 -39
- package/src/stores/delivery.store.ts +0 -152
- package/src/stores/session.store.ts +0 -28
- package/src/stores/toast.store.ts +0 -43
- package/src/testids.ts +0 -136
- package/src/theme.ts +0 -194
- package/src/ui.ts +0 -5
- package/src/workflows/checkout.ts +0 -119
- /package/dist/components/{CustomerAccountShell.d.ts → account/CustomerAccountShell.d.ts} +0 -0
- /package/dist/components/{SignInModal.d.ts → account/SignInModal.d.ts} +0 -0
- /package/dist/components/{CartDrawer.d.ts → cart/CartDrawer.d.ts} +0 -0
- /package/dist/components/{QuantityInput.d.ts → cart/QuantityInput.d.ts} +0 -0
- /package/dist/components/{DeliveryEstimator.d.ts → checkout/DeliveryEstimator.d.ts} +0 -0
- /package/dist/components/{ProductGrid.d.ts → collection/ProductGrid.d.ts} +0 -0
- /package/dist/components/{StorefrontErrorBoundary.d.ts → layout/StorefrontErrorBoundary.d.ts} +0 -0
- /package/dist/components/{StorefrontFooter.d.ts → layout/StorefrontFooter.d.ts} +0 -0
- /package/dist/components/{StorefrontHeader.d.ts → layout/StorefrontHeader.d.ts} +0 -0
- /package/dist/components/{Toaster.d.ts → layout/Toaster.d.ts} +0 -0
- /package/dist/components/{OrderTrackingTimeline.d.ts → order/OrderTrackingTimeline.d.ts} +0 -0
- /package/dist/components/{ProductEnquiryForm.d.ts → product/ProductEnquiryForm.d.ts} +0 -0
- /package/dist/components/{ProductSpecs.d.ts → product/ProductSpecs.d.ts} +0 -0
- /package/dist/components/{RelatedProducts.d.ts → product/RelatedProducts.d.ts} +0 -0
- /package/dist/{order-status.d.ts → data/order-status.d.ts} +0 -0
- /package/dist/{component-selectors.d.ts → extend/component-selectors.d.ts} +0 -0
- /package/dist/{format.d.ts → lib/format.d.ts} +0 -0
- /package/dist/{motion.d.ts → lib/motion.d.ts} +0 -0
- /package/dist/{pages → views}/CatalogPage.d.ts +0 -0
- /package/dist/{pages → views}/CheckoutPage.d.ts +0 -0
- /package/dist/{pages → views}/MyPurchasesPage.d.ts +0 -0
- /package/dist/{pages → views}/NotFoundPage.d.ts +0 -0
- /package/dist/{pages → views}/OrderConfirmationPage.d.ts +0 -0
- /package/dist/{pages → views}/PolicyPage.d.ts +0 -0
- /package/dist/{pages → views}/ProductDetailPage.d.ts +0 -0
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { useCallback } from 'react'
|
|
2
|
-
import { validateDiscount } from '@fayz-ai/shop'
|
|
3
|
-
import { useStorefrontConfig } from '../config'
|
|
4
|
-
|
|
5
|
-
export interface DiscountValidation {
|
|
6
|
-
valid: boolean
|
|
7
|
-
percent: number
|
|
8
|
-
message?: string
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const REASON_MESSAGE: Record<string, string> = {
|
|
12
|
-
expired: 'Cupom expirado.',
|
|
13
|
-
not_started: 'Cupom ainda não está ativo.',
|
|
14
|
-
usage_limit: 'Cupom esgotado.',
|
|
15
|
-
not_found: 'Cupom inválido ou expirado.',
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Storefront coupon validator. The store's own config.discounts (simple percent
|
|
20
|
-
* codes) are trusted directly; everything else goes through the provider-backed
|
|
21
|
-
* validateDiscount primitive, which enforces status/date-window/usage-limit.
|
|
22
|
-
* The storefront cart models discounts as a percentage, so non-percentage codes
|
|
23
|
-
* are rejected for client-side preview (the server still honors them at checkout).
|
|
24
|
-
*/
|
|
25
|
-
export function useDiscountValidator(): (code: string) => Promise<DiscountValidation> {
|
|
26
|
-
const config = useStorefrontConfig()
|
|
27
|
-
return useCallback(async (code: string) => {
|
|
28
|
-
const normalized = code.trim().toUpperCase()
|
|
29
|
-
if (!normalized) return { valid: false, percent: 0, message: 'Informe um cupom.' }
|
|
30
|
-
|
|
31
|
-
const configDiscount = config.discounts?.find((d) => d.code.trim().toUpperCase() === normalized)
|
|
32
|
-
if (configDiscount) return { valid: true, percent: configDiscount.percent }
|
|
33
|
-
|
|
34
|
-
const validation = await validateDiscount({ code: normalized })
|
|
35
|
-
if (!validation.valid) {
|
|
36
|
-
return { valid: false, percent: 0, message: REASON_MESSAGE[validation.reason ?? 'not_found'] ?? 'Cupom inválido ou expirado.' }
|
|
37
|
-
}
|
|
38
|
-
if (validation.type !== 'percentage') {
|
|
39
|
-
return { valid: false, percent: 0, message: 'Este cupom não é suportado na loja.' }
|
|
40
|
-
}
|
|
41
|
-
return { valid: true, percent: validation.value }
|
|
42
|
-
}, [config.discounts])
|
|
43
|
-
}
|
package/src/hooks/useMyOrders.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useState } from 'react'
|
|
2
|
-
import { getShopProvider } from '@fayz-ai/shop/runtime'
|
|
3
|
-
import type { Order } from '@fayz-ai/shop/types'
|
|
4
|
-
import { useSessionStore } from '../stores/session.store'
|
|
5
|
-
|
|
6
|
-
export function useMyOrders(): { orders: Order[]; loading: boolean; refresh: () => void } {
|
|
7
|
-
const customerId = useSessionStore((s) => s.customerId)
|
|
8
|
-
const email = useSessionStore((s) => s.email)
|
|
9
|
-
const [orders, setOrders] = useState<Order[]>([])
|
|
10
|
-
const [loading, setLoading] = useState(true)
|
|
11
|
-
const [tick, setTick] = useState(0)
|
|
12
|
-
|
|
13
|
-
const refresh = useCallback(() => setTick((t) => t + 1), [])
|
|
14
|
-
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
let cancelled = false
|
|
17
|
-
if (!customerId && !email) {
|
|
18
|
-
setOrders([])
|
|
19
|
-
setLoading(false)
|
|
20
|
-
return
|
|
21
|
-
}
|
|
22
|
-
setLoading(true)
|
|
23
|
-
// Scope by customerId (RLS-enforced to the owner on Supabase) when available;
|
|
24
|
-
// fall back to email only for legacy sessions without a linked customer.
|
|
25
|
-
const query = customerId ? { customerId, limit: 50 } : { customerEmail: email!, limit: 50 }
|
|
26
|
-
getShopProvider()
|
|
27
|
-
.listOrders(query)
|
|
28
|
-
.then((data) => {
|
|
29
|
-
if (!cancelled) setOrders(data)
|
|
30
|
-
})
|
|
31
|
-
.catch(() => {})
|
|
32
|
-
.finally(() => {
|
|
33
|
-
if (!cancelled) setLoading(false)
|
|
34
|
-
})
|
|
35
|
-
return () => {
|
|
36
|
-
cancelled = true
|
|
37
|
-
}
|
|
38
|
-
}, [customerId, email, tick])
|
|
39
|
-
|
|
40
|
-
return { orders, loading, refresh }
|
|
41
|
-
}
|
package/src/hooks/useProduct.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react'
|
|
2
|
-
import { getShopProvider } from '@fayz-ai/shop/runtime'
|
|
3
|
-
import type { Product } from '@fayz-ai/shop/types'
|
|
4
|
-
|
|
5
|
-
export function useProduct(slug: string): {
|
|
6
|
-
product: Product | null
|
|
7
|
-
loading: boolean
|
|
8
|
-
error: string | null
|
|
9
|
-
} {
|
|
10
|
-
const [product, setProduct] = useState<Product | null>(null)
|
|
11
|
-
const [loading, setLoading] = useState(true)
|
|
12
|
-
const [error, setError] = useState<string | null>(null)
|
|
13
|
-
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
let cancelled = false
|
|
16
|
-
setLoading(true)
|
|
17
|
-
getShopProvider()
|
|
18
|
-
.listProducts({ slug, status: 'active', limit: 1 })
|
|
19
|
-
.then((data) => {
|
|
20
|
-
if (cancelled) return
|
|
21
|
-
setProduct(data[0] ?? null)
|
|
22
|
-
setError(null)
|
|
23
|
-
})
|
|
24
|
-
.catch((e: unknown) => {
|
|
25
|
-
if (!cancelled) setError(e instanceof Error ? e.message : String(e))
|
|
26
|
-
})
|
|
27
|
-
.finally(() => {
|
|
28
|
-
if (!cancelled) setLoading(false)
|
|
29
|
-
})
|
|
30
|
-
return () => {
|
|
31
|
-
cancelled = true
|
|
32
|
-
}
|
|
33
|
-
}, [slug])
|
|
34
|
-
|
|
35
|
-
return { product, loading, error }
|
|
36
|
-
}
|
package/src/hooks/useProducts.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react'
|
|
2
|
-
import { getShopProvider } from '@fayz-ai/shop/runtime'
|
|
3
|
-
import type { Product, ListProductsOptions } from '@fayz-ai/shop/types'
|
|
4
|
-
|
|
5
|
-
export function useProducts(opts: ListProductsOptions): {
|
|
6
|
-
products: Product[]
|
|
7
|
-
loading: boolean
|
|
8
|
-
error: string | null
|
|
9
|
-
reload: () => void
|
|
10
|
-
} {
|
|
11
|
-
const [products, setProducts] = useState<Product[]>([])
|
|
12
|
-
const [loading, setLoading] = useState(true)
|
|
13
|
-
const [error, setError] = useState<string | null>(null)
|
|
14
|
-
const [nonce, setNonce] = useState(0)
|
|
15
|
-
const key = JSON.stringify(opts)
|
|
16
|
-
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
let cancelled = false
|
|
19
|
-
setLoading(true)
|
|
20
|
-
getShopProvider()
|
|
21
|
-
.listProducts(JSON.parse(key) as ListProductsOptions)
|
|
22
|
-
.then((data) => {
|
|
23
|
-
if (cancelled) return
|
|
24
|
-
setProducts(data)
|
|
25
|
-
setError(null)
|
|
26
|
-
})
|
|
27
|
-
.catch((e: unknown) => {
|
|
28
|
-
if (!cancelled) setError(e instanceof Error ? e.message : String(e))
|
|
29
|
-
})
|
|
30
|
-
.finally(() => {
|
|
31
|
-
if (!cancelled) setLoading(false)
|
|
32
|
-
})
|
|
33
|
-
return () => {
|
|
34
|
-
cancelled = true
|
|
35
|
-
}
|
|
36
|
-
}, [key, nonce])
|
|
37
|
-
|
|
38
|
-
return { products, loading, error, reload: () => setNonce((n) => n + 1) }
|
|
39
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { getShopProvider } from '@fayz-ai/shop/runtime'
|
|
2
|
-
import type { CreateProductEnquiryInput } from '@fayz-ai/shop/types'
|
|
3
|
-
import { useStorefrontConfig } from '../config'
|
|
4
|
-
import { navigateTo } from '../router'
|
|
5
|
-
import { useCatalogStore } from '../stores/catalog.store'
|
|
6
|
-
import { useCartStore } from '../stores/cart.store'
|
|
7
|
-
import type { ProductOptionSelection } from '../product-options'
|
|
8
|
-
import type { Product } from '@fayz-ai/shop/types'
|
|
9
|
-
|
|
10
|
-
export function useStorefront() {
|
|
11
|
-
return useStorefrontConfig()
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function useCatalog() {
|
|
15
|
-
const config = useStorefrontConfig()
|
|
16
|
-
const catalog = useCatalogStore()
|
|
17
|
-
return {
|
|
18
|
-
...catalog,
|
|
19
|
-
catalogPath: config.catalogPath,
|
|
20
|
-
config,
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function useCart() {
|
|
25
|
-
return useCartStore()
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function useEnquiry() {
|
|
29
|
-
const config = useStorefrontConfig()
|
|
30
|
-
const createProductEnquiry = async (input: CreateProductEnquiryInput) => {
|
|
31
|
-
const provider = getShopProvider()
|
|
32
|
-
if (!provider.createProductEnquiry) {
|
|
33
|
-
throw new Error('The active shop provider does not support product enquiries.')
|
|
34
|
-
}
|
|
35
|
-
return provider.createProductEnquiry(input)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
enquiry: config.enquiry,
|
|
40
|
-
createProductEnquiry,
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function useStorefrontActions() {
|
|
45
|
-
const addItem = useCartStore((state) => state.addItem)
|
|
46
|
-
const openDrawer = useCartStore((state) => state.openDrawer)
|
|
47
|
-
const closeDrawer = useCartStore((state) => state.closeDrawer)
|
|
48
|
-
const { createProductEnquiry } = useEnquiry()
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
navigateTo,
|
|
52
|
-
addToCart: (product: Product, quantity?: number, options?: ProductOptionSelection) =>
|
|
53
|
-
addItem(product, quantity, options),
|
|
54
|
-
openCart: openDrawer,
|
|
55
|
-
closeCart: closeDrawer,
|
|
56
|
-
createProductEnquiry,
|
|
57
|
-
}
|
|
58
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { useEffect } from 'react'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Minimal per-route head manager: sets document.title and meta description so
|
|
5
|
-
* each storefront page (product, catalog, account, checkout) has its own title
|
|
6
|
-
* and shareable description instead of one static SPA title. A real SSR/prerender
|
|
7
|
-
* pass (M12) layers OG/canonical on top; this covers the client-rendered baseline.
|
|
8
|
-
*/
|
|
9
|
-
export function useStorefrontHead(input: { title?: string; description?: string | null }): void {
|
|
10
|
-
const { title, description } = input
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
if (title) document.title = title
|
|
13
|
-
}, [title])
|
|
14
|
-
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
if (!description) return
|
|
17
|
-
let tag = document.head.querySelector<HTMLMetaElement>('meta[name="description"]')
|
|
18
|
-
if (!tag) {
|
|
19
|
-
tag = document.createElement('meta')
|
|
20
|
-
tag.setAttribute('name', 'description')
|
|
21
|
-
document.head.appendChild(tag)
|
|
22
|
-
}
|
|
23
|
-
tag.setAttribute('content', description.slice(0, 160))
|
|
24
|
-
}, [description])
|
|
25
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
// Factory
|
|
2
|
-
export { createStorefront, createStorefrontApp, initStorefrontRuntime, StorefrontShell } from './createStorefrontApp'
|
|
3
|
-
export type { CreateStorefrontOptions } from './createStorefrontApp'
|
|
4
|
-
export {
|
|
5
|
-
defineStorefrontConfig,
|
|
6
|
-
defineStorefrontComponents,
|
|
7
|
-
defineStorefrontRoutes,
|
|
8
|
-
defineStorefrontSections,
|
|
9
|
-
defineStorefrontApp,
|
|
10
|
-
} from './define'
|
|
11
|
-
export type {
|
|
12
|
-
StorefrontConfig,
|
|
13
|
-
ResolvedStorefrontConfig,
|
|
14
|
-
StorefrontRouteComponentProps,
|
|
15
|
-
StorefrontRouteChrome,
|
|
16
|
-
StorefrontCommerceMode,
|
|
17
|
-
StorefrontImageLoadingConfig,
|
|
18
|
-
StorefrontImageLoadingMode,
|
|
19
|
-
StorefrontRouteDefinition,
|
|
20
|
-
StorefrontRouteKind,
|
|
21
|
-
StorefrontRouteParams,
|
|
22
|
-
StorefrontEnquiryConfig,
|
|
23
|
-
} from './config'
|
|
24
|
-
export type {
|
|
25
|
-
StorefrontActions,
|
|
26
|
-
StorefrontComponents,
|
|
27
|
-
ProductCardProps,
|
|
28
|
-
ProductDetailProps,
|
|
29
|
-
ProductGalleryProps,
|
|
30
|
-
ProductPriceProps,
|
|
31
|
-
ProductActionsProps,
|
|
32
|
-
ProductEnquiryFormContractProps,
|
|
33
|
-
CategoryCardProps,
|
|
34
|
-
CollectionSectionProps,
|
|
35
|
-
HeroSectionContractProps,
|
|
36
|
-
MediaCarouselProps as MediaCarouselContractProps,
|
|
37
|
-
ProductSliderProps as ProductSliderContractProps,
|
|
38
|
-
StorefrontChromeProps,
|
|
39
|
-
StorefrontStateProps,
|
|
40
|
-
} from './component-contracts'
|
|
41
|
-
export { useStorefrontConfig, useStorefrontConfigOptional } from './config'
|
|
42
|
-
|
|
43
|
-
// Manifest path (renderApp(defineStorefront(config)) / storefront scaffold)
|
|
44
|
-
export { defineStorefront, StorefrontScaffold } from './scaffold'
|
|
45
|
-
|
|
46
|
-
// Block system (storefront sections as registry blocks)
|
|
47
|
-
export { registerStorefrontBlocks, sectionsToBlocks } from './blocks'
|
|
48
|
-
|
|
49
|
-
// Routing
|
|
50
|
-
export { Link, navigateTo, useHashPath, matchPath } from './router'
|
|
51
|
-
export type { LinkProps } from './router'
|
|
52
|
-
|
|
53
|
-
// Stores
|
|
54
|
-
export {
|
|
55
|
-
useCartStore,
|
|
56
|
-
selectCount,
|
|
57
|
-
selectSubtotal,
|
|
58
|
-
selectDiscountTotal,
|
|
59
|
-
selectShipping,
|
|
60
|
-
selectTotal,
|
|
61
|
-
} from './stores/cart.store'
|
|
62
|
-
export type { CartLine, CartState } from './stores/cart.store'
|
|
63
|
-
export { useSessionStore } from './stores/session.store'
|
|
64
|
-
export type { SessionState } from './stores/session.store'
|
|
65
|
-
export {
|
|
66
|
-
signInByEmail,
|
|
67
|
-
signUpCustomer,
|
|
68
|
-
establishCustomerSession,
|
|
69
|
-
signOutCustomer,
|
|
70
|
-
getCustomerAuthAdapter,
|
|
71
|
-
resolveAuthAdapter,
|
|
72
|
-
} from './auth'
|
|
73
|
-
export type { StorefrontAuthAdapter, StorefrontAuthConfig, EstablishSessionOptions } from './auth'
|
|
74
|
-
export { useCatalogStore } from './stores/catalog.store'
|
|
75
|
-
export type { CatalogState, CatalogSort } from './stores/catalog.store'
|
|
76
|
-
|
|
77
|
-
// Hooks
|
|
78
|
-
export {
|
|
79
|
-
useProducts,
|
|
80
|
-
useProduct,
|
|
81
|
-
useCategories,
|
|
82
|
-
useStorefront,
|
|
83
|
-
useCatalog,
|
|
84
|
-
useCart,
|
|
85
|
-
useEnquiry,
|
|
86
|
-
useStorefrontActions,
|
|
87
|
-
useMyOrders,
|
|
88
|
-
useDiscountValidator,
|
|
89
|
-
} from './hooks'
|
|
90
|
-
|
|
91
|
-
// Components (for custom layouts)
|
|
92
|
-
export { StorefrontHeader } from './components/StorefrontHeader'
|
|
93
|
-
export { SmoothImage } from './components/SmoothImage'
|
|
94
|
-
export type { SmoothImageProps } from './components/SmoothImage'
|
|
95
|
-
export { ProductCard } from './components/ProductCard'
|
|
96
|
-
export { ProductEnquiryForm } from './components/ProductEnquiryForm'
|
|
97
|
-
export type { ProductEnquiryFormProps } from './components/ProductEnquiryForm'
|
|
98
|
-
export { OrderTrackingTimeline } from './components/OrderTrackingTimeline'
|
|
99
|
-
export { ProductGrid } from './components/ProductGrid'
|
|
100
|
-
export { FiltersPanel } from './components/FiltersPanel'
|
|
101
|
-
export { CartDrawer } from './components/CartDrawer'
|
|
102
|
-
export { Price } from './components/Price'
|
|
103
|
-
export { QuantityInput } from './components/QuantityInput'
|
|
104
|
-
export { ProductOptionSelector } from './components/ProductOptionSelector'
|
|
105
|
-
export type { ProductOptionSelectorProps } from './components/ProductOptionSelector'
|
|
106
|
-
export {
|
|
107
|
-
getProductOptionGroups,
|
|
108
|
-
normalizeProductOptionSelection,
|
|
109
|
-
formatProductOptionSelection,
|
|
110
|
-
productOptionSelectionKey,
|
|
111
|
-
} from './product-options'
|
|
112
|
-
export type { ProductOptionGroup, ProductOptionSelection } from './product-options'
|
|
113
|
-
|
|
114
|
-
// Pages (for custom routing)
|
|
115
|
-
export { CatalogPage } from './pages/CatalogPage'
|
|
116
|
-
export { ProductDetailPage } from './pages/ProductDetailPage'
|
|
117
|
-
export { CheckoutPage } from './pages/CheckoutPage'
|
|
118
|
-
export { OrderConfirmationPage } from './pages/OrderConfirmationPage'
|
|
119
|
-
export { MyPurchasesPage } from './pages/MyPurchasesPage'
|
|
120
|
-
export { placeStorefrontOrder } from './workflows/checkout'
|
|
121
|
-
export type {
|
|
122
|
-
PlaceStorefrontOrderInput,
|
|
123
|
-
PlaceStorefrontOrderResult,
|
|
124
|
-
StorefrontCheckoutAddress,
|
|
125
|
-
StorefrontCheckoutCustomer,
|
|
126
|
-
} from './workflows/checkout'
|
|
127
|
-
|
|
128
|
-
// Theming + templates
|
|
129
|
-
export { StorefrontThemeStyle, themeToCss } from './theme'
|
|
130
|
-
export type {
|
|
131
|
-
StorefrontTheme,
|
|
132
|
-
StorefrontThemeColors,
|
|
133
|
-
StorefrontThemeFont,
|
|
134
|
-
StorefrontRadius,
|
|
135
|
-
HeaderVariant,
|
|
136
|
-
HeroVariant,
|
|
137
|
-
CardStyle,
|
|
138
|
-
} from './theme'
|
|
139
|
-
export type { StorefrontSection, HomeSection, HomeConfig, HeroSlide, MediaCarouselItem, NavLink, FooterConfig } from './sections'
|
|
140
|
-
export { bannerPlaceholder } from './sections'
|
|
141
|
-
export {
|
|
142
|
-
storefrontTemplates,
|
|
143
|
-
mareTemplate,
|
|
144
|
-
sertaoTemplate,
|
|
145
|
-
voltTemplate,
|
|
146
|
-
atelierTemplate,
|
|
147
|
-
foodTemplate,
|
|
148
|
-
} from './presets'
|
|
149
|
-
export type { StorefrontTemplate, StorefrontTemplateId } from './presets'
|
|
150
|
-
|
|
151
|
-
// Home sections (for custom compositions)
|
|
152
|
-
export { HomePage, StorefrontSections } from './pages/HomePage'
|
|
153
|
-
export { HeroSection } from './components/sections/HeroSection'
|
|
154
|
-
export { MediaCarousel } from './components/sections/MediaCarousel'
|
|
155
|
-
export type { MediaCarouselProps } from './components/sections/MediaCarousel'
|
|
156
|
-
export { CategoryShowcase } from './components/sections/CategoryShowcase'
|
|
157
|
-
export { ProductRail } from './components/sections/ProductRail'
|
|
158
|
-
export { ProductSlider } from './components/sections/ProductSlider'
|
|
159
|
-
export type { ProductSliderProps } from './components/sections/ProductSlider'
|
|
160
|
-
export {
|
|
161
|
-
BenefitsRow,
|
|
162
|
-
PromoBanner,
|
|
163
|
-
ManifestoBlock,
|
|
164
|
-
Testimonials,
|
|
165
|
-
NewsletterBand,
|
|
166
|
-
} from './components/sections/MiscSections'
|
|
167
|
-
export { StorefrontFooter } from './components/StorefrontFooter'
|
|
168
|
-
|
|
169
|
-
// Motion (core animation primitives)
|
|
170
|
-
export { Reveal, useInView, useScrolled, usePopOnChange, prefersReducedMotion } from './motion'
|
|
171
|
-
export type { RevealProps } from './motion'
|
|
172
|
-
|
|
173
|
-
// Utilities
|
|
174
|
-
export { formatMoney, roundCents } from './format'
|
|
175
|
-
export { TID } from './testids'
|
|
176
|
-
export {
|
|
177
|
-
productCardComponentContract,
|
|
178
|
-
storefrontComponentContracts,
|
|
179
|
-
} from './component-selectors'
|
|
180
|
-
export type {
|
|
181
|
-
ProductCardComponentContract,
|
|
182
|
-
ProductDetailComponentContract,
|
|
183
|
-
} from './component-selectors'
|
|
184
|
-
|
|
185
|
-
// ---------------------------------------------------------------------------
|
|
186
|
-
// Front-door re-exports: storefront apps depend on @fayz-ai/storefront alone.
|
|
187
|
-
// Runtime helpers come from @fayz-ai/core; UI / shop catalog / shop provider
|
|
188
|
-
// live on their own subpaths (./ui, ./catalog, ./shop) to keep module graphs
|
|
189
|
-
// separate. Mirrors the @fayz-ai/saas front door.
|
|
190
|
-
// ---------------------------------------------------------------------------
|
|
191
|
-
// renderApp is wrapped (not re-exported) so the 'storefront' scaffold registers
|
|
192
|
-
// on first render instead of at import time — keeps the barrel side-effect-free.
|
|
193
|
-
import { renderApp as coreRenderApp } from '@fayz-ai/core'
|
|
194
|
-
import { registerStorefrontScaffold } from './scaffold'
|
|
195
|
-
|
|
196
|
-
export const renderApp: typeof coreRenderApp = (...args) => {
|
|
197
|
-
registerStorefrontScaffold()
|
|
198
|
-
return coreRenderApp(...args)
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export { getSupabaseClientOptional } from '@fayz-ai/core'
|
|
202
|
-
export { registerStorefrontScaffold } from './scaffold'
|
package/src/motion.tsx
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useRef, useState } from 'react'
|
|
2
|
-
|
|
3
|
-
// ---------------------------------------------------------------------------
|
|
4
|
-
// Core motion primitives — every storefront inherits these; stores never
|
|
5
|
-
// implement animation ad hoc. All effects respect prefers-reduced-motion.
|
|
6
|
-
// ---------------------------------------------------------------------------
|
|
7
|
-
|
|
8
|
-
export function prefersReducedMotion(): boolean {
|
|
9
|
-
if (typeof window === 'undefined' || !window.matchMedia) return false
|
|
10
|
-
return window.matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/** True once the element has entered the viewport (one-shot). */
|
|
14
|
-
export function useInView<T extends HTMLElement>(margin = '0px 0px -8% 0px'): [React.RefObject<T>, boolean] {
|
|
15
|
-
const ref = useRef<T>(null)
|
|
16
|
-
const [inView, setInView] = useState(() => prefersReducedMotion())
|
|
17
|
-
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
if (inView) return
|
|
20
|
-
const el = ref.current
|
|
21
|
-
if (!el || typeof IntersectionObserver === 'undefined') {
|
|
22
|
-
setInView(true)
|
|
23
|
-
return
|
|
24
|
-
}
|
|
25
|
-
const observer = new IntersectionObserver(
|
|
26
|
-
(entries) => {
|
|
27
|
-
if (entries.some((e) => e.isIntersecting)) {
|
|
28
|
-
setInView(true)
|
|
29
|
-
observer.disconnect()
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
{ rootMargin: margin },
|
|
33
|
-
)
|
|
34
|
-
observer.observe(el)
|
|
35
|
-
return () => observer.disconnect()
|
|
36
|
-
}, [inView, margin])
|
|
37
|
-
|
|
38
|
-
return [ref, inView]
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface RevealProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
42
|
-
/** Stagger delay in ms */
|
|
43
|
-
delay?: number
|
|
44
|
-
children: React.ReactNode
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** Plays a fade-up entrance when the element scrolls into view.
|
|
48
|
-
* Content is VISIBLE by default — never pre-hidden — so screenshots,
|
|
49
|
-
* crawlers and environments without IntersectionObserver always see it;
|
|
50
|
-
* the animation's own from-state handles the fade. */
|
|
51
|
-
export function Reveal({ delay = 0, children, className, style, ...rest }: RevealProps) {
|
|
52
|
-
const [ref, inView] = useInView<HTMLDivElement>()
|
|
53
|
-
return (
|
|
54
|
-
<div
|
|
55
|
-
ref={ref}
|
|
56
|
-
className={`${inView ? 'animate-fade-up' : ''} ${className ?? ''}`}
|
|
57
|
-
style={{ ...style, animationDelay: delay ? `${delay}ms` : undefined }}
|
|
58
|
-
{...rest}
|
|
59
|
-
>
|
|
60
|
-
{children}
|
|
61
|
-
</div>
|
|
62
|
-
)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** True after the window has scrolled past the threshold (header treatments). */
|
|
66
|
-
export function useScrolled(threshold = 8): boolean {
|
|
67
|
-
const [scrolled, setScrolled] = useState(false)
|
|
68
|
-
useEffect(() => {
|
|
69
|
-
const onScroll = () => setScrolled(window.scrollY > threshold)
|
|
70
|
-
onScroll()
|
|
71
|
-
window.addEventListener('scroll', onScroll, { passive: true })
|
|
72
|
-
return () => window.removeEventListener('scroll', onScroll)
|
|
73
|
-
}, [threshold])
|
|
74
|
-
return scrolled
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** Re-triggers a CSS animation class whenever `value` changes (cart badge pop). */
|
|
78
|
-
export function usePopOnChange(value: number): boolean {
|
|
79
|
-
const [pop, setPop] = useState(false)
|
|
80
|
-
const prev = useRef(value)
|
|
81
|
-
useEffect(() => {
|
|
82
|
-
if (prev.current !== value && value > 0) {
|
|
83
|
-
setPop(true)
|
|
84
|
-
const t = setTimeout(() => setPop(false), 400)
|
|
85
|
-
return () => clearTimeout(t)
|
|
86
|
-
}
|
|
87
|
-
prev.current = value
|
|
88
|
-
return undefined
|
|
89
|
-
}, [value])
|
|
90
|
-
useEffect(() => {
|
|
91
|
-
prev.current = value
|
|
92
|
-
})
|
|
93
|
-
return pop
|
|
94
|
-
}
|
package/src/order-status.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { FinancialStatus } from '@fayz-ai/shop/types'
|
|
2
|
-
|
|
3
|
-
type Tone = 'positive' | 'pending' | 'negative'
|
|
4
|
-
|
|
5
|
-
const FINANCIAL: Record<FinancialStatus, { label: string; tone: Tone }> = {
|
|
6
|
-
pending: { label: 'Pendente', tone: 'pending' },
|
|
7
|
-
paid: { label: 'Pago', tone: 'positive' },
|
|
8
|
-
partially_paid: { label: 'Parcialmente pago', tone: 'pending' },
|
|
9
|
-
partially_refunded: { label: 'Parcialmente reembolsado', tone: 'negative' },
|
|
10
|
-
refunded: { label: 'Reembolsado', tone: 'negative' },
|
|
11
|
-
voided: { label: 'Cancelado', tone: 'negative' },
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const TONE_CLASS: Record<Tone, string> = {
|
|
15
|
-
positive: 'bg-emerald-100 text-emerald-800',
|
|
16
|
-
pending: 'bg-amber-100 text-amber-800',
|
|
17
|
-
negative: 'bg-rose-100 text-rose-800',
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** One source of truth for a financial-status pill — label + color by status,
|
|
21
|
-
* so a pending or refunded order never renders inside a green "success" pill. */
|
|
22
|
-
export function financialStatusBadge(status: FinancialStatus): { label: string; className: string } {
|
|
23
|
-
const entry = FINANCIAL[status] ?? { label: status, tone: 'pending' as Tone }
|
|
24
|
-
return { label: entry.label, className: TONE_CLASS[entry.tone] }
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function isPaid(status: FinancialStatus): boolean {
|
|
28
|
-
return status === 'paid' || status === 'partially_paid'
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function isRefunded(status: FinancialStatus): boolean {
|
|
32
|
-
return status === 'refunded' || status === 'partially_refunded'
|
|
33
|
-
}
|