AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

renderer.tsx 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import type { ReactNode } from 'react';
  2. import { StorefrontProvider } from './context';
  3. import { CartPage } from './pages/cart';
  4. import { CheckoutPage } from './pages/checkout';
  5. import { OrderPage } from './pages/order';
  6. import { ProductPage } from './pages/product';
  7. import { ShopPage } from './pages/shop';
  8. import { About } from './sections/about';
  9. import { Contact } from './sections/contact';
  10. import { Faq } from './sections/faq';
  11. import { FeaturedProduct } from './sections/featured-product';
  12. import { Footer } from './sections/footer';
  13. import { Header } from './sections/header';
  14. import { Hero } from './sections/hero';
  15. import { Newsletter } from './sections/newsletter';
  16. import { ProductGrid } from './sections/product-grid';
  17. import { Testimonials } from './sections/testimonials';
  18. import { themeStyle } from './theme';
  19. import { WhatsAppButton } from './whatsapp';
  20. import type {
  21. FontMap,
  22. PlanSection,
  23. ShopInfo,
  24. StoreCart,
  25. StorePlan,
  26. StoreProduct,
  27. StorefrontView,
  28. } from './types';
  29. /**
  30. * Draw one section. To add a new section type: add it to PlanSchema.php and
  31. * types.ts, write its component, and add one line here.
  32. */
  33. function Section({ section }: { section: PlanSection }) {
  34. switch (section.type) {
  35. case 'hero':
  36. return <Hero section={section} />;
  37. case 'product_grid':
  38. return <ProductGrid section={section} />;
  39. case 'featured_product':
  40. return <FeaturedProduct section={section} />;
  41. case 'about':
  42. return <About section={section} />;
  43. case 'testimonials':
  44. return <Testimonials section={section} />;
  45. case 'faq':
  46. return <Faq section={section} />;
  47. case 'newsletter':
  48. return <Newsletter section={section} />;
  49. case 'contact':
  50. return <Contact section={section} />;
  51. default:
  52. // A type this version of the app does not know. Skip it and keep the page working.
  53. return null;
  54. }
  55. }
  56. function PageBody({ plan, view }: { plan: StorePlan; view: StorefrontView }) {
  57. if (view.type === 'shop') {
  58. return <ShopPage />;
  59. }
  60. if (view.type === 'cart') {
  61. return <CartPage />;
  62. }
  63. if (view.type === 'checkout') {
  64. return (
  65. <CheckoutPage
  66. states={view.states}
  67. shippingByState={view.shippingByState}
  68. />
  69. );
  70. }
  71. if (view.type === 'order') {
  72. return <OrderPage order={view.order} />;
  73. }
  74. if (view.type === 'product') {
  75. return <ProductPage product={view.product} />;
  76. }
  77. const page =
  78. plan.pages.find((candidate) => candidate.id === view.pageId) ??
  79. plan.pages[0];
  80. return (
  81. <main>
  82. {/* Extra pages get a page heading for screen readers. The home page has its hero headline. */}
  83. {page && page.id !== 'home' && (
  84. <h1 className="sr-only">{page.title}</h1>
  85. )}
  86. {page?.sections.map((section) => (
  87. <Section key={section.id} section={section} />
  88. ))}
  89. </main>
  90. );
  91. }
  92. /**
  93. * Turn a store plan into one storefront page: the shared header, the page itself, the shared footer.
  94. */
  95. export function StorefrontRenderer({
  96. plan,
  97. fonts,
  98. view,
  99. baseUrl,
  100. language,
  101. products,
  102. cart,
  103. storeName,
  104. shop,
  105. }: {
  106. plan: StorePlan;
  107. fonts: FontMap;
  108. view: StorefrontView;
  109. baseUrl: string;
  110. language: string;
  111. products: StoreProduct[];
  112. cart: StoreCart;
  113. storeName: string;
  114. shop: ShopInfo;
  115. }): ReactNode {
  116. const isHome = view.type === 'page' && view.pageId === 'home';
  117. return (
  118. <StorefrontProvider
  119. value={{
  120. baseUrl,
  121. isHome,
  122. language,
  123. products,
  124. cart,
  125. storeName,
  126. shop,
  127. }}
  128. >
  129. <div
  130. className="sf-root flex min-h-screen flex-col"
  131. style={themeStyle(plan.theme, fonts)}
  132. >
  133. <Header section={plan.header} />
  134. <div className="flex-1">
  135. <PageBody plan={plan} view={view} />
  136. </div>
  137. <Footer section={plan.footer} />
  138. {/* Room under the footer so the WhatsApp button never covers its links. */}
  139. {shop.whatsapp && <div className="h-20" aria-hidden="true" />}
  140. <WhatsAppButton />
  141. </div>
  142. </StorefrontProvider>
  143. );
  144. }