@faststore/core 2.0.118-alpha.0 → 2.0.121-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 (164) hide show
  1. package/.turbo/turbo-build.log +37 -25
  2. package/@generated/graphql/index.ts +22 -2
  3. package/@generated/graphql/persisted.json +1 -1
  4. package/CHANGELOG.md +10 -0
  5. package/cms/faststore/content-types.json +6 -0
  6. package/cms/faststore/sections.json +8 -0
  7. package/faststore.config.js +1 -0
  8. package/package.json +3 -3
  9. package/src/Layout.tsx +2 -24
  10. package/src/components/cms/GlobalSections.tsx +81 -0
  11. package/src/components/cms/RenderSections.tsx +39 -0
  12. package/src/components/common/Alert/Alert.tsx +7 -5
  13. package/src/components/common/Alert/index.ts +1 -0
  14. package/src/components/sections/Alert/Alert.tsx +28 -0
  15. package/src/pages/404.tsx +25 -3
  16. package/src/pages/500.tsx +25 -3
  17. package/src/pages/[...slug].tsx +85 -66
  18. package/src/pages/[slug]/p.tsx +16 -6
  19. package/src/pages/account.tsx +25 -3
  20. package/src/pages/checkout.tsx +25 -3
  21. package/src/pages/index.tsx +20 -10
  22. package/src/pages/login.tsx +25 -3
  23. package/src/pages/s.tsx +63 -39
  24. package/src/sdk/session/index.ts +4 -0
  25. package/.next/BUILD_ID +0 -1
  26. package/.next/build-manifest.json +0 -99
  27. package/.next/cache/.tsbuildinfo +0 -1
  28. package/.next/cache/config.json +0 -7
  29. package/.next/cache/eslint/.cache_1gneedd +0 -1
  30. package/.next/cache/next-server.js.nft.json +0 -1
  31. package/.next/cache/webpack/client-production/0.pack +0 -0
  32. package/.next/cache/webpack/client-production/index.pack +0 -0
  33. package/.next/cache/webpack/server-production/0.pack +0 -0
  34. package/.next/cache/webpack/server-production/index.pack +0 -0
  35. package/.next/export-marker.json +0 -1
  36. package/.next/images-manifest.json +0 -1
  37. package/.next/next-server.js.nft.json +0 -1
  38. package/.next/package.json +0 -1
  39. package/.next/prerender-manifest.json +0 -1
  40. package/.next/react-loadable-manifest.json +0 -42
  41. package/.next/required-server-files.json +0 -1
  42. package/.next/routes-manifest.json +0 -1
  43. package/.next/server/chunks/120.js +0 -435
  44. package/.next/server/chunks/123.js +0 -58
  45. package/.next/server/chunks/1394.js +0 -3801
  46. package/.next/server/chunks/1597.js +0 -151
  47. package/.next/server/chunks/1608.js +0 -515
  48. package/.next/server/chunks/2154.js +0 -206
  49. package/.next/server/chunks/247.js +0 -61
  50. package/.next/server/chunks/2502.js +0 -584
  51. package/.next/server/chunks/2914.js +0 -95
  52. package/.next/server/chunks/2922.js +0 -7293
  53. package/.next/server/chunks/3264.js +0 -67
  54. package/.next/server/chunks/3431.js +0 -7241
  55. package/.next/server/chunks/350.js +0 -142
  56. package/.next/server/chunks/3746.js +0 -250
  57. package/.next/server/chunks/3898.js +0 -240
  58. package/.next/server/chunks/4312.js +0 -674
  59. package/.next/server/chunks/4371.js +0 -1424
  60. package/.next/server/chunks/5098.js +0 -124
  61. package/.next/server/chunks/5335.js +0 -544
  62. package/.next/server/chunks/5576.js +0 -79
  63. package/.next/server/chunks/6280.js +0 -322
  64. package/.next/server/chunks/6465.js +0 -91
  65. package/.next/server/chunks/676.js +0 -32
  66. package/.next/server/chunks/6859.js +0 -959
  67. package/.next/server/chunks/6881.js +0 -320
  68. package/.next/server/chunks/6898.js +0 -149
  69. package/.next/server/chunks/7104.js +0 -235
  70. package/.next/server/chunks/7181.js +0 -664
  71. package/.next/server/chunks/7183.js +0 -79
  72. package/.next/server/chunks/8098.js +0 -246
  73. package/.next/server/chunks/810.js +0 -432
  74. package/.next/server/chunks/8287.js +0 -58
  75. package/.next/server/chunks/9143.js +0 -106
  76. package/.next/server/chunks/9557.js +0 -119
  77. package/.next/server/chunks/9854.js +0 -72
  78. package/.next/server/chunks/font-manifest.json +0 -1
  79. package/.next/server/font-manifest.json +0 -1
  80. package/.next/server/middleware-build-manifest.js +0 -1
  81. package/.next/server/middleware-manifest.json +0 -6
  82. package/.next/server/middleware-react-loadable-manifest.js +0 -1
  83. package/.next/server/pages/404.js.nft.json +0 -1
  84. package/.next/server/pages/500.js.nft.json +0 -1
  85. package/.next/server/pages/[...slug].js +0 -666
  86. package/.next/server/pages/[...slug].js.nft.json +0 -1
  87. package/.next/server/pages/[slug]/p.js +0 -2327
  88. package/.next/server/pages/[slug]/p.js.nft.json +0 -1
  89. package/.next/server/pages/_app.js +0 -2454
  90. package/.next/server/pages/_app.js.nft.json +0 -1
  91. package/.next/server/pages/_document.js +0 -304
  92. package/.next/server/pages/_document.js.nft.json +0 -1
  93. package/.next/server/pages/_error.js +0 -164
  94. package/.next/server/pages/_error.js.nft.json +0 -1
  95. package/.next/server/pages/account.js.nft.json +0 -1
  96. package/.next/server/pages/api/graphql.js +0 -315
  97. package/.next/server/pages/api/graphql.js.nft.json +0 -1
  98. package/.next/server/pages/api/preview.js +0 -118
  99. package/.next/server/pages/api/preview.js.nft.json +0 -1
  100. package/.next/server/pages/checkout.js.nft.json +0 -1
  101. package/.next/server/pages/en-US/404.html +0 -81
  102. package/.next/server/pages/en-US/500.html +0 -81
  103. package/.next/server/pages/en-US/account.html +0 -81
  104. package/.next/server/pages/en-US/checkout.html +0 -81
  105. package/.next/server/pages/en-US/login.html +0 -81
  106. package/.next/server/pages/en-US/s.html +0 -81
  107. package/.next/server/pages/en-US.html +0 -81
  108. package/.next/server/pages/en-US.json +0 -1
  109. package/.next/server/pages/index.js +0 -475
  110. package/.next/server/pages/index.js.nft.json +0 -1
  111. package/.next/server/pages/login.js.nft.json +0 -1
  112. package/.next/server/pages/s.js.nft.json +0 -1
  113. package/.next/server/pages-manifest.json +0 -16
  114. package/.next/server/webpack-api-runtime.js +0 -229
  115. package/.next/server/webpack-runtime.js +0 -229
  116. package/.next/static/chunks/143.dd8a556e6957baa1.js +0 -1
  117. package/.next/static/chunks/170.79b2f8527e327bca.js +0 -1
  118. package/.next/static/chunks/264-5b07911df63b8601.js +0 -1
  119. package/.next/static/chunks/351-a4e28d64f48c5269.js +0 -1
  120. package/.next/static/chunks/54.e6562383f8a1dfe7.js +0 -1
  121. package/.next/static/chunks/597.fc79494903e8bb84.js +0 -1
  122. package/.next/static/chunks/608.59e69b83f35d9c44.js +0 -1
  123. package/.next/static/chunks/651.7142f31ce1e052b3.js +0 -1
  124. package/.next/static/chunks/741.52f7fb873418346f.js +0 -1
  125. package/.next/static/chunks/781-e1b538e051ff4c3e.js +0 -1
  126. package/.next/static/chunks/98.97381d2021f86cd9.js +0 -1
  127. package/.next/static/chunks/996.98e590872c51f815.js +0 -1
  128. package/.next/static/chunks/framework-dfd14d7ce6600b03.js +0 -1
  129. package/.next/static/chunks/main-9746772201fe3ac1.js +0 -1
  130. package/.next/static/chunks/pages/404-3637ef83b3359df7.js +0 -1
  131. package/.next/static/chunks/pages/500-910883c20541d9ce.js +0 -1
  132. package/.next/static/chunks/pages/[...slug]-29d3b81ee0953846.js +0 -1
  133. package/.next/static/chunks/pages/[slug]/p-9b24055cb30ee7a8.js +0 -1
  134. package/.next/static/chunks/pages/_app-4aeb21d72aeea9b7.js +0 -1
  135. package/.next/static/chunks/pages/_error-a7a0c1d9bfbb4f38.js +0 -1
  136. package/.next/static/chunks/pages/account-b8fc5222ffe89b60.js +0 -1
  137. package/.next/static/chunks/pages/checkout-f8cb7cb22225ef9d.js +0 -1
  138. package/.next/static/chunks/pages/index-d48285f48d2a66ea.js +0 -1
  139. package/.next/static/chunks/pages/login-45cc84352bac2408.js +0 -1
  140. package/.next/static/chunks/pages/s-ba2868e14fedb65b.js +0 -1
  141. package/.next/static/chunks/polyfills-c67a75d1b6f99dc8.js +0 -1
  142. package/.next/static/chunks/webpack-f725b61675603493.js +0 -1
  143. package/.next/static/css/1f987650dd4e39d0.css +0 -1
  144. package/.next/static/css/3a57acf6e411f24d.css +0 -1
  145. package/.next/static/css/4abccf9803c3c356.css +0 -1
  146. package/.next/static/css/502746c995f64cce.css +0 -1
  147. package/.next/static/css/6507cb48401e73a4.css +0 -1
  148. package/.next/static/css/6f4d3e91f1d161a8.css +0 -1
  149. package/.next/static/media/brandless-neutral.76ddf63a.png +0 -0
  150. package/.next/static/vmkgl19jDr5XASw3dFJg7/_buildManifest.js +0 -1
  151. package/.next/static/vmkgl19jDr5XASw3dFJg7/_ssgManifest.js +0 -1
  152. package/.next/trace +0 -64
  153. package/public/~partytown/debug/partytown-atomics.js +0 -556
  154. package/public/~partytown/debug/partytown-media.js +0 -374
  155. package/public/~partytown/debug/partytown-sandbox-sw.js +0 -543
  156. package/public/~partytown/debug/partytown-sw.js +0 -59
  157. package/public/~partytown/debug/partytown-ww-atomics.js +0 -1789
  158. package/public/~partytown/debug/partytown-ww-sw.js +0 -1781
  159. package/public/~partytown/debug/partytown.js +0 -72
  160. package/public/~partytown/partytown-atomics.js +0 -2
  161. package/public/~partytown/partytown-media.js +0 -2
  162. package/public/~partytown/partytown-sw.js +0 -2
  163. package/public/~partytown/partytown.js +0 -2
  164. 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 131 kB
45
+ ├ └ css/384a7a015bca80d6.css 3.01 kB
46
+ ├ ○ /404 950 B 110 kB
47
+ /500 718 B 110 kB
48
+ /account 671 B 110 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 869 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
57
  ├ 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
58
+ ├ chunks/pages/_app-c3a2ae2beed7c7e5.js 6.43 kB
59
+ ├ chunks/webpack-4b9a36060b4c8160.js 2.22 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)
@@ -91,6 +91,13 @@ export type IStoreCurrency = {
91
91
  symbol: Scalars['String']
92
92
  }
93
93
 
94
+ export type IStoreGeoCoordinates = {
95
+ /** The latitude of the geographic coordinates. */
96
+ latitude: Scalars['Float']
97
+ /** The longitude of the geographic coordinates. */
98
+ longitude: Scalars['Float']
99
+ }
100
+
94
101
  /** Image input. */
95
102
  export type IStoreImage = {
96
103
  /** Alias for the input image. */
@@ -180,9 +187,11 @@ export type IStoreSession = {
180
187
  country: Scalars['String']
181
188
  /** Session input currency. */
182
189
  currency: IStoreCurrency
190
+ /** Session input geoCoordinates. */
191
+ geoCoordinates: InputMaybe<IStoreGeoCoordinates>
183
192
  /** Session input locale. */
184
193
  locale: Scalars['String']
185
- /** Session input postal code. */
194
+ /** Session input person. */
186
195
  person: InputMaybe<IStorePerson>
187
196
  /** Session input postal code. */
188
197
  postalCode: InputMaybe<Scalars['String']>
@@ -628,6 +637,14 @@ export type StoreFacetValueRange = {
628
637
  selected: Scalars['Float']
629
638
  }
630
639
 
640
+ /** Geographic coordinates information. */
641
+ export type StoreGeoCoordinates = {
642
+ /** The latitude of the geographic coordinates. */
643
+ latitude: Scalars['Float']
644
+ /** The longitude of the geographic coordinates. */
645
+ longitude: Scalars['Float']
646
+ }
647
+
631
648
  /** Image. */
632
649
  export type StoreImage = {
633
650
  /** Alias for the image. */
@@ -840,9 +857,11 @@ export type StoreSession = {
840
857
  country: Scalars['String']
841
858
  /** Session currency. */
842
859
  currency: StoreCurrency
860
+ /** Session input geoCoordinates. */
861
+ geoCoordinates: Maybe<StoreGeoCoordinates>
843
862
  /** Session locale. */
844
863
  locale: Scalars['String']
845
- /** Session postal code. */
864
+ /** Session input person. */
846
865
  person: Maybe<StorePerson>
847
866
  /** Session postal code. */
848
867
  postalCode: Maybe<Scalars['String']>
@@ -1304,6 +1323,7 @@ export type ValidateSessionMutation = {
1304
1323
  channel: string | null
1305
1324
  country: string
1306
1325
  postalCode: string | null
1326
+ geoCoordinates: { latitude: number; longitude: number } | null
1307
1327
  currency: { code: string; symbol: string }
1308
1328
  person: {
1309
1329
  id: string
@@ -8,6 +8,6 @@
8
8
  "ProductsQuery": "query ProductsQuery($first: Int!, $after: String, $sort: StoreSort!, $term: String!, $selectedFacets: [IStoreSelectedFacet!]!) {\n search(\n first: $first\n after: $after\n sort: $sort\n term: $term\n selectedFacets: $selectedFacets\n ) {\n products {\n pageInfo {\n totalCount\n }\n edges {\n node {\n id: productID\n slug\n sku\n brand {\n brandName: name\n name\n }\n name\n gtin\n isVariantOf {\n productGroupID\n name\n }\n image {\n url\n alternateName\n }\n offers {\n lowPrice\n offers {\n availability\n price\n listPrice\n quantity\n seller {\n identifier\n }\n }\n }\n }\n }\n }\n }\n}\n",
9
9
  "SearchSuggestionsQuery": "query SearchSuggestionsQuery($term: String!, $selectedFacets: [IStoreSelectedFacet!]) {\n search(first: 5, term: $term, selectedFacets: $selectedFacets) {\n suggestions {\n terms {\n value\n }\n products {\n id: productID\n slug\n sku\n brand {\n brandName: name\n name\n }\n name\n gtin\n isVariantOf {\n productGroupID\n name\n }\n image {\n url\n alternateName\n }\n offers {\n lowPrice\n offers {\n availability\n price\n listPrice\n quantity\n seller {\n identifier\n }\n }\n }\n }\n }\n }\n}\n",
10
10
  "TopSearchSuggestionsQuery": "query TopSearchSuggestionsQuery($term: String!, $selectedFacets: [IStoreSelectedFacet!]) {\n search(first: 5, term: $term, selectedFacets: $selectedFacets) {\n suggestions {\n terms {\n value\n }\n }\n }\n}\n",
11
- "ValidateSession": "mutation ValidateSession($session: IStoreSession!, $search: String!) {\n validateSession(session: $session, search: $search) {\n locale\n channel\n country\n postalCode\n currency {\n code\n symbol\n }\n person {\n id\n email\n givenName\n familyName\n }\n }\n}\n",
11
+ "ValidateSession": "mutation ValidateSession($session: IStoreSession!, $search: String!) {\n validateSession(session: $session, search: $search) {\n locale\n channel\n country\n postalCode\n geoCoordinates {\n latitude\n longitude\n }\n currency {\n code\n symbol\n }\n person {\n id\n email\n givenName\n familyName\n }\n }\n}\n",
12
12
  "ShippingSimulationQuery": "query ShippingSimulationQuery($postalCode: String!, $country: String!, $items: [IShippingItem!]!) {\n shipping(items: $items, postalCode: $postalCode, country: $country) {\n logisticsInfo {\n slas {\n carrier\n price\n shippingEstimate\n localizedEstimates\n }\n }\n address {\n city\n neighborhood\n }\n }\n}\n"
13
13
  }
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.121-alpha.0](https://github.com/vtex/faststore/compare/v2.0.120-alpha.0...v2.0.121-alpha.0) (2023-04-27)
7
+
8
+ **Note:** Version bump only for package @faststore/core
9
+
10
+ ## [2.0.120-alpha.0](https://github.com/vtex/faststore/compare/v2.0.119-alpha.0...v2.0.120-alpha.0) (2023-04-27)
11
+
12
+ ### Features
13
+
14
+ - Integrates Global Sections, with Alert component ([#1722](https://github.com/vtex/faststore/issues/1722)) ([da38b2a](https://github.com/vtex/faststore/commit/da38b2af3db5bd6abd57707d11d67d7463d5fa12))
15
+
6
16
  ## [2.0.118-alpha.0](https://github.com/vtex/faststore/compare/v2.0.117-alpha.0...v2.0.118-alpha.0) (2023-04-26)
7
17
 
8
18
  **Note:** Version bump only for package @faststore/core
@@ -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": {
@@ -30,6 +30,7 @@ module.exports = {
30
30
  channel: '{"salesChannel":"1","regionId":""}',
31
31
  country: 'USA',
32
32
  postalCode: null,
33
+ geoCoordinates: null,
33
34
  person: null,
34
35
  },
35
36
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/core",
3
- "version": "2.0.118-alpha.0",
3
+ "version": "2.0.121-alpha.0",
4
4
  "license": "MIT",
5
5
  "browserslist": "supports es6-module and not dead",
6
6
  "scripts": {
@@ -32,7 +32,7 @@
32
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
- "@faststore/sdk": "^2.0.3-alpha.0",
35
+ "@faststore/sdk": "^2.0.118-alpha.0",
36
36
  "@faststore/ui": "^2.0.117-alpha.0",
37
37
  "@types/react": "^18.0.14",
38
38
  "@vtex/client-cms": "^0.2.12",
@@ -108,5 +108,5 @@
108
108
  "msw": {
109
109
  "workerDirectory": "public"
110
110
  },
111
- "gitHead": "e39696d0990df21098a6249c50963690bb2104a2"
111
+ "gitHead": "2571f06b295c21d4046b26760852d7e87057d5e7"
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