AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

renderer.tsx 4.9KB

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