@faststore/core 2.0.117-alpha.0 → 2.0.120-alpha.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.
Files changed (160) hide show
  1. package/.turbo/turbo-build.log +38 -26
  2. package/CHANGELOG.md +10 -0
  3. package/cms/faststore/content-types.json +6 -0
  4. package/cms/faststore/sections.json +8 -0
  5. package/package.json +3 -3
  6. package/src/Layout.tsx +2 -24
  7. package/src/components/cms/GlobalSections.tsx +81 -0
  8. package/src/components/cms/RenderSections.tsx +39 -0
  9. package/src/components/common/Alert/Alert.tsx +7 -5
  10. package/src/components/common/Alert/index.ts +1 -0
  11. package/src/components/sections/Alert/Alert.tsx +28 -0
  12. package/src/pages/404.tsx +25 -3
  13. package/src/pages/500.tsx +25 -3
  14. package/src/pages/[...slug].tsx +85 -66
  15. package/src/pages/[slug]/p.tsx +16 -6
  16. package/src/pages/account.tsx +25 -3
  17. package/src/pages/checkout.tsx +25 -3
  18. package/src/pages/index.tsx +20 -10
  19. package/src/pages/login.tsx +25 -3
  20. package/src/pages/s.tsx +63 -39
  21. package/.next/BUILD_ID +0 -1
  22. package/.next/build-manifest.json +0 -99
  23. package/.next/cache/.tsbuildinfo +0 -1
  24. package/.next/cache/config.json +0 -7
  25. package/.next/cache/eslint/.cache_1gneedd +0 -1
  26. package/.next/cache/next-server.js.nft.json +0 -1
  27. package/.next/cache/webpack/client-production/0.pack +0 -0
  28. package/.next/cache/webpack/client-production/index.pack +0 -0
  29. package/.next/cache/webpack/server-production/0.pack +0 -0
  30. package/.next/cache/webpack/server-production/index.pack +0 -0
  31. package/.next/export-marker.json +0 -1
  32. package/.next/images-manifest.json +0 -1
  33. package/.next/next-server.js.nft.json +0 -1
  34. package/.next/package.json +0 -1
  35. package/.next/prerender-manifest.json +0 -1
  36. package/.next/react-loadable-manifest.json +0 -42
  37. package/.next/required-server-files.json +0 -1
  38. package/.next/routes-manifest.json +0 -1
  39. package/.next/server/chunks/120.js +0 -435
  40. package/.next/server/chunks/123.js +0 -58
  41. package/.next/server/chunks/1394.js +0 -3801
  42. package/.next/server/chunks/1597.js +0 -151
  43. package/.next/server/chunks/1608.js +0 -515
  44. package/.next/server/chunks/2154.js +0 -206
  45. package/.next/server/chunks/247.js +0 -61
  46. package/.next/server/chunks/2502.js +0 -584
  47. package/.next/server/chunks/2914.js +0 -95
  48. package/.next/server/chunks/2922.js +0 -7293
  49. package/.next/server/chunks/3264.js +0 -67
  50. package/.next/server/chunks/3431.js +0 -7241
  51. package/.next/server/chunks/350.js +0 -142
  52. package/.next/server/chunks/3746.js +0 -250
  53. package/.next/server/chunks/3898.js +0 -240
  54. package/.next/server/chunks/4312.js +0 -674
  55. package/.next/server/chunks/4371.js +0 -1424
  56. package/.next/server/chunks/5098.js +0 -124
  57. package/.next/server/chunks/5335.js +0 -544
  58. package/.next/server/chunks/5576.js +0 -79
  59. package/.next/server/chunks/6280.js +0 -322
  60. package/.next/server/chunks/6465.js +0 -91
  61. package/.next/server/chunks/676.js +0 -32
  62. package/.next/server/chunks/6859.js +0 -959
  63. package/.next/server/chunks/6881.js +0 -320
  64. package/.next/server/chunks/6898.js +0 -149
  65. package/.next/server/chunks/7104.js +0 -235
  66. package/.next/server/chunks/7181.js +0 -664
  67. package/.next/server/chunks/7183.js +0 -79
  68. package/.next/server/chunks/8098.js +0 -246
  69. package/.next/server/chunks/810.js +0 -432
  70. package/.next/server/chunks/8287.js +0 -58
  71. package/.next/server/chunks/9143.js +0 -106
  72. package/.next/server/chunks/9557.js +0 -119
  73. package/.next/server/chunks/9854.js +0 -72
  74. package/.next/server/chunks/font-manifest.json +0 -1
  75. package/.next/server/font-manifest.json +0 -1
  76. package/.next/server/middleware-build-manifest.js +0 -1
  77. package/.next/server/middleware-manifest.json +0 -6
  78. package/.next/server/middleware-react-loadable-manifest.js +0 -1
  79. package/.next/server/pages/404.js.nft.json +0 -1
  80. package/.next/server/pages/500.js.nft.json +0 -1
  81. package/.next/server/pages/[...slug].js +0 -666
  82. package/.next/server/pages/[...slug].js.nft.json +0 -1
  83. package/.next/server/pages/[slug]/p.js +0 -2327
  84. package/.next/server/pages/[slug]/p.js.nft.json +0 -1
  85. package/.next/server/pages/_app.js +0 -2454
  86. package/.next/server/pages/_app.js.nft.json +0 -1
  87. package/.next/server/pages/_document.js +0 -304
  88. package/.next/server/pages/_document.js.nft.json +0 -1
  89. package/.next/server/pages/_error.js +0 -164
  90. package/.next/server/pages/_error.js.nft.json +0 -1
  91. package/.next/server/pages/account.js.nft.json +0 -1
  92. package/.next/server/pages/api/graphql.js +0 -315
  93. package/.next/server/pages/api/graphql.js.nft.json +0 -1
  94. package/.next/server/pages/api/preview.js +0 -118
  95. package/.next/server/pages/api/preview.js.nft.json +0 -1
  96. package/.next/server/pages/checkout.js.nft.json +0 -1
  97. package/.next/server/pages/en-US/404.html +0 -81
  98. package/.next/server/pages/en-US/500.html +0 -81
  99. package/.next/server/pages/en-US/account.html +0 -81
  100. package/.next/server/pages/en-US/checkout.html +0 -81
  101. package/.next/server/pages/en-US/login.html +0 -81
  102. package/.next/server/pages/en-US/s.html +0 -81
  103. package/.next/server/pages/en-US.html +0 -81
  104. package/.next/server/pages/en-US.json +0 -1
  105. package/.next/server/pages/index.js +0 -475
  106. package/.next/server/pages/index.js.nft.json +0 -1
  107. package/.next/server/pages/login.js.nft.json +0 -1
  108. package/.next/server/pages/s.js.nft.json +0 -1
  109. package/.next/server/pages-manifest.json +0 -16
  110. package/.next/server/webpack-api-runtime.js +0 -229
  111. package/.next/server/webpack-runtime.js +0 -229
  112. package/.next/static/chunks/143.dd8a556e6957baa1.js +0 -1
  113. package/.next/static/chunks/170.79b2f8527e327bca.js +0 -1
  114. package/.next/static/chunks/264-5b07911df63b8601.js +0 -1
  115. package/.next/static/chunks/351-a4e28d64f48c5269.js +0 -1
  116. package/.next/static/chunks/54.e6562383f8a1dfe7.js +0 -1
  117. package/.next/static/chunks/597.fc79494903e8bb84.js +0 -1
  118. package/.next/static/chunks/608.59e69b83f35d9c44.js +0 -1
  119. package/.next/static/chunks/651.7142f31ce1e052b3.js +0 -1
  120. package/.next/static/chunks/741.52f7fb873418346f.js +0 -1
  121. package/.next/static/chunks/781-e1b538e051ff4c3e.js +0 -1
  122. package/.next/static/chunks/98.97381d2021f86cd9.js +0 -1
  123. package/.next/static/chunks/996.98e590872c51f815.js +0 -1
  124. package/.next/static/chunks/framework-dfd14d7ce6600b03.js +0 -1
  125. package/.next/static/chunks/main-9746772201fe3ac1.js +0 -1
  126. package/.next/static/chunks/pages/404-3637ef83b3359df7.js +0 -1
  127. package/.next/static/chunks/pages/500-910883c20541d9ce.js +0 -1
  128. package/.next/static/chunks/pages/[...slug]-29d3b81ee0953846.js +0 -1
  129. package/.next/static/chunks/pages/[slug]/p-9b24055cb30ee7a8.js +0 -1
  130. package/.next/static/chunks/pages/_app-4aeb21d72aeea9b7.js +0 -1
  131. package/.next/static/chunks/pages/_error-a7a0c1d9bfbb4f38.js +0 -1
  132. package/.next/static/chunks/pages/account-b8fc5222ffe89b60.js +0 -1
  133. package/.next/static/chunks/pages/checkout-f8cb7cb22225ef9d.js +0 -1
  134. package/.next/static/chunks/pages/index-d48285f48d2a66ea.js +0 -1
  135. package/.next/static/chunks/pages/login-45cc84352bac2408.js +0 -1
  136. package/.next/static/chunks/pages/s-ba2868e14fedb65b.js +0 -1
  137. package/.next/static/chunks/polyfills-c67a75d1b6f99dc8.js +0 -1
  138. package/.next/static/chunks/webpack-f725b61675603493.js +0 -1
  139. package/.next/static/css/1f987650dd4e39d0.css +0 -1
  140. package/.next/static/css/3a57acf6e411f24d.css +0 -1
  141. package/.next/static/css/4abccf9803c3c356.css +0 -1
  142. package/.next/static/css/502746c995f64cce.css +0 -1
  143. package/.next/static/css/6507cb48401e73a4.css +0 -1
  144. package/.next/static/css/6f4d3e91f1d161a8.css +0 -1
  145. package/.next/static/kFT8gMGQbscGgKaZLxG_K/_buildManifest.js +0 -1
  146. package/.next/static/kFT8gMGQbscGgKaZLxG_K/_ssgManifest.js +0 -1
  147. package/.next/static/media/brandless-neutral.76ddf63a.png +0 -0
  148. package/.next/trace +0 -64
  149. package/public/~partytown/debug/partytown-atomics.js +0 -556
  150. package/public/~partytown/debug/partytown-media.js +0 -374
  151. package/public/~partytown/debug/partytown-sandbox-sw.js +0 -543
  152. package/public/~partytown/debug/partytown-sw.js +0 -59
  153. package/public/~partytown/debug/partytown-ww-atomics.js +0 -1789
  154. package/public/~partytown/debug/partytown-ww-sw.js +0 -1781
  155. package/public/~partytown/debug/partytown.js +0 -72
  156. package/public/~partytown/partytown-atomics.js +0 -2
  157. package/public/~partytown/partytown-media.js +0 -2
  158. package/public/~partytown/partytown-sw.js +0 -2
  159. package/public/~partytown/partytown.js +0 -2
  160. package/src/components/cms/RenderPageSections.tsx +0 -37
@@ -13,39 +13,51 @@ info - Disabled SWC as replacement for Babel because of custom Babel configurat
13
13
  info - Using external babel configuration from /home/runner/work/faststore/faststore/packages/core/.babelrc
14
14
  info - Compiled successfully
15
15
  info - Collecting page data...
16
- info - Generating static pages (0/13)
17
- info - Generating static pages (3/13)
18
- info - Generating static pages (6/13)
19
- info - Generating static pages (9/13)
16
+ info - Generating static pages (0/7)
17
+ warn - Children not found. Add a new component for this section or remove it from the CMS
18
+ warn - Children not found. Add a new component for this section or remove it from the CMS
19
+ info - Generating static pages (1/7)
20
+ warn - Children not found. Add a new component for this section or remove it from the CMS
21
+ warn - Children not found. Add a new component for this section or remove it from the CMS
22
+ warn - Children not found. Add a new component for this section or remove it from the CMS
23
+ warn - Children not found. Add a new component for this section or remove it from the CMS
24
+ info - Generating static pages (3/7)
25
+ warn - Children not found. Add a new component for this section or remove it from the CMS
26
+ warn - Children not found. Add a new component for this section or remove it from the CMS
20
27
  warn - CallToAction not found. Add a new component for this section or remove it from the CMS
21
28
  warn - CallToAction not found. Add a new component for this section or remove it from the CMS
22
29
  warn - CallToAction not found. Add a new component for this section or remove it from the CMS
23
- info - Generating static pages (13/13)
30
+ warn - Children not found. Add a new component for this section or remove it from the CMS
31
+ warn - Children not found. Add a new component for this section or remove it from the CMS
32
+ info - Generating static pages (5/7)
33
+ warn - Children not found. Add a new component for this section or remove it from the CMS
34
+ warn - Children not found. Add a new component for this section or remove it from the CMS
35
+ info - Generating static pages (7/7)
24
36
  info - Finalizing page optimization...
25
37
 
26
38
  Route (pages) Size First Load JS
27
- ┌ ● / 8.65 kB 117 kB
28
- ├ └ css/3a57acf6e411f24d.css 1.69 kB
29
- ├ /_app 0 B 96.8 kB
30
- ├ ● /[...slug] 9.46 kB 122 kB
31
- ├ └ css/1f987650dd4e39d0.css 1.33 kB
32
- ├ ● /[slug]/p 16.8 kB 125 kB
33
- ├ └ css/4abccf9803c3c356.css 1.82 kB
34
- ├ ○ /404 665 B 103 kB
35
- /500 439 B 102 kB
36
- /account 383 B 102 kB
37
- ├ λ /api/graphql 0 B 96.8 kB
38
- ├ λ /api/preview 0 B 96.8 kB
39
- /checkout 371 B 102 kB
40
- /login 577 B 103 kB
41
- /s 895 B 113 kB
42
- └ css/6f4d3e91f1d161a8.css 1.29 kB
43
- + First Load JS shared by all 120 kB
39
+ ┌ ● / 4.05 kB 122 kB
40
+ ├ └ css/777fb0b5b1c2fa32.css 2.87 kB
41
+ ├ /_app 0 B 77.8 kB
42
+ ├ ● /[...slug] 2.29 kB 130 kB
43
+ ├ └ css/c302d203b46499ff.css 2.52 kB
44
+ ├ ● /[slug]/p 12.3 kB 130 kB
45
+ ├ └ css/384a7a015bca80d6.css 3.01 kB
46
+ ├ ○ /404 950 B 110 kB
47
+ /500 718 B 109 kB
48
+ /account 670 B 109 kB
49
+ ├ λ /api/graphql 0 B 77.8 kB
50
+ ├ λ /api/preview 0 B 77.8 kB
51
+ /checkout 659 B 109 kB
52
+ /login 870 B 110 kB
53
+ /s 2.77 kB 121 kB
54
+ └ css/57c1885d16efdc73.css 2.48 kB
55
+ + First Load JS shared by all 100 kB
44
56
  ├ chunks/framework-dfd14d7ce6600b03.js 45.3 kB
45
- ├ chunks/main-9746772201fe3ac1.js 23.9 kB
46
- ├ chunks/pages/_app-4aeb21d72aeea9b7.js 25.5 kB
47
- ├ chunks/webpack-f725b61675603493.js 2.15 kB
48
- └ css/502746c995f64cce.css 23.6 kB
57
+ ├ chunks/main-bf297268d707456d.js 23.9 kB
58
+ ├ chunks/pages/_app-3cf84159cce4c8ef.js 6.41 kB
59
+ ├ chunks/webpack-e105e23dccb05796.js 2.2 kB
60
+ └ css/4e34a56a38b0d9d5.css 22.5 kB
49
61
 
50
62
  λ (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps)
51
63
  ○ (Static) automatically rendered as static HTML (uses no initial props)
package/CHANGELOG.md CHANGED
@@ -3,6 +3,16 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [2.0.120-alpha.0](https://github.com/vtex/faststore/compare/v2.0.119-alpha.0...v2.0.120-alpha.0) (2023-04-27)
7
+
8
+ ### Features
9
+
10
+ - Integrates Global Sections, with Alert component ([#1722](https://github.com/vtex/faststore/issues/1722)) ([da38b2a](https://github.com/vtex/faststore/commit/da38b2af3db5bd6abd57707d11d67d7463d5fa12))
11
+
12
+ ## [2.0.118-alpha.0](https://github.com/vtex/faststore/compare/v2.0.117-alpha.0...v2.0.118-alpha.0) (2023-04-26)
13
+
14
+ **Note:** Version bump only for package @faststore/core
15
+
6
16
  ## [2.0.117-alpha.0](https://github.com/vtex/faststore/compare/v2.0.116-alpha.0...v2.0.117-alpha.0) (2023-04-26)
7
17
 
8
18
  ### Features
@@ -4,6 +4,12 @@
4
4
  "name": "Global Alert Page",
5
5
  "configurationSchemaSets": []
6
6
  },
7
+ {
8
+ "id": "globalSections",
9
+ "name": "Global Sections",
10
+ "configurationSchemaSets": [],
11
+ "isSingleton": true
12
+ },
7
13
  {
8
14
  "id": "page",
9
15
  "name": "Page",
@@ -990,6 +990,14 @@
990
990
  }
991
991
  }
992
992
  },
993
+ {
994
+ "name": "Children",
995
+ "schema": {
996
+ "title": "Children",
997
+ "type": "object",
998
+ "properties": {}
999
+ }
1000
+ },
993
1001
  {
994
1002
  "name": "BannerNewsletter",
995
1003
  "schema": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/core",
3
- "version": "2.0.117-alpha.0",
3
+ "version": "2.0.120-alpha.0",
4
4
  "license": "MIT",
5
5
  "browserslist": "supports es6-module and not dead",
6
6
  "scripts": {
@@ -29,7 +29,7 @@
29
29
  "@envelop/graphql-jit": "^1.1.1",
30
30
  "@envelop/parser-cache": "^2.2.0",
31
31
  "@envelop/validation-cache": "^2.2.0",
32
- "@faststore/api": "^2.0.105-alpha.0",
32
+ "@faststore/api": "^2.0.118-alpha.0",
33
33
  "@faststore/components": "^2.0.117-alpha.0",
34
34
  "@faststore/graphql-utils": "^2.0.3-alpha.0",
35
35
  "@faststore/sdk": "^2.0.3-alpha.0",
@@ -108,5 +108,5 @@
108
108
  "msw": {
109
109
  "workerDirectory": "public"
110
110
  },
111
- "gitHead": "0d97039ebb2acb1c000ca9a4c914c2388a4cd49e"
111
+ "gitHead": "7c7da070b4a307b9c158fef70b22234831a97756"
112
112
  }
package/src/Layout.tsx CHANGED
@@ -1,12 +1,7 @@
1
1
  import type { PropsWithChildren } from 'react'
2
2
  import { lazy, Suspense } from 'react'
3
3
 
4
- import { Icon, useUI } from '@faststore/ui'
5
- import Alert from 'src/components/common/Alert'
6
- import Footer from 'src/components/common/Footer'
7
- import Navbar from 'src/components/navigation/Navbar'
8
- import Toast from 'src/components/common/Toast'
9
- import RegionBar from 'src/components/region/RegionBar'
4
+ import { useUI } from '@faststore/ui'
10
5
 
11
6
  const CartSidebar = lazy(() => import('src/components/cart/CartSidebar'))
12
7
  const RegionModal = lazy(() => import('src/components/region/RegionModal'))
@@ -16,24 +11,7 @@ function Layout({ children }: PropsWithChildren) {
16
11
 
17
12
  return (
18
13
  <>
19
- <Alert
20
- icon={<Icon name="Bell" />}
21
- link={{ children: 'Buy now', href: '/office', target: '_self' }}
22
- dismissible
23
- >
24
- Get 10% off today:&nbsp;<span>NEW10</span>
25
- </Alert>
26
-
27
- <Navbar />
28
-
29
- <Toast />
30
-
31
- <main>
32
- <RegionBar className="display-mobile" />
33
- {children}
34
- </main>
35
-
36
- <Footer />
14
+ {children}
37
15
 
38
16
  {displayCart && (
39
17
  <Suspense fallback={null}>
@@ -0,0 +1,81 @@
1
+ import { PropsWithChildren, useMemo } from 'react'
2
+
3
+ import { Locator, Section } from '@vtex/client-cms'
4
+ import { PageContentType, getPage } from 'src/server/cms'
5
+ import CUSTOM_COMPONENTS from 'src/customizations/components'
6
+ import type { ComponentType } from 'react'
7
+
8
+ import RenderSections from './RenderSections'
9
+ import { RegionBar } from '@faststore/components'
10
+ import Alert from 'src/components/sections/Alert/Alert'
11
+ import Navbar from 'src/components/navigation/Navbar'
12
+ import Footer from 'src/components/common/Footer'
13
+ import Toast from 'src/components/common/Toast'
14
+
15
+ // TODO: When the CMS is finished, switch to using 'globalSections'.
16
+ export const GLOBAL_SECTIONS_CONTENT_TYPE = 'globalAlert'
17
+
18
+ export type GlobalSectionsData = {
19
+ sections: Section[]
20
+ }
21
+
22
+ /* A list of components that can be used in the CMS. */
23
+ const COMPONENTS: Record<string, ComponentType<any>> = {
24
+ Alert,
25
+ ...CUSTOM_COMPONENTS,
26
+ }
27
+
28
+ const useDividedSections = (sections: Section[]) => {
29
+ return useMemo(() => {
30
+ const indexChildren = sections.findIndex(({ name }) => name === 'Children')
31
+ const hasChildren = indexChildren > -1
32
+
33
+ return {
34
+ hasChildren,
35
+ firstSections: hasChildren ? sections.slice(0, indexChildren) : sections,
36
+ ...(hasChildren && { lastSections: sections.slice(indexChildren + 1) }),
37
+ }
38
+ }, [sections])
39
+ }
40
+
41
+ function GlobalSections({
42
+ children,
43
+ sections,
44
+ }: PropsWithChildren<GlobalSectionsData>) {
45
+ const { hasChildren, firstSections, lastSections } =
46
+ useDividedSections(sections)
47
+
48
+ return (
49
+ <>
50
+ <RenderSections sections={firstSections} components={COMPONENTS} />
51
+ <Navbar />
52
+
53
+ <Toast />
54
+
55
+ <main>
56
+ <RegionBar className="display-mobile" />
57
+ {children}
58
+ </main>
59
+
60
+ <Footer />
61
+ {hasChildren && (
62
+ <RenderSections sections={lastSections} components={COMPONENTS} />
63
+ )}
64
+ </>
65
+ )
66
+ }
67
+
68
+ export default GlobalSections
69
+
70
+ export const getGlobalSectionsData = async (
71
+ previewData: Locator
72
+ ): Promise<GlobalSectionsData> => {
73
+ const { sections } = await getPage<PageContentType>({
74
+ ...(previewData?.contentType === GLOBAL_SECTIONS_CONTENT_TYPE
75
+ ? previewData
76
+ : { filters: { 'settings.seo.slug': '/' } }),
77
+ contentType: GLOBAL_SECTIONS_CONTENT_TYPE,
78
+ })
79
+
80
+ return { sections }
81
+ }
@@ -0,0 +1,39 @@
1
+ import chalk from 'chalk'
2
+ import { ComponentType, PropsWithChildren, ReactNode, useMemo } from 'react'
3
+
4
+ import SectionBoundary from './SectionBoundary'
5
+
6
+ interface Props {
7
+ components: Record<string, ComponentType<any>>
8
+ sections: Array<{ name: string; data: any }>
9
+ context?: unknown
10
+ }
11
+
12
+ const RenderSections = ({ sections = [], context, components }: Props) => {
13
+ return (
14
+ <>
15
+ {sections.map(({ name, data }, index) => {
16
+ const Component = components[name]
17
+
18
+ if (!Component) {
19
+ // TODO: add a documentation link to help to do this
20
+ console.info(
21
+ `${chalk.yellow(
22
+ 'warn'
23
+ )} - ${name} not found. Add a new component for this section or remove it from the CMS`
24
+ )
25
+
26
+ return null
27
+ }
28
+
29
+ return (
30
+ <SectionBoundary key={`cms-section-${index}`} name={name}>
31
+ <Component {...data} context={context} />
32
+ </SectionBoundary>
33
+ )
34
+ })}
35
+ </>
36
+ )
37
+ }
38
+
39
+ export default RenderSections
@@ -1,17 +1,21 @@
1
1
  import type { PropsWithChildren, ReactNode } from 'react'
2
2
  import { useCallback, useState } from 'react'
3
3
 
4
- import { Alert as UIAlert, AlertProps } from '@faststore/ui'
4
+ import { Alert as UIAlert, AlertProps as UIAlertProps } from '@faststore/ui'
5
5
  import { mark } from 'src/sdk/tests/mark'
6
6
 
7
- interface Props extends AlertProps {
7
+ export interface AlertProps extends UIAlertProps {
8
8
  /**
9
9
  * For CMS integration purposes, should be used to pass content through it
10
10
  * instead pass through children
11
11
  */
12
12
  content?: ReactNode
13
13
  }
14
- function Alert(args: PropsWithChildren<Props>) {
14
+ function Alert({
15
+ content,
16
+ children,
17
+ ...otherProps
18
+ }: PropsWithChildren<AlertProps>) {
15
19
  const [displayAlert, setDisplayAlert] = useState(true)
16
20
 
17
21
  const onAlertClose = useCallback(
@@ -23,8 +27,6 @@ function Alert(args: PropsWithChildren<Props>) {
23
27
  return null
24
28
  }
25
29
 
26
- const { content, children, ...otherProps } = args
27
-
28
30
  return (
29
31
  <UIAlert onClose={onAlertClose} {...otherProps}>
30
32
  {content ?? children}
@@ -1 +1,2 @@
1
1
  export { default } from './Alert'
2
+ export type { AlertProps } from './Alert'
@@ -0,0 +1,28 @@
1
+ import { Icon as UIIcon } from '@faststore/ui'
2
+ import Section from '../Section'
3
+ import UIAlert from 'src/components/common/Alert'
4
+
5
+ export interface AlertProps {
6
+ icon: string
7
+ content: string
8
+ link: {
9
+ text: string
10
+ to: string
11
+ }
12
+ dismissible: boolean
13
+ }
14
+
15
+ // TODO: Change actionPath and actionLabel with Link
16
+ function Alert({ icon, content, link, dismissible }: AlertProps) {
17
+ return (
18
+ <UIAlert
19
+ icon={<UIIcon name={icon} />}
20
+ link={{ children: link?.text, href: link?.to, target: '_self' }}
21
+ dismissible={dismissible}
22
+ >
23
+ {content}
24
+ </UIAlert>
25
+ )
26
+ }
27
+
28
+ export default Alert
package/src/pages/404.tsx CHANGED
@@ -1,6 +1,12 @@
1
1
  import { NextSeo } from 'next-seo'
2
2
  import { useRouter } from 'next/router'
3
3
  import { EmptyState as UIEmptyState, Icon as UIIcon } from '@faststore/ui'
4
+ import GlobalSections, {
5
+ GlobalSectionsData,
6
+ getGlobalSectionsData,
7
+ } from 'src/components/cms/GlobalSections'
8
+ import { GetStaticProps } from 'next'
9
+ import { Locator } from '@vtex/client-cms'
4
10
 
5
11
  const useErrorState = () => {
6
12
  const router = useRouter()
@@ -12,11 +18,15 @@ const useErrorState = () => {
12
18
  }
13
19
  }
14
20
 
15
- function Page() {
21
+ type Props = {
22
+ globalSections: GlobalSectionsData
23
+ }
24
+
25
+ function Page({ globalSections }: Props) {
16
26
  const { fromUrl } = useErrorState()
17
27
 
18
28
  return (
19
- <>
29
+ <GlobalSections {...globalSections}>
20
30
  <NextSeo noindex nofollow />
21
31
 
22
32
  <UIEmptyState
@@ -33,8 +43,20 @@ function Page() {
33
43
  >
34
44
  <p>This app could not find url {fromUrl}</p>
35
45
  </UIEmptyState>
36
- </>
46
+ </GlobalSections>
37
47
  )
38
48
  }
39
49
 
50
+ export const getStaticProps: GetStaticProps<
51
+ Props,
52
+ Record<string, string>,
53
+ Locator
54
+ > = async ({ previewData }) => {
55
+ const globalSections = await getGlobalSectionsData(previewData)
56
+
57
+ return {
58
+ props: { globalSections },
59
+ }
60
+ }
61
+
40
62
  export default Page
package/src/pages/500.tsx CHANGED
@@ -1,5 +1,15 @@
1
+ import { Locator } from '@vtex/client-cms'
2
+ import { GetStaticProps } from 'next'
1
3
  import { NextSeo } from 'next-seo'
2
4
  import { useRouter } from 'next/router'
5
+ import GlobalSections, {
6
+ GlobalSectionsData,
7
+ getGlobalSectionsData,
8
+ } from 'src/components/cms/GlobalSections'
9
+
10
+ type Props = {
11
+ globalSections: GlobalSectionsData
12
+ }
3
13
 
4
14
  const useErrorState = () => {
5
15
  const router = useRouter()
@@ -11,11 +21,11 @@ const useErrorState = () => {
11
21
  }
12
22
  }
13
23
 
14
- function Page() {
24
+ function Page({ globalSections }: Props) {
15
25
  const { errorId, fromUrl } = useErrorState()
16
26
 
17
27
  return (
18
- <>
28
+ <GlobalSections {...globalSections}>
19
29
  <NextSeo noindex nofollow />
20
30
 
21
31
  <h1>500</h1>
@@ -24,8 +34,20 @@ function Page() {
24
34
  <div>
25
35
  The server errored with id {errorId} when visiting page {fromUrl}
26
36
  </div>
27
- </>
37
+ </GlobalSections>
28
38
  )
29
39
  }
30
40
 
41
+ export const getStaticProps: GetStaticProps<
42
+ Props,
43
+ Record<string, string>,
44
+ Locator
45
+ > = async ({ previewData }) => {
46
+ const globalSections = await getGlobalSectionsData(previewData)
47
+
48
+ return {
49
+ props: { globalSections },
50
+ }
51
+ }
52
+
31
53
  export default Page
@@ -27,10 +27,19 @@ import { mark } from 'src/sdk/tests/mark'
27
27
  import { execute } from 'src/server'
28
28
 
29
29
  import storeConfig from '../../faststore.config'
30
+ import GlobalSections, {
31
+ getGlobalSectionsData,
32
+ GlobalSectionsData,
33
+ } from 'src/components/cms/GlobalSections'
34
+ import { Locator } from '@vtex/client-cms'
35
+
36
+ type Props = ServerCollectionPageQueryQuery & {
37
+ globalSections: GlobalSectionsData
38
+ }
30
39
 
31
- type Props = ServerCollectionPageQueryQuery
32
-
33
- const useSearchParams = ({ collection }: Props): SearchState => {
40
+ const useSearchParams = ({
41
+ collection,
42
+ }: ServerCollectionPageQueryQuery): SearchState => {
34
43
  const selectedFacets = collection?.meta.selectedFacets
35
44
  const { asPath } = useRouter()
36
45
 
@@ -48,7 +57,7 @@ const useSearchParams = ({ collection }: Props): SearchState => {
48
57
  return useMemo(() => parseSearchState(new URL(hrefState)), [hrefState])
49
58
  }
50
59
 
51
- function Page(props: Props) {
60
+ function Page({ globalSections, ...props }: Props) {
52
61
  const { collection } = props
53
62
  const router = useRouter()
54
63
  const applySearchState = useApplySearchState()
@@ -62,64 +71,66 @@ function Page(props: Props) {
62
71
  const canonical = `${storeConfig.storeUrl}${pathname}${pageQuery}`
63
72
 
64
73
  return (
65
- <SearchProvider
66
- onChange={applySearchState}
67
- itemsPerPage={ITEMS_PER_PAGE}
68
- {...searchParams}
69
- >
70
- {/* SEO */}
71
- <NextSeo
72
- title={title}
73
- description={description}
74
- titleTemplate={storeConfig.seo.titleTemplate}
75
- canonical={canonical}
76
- openGraph={{
77
- type: 'website',
78
- title,
79
- description,
80
- }}
81
- />
82
- <BreadcrumbJsonLd
83
- itemListElements={collection?.breadcrumbList.itemListElement ?? []}
84
- />
85
-
86
- {/*
87
- WARNING: Do not import or render components from any
88
- other folder than '../components/sections' in here.
89
-
90
- This is necessary to keep the integration with the CMS
91
- easy and consistent, enabling the change and reorder
92
- of elements on this page.
93
-
94
- If needed, wrap your component in a <Section /> component
95
- (not the HTML tag) before rendering it here.
96
- */}
97
- <Breadcrumb
98
- breadcrumbList={collection?.breadcrumbList.itemListElement}
99
- name={title}
100
- />
101
-
102
- <Hero
103
- variant="secondary"
104
- title={title}
105
- subtitle={`All the amazing ${title} from the brands we partner with.`}
106
- image={{
107
- src: 'https://storeframework.vtexassets.com/arquivos/ids/190897/Photo.jpg',
108
- alt: 'Quest 2 Controller on a table',
109
- }}
110
- />
111
-
112
- <ProductGallery title={title} />
113
-
114
- <ProductShelf
115
- first={ITEMS_PER_SECTION}
116
- sort="score_desc"
117
- title="You might also like"
118
- withDivisor
119
- />
120
-
121
- <ScrollToTopButton />
122
- </SearchProvider>
74
+ <GlobalSections {...globalSections}>
75
+ <SearchProvider
76
+ onChange={applySearchState}
77
+ itemsPerPage={ITEMS_PER_PAGE}
78
+ {...searchParams}
79
+ >
80
+ {/* SEO */}
81
+ <NextSeo
82
+ title={title}
83
+ description={description}
84
+ titleTemplate={storeConfig.seo.titleTemplate}
85
+ canonical={canonical}
86
+ openGraph={{
87
+ type: 'website',
88
+ title,
89
+ description,
90
+ }}
91
+ />
92
+ <BreadcrumbJsonLd
93
+ itemListElements={collection?.breadcrumbList.itemListElement ?? []}
94
+ />
95
+
96
+ {/*
97
+ WARNING: Do not import or render components from any
98
+ other folder than '../components/sections' in here.
99
+
100
+ This is necessary to keep the integration with the CMS
101
+ easy and consistent, enabling the change and reorder
102
+ of elements on this page.
103
+
104
+ If needed, wrap your component in a <Section /> component
105
+ (not the HTML tag) before rendering it here.
106
+ */}
107
+ <Breadcrumb
108
+ breadcrumbList={collection?.breadcrumbList.itemListElement}
109
+ name={title}
110
+ />
111
+
112
+ <Hero
113
+ variant="secondary"
114
+ title={title}
115
+ subtitle={`All the amazing ${title} from the brands we partner with.`}
116
+ image={{
117
+ src: 'https://storeframework.vtexassets.com/arquivos/ids/190897/Photo.jpg',
118
+ alt: 'Quest 2 Controller on a table',
119
+ }}
120
+ />
121
+
122
+ <ProductGallery title={title} />
123
+
124
+ <ProductShelf
125
+ first={ITEMS_PER_SECTION}
126
+ sort="score_desc"
127
+ title="You might also like"
128
+ withDivisor
129
+ />
130
+
131
+ <ScrollToTopButton />
132
+ </SearchProvider>
133
+ </GlobalSections>
123
134
  )
124
135
  }
125
136
 
@@ -148,9 +159,12 @@ const query = gql`
148
159
  `
149
160
 
150
161
  export const getStaticProps: GetStaticProps<
151
- ServerCollectionPageQueryQuery,
152
- { slug: string[] }
153
- > = async ({ params }) => {
162
+ Props,
163
+ { slug: string[] },
164
+ Locator
165
+ > = async (context) => {
166
+ const { params } = context
167
+
154
168
  const { data, errors = [] } = await execute<
155
169
  ServerCollectionPageQueryQueryVariables,
156
170
  ServerCollectionPageQueryQuery
@@ -171,8 +185,13 @@ export const getStaticProps: GetStaticProps<
171
185
  throw errors[0]
172
186
  }
173
187
 
188
+ const globalSections = await getGlobalSectionsData(context.previewData)
189
+
174
190
  return {
175
- props: data,
191
+ props: {
192
+ ...data,
193
+ globalSections,
194
+ },
176
195
  }
177
196
  }
178
197