@akinon/projectzero 2.0.152-rc.0 → 2.0.152-rc.2

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 (38) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/app-template/CHANGELOG.md +69 -0
  3. package/app-template/docs/plugins.md +6 -0
  4. package/app-template/next-env.d.ts +1 -1
  5. package/app-template/package.json +29 -29
  6. package/app-template/public/locales/en/common.json +5 -0
  7. package/app-template/public/locales/en/product.json +6 -0
  8. package/app-template/public/locales/tr/common.json +5 -0
  9. package/app-template/public/locales/tr/product.json +6 -0
  10. package/app-template/src/__tests__/data-source-landing-page.test.tsx +132 -0
  11. package/app-template/src/app/[pz]/[...prettyurl]/page.tsx +14 -0
  12. package/app-template/src/app/[pz]/account/orders/[id]/(detail)/page.tsx +21 -0
  13. package/app-template/src/app/[pz]/data-source-landing-page/[pk]/loading.tsx +5 -0
  14. package/app-template/src/app/[pz]/data-source-landing-page/[pk]/page.tsx +62 -0
  15. package/app-template/src/app/[pz]/product/[pk]/page.tsx +7 -1
  16. package/app-template/src/types/widgets.ts +58 -0
  17. package/app-template/src/utils/__tests__/sanitize.test.ts +127 -0
  18. package/app-template/src/utils/sanitize.ts +167 -0
  19. package/app-template/src/views/category/category-info.tsx +15 -9
  20. package/app-template/src/views/data-source-page/__tests__/header.test.tsx +173 -0
  21. package/app-template/src/views/data-source-page/__tests__/layout.test.tsx +83 -0
  22. package/app-template/src/views/data-source-page/__tests__/sections.test.tsx +143 -0
  23. package/app-template/src/views/data-source-page/banner.tsx +45 -0
  24. package/app-template/src/views/data-source-page/footer.tsx +27 -0
  25. package/app-template/src/views/data-source-page/header.tsx +140 -0
  26. package/app-template/src/views/data-source-page/layout.tsx +45 -0
  27. package/app-template/src/views/data-source-page/products.tsx +55 -0
  28. package/app-template/src/views/data-source-page/stories.tsx +70 -0
  29. package/app-template/src/views/product/__tests__/product-offers.test.tsx +217 -0
  30. package/app-template/src/views/product/index.ts +1 -0
  31. package/app-template/src/views/product/product-info.tsx +14 -0
  32. package/app-template/src/views/product/product-offers.tsx +125 -0
  33. package/app-template/src/views/product/rate-review.tsx +21 -0
  34. package/app-template/src/views/product-item/index.tsx +5 -0
  35. package/app-template/tsconfig.json +3 -0
  36. package/commands/plugins.ts +4 -0
  37. package/dist/commands/plugins.js +4 -0
  38. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @akinon/projectzero
2
2
 
3
+ ## 2.0.152-rc.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 9c778307: ZERO-5200: Show the other sellers of a product with their price and stock on the product detail page
8
+
9
+ ## 2.0.152-rc.1
10
+
11
+ ### Patch Changes
12
+
13
+ - 97d29893: ZERO-5220: add the pz-rate-review plugin for the Rate & Review extension
14
+
3
15
  ## 2.0.152-rc.0
4
16
 
5
17
  ### Patch Changes
@@ -1,5 +1,74 @@
1
1
  # projectzeronext
2
2
 
3
+ ## 2.0.152-rc.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 219164a3: ZERO-2301: Add data source landing page data fetcher for Seller Center store pages
8
+ - Updated dependencies [219164a3]
9
+ - Updated dependencies [9c778307]
10
+ - @akinon/next@2.0.152-rc.2
11
+ - @akinon/pz-theme@2.0.152-rc.2
12
+ - @akinon/pz-virtual-try-on@2.0.152-rc.2
13
+ - @akinon/pz-akifast@2.0.152-rc.2
14
+ - @akinon/pz-apple-pay@2.0.152-rc.2
15
+ - @akinon/pz-b2b@2.0.152-rc.2
16
+ - @akinon/pz-basket-gift-pack@2.0.152-rc.2
17
+ - @akinon/pz-bkm@2.0.152-rc.2
18
+ - @akinon/pz-checkout-gift-pack@2.0.152-rc.2
19
+ - @akinon/pz-click-collect@2.0.152-rc.2
20
+ - @akinon/pz-credit-payment@2.0.152-rc.2
21
+ - @akinon/pz-cybersource-uc@2.0.152-rc.2
22
+ - @akinon/pz-flow-payment@2.0.152-rc.2
23
+ - @akinon/pz-google-pay@2.0.152-rc.2
24
+ - @akinon/pz-gpay@2.0.152-rc.2
25
+ - @akinon/pz-haso@2.0.152-rc.2
26
+ - @akinon/pz-hepsipay@2.0.152-rc.2
27
+ - @akinon/pz-masterpass@2.0.152-rc.2
28
+ - @akinon/pz-masterpass-rest@2.0.152-rc.2
29
+ - @akinon/pz-multi-basket@2.0.152-rc.2
30
+ - @akinon/pz-one-click-checkout@2.0.152-rc.2
31
+ - @akinon/pz-otp@2.0.152-rc.2
32
+ - @akinon/pz-pay-on-delivery@2.0.152-rc.2
33
+ - @akinon/pz-saved-card@2.0.152-rc.2
34
+ - @akinon/pz-similar-products@2.0.152-rc.2
35
+ - @akinon/pz-tabby-extension@2.0.152-rc.2
36
+ - @akinon/pz-tamara-extension@2.0.152-rc.2
37
+
38
+ ## 2.0.152-rc.1
39
+
40
+ ### Patch Changes
41
+
42
+ - Updated dependencies [97d29893]
43
+ - Updated dependencies [ad5240c4]
44
+ - @akinon/next@2.0.152-rc.1
45
+ - @akinon/pz-theme@2.0.152-rc.1
46
+ - @akinon/pz-virtual-try-on@2.0.152-rc.1
47
+ - @akinon/pz-akifast@2.0.152-rc.1
48
+ - @akinon/pz-apple-pay@2.0.152-rc.1
49
+ - @akinon/pz-b2b@2.0.152-rc.1
50
+ - @akinon/pz-basket-gift-pack@2.0.152-rc.1
51
+ - @akinon/pz-bkm@2.0.152-rc.1
52
+ - @akinon/pz-checkout-gift-pack@2.0.152-rc.1
53
+ - @akinon/pz-click-collect@2.0.152-rc.1
54
+ - @akinon/pz-credit-payment@2.0.152-rc.1
55
+ - @akinon/pz-cybersource-uc@2.0.152-rc.1
56
+ - @akinon/pz-flow-payment@2.0.152-rc.1
57
+ - @akinon/pz-google-pay@2.0.152-rc.1
58
+ - @akinon/pz-gpay@2.0.152-rc.1
59
+ - @akinon/pz-haso@2.0.152-rc.1
60
+ - @akinon/pz-hepsipay@2.0.152-rc.1
61
+ - @akinon/pz-masterpass@2.0.152-rc.1
62
+ - @akinon/pz-masterpass-rest@2.0.152-rc.1
63
+ - @akinon/pz-multi-basket@2.0.152-rc.1
64
+ - @akinon/pz-one-click-checkout@2.0.152-rc.1
65
+ - @akinon/pz-otp@2.0.152-rc.1
66
+ - @akinon/pz-pay-on-delivery@2.0.152-rc.1
67
+ - @akinon/pz-saved-card@2.0.152-rc.1
68
+ - @akinon/pz-similar-products@2.0.152-rc.1
69
+ - @akinon/pz-tabby-extension@2.0.152-rc.1
70
+ - @akinon/pz-tamara-extension@2.0.152-rc.1
71
+
3
72
  ## 2.0.152-rc.0
4
73
 
5
74
  ### Patch Changes
@@ -109,3 +109,9 @@ Integrates Tabby’s installment and deferred payment solutions into the checkou
109
109
  Adds Tamara’s "Buy Now, Pay Later" feature to the payment options. Customers can defer payments while ensuring a seamless checkout experience.
110
110
 
111
111
  [Click here for details](https://www.npmjs.com/package/@akinon/pz-tamara-extension)
112
+
113
+ ### Rate & Review
114
+
115
+ Connects the storefront to the Akinon Rate & Review extension: approved review lists and rating summaries on product pages, rating badges on listings and a review form on the order page. Credentials stay on the server and the customer identity comes from the session.
116
+
117
+ [Click here for details](https://www.npmjs.com/package/@akinon/pz-rate-review)
@@ -1,7 +1,7 @@
1
1
  /// <reference types="next" />
2
2
  /// <reference types="next/image-types/global" />
3
3
  /// <reference types="next/navigation-types/compat/navigation" />
4
- import "./.next/types/routes.d.ts";
4
+ import "./.next/dev/types/routes.d.ts";
5
5
 
6
6
  // NOTE: This file should not be edited
7
7
  // see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "projectzeronext",
3
- "version": "2.0.152-rc.0",
3
+ "version": "2.0.152-rc.2",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -24,33 +24,33 @@
24
24
  "test:middleware": "jest middleware-matcher.test.ts --bail"
25
25
  },
26
26
  "dependencies": {
27
- "@akinon/next": "2.0.152-rc.0",
28
- "@akinon/pz-akifast": "2.0.152-rc.0",
29
- "@akinon/pz-apple-pay": "2.0.152-rc.0",
30
- "@akinon/pz-b2b": "2.0.152-rc.0",
31
- "@akinon/pz-basket-gift-pack": "2.0.152-rc.0",
32
- "@akinon/pz-bkm": "2.0.152-rc.0",
33
- "@akinon/pz-checkout-gift-pack": "2.0.152-rc.0",
34
- "@akinon/pz-click-collect": "2.0.152-rc.0",
35
- "@akinon/pz-credit-payment": "2.0.152-rc.0",
36
- "@akinon/pz-cybersource-uc": "2.0.152-rc.0",
37
- "@akinon/pz-flow-payment": "2.0.152-rc.0",
38
- "@akinon/pz-google-pay": "2.0.152-rc.0",
39
- "@akinon/pz-gpay": "2.0.152-rc.0",
40
- "@akinon/pz-haso": "2.0.152-rc.0",
41
- "@akinon/pz-hepsipay": "2.0.152-rc.0",
42
- "@akinon/pz-masterpass": "2.0.152-rc.0",
43
- "@akinon/pz-masterpass-rest": "2.0.152-rc.0",
44
- "@akinon/pz-multi-basket": "2.0.152-rc.0",
45
- "@akinon/pz-one-click-checkout": "2.0.152-rc.0",
46
- "@akinon/pz-otp": "2.0.152-rc.0",
47
- "@akinon/pz-pay-on-delivery": "2.0.152-rc.0",
48
- "@akinon/pz-saved-card": "2.0.152-rc.0",
49
- "@akinon/pz-similar-products": "2.0.152-rc.0",
50
- "@akinon/pz-tabby-extension": "2.0.152-rc.0",
51
- "@akinon/pz-tamara-extension": "2.0.152-rc.0",
52
- "@akinon/pz-theme": "2.0.152-rc.0",
53
- "@akinon/pz-virtual-try-on": "2.0.152-rc.0",
27
+ "@akinon/next": "2.0.152-rc.2",
28
+ "@akinon/pz-akifast": "2.0.152-rc.2",
29
+ "@akinon/pz-apple-pay": "2.0.152-rc.2",
30
+ "@akinon/pz-b2b": "2.0.152-rc.2",
31
+ "@akinon/pz-basket-gift-pack": "2.0.152-rc.2",
32
+ "@akinon/pz-bkm": "2.0.152-rc.2",
33
+ "@akinon/pz-checkout-gift-pack": "2.0.152-rc.2",
34
+ "@akinon/pz-click-collect": "2.0.152-rc.2",
35
+ "@akinon/pz-credit-payment": "2.0.152-rc.2",
36
+ "@akinon/pz-cybersource-uc": "2.0.152-rc.2",
37
+ "@akinon/pz-flow-payment": "2.0.152-rc.2",
38
+ "@akinon/pz-google-pay": "2.0.152-rc.2",
39
+ "@akinon/pz-gpay": "2.0.152-rc.2",
40
+ "@akinon/pz-haso": "2.0.152-rc.2",
41
+ "@akinon/pz-hepsipay": "2.0.152-rc.2",
42
+ "@akinon/pz-masterpass": "2.0.152-rc.2",
43
+ "@akinon/pz-masterpass-rest": "2.0.152-rc.2",
44
+ "@akinon/pz-multi-basket": "2.0.152-rc.2",
45
+ "@akinon/pz-one-click-checkout": "2.0.152-rc.2",
46
+ "@akinon/pz-otp": "2.0.152-rc.2",
47
+ "@akinon/pz-pay-on-delivery": "2.0.152-rc.2",
48
+ "@akinon/pz-saved-card": "2.0.152-rc.2",
49
+ "@akinon/pz-similar-products": "2.0.152-rc.2",
50
+ "@akinon/pz-tabby-extension": "2.0.152-rc.2",
51
+ "@akinon/pz-tamara-extension": "2.0.152-rc.2",
52
+ "@akinon/pz-theme": "2.0.152-rc.2",
53
+ "@akinon/pz-virtual-try-on": "2.0.152-rc.2",
54
54
  "@hookform/resolvers": "2.9.0",
55
55
  "@next/third-parties": "16.2.6",
56
56
  "@react-google-maps/api": "2.17.1",
@@ -74,7 +74,7 @@
74
74
  "yup": "0.32.11"
75
75
  },
76
76
  "devDependencies": {
77
- "@akinon/eslint-plugin-projectzero": "2.0.152-rc.0",
77
+ "@akinon/eslint-plugin-projectzero": "2.0.152-rc.2",
78
78
  "@semantic-release/changelog": "6.0.2",
79
79
  "@semantic-release/exec": "6.0.3",
80
80
  "@semantic-release/git": "10.0.1",
@@ -144,5 +144,10 @@
144
144
  "address": {
145
145
  "label": "Select Address"
146
146
  }
147
+ },
148
+ "data_source_page": {
149
+ "search_placeholder": "Search in store",
150
+ "search_button": "Search in store",
151
+ "all_products": "All products of the store"
147
152
  }
148
153
  }
@@ -34,6 +34,12 @@
34
34
  "installment_not_available": "Installment options not available",
35
35
  "cash": "Cash",
36
36
  "installment": "Installment",
37
+ "offers": {
38
+ "title": "OTHER SELLERS OF THE PRODUCT",
39
+ "see_all": "See All",
40
+ "in_stock": "In Stock",
41
+ "out_of_stock": "Out of Stock"
42
+ },
37
43
  "stock_alert": {
38
44
  "title": "Stock Alert",
39
45
  "success_description": "When your size is back in stock we'll send an email to: <Email/>",
@@ -144,5 +144,10 @@
144
144
  "address": {
145
145
  "label": "Adres Seçiniz"
146
146
  }
147
+ },
148
+ "data_source_page": {
149
+ "search_placeholder": "Mağazada ara",
150
+ "search_button": "Mağazada ara",
151
+ "all_products": "Mağazanın tüm ürünleri"
147
152
  }
148
153
  }
@@ -34,6 +34,12 @@
34
34
  "installment_not_available": "Taksit seçenekleri mevcut değil",
35
35
  "cash": "Peşin",
36
36
  "installment": "Taksit",
37
+ "offers": {
38
+ "title": "ÜRÜNÜN DİĞER SATICILARI",
39
+ "see_all": "Hepsini gör",
40
+ "in_stock": "Stokta var",
41
+ "out_of_stock": "Stokta yok"
42
+ },
37
43
  "stock_alert": {
38
44
  "title": "Stok Uyarısı",
39
45
  "success_description": "Bedeniniz stoklara tekrar girdiğinde şu adrese bir e-posta göndereceğiz: <Email/>",
@@ -0,0 +1,132 @@
1
+ import { render, screen } from '@testing-library/react';
2
+ import { getDataSourcePageData, getWidgetData } from '@akinon/next/data/server';
3
+ import Page, {
4
+ generateMetadata
5
+ } from '../app/[pz]/data-source-landing-page/[pk]/page';
6
+
7
+ jest.mock('@akinon/next/data/server', () => ({
8
+ getDataSourcePageData: jest.fn(),
9
+ getWidgetData: jest.fn()
10
+ }));
11
+
12
+ jest.mock('@akinon/next/hocs/server', () => ({
13
+ withSegmentDefaults: (component) => component
14
+ }));
15
+
16
+ jest.mock('@akinon/next/utils/pz-segments', () => ({
17
+ parsePzParams: () => ({ locale: 'tr' })
18
+ }));
19
+
20
+ jest.mock('next/navigation', () => ({
21
+ notFound: jest.fn(() => {
22
+ throw new Error('NEXT_NOT_FOUND');
23
+ })
24
+ }));
25
+
26
+ // `@theme/*` modules resolve to these paths; jest keys mocks by resolved path.
27
+ jest.mock('../settings', () => ({ __esModule: true, default: {} }));
28
+ jest.mock('../views/data-source-page/layout', () => ({
29
+ __esModule: true,
30
+ default: ({ data }) => <div data-testid="store-page">{data.pk}</div>
31
+ }));
32
+
33
+ const mockGetDataSourcePageData = getDataSourcePageData as jest.Mock;
34
+ const mockGetWidgetData = getWidgetData as jest.Mock;
35
+
36
+ const page = {
37
+ pk: 3,
38
+ data_source: {
39
+ pk: 17,
40
+ name: 'ayse-ticaret',
41
+ slug: 'ayse-ticaret',
42
+ title: 'Ayşe Ticaret'
43
+ },
44
+ widget: 'ayse-ticaret-0',
45
+ product_collection_widget: 'ayse-ticaret-collection',
46
+ is_active: true
47
+ };
48
+
49
+ const renderPage = async (pk: string) =>
50
+ render(await Page({ params: { pk }, searchParams: {} }));
51
+
52
+ // Route params arrive as strings even though the page types them as numbers.
53
+ const metadataFor = (pk: string) =>
54
+ generateMetadata({
55
+ params: Promise.resolve({ pk })
56
+ } as unknown as Parameters<typeof generateMetadata>[0]);
57
+
58
+ describe('data source landing page route', () => {
59
+ beforeEach(() => {
60
+ jest.clearAllMocks();
61
+ });
62
+
63
+ it('renders the store page for an active landing page', async () => {
64
+ mockGetDataSourcePageData.mockResolvedValue(page);
65
+
66
+ await renderPage('3');
67
+
68
+ expect(mockGetDataSourcePageData).toHaveBeenCalledWith({ pk: 3 });
69
+ expect(screen.getByTestId('store-page')).toHaveTextContent('3');
70
+ });
71
+
72
+ it.each([
73
+ ['a missing page', null],
74
+ ['a failed request', undefined],
75
+ ['an inactive page', { ...page, is_active: false }]
76
+ ])('responds with not found for %s', async (_, data) => {
77
+ mockGetDataSourcePageData.mockResolvedValue(data);
78
+
79
+ await expect(renderPage('3')).rejects.toThrow('NEXT_NOT_FOUND');
80
+ });
81
+
82
+ it('responds with not found for an invalid pk without fetching', async () => {
83
+ await expect(renderPage('03')).rejects.toThrow('NEXT_NOT_FOUND');
84
+ await expect(renderPage('abc')).rejects.toThrow('NEXT_NOT_FOUND');
85
+ expect(mockGetDataSourcePageData).not.toHaveBeenCalled();
86
+ });
87
+
88
+ it('builds the metadata from the store and its page widget', async () => {
89
+ mockGetDataSourcePageData.mockResolvedValue(page);
90
+ mockGetWidgetData.mockResolvedValue({
91
+ attributes: {
92
+ footer: {
93
+ value: { description: '<p>Kargo &amp; İade</p><p>Hızlı teslimat</p>' }
94
+ }
95
+ }
96
+ });
97
+
98
+ await expect(metadataFor('3')).resolves.toEqual({
99
+ title: 'Ayşe Ticaret',
100
+ description: 'Kargo & İade Hızlı teslimat'
101
+ });
102
+ expect(mockGetDataSourcePageData).toHaveBeenCalledWith({
103
+ pk: 3,
104
+ locale: 'tr'
105
+ });
106
+ expect(mockGetWidgetData).toHaveBeenCalledWith({
107
+ slug: 'ayse-ticaret-0',
108
+ locale: 'tr'
109
+ });
110
+
111
+ mockGetWidgetData.mockResolvedValue({
112
+ attributes: { banner: { value: { subtitle: 'Yeni sezon' } } }
113
+ });
114
+ mockGetDataSourcePageData.mockResolvedValue({
115
+ ...page,
116
+ data_source: { ...page.data_source, title: '' }
117
+ });
118
+
119
+ await expect(metadataFor('3')).resolves.toEqual({
120
+ title: 'ayse-ticaret',
121
+ description: 'Yeni sezon'
122
+ });
123
+ });
124
+
125
+ it('returns empty metadata when there is no page', async () => {
126
+ mockGetDataSourcePageData.mockResolvedValue(null);
127
+
128
+ await expect(metadataFor('3')).resolves.toEqual({});
129
+ await expect(metadataFor('x')).resolves.toEqual({});
130
+ expect(mockGetWidgetData).not.toHaveBeenCalled();
131
+ });
132
+ });
@@ -115,6 +115,14 @@ export async function generateMetadata(props: AsyncPageProps) {
115
115
  result = await module['generateMetadata']?.(commonProps as any);
116
116
  });
117
117
  }
118
+
119
+ if (prettyUrlResult.path.startsWith('/data-source-landing-page/')) {
120
+ await import('@data-source-landing-page/[pk]/page').then(
121
+ async (module) => {
122
+ result = await module['generateMetadata']?.(commonProps as any);
123
+ }
124
+ );
125
+ }
118
126
  // eslint-disable-next-line no-empty
119
127
  } catch (error) {}
120
128
 
@@ -189,5 +197,11 @@ export default async function Page(props) {
189
197
  return <FlatPage {...commonProps} />;
190
198
  }
191
199
 
200
+ if (result.path.startsWith('/data-source-landing-page/')) {
201
+ const DataSourcePage = (await import('@data-source-landing-page/[pk]/page'))
202
+ .default;
203
+ return <DataSourcePage {...commonProps} />;
204
+ }
205
+
192
206
  return null;
193
207
  }
@@ -13,6 +13,9 @@ import { ROUTES } from '@theme/routes';
13
13
  import { useLocalization } from '@akinon/next/hooks';
14
14
  import settings from 'settings';
15
15
  import { getOrderStatus } from 'utils';
16
+ import PluginModule, { Component } from '@akinon/next/components/plugin-module';
17
+
18
+ const DELIVERED_ORDER_ITEM_STATUS = '550';
16
19
 
17
20
  const AccountOrderDetail = () => {
18
21
  const { id } = useParams<{ id: string }>();
@@ -228,6 +231,24 @@ const AccountOrderDetail = () => {
228
231
  {itemStatus.label}
229
232
  </div>
230
233
 
234
+ {item?.status?.value?.toString() ===
235
+ DELIVERED_ORDER_ITEM_STATUS && (
236
+ <PluginModule
237
+ component={Component.OrderItemRateAction}
238
+ props={{
239
+ orderId: order.id,
240
+ orderNumber: order.number,
241
+ orderDate: order.created_date,
242
+ product: {
243
+ sku: item.product.sku,
244
+ base_code: item.product.base_code,
245
+ name: item.product.name
246
+ },
247
+ classNames: { root: 'lg:ml-6' }
248
+ }}
249
+ />
250
+ )}
251
+
231
252
  {(item?.is_cancellable || item?.is_refundable) &&
232
253
  order?.is_cancellable && (
233
254
  <div className="lg:ml-24">
@@ -0,0 +1,5 @@
1
+ import { PageLoaderSpinner } from '@theme/views/page-loader-spinner';
2
+
3
+ export default function Loading() {
4
+ return <PageLoaderSpinner />;
5
+ }
@@ -0,0 +1,62 @@
1
+ import { getDataSourcePageData, getWidgetData } from '@akinon/next/data/server';
2
+ import { withSegmentDefaults } from '@akinon/next/hocs/server';
3
+ import {
4
+ AsyncPageProps,
5
+ Metadata,
6
+ ResolvedPageProps
7
+ } from '@akinon/next/types';
8
+ import { parsePzParams } from '@akinon/next/utils/pz-segments';
9
+ import settings from '@theme/settings';
10
+ import { DataSourcePageData } from '@theme/types';
11
+ import { toPlainText } from '@theme/utils/sanitize';
12
+ import DataSourcePageLayout from '@theme/views/data-source-page/layout';
13
+ import { notFound } from 'next/navigation';
14
+
15
+ const isValidPk = (pk: unknown) => /^[1-9]\d*$/.test(String(pk));
16
+
17
+ export async function generateMetadata(
18
+ props: AsyncPageProps<{ pk: number }>
19
+ ): Promise<Metadata> {
20
+ const params = await props.params;
21
+
22
+ if (!isValidPk(params.pk)) {
23
+ return {};
24
+ }
25
+
26
+ const { locale } = parsePzParams(params, settings);
27
+ const data = await getDataSourcePageData({ pk: Number(params.pk), locale });
28
+ const title = data?.data_source?.title || data?.data_source?.name;
29
+
30
+ if (!title) {
31
+ return {};
32
+ }
33
+
34
+ const pageData = await getWidgetData<DataSourcePageData>({
35
+ slug: data.widget,
36
+ locale
37
+ });
38
+ const description = (
39
+ pageData?.attributes?.banner?.value?.subtitle ||
40
+ toPlainText(pageData?.attributes?.footer?.value?.description)
41
+ ).slice(0, 160);
42
+
43
+ return description ? { title, description } : { title };
44
+ }
45
+
46
+ async function Page({ params }: ResolvedPageProps<{ pk: number }>) {
47
+ if (!isValidPk(params.pk)) {
48
+ notFound();
49
+ }
50
+
51
+ const data = await getDataSourcePageData({ pk: Number(params.pk) });
52
+
53
+ if (!data?.pk || data.is_active === false) {
54
+ notFound();
55
+ }
56
+
57
+ return <DataSourcePageLayout data={data} />;
58
+ }
59
+
60
+ export default withSegmentDefaults(Page, {
61
+ segmentType: 'page'
62
+ });
@@ -2,7 +2,11 @@ import { getProductData, getWidgetData } from '@akinon/next/data/server';
2
2
  import { withSegmentDefaults } from '@akinon/next/hocs/server';
3
3
  import { AsyncPageProps, ResolvedPageProps, Metadata } from '@akinon/next/types';
4
4
  import { generateJsonLd, serializeJsonLd } from '@theme/utils/generate-jsonld';
5
- import { AccordionWrapper, ProductInfo } from '@theme/views/product';
5
+ import {
6
+ AccordionWrapper,
7
+ ProductInfo,
8
+ ProductRateReview
9
+ } from '@theme/views/product';
6
10
  import ProductLayout from '@theme/views/product/layout';
7
11
  import { notFound } from 'next/navigation';
8
12
 
@@ -83,6 +87,8 @@ async function Page({ params, searchParams }: ResolvedPageProps<{ pk: number }>)
83
87
  data={data}
84
88
  deliveryReturn={deliveryReturn?.attributes}
85
89
  />
90
+
91
+ <ProductRateReview data={data} />
86
92
  </div>
87
93
  </ProductLayout>
88
94
  <script
@@ -113,3 +113,61 @@ export type AccountFaqItem = {
113
113
  }
114
114
  ];
115
115
  };
116
+
117
+ export type DataSourceProductRecommendation = {
118
+ title?: {
119
+ value: string;
120
+ };
121
+ };
122
+
123
+ export type DataSourcePageStory = {
124
+ value?: {
125
+ title?: string;
126
+ link?: string;
127
+ };
128
+ kwargs?: {
129
+ value?: {
130
+ image?: ImageType;
131
+ };
132
+ };
133
+ };
134
+
135
+ export type DataSourcePageData = {
136
+ header?: {
137
+ value?: {
138
+ logo_link?: string;
139
+ menu_1_title?: string;
140
+ menu_1_link?: string;
141
+ menu_2_title?: string;
142
+ menu_2_link?: string;
143
+ search_placeholder?: string;
144
+ follow_button_title?: string;
145
+ follow_button_title_color?: string;
146
+ follow_button_background?: string;
147
+ };
148
+ kwargs?: {
149
+ value?: {
150
+ logo?: ImageType;
151
+ };
152
+ };
153
+ };
154
+ banner?: {
155
+ value?: {
156
+ title?: string;
157
+ subtitle?: string;
158
+ };
159
+ kwargs?: {
160
+ value?: {
161
+ image?: ImageType;
162
+ mobile_image?: ImageType;
163
+ };
164
+ };
165
+ };
166
+ stories?: DataSourcePageStory[];
167
+ footer?: {
168
+ value?: {
169
+ title?: string;
170
+ description?: string;
171
+ };
172
+ };
173
+ };