@akinon/projectzero 2.0.153-rc.4 → 2.0.153

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 (53) hide show
  1. package/CHANGELOG.md +1 -9
  2. package/app-template/.env.example +0 -1
  3. package/app-template/AGENTS.md +0 -8
  4. package/app-template/CHANGELOG.md +32 -88
  5. package/app-template/README.md +1 -25
  6. package/app-template/docs/plugins.md +0 -6
  7. package/app-template/next-env.d.ts +1 -1
  8. package/app-template/next.config.mjs +1 -7
  9. package/app-template/package.json +41 -41
  10. package/app-template/public/locales/en/common.json +0 -5
  11. package/app-template/public/locales/en/product.json +0 -6
  12. package/app-template/public/locales/tr/common.json +0 -5
  13. package/app-template/public/locales/tr/product.json +0 -6
  14. package/app-template/src/app/[pz]/[...prettyurl]/page.tsx +0 -14
  15. package/app-template/src/app/[pz]/account/orders/[id]/(detail)/page.tsx +0 -21
  16. package/app-template/src/app/[pz]/product/[pk]/page.tsx +1 -7
  17. package/app-template/src/hooks/index.ts +0 -2
  18. package/app-template/src/hooks/use-fav-button.tsx +13 -35
  19. package/app-template/src/plugins.js +0 -1
  20. package/app-template/src/proxy.ts +1 -2
  21. package/app-template/src/types/widgets.ts +0 -58
  22. package/app-template/src/views/category/category-info.tsx +17 -31
  23. package/app-template/src/views/header/search/index.tsx +5 -13
  24. package/app-template/src/views/product/index.ts +0 -1
  25. package/app-template/src/views/product/product-info.tsx +0 -14
  26. package/app-template/src/views/product/slider.tsx +38 -85
  27. package/app-template/src/views/product-item/index.tsx +1 -6
  28. package/app-template/tsconfig.json +0 -3
  29. package/commands/plugins.ts +0 -8
  30. package/dist/commands/plugins.js +0 -8
  31. package/package.json +1 -1
  32. package/app-template/src/__tests__/data-source-landing-page.test.tsx +0 -132
  33. package/app-template/src/app/[pz]/data-source-landing-page/[pk]/loading.tsx +0 -5
  34. package/app-template/src/app/[pz]/data-source-landing-page/[pk]/page.tsx +0 -62
  35. package/app-template/src/app/api/client-env/route.ts +0 -5
  36. package/app-template/src/app/global-error.tsx +0 -22
  37. package/app-template/src/hooks/favourite-product-ids-context.tsx +0 -104
  38. package/app-template/src/utils/__tests__/favourite-product-ids-fallback.test.ts +0 -42
  39. package/app-template/src/utils/__tests__/sanitize.test.ts +0 -127
  40. package/app-template/src/utils/favourite-product-ids-fallback.ts +0 -51
  41. package/app-template/src/utils/sanitize.ts +0 -167
  42. package/app-template/src/views/data-source-page/__tests__/header.test.tsx +0 -173
  43. package/app-template/src/views/data-source-page/__tests__/layout.test.tsx +0 -83
  44. package/app-template/src/views/data-source-page/__tests__/sections.test.tsx +0 -143
  45. package/app-template/src/views/data-source-page/banner.tsx +0 -45
  46. package/app-template/src/views/data-source-page/footer.tsx +0 -27
  47. package/app-template/src/views/data-source-page/header.tsx +0 -140
  48. package/app-template/src/views/data-source-page/layout.tsx +0 -45
  49. package/app-template/src/views/data-source-page/products.tsx +0 -55
  50. package/app-template/src/views/data-source-page/stories.tsx +0 -70
  51. package/app-template/src/views/product/__tests__/product-offers.test.tsx +0 -217
  52. package/app-template/src/views/product/product-offers.tsx +0 -125
  53. package/app-template/src/views/product/rate-review.tsx +0 -21
@@ -113,61 +113,3 @@ 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
- };
@@ -7,12 +7,10 @@ import { CategoryHeader } from './category-header';
7
7
  import { Filters } from './filters';
8
8
  import { Pagination } from '@theme/components';
9
9
  import { ProductItem } from '@theme/views/product-item';
10
- import PluginModule, { Component } from '@akinon/next/components/plugin-module';
11
10
  import { GetCategoryResponse } from '@akinon/next/types';
12
11
  import { useAppDispatch, useAppSelector } from '@akinon/next/redux/hooks';
13
12
  import { setFacets, setMenuOpen } from '@theme/redux/reducers/category';
14
13
  import CategoryActiveFilters from '@theme/views/category/category-active-filters';
15
- import { FavouriteProductIdsProvider } from '@theme/hooks/favourite-product-ids-context';
16
14
  import { useLocalization } from '@akinon/next/hooks';
17
15
  import { Link, LoaderSpinner } from '@akinon/next/components';
18
16
  import { ROUTES } from '@theme/routes';
@@ -64,11 +62,6 @@ export default function ListPage(props: ListPageProps) {
64
62
 
65
63
  const { t } = useLocalization();
66
64
 
67
- const productPks = useMemo(
68
- () => data?.products?.map((product) => product.pk) ?? [],
69
- [data?.products]
70
- );
71
-
72
65
  useEffect(() => {
73
66
  dispatch(setFacets(data.facets));
74
67
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -112,30 +105,23 @@ export default function ListPage(props: ListPageProps) {
112
105
 
113
106
  {data.products?.length === 0 && page > 1 && <LoaderSpinner />}
114
107
 
115
- <FavouriteProductIdsProvider productIds={productPks}>
116
- <div
117
- className={clsx('grid gap-x-4 gap-y-12 grid-cols-2', {
118
- 'md:grid-cols-3': layoutSize === 3,
119
- 'lg:grid-cols-2': layoutSize === 2,
120
- 'lg:grid-cols-3': layoutSize === 3
121
- })}
122
- >
123
- <PluginModule
124
- component={Component.RateReviewPlpProvider}
125
- props={{ products: data?.products ?? [] }}
126
- >
127
- {data?.products?.map((product, index) => (
128
- <ProductItem
129
- key={product.pk}
130
- product={product}
131
- width={itemDimensions.width}
132
- height={itemDimensions.height}
133
- index={index}
134
- />
135
- ))}
136
- </PluginModule>
137
- </div>
138
- </FavouriteProductIdsProvider>
108
+ <div
109
+ className={clsx('grid gap-x-4 gap-y-12 grid-cols-2', {
110
+ 'md:grid-cols-3': layoutSize === 3,
111
+ 'lg:grid-cols-2': layoutSize === 2,
112
+ 'lg:grid-cols-3': layoutSize === 3
113
+ })}
114
+ >
115
+ {data?.products?.map((product, index) => (
116
+ <ProductItem
117
+ key={product.pk}
118
+ product={product}
119
+ width={itemDimensions.width}
120
+ height={itemDimensions.height}
121
+ index={index}
122
+ />
123
+ ))}
124
+ </div>
139
125
  {data?.products?.length > 0 && (
140
126
  <Pagination
141
127
  total={data.pagination.total_count}
@@ -4,7 +4,8 @@ import { useEffect, useRef, useState } from 'react';
4
4
  import { useAppDispatch, useAppSelector } from '@akinon/next/redux/hooks';
5
5
  import { closeSearch } from '@akinon/next/redux/reducers/header';
6
6
  import clsx from 'clsx';
7
- import { Icon, Input } from '@theme/components';
7
+
8
+ import { Icon } from '@theme/components';
8
9
  import Results from './results';
9
10
  import { ROUTES } from '@theme/routes';
10
11
  import { useLocalization, useRouter } from '@akinon/next/hooks';
@@ -41,14 +42,6 @@ export default function Search() {
41
42
  };
42
43
  }, [isSearchOpen, dispatch]);
43
44
 
44
- const handleSearchTextChange = (e: React.ChangeEvent<HTMLInputElement>) => {
45
- setSearchText(e.target.value);
46
- };
47
-
48
- const handleCloseSearch = () => {
49
- dispatch(closeSearch());
50
- };
51
-
52
45
  return (
53
46
  <>
54
47
  <div
@@ -74,9 +67,9 @@ export default function Search() {
74
67
  {t('common.search.results_for')}
75
68
  </span>
76
69
  <div className="flex items-center">
77
- <Input
70
+ <input
78
71
  value={searchText}
79
- onChange={handleSearchTextChange}
72
+ onChange={(e) => setSearchText(e.target.value)}
80
73
  onKeyDown={(e) => {
81
74
  if (e.key === 'Enter' && searchText.trim() !== '') {
82
75
  router.push(`${ROUTES.LIST}/?search_text=${searchText}`);
@@ -98,12 +91,11 @@ export default function Search() {
98
91
  <Icon
99
92
  name="close"
100
93
  size={14}
101
- onClick={handleCloseSearch}
94
+ onClick={() => dispatch(closeSearch())}
102
95
  className="cursor-pointer"
103
96
  />
104
97
  </div>
105
98
  </div>
106
-
107
99
  <Results searchText={searchText} />
108
100
  </div>
109
101
  </div>
@@ -6,5 +6,4 @@ export { default as ProductGroupInfo } from './product-group-info';
6
6
  export { default as MiscButtons } from './misc-buttons';
7
7
  export { default as ProductInfoSlider } from './slider';
8
8
  export { default as AccordionWrapper } from './accordion-wrapper';
9
- export { default as ProductRateReview } from './rate-review';
10
9
  export { default as CombineProductCard } from './combine-product-card';
@@ -13,7 +13,6 @@ import { useStockAlert } from '../../hooks/use-stock-alert';
13
13
  import { ProductVariants } from './product-variants';
14
14
  import { ProductActions } from './product-actions';
15
15
  import { ProductShare } from './product-share';
16
- import { ProductOffers } from './product-offers';
17
16
  import PluginModule, { Component } from '@akinon/next/components/plugin-module';
18
17
 
19
18
  export default function ProductInfo({ data }: ProductPageProps) {
@@ -74,17 +73,6 @@ export default function ProductInfo({ data }: ProductPageProps) {
74
73
 
75
74
  return (
76
75
  <>
77
- <PluginModule
78
- component={Component.RateReviewBadge}
79
- props={{
80
- product: {
81
- sku: data.product.sku,
82
- base_code: data.product.base_code
83
- },
84
- classNames: { root: 'mt-2' }
85
- }}
86
- />
87
-
88
76
  <div
89
77
  className={clsx(
90
78
  'fixed bottom-0 left-0 w-1/2 h-14 z-[20] bg-white mt-0 border-t border-gray-500 items-center justify-center',
@@ -133,8 +121,6 @@ export default function ProductInfo({ data }: ProductPageProps) {
133
121
  />
134
122
 
135
123
  <ProductShare productName={data.product.name} className="my-2 sm:mb-4" />
136
-
137
- <ProductOffers offers={data.offers} productPk={data.product.pk} />
138
124
  </>
139
125
  );
140
126
  }
@@ -36,100 +36,53 @@ export default function ProductInfoSlider({ product }: ProductSliderItem) {
36
36
  carouselRef.current?.next();
37
37
  };
38
38
 
39
- const handleThumbnailClick = (index: number) => {
39
+ const handleThumbnailClick = (index) => {
40
40
  setActiveIndex(index);
41
41
  carouselRef.current?.goToSlide(index);
42
42
  };
43
43
 
44
44
  return (
45
- <>
46
- <div className="lg:grid lg:grid-cols-6">
47
- <div className="lg:col-span-1">
48
- <div className="flex flex-col items-center justify-center md:mr-[6px]">
49
- <button
50
- onClick={goToPrev}
51
- className={twMerge(
52
- 'hidden justify-center p-2 mb-3 border border-gray-100 rounded-full cursor-pointer lg:block',
53
- [activeIndex === 0 && 'cursor-not-allowed opacity-45']
54
- )}
55
- disabled={activeIndex === 0}
56
- >
57
- <Icon name="chevron-up" size={15} className="fill-[#000000]" />
58
- </button>
59
- <div className="hidden flex-col items-center overflow-scroll w-[80px] max-h-[620px] lg:block">
60
- {product?.productimage_set?.map((item, index) => (
61
- <Image
62
- key={index}
63
- src={item.image}
64
- alt={`Thumbnail ${index}`}
65
- width={80}
66
- height={128}
67
- aspectRatio={80 / 128}
68
- className={twMerge('cursor-pointer', [
69
- activeIndex === index && 'border-2 border-primary'
70
- ])}
71
- onClick={() => handleThumbnailClick(index)}
72
- />
73
- ))}
74
- </div>
75
- <button
76
- onClick={goToNext}
77
- className={twMerge(
78
- 'hidden justify-center p-2 mt-3 border border-gray-100 rounded-full cursor-pointer lg:block',
79
- [
80
- activeIndex === product.productimage_set.length - 1 &&
81
- 'cursor-not-allowed opacity-45'
82
- ]
83
- )}
84
- disabled={activeIndex === product.productimage_set.length - 1}
85
- >
86
- <Icon name="chevron-down" size={15} className="fill-[#000000]" />
87
- </button>
88
- </div>
89
- </div>
90
-
91
- <div className="relative lg:col-span-5">
92
- <FavButton className="absolute right-8 top-6 z-[20] sm:hidden" />
93
-
94
- <PluginModule
95
- component={Component.ProductImageSearchFeature}
96
- props={{
97
- product,
98
- activeIndex,
99
- showResetButton: true
100
- }}
101
- />
102
-
103
- <CarouselCore
104
- responsive={{
105
- all: {
106
- breakpoint: { max: 5000, min: 0 },
107
- items: 1
108
- }
109
- }}
110
- arrows={false}
111
- swipeable={true}
112
- ref={carouselRef}
113
- afterChange={(previousSlide, { currentSlide }) => {
114
- setActiveIndex(currentSlide);
115
- }}
116
- containerAspectRatio={{ mobile: 520 / 798, desktop: 484 / 726 }}
45
+ <div className="lg:grid lg:grid-cols-6">
46
+ <div className="lg:col-span-1">
47
+ <div className="flex flex-col items-center justify-center md:mr-[6px]">
48
+ <button
49
+ onClick={goToPrev}
50
+ className={twMerge(
51
+ 'hidden justify-center p-2 mb-3 border border-gray-100 rounded-full cursor-pointer lg:block',
52
+ [activeIndex === 0 && 'cursor-not-allowed opacity-45']
53
+ )}
54
+ disabled={activeIndex === 0}
117
55
  >
118
- {product?.productimage_set?.map((item, i) => (
56
+ <Icon name="chevron-up" size={15} className="fill-[#000000]" />
57
+ </button>
58
+ <div className="hidden flex-col items-center overflow-scroll w-[80px] max-h-[620px] lg:block">
59
+ {product?.productimage_set?.map((item, index) => (
119
60
  <Image
120
- key={i}
61
+ key={index}
121
62
  src={item.image}
122
- alt={product?.name || 'Product image'}
123
- draggable={false}
124
- aspectRatio={484 / 726}
125
- sizes="(min-width: 425px) 512px,
126
- (min-width: 601px) 576px,
127
- (min-width: 768px) 336px,
128
- (min-width: 1024px) 484px, 368px"
129
- fill
63
+ alt={`Thumbnail ${index}`}
64
+ width={80}
65
+ height={128}
66
+ className={twMerge('cursor-pointer', [
67
+ activeIndex === index && 'border-2 border-primary'
68
+ ])}
69
+ onClick={() => handleThumbnailClick(index)}
130
70
  />
131
71
  ))}
132
- </CarouselCore>
72
+ </div>
73
+ <button
74
+ onClick={goToNext}
75
+ className={twMerge(
76
+ 'hidden justify-center p-2 mt-3 border border-gray-100 rounded-full cursor-pointer lg:block',
77
+ [
78
+ activeIndex === product.productimage_set.length - 1 &&
79
+ 'cursor-not-allowed opacity-45'
80
+ ]
81
+ )}
82
+ disabled={activeIndex === product.productimage_set.length - 1}
83
+ >
84
+ <Icon name="chevron-down" size={15} className="fill-[#000000]" />
85
+ </button>
133
86
  </div>
134
87
  </div>
135
88
 
@@ -187,6 +140,6 @@ export default function ProductInfoSlider({ product }: ProductSliderItem) {
187
140
  ))}
188
141
  </CarouselCore>
189
142
  </div>
190
- </>
143
+ </div>
191
144
  );
192
145
  }
@@ -10,7 +10,6 @@ import useFavButton from '../../hooks/use-fav-button';
10
10
  import { Product } from '@akinon/next/types';
11
11
  import { Image } from '@akinon/next/components/image';
12
12
  import { Price, Link } from '@theme/components';
13
- import PluginModule, { Component } from '@akinon/next/components/plugin-module';
14
13
 
15
14
  interface Props {
16
15
  product: Product;
@@ -23,7 +22,7 @@ export const ProductItem = (props: Props) => {
23
22
  // TODO: Static image will change (TR)
24
23
  const { product, width, height, index } = props;
25
24
  const [viewed, setViewed] = useState(false);
26
- const { FavButton } = useFavButton(product.pk, product);
25
+ const { FavButton } = useFavButton(product.pk);
27
26
  const { ref, inView } = useInView();
28
27
 
29
28
  const image_url = product.productimage_set[0]?.image;
@@ -82,10 +81,6 @@ export const ProductItem = (props: Props) => {
82
81
  >
83
82
  {product_name}
84
83
  </Link>
85
- <PluginModule
86
- component={Component.RateReviewPlpBadge}
87
- props={{ product }}
88
- />
89
84
  <div className="font-semibold">
90
85
  {parseFloat(retail_price) > parseFloat(price) && (
91
86
  <Price
@@ -24,9 +24,6 @@
24
24
  ],
25
25
  "@flat-page/*": [
26
26
  "./app/[pz]/flat-page/*"
27
- ],
28
- "@data-source-landing-page/*": [
29
- "./app/[pz]/data-source-landing-page/*"
30
27
  ]
31
28
  },
32
29
  "allowSyntheticDefaultImports": true,
@@ -164,10 +164,6 @@ export default async () => {
164
164
  name: 'Tamara Payment Extension',
165
165
  value: 'pz-tamara-extension'
166
166
  },
167
- {
168
- name: 'Similar Products',
169
- value: 'pz-similar-products'
170
- },
171
167
  {
172
168
  name: 'Hepsipay',
173
169
  value: 'pz-hepsipay'
@@ -180,10 +176,6 @@ export default async () => {
180
176
  name: 'Virtual Try-On',
181
177
  value: 'pz-virtual-try-on'
182
178
  },
183
- {
184
- name: 'Rate & Review',
185
- value: 'pz-rate-review'
186
- },
187
179
  {
188
180
  name: 'Masterpass Rest',
189
181
  value: 'pz-masterpass-rest'
@@ -183,10 +183,6 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
183
183
  name: 'Tamara Payment Extension',
184
184
  value: 'pz-tamara-extension'
185
185
  },
186
- {
187
- name: 'Similar Products',
188
- value: 'pz-similar-products'
189
- },
190
186
  {
191
187
  name: 'Hepsipay',
192
188
  value: 'pz-hepsipay'
@@ -199,10 +195,6 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
199
195
  name: 'Virtual Try-On',
200
196
  value: 'pz-virtual-try-on'
201
197
  },
202
- {
203
- name: 'Rate & Review',
204
- value: 'pz-rate-review'
205
- },
206
198
  {
207
199
  name: 'Masterpass Rest',
208
200
  value: 'pz-masterpass-rest'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akinon/projectzero",
3
- "version": "2.0.153-rc.4",
3
+ "version": "2.0.153",
4
4
  "private": false,
5
5
  "description": "CLI tool to manage your Project Zero Next project",
6
6
  "bin": {
@@ -1,132 +0,0 @@
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
- });
@@ -1,5 +0,0 @@
1
- import { PageLoaderSpinner } from '@theme/views/page-loader-spinner';
2
-
3
- export default function Loading() {
4
- return <PageLoaderSpinner />;
5
- }
@@ -1,62 +0,0 @@
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
- });
@@ -1,5 +0,0 @@
1
- export { GET } from '@akinon/next/api/client-env';
2
-
3
- // NEXT_PUBLIC_* values are read from the server runtime, not the build. Force
4
- // dynamic so Next never statically caches an (empty) build-time response.
5
- export const dynamic = 'force-dynamic';