@akinon/projectzero 1.86.0-rc.3 → 1.86.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.
@@ -0,0 +1,5 @@
1
+ {
2
+ "tests": [
3
+ "test:middleware"
4
+ ]
5
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "projectzeronext",
3
- "version": "1.86.0-rc.3",
3
+ "version": "1.86.0",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -19,25 +19,26 @@
19
19
  "prebuild": "pz-prebuild",
20
20
  "postbuild": "pz-postbuild",
21
21
  "poststart": "pz-poststart",
22
- "prestart": "pz-prestart"
22
+ "prestart": "pz-prestart",
23
+ "test:middleware": "jest middleware-matcher.test.ts --bail"
23
24
  },
24
25
  "dependencies": {
25
- "@akinon/next": "1.86.0-rc.3",
26
- "@akinon/pz-akifast": "1.86.0-rc.3",
27
- "@akinon/pz-b2b": "1.86.0-rc.3",
28
- "@akinon/pz-basket-gift-pack": "1.86.0-rc.3",
29
- "@akinon/pz-bkm": "1.86.0-rc.3",
30
- "@akinon/pz-checkout-gift-pack": "1.86.0-rc.3",
31
- "@akinon/pz-click-collect": "1.86.0-rc.3",
32
- "@akinon/pz-credit-payment": "1.86.0-rc.3",
33
- "@akinon/pz-gpay": "1.86.0-rc.3",
34
- "@akinon/pz-masterpass": "1.86.0-rc.3",
35
- "@akinon/pz-one-click-checkout": "1.86.0-rc.3",
36
- "@akinon/pz-otp": "1.86.0-rc.3",
37
- "@akinon/pz-pay-on-delivery": "1.86.0-rc.3",
38
- "@akinon/pz-saved-card": "1.86.0-rc.3",
39
- "@akinon/pz-tabby-extension": "1.86.0-rc.3",
40
- "@akinon/pz-tamara-extension": "1.86.0-rc.3",
26
+ "@akinon/next": "1.86.0",
27
+ "@akinon/pz-akifast": "1.86.0",
28
+ "@akinon/pz-b2b": "1.86.0",
29
+ "@akinon/pz-basket-gift-pack": "1.86.0",
30
+ "@akinon/pz-bkm": "1.86.0",
31
+ "@akinon/pz-checkout-gift-pack": "1.86.0",
32
+ "@akinon/pz-click-collect": "1.86.0",
33
+ "@akinon/pz-credit-payment": "1.86.0",
34
+ "@akinon/pz-gpay": "1.86.0",
35
+ "@akinon/pz-masterpass": "1.86.0",
36
+ "@akinon/pz-one-click-checkout": "1.86.0",
37
+ "@akinon/pz-otp": "1.86.0",
38
+ "@akinon/pz-pay-on-delivery": "1.86.0",
39
+ "@akinon/pz-saved-card": "1.86.0",
40
+ "@akinon/pz-tabby-extension": "1.86.0",
41
+ "@akinon/pz-tamara-extension": "1.86.0",
41
42
  "@hookform/resolvers": "2.9.0",
42
43
  "@next/third-parties": "14.1.0",
43
44
  "@react-google-maps/api": "2.17.1",
@@ -57,11 +58,10 @@
57
58
  "react-string-replace": "1.1.0",
58
59
  "start-server-and-test": "2.0.3",
59
60
  "tailwind-merge": "1.8.0",
60
- "tailwindcss": "3.4.17",
61
61
  "yup": "0.32.11"
62
62
  },
63
63
  "devDependencies": {
64
- "@akinon/eslint-plugin-projectzero": "1.86.0-rc.3",
64
+ "@akinon/eslint-plugin-projectzero": "1.86.0",
65
65
  "@semantic-release/changelog": "6.0.2",
66
66
  "@semantic-release/exec": "6.0.3",
67
67
  "@semantic-release/git": "10.0.1",
@@ -71,7 +71,7 @@
71
71
  "@testing-library/react": "13.1.1",
72
72
  "@testing-library/user-event": "14.1.1",
73
73
  "@types/googlemaps": "3.43.3",
74
- "@types/jest": "27.4.1",
74
+ "@types/jest": "29.5.14",
75
75
  "@types/react": "18.2.27",
76
76
  "@types/react-dom": "18.2.12",
77
77
  "@typescript-eslint/eslint-plugin": "6.7.4",
@@ -86,6 +86,7 @@
86
86
  "husky": "8.0.0",
87
87
  "jest": "29.7.0",
88
88
  "jest-css-modules-transform": "4.3.0",
89
+ "jest-environment-jsdom": "29.7.0",
89
90
  "lint-staged": "13.1.0",
90
91
  "prettier": "2.6.2",
91
92
  "react-number-format": "5.3.4",
@@ -97,8 +98,8 @@
97
98
  "stylelint-config-standard": "25.0.0",
98
99
  "stylelint-scss": "4.2.0",
99
100
  "stylelint-selector-bem-pattern": "2.1.1",
100
- "tailwindcss": "3.4.14",
101
- "ts-jest": "29.1.1",
101
+ "tailwindcss": "3.4.17",
102
+ "ts-jest": "29.2.6",
102
103
  "ts-node": "10.7.0",
103
104
  "typescript": "5.2.2"
104
105
  },
@@ -0,0 +1,135 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+
4
+ describe('Middleware matcher regex tests', () => {
5
+ const middlewareFilePath = path.resolve(__dirname, '../middleware.ts');
6
+ const middlewareContent = fs.readFileSync(middlewareFilePath, 'utf8');
7
+
8
+ let actualMatcherStrings: string[] = [];
9
+ let matcherPatterns: RegExp[] = [];
10
+
11
+ const matcherBlockRegex = middlewareContent.match(/matcher:\s*\[([\s\S]*?)\](?=\s*[,}])/);
12
+
13
+ if (matcherBlockRegex && matcherBlockRegex[1]) {
14
+ const matcherContentInsideBrackets = matcherBlockRegex[1];
15
+
16
+ actualMatcherStrings = matcherContentInsideBrackets
17
+ .split(',')
18
+ .map(line => {
19
+ const uncommentedLine = line.replace(/\/\/.*$/, '').trim();
20
+ const quoteMatch = uncommentedLine.match(/^(['"])(.*)\1$/);
21
+ return quoteMatch ? quoteMatch[2] : null;
22
+ })
23
+ .filter((pattern): pattern is string => pattern !== null && pattern !== '');
24
+
25
+ matcherPatterns = matcherContentInsideBrackets
26
+ .split(',')
27
+ .map((pattern) => pattern.trim())
28
+ .filter(Boolean)
29
+ .map((pattern) => {
30
+ let cleanPattern = pattern
31
+ .replace(/^['"]|['"]$/g, '');
32
+
33
+ try {
34
+ if (cleanPattern.includes('(?!') && cleanPattern.includes('api') && cleanPattern.includes('_next')) {
35
+ cleanPattern = '^(?!/(?:api|_next)/)(?!.*\\.\\w+$).*$';
36
+ }
37
+
38
+ return new RegExp(cleanPattern);
39
+ } catch (error) {
40
+ console.error(`Invalid simplified regex: ${cleanPattern}`, error);
41
+ return null;
42
+ }
43
+ })
44
+ .filter(Boolean) as RegExp[];
45
+ }
46
+
47
+ const testPath = (path: string): boolean => {
48
+ return matcherPatterns.some((pattern) => {
49
+ try {
50
+ const result = pattern.test(path);
51
+ return result;
52
+ } catch (error) {
53
+ console.error(
54
+ `Error testing path: ${path} | Pattern: ${pattern.toString()}`,
55
+ error
56
+ );
57
+ return false;
58
+ }
59
+ });
60
+ };
61
+
62
+ it('should NOT match api routes', () => {
63
+ const apiPaths = ['/api/products', '/api/auth/login', '/api/v1/users'];
64
+ apiPaths.forEach((path) => {
65
+ expect(testPath(path)).toBe(false);
66
+ });
67
+ });
68
+
69
+ it('should NOT match _next routes', () => {
70
+ const nextPaths = [
71
+ '/_next/static/chunks/main.js',
72
+ '/_next/image',
73
+ '/_next/data/build-id/products.json'
74
+ ];
75
+ nextPaths.forEach((path) => {
76
+ expect(testPath(path)).toBe(false);
77
+ });
78
+ });
79
+
80
+ it('should NOT match static files with extensions', () => {
81
+ const staticFiles = [
82
+ '/images/logo.png',
83
+ '/styles/main.css',
84
+ '/fonts/roboto.woff2',
85
+ '/favicon.ico',
86
+ '/manifest.json'
87
+ ];
88
+ staticFiles.forEach((path) => {
89
+ expect(testPath(path)).toBe(false);
90
+ });
91
+ });
92
+
93
+ it('should match dynamic routes and specific patterns', () => {
94
+ const validPaths = [
95
+ '/profile/settings',
96
+ '/dashboard/stats',
97
+ '/products/123'
98
+ ];
99
+ validPaths.forEach((path) => {
100
+ expect(testPath(path)).toBe(true);
101
+ });
102
+ });
103
+
104
+ it('should match checkout-with-token routes', () => {
105
+ const expectedRegexString = '\'/(.*orders\\\\/checkout-with-token.*)\'';
106
+ expect(middlewareContent.includes(expectedRegexString)).toBe(true);
107
+
108
+ const checkoutPaths = [
109
+ '/orders/checkout-with-token/123',
110
+ '/orders/checkout-with-token/abc-xyz',
111
+ '/orders/checkout-with-token'
112
+ ];
113
+ checkoutPaths.forEach((path) => {
114
+ expect(testPath(path)).toBe(true);
115
+ });
116
+ });
117
+
118
+ it('should contain the exact specific extensions regex string in the file content', () => {
119
+ const expectedRegexString = '\'/(.+\\\\.)(html|htm|aspx|asp|php)\'';
120
+ expect(middlewareContent.includes(expectedRegexString)).toBe(true);
121
+ });
122
+
123
+ it('should include the sitemap pattern specifically within the matcher array', () => {
124
+ const sitemapPattern = '/(.*sitemap\\\\.xml)';
125
+ expect(actualMatcherStrings).toContain(sitemapPattern);
126
+ });
127
+
128
+ it('should verify that api pattern is excluded in the matcher configuration', () => {
129
+ expect(/api/.test(middlewareContent)).toBe(true);
130
+ });
131
+
132
+ it('should verify that _next pattern is excluded in the matcher configuration', () => {
133
+ expect(/_next/.test(middlewareContent)).toBe(true);
134
+ });
135
+ });
@@ -1,14 +1,87 @@
1
- import { BasketContent } from '@theme/views/basket/basket-content';
2
- import { getBasketData } from '@akinon/next/data/server/basket';
1
+ 'use client';
2
+
3
+ import { useEffect } from 'react';
4
+ import { ROUTES } from '@theme/routes';
5
+ import { useGetBasketQuery } from '@akinon/next/data/client/basket';
6
+ import { pushCartView } from '@theme/utils/gtm';
7
+ import { Button, LoaderSpinner, Link } from '@theme/components';
8
+ import { BasketItem, Summary } from '@theme/views/basket';
9
+ import { useLocalization } from '@akinon/next/hooks';
10
+ import PluginModule, { Component } from '@akinon/next/components/plugin-module';
3
11
  import settings from '@theme/settings';
4
12
 
5
- export default async function Page() {
6
- const { basket } = await getBasketData();
13
+ export default function Page() {
14
+ const { data: basket, isLoading, isSuccess } = useGetBasketQuery();
15
+ const { t } = useLocalization();
16
+ const multiBasket = settings.plugins?.multiBasket ?? false;
17
+
18
+ useEffect(() => {
19
+ if (isSuccess) {
20
+ const products = basket.basketitem_set.map((basketItem) => ({
21
+ ...basketItem.product
22
+ }));
23
+ pushCartView(products);
24
+ }
25
+ }, [basket, isSuccess]);
26
+
27
+ return (
28
+ <div className="max-w-screen-xl p-4 flex flex-col text-primary-800 lg:p-8 xl:flex-row xl:mx-auto">
29
+ {isLoading && (
30
+ <div className="flex justify-center w-full">
31
+ <LoaderSpinner />
32
+ </div>
33
+ )}
34
+ {isSuccess &&
35
+ (basket && basket.basketitem_set && basket.basketitem_set.length > 0 ? (
36
+ <>
37
+ <div className="flex-1 xl:mr-16">
38
+ <div className="flex items-center justify-between py-2 border-b border-gray-200 lg:py-3">
39
+ <h2 className="text-xl lg:text-2xl font-light">
40
+ {t('basket.my_cart')}
41
+ </h2>
42
+ <Link
43
+ href={ROUTES.HOME}
44
+ className="text-xs hover:text-secondary-500"
45
+ >
46
+ {t('basket.back_to_shopping')}
47
+ </Link>
48
+ </div>
49
+ <ul>
50
+ {multiBasket ? (
51
+ <PluginModule
52
+ component={Component.MultiBasket}
53
+ props={{ BasketItem }}
54
+ />
55
+ ) : (
56
+ basket.basketitem_set.map((basketItem, index) => (
57
+ <BasketItem basketItem={basketItem} key={index} />
58
+ ))
59
+ )}
60
+ </ul>
61
+ </div>
62
+ <Summary basket={basket} />
63
+ </>
64
+ ) : (
65
+ <div className="flex flex-col items-center container max-w-screen-sm py-4 px-4 xs:py-6 xs:px-6 sm:py-8 sm:px-8 lg:max-w-screen-xl">
66
+ <h1
67
+ className="w-full text-xl font-light text-secondary text-center sm:text-2xl"
68
+ data-testid="basket-empty"
69
+ >
70
+ {t('basket.empty.title')}
71
+ </h1>
7
72
 
8
- const multiBasket: boolean =
9
- typeof settings.plugins?.multiBasket === 'boolean'
10
- ? settings.plugins.multiBasket
11
- : false;
73
+ <div className="w-full text-sm text-black-800 text-center my-4 mb-2 sm:text-base">
74
+ <p>{t('basket.empty.content_first')}</p>
75
+ <p>{t('basket.empty.content_second')}.</p>
76
+ </div>
12
77
 
13
- return <BasketContent initialBasket={basket} multiBasket={multiBasket} />;
78
+ <Link href={ROUTES.HOME} passHref>
79
+ <Button className="px-10 mt-2" appearance="filled">
80
+ {t('basket.empty.button')}
81
+ </Button>
82
+ </Link>
83
+ </div>
84
+ ))}
85
+ </div>
86
+ );
14
87
  }
@@ -1,10 +1,6 @@
1
1
  const { LocaleUrlStrategy } = require('@akinon/next/localization');
2
2
  const { ROUTES } = require('@theme/routes');
3
3
 
4
- /* IMPORTANT *
5
- * In order to use one locale in the locales array and hide the default locale in the URL, you need to set the localeUrlStrategy to LocaleUrlStrategy.ShowAllLocales.
6
- */
7
-
8
4
  const commerceUrl = encodeURI(process.env.SERVICE_BACKEND_URL ?? 'default');
9
5
 
10
6
  /** @type {import('@akinon/next/types').Settings} */
@@ -18,7 +14,6 @@ module.exports = {
18
14
  { translationKey: 'size', key: 'size' }
19
15
  ],
20
16
  localization: {
21
- // If there is one locale in the locales array, the default locale will be hidden in the URL.
22
17
  locales: [
23
18
  {
24
19
  label: 'EN',
@@ -46,7 +41,7 @@ module.exports = {
46
41
  }
47
42
  ],
48
43
  defaultLocaleValue: 'en',
49
- localeUrlStrategy: LocaleUrlStrategy.HideDefaultLocale, // If there is one locale in the locales array, the default locale will be hidden in the URL and localeUrlStrategy should be set to LocaleUrlStrategy.ShowAllLocales.
44
+ localeUrlStrategy: LocaleUrlStrategy.HideDefaultLocale,
50
45
  redirectToDefaultLocale: true,
51
46
  defaultCurrencyCode: 'usd'
52
47
  },
@@ -3,7 +3,7 @@ import {
3
3
  useUpdateQuantityMutation
4
4
  } from '@akinon/next/data/client/basket';
5
5
  import { useAppDispatch } from '@akinon/next/redux/hooks';
6
- import { Basket, BasketItem as BasketItemType } from '@akinon/next/types';
6
+ import { BasketItem as BasketItemType } from '@akinon/next/types';
7
7
  import { Price, Button, Icon, Modal, Select, Link } from '@theme/components';
8
8
  import { useState } from 'react';
9
9
  import { useAddFavoriteMutation } from '@akinon/next/data/client/wishlist';
@@ -19,12 +19,11 @@ import { pushRemoveFromCart } from '@theme/utils/gtm';
19
19
  interface Props {
20
20
  basketItem?: BasketItemType;
21
21
  namespace?: string;
22
- onBasketUpdate?: (basket: Basket) => void;
23
22
  }
24
23
 
25
24
  export const BasketItem = (props: Props) => {
26
25
  const { t } = useLocalization();
27
- const { basketItem, namespace, onBasketUpdate } = props;
26
+ const { basketItem, namespace } = props;
28
27
  const [updateQuantityMutation] = useUpdateQuantityMutation();
29
28
  const dispatch = useAppDispatch();
30
29
  const [isRemoveBasketModalOpen, setRemoveBasketModalOpen] = useState(false);
@@ -50,21 +49,19 @@ export const BasketItem = (props: Props) => {
50
49
  requestParams.namespace = namespace;
51
50
  }
52
51
 
53
- try {
54
- const response = await updateQuantityMutation(requestParams).unwrap();
55
- dispatch(
56
- basketApi.util.updateQueryData(
57
- 'getBasket',
58
- undefined,
59
- (draftBasket) => {
60
- Object.assign(draftBasket, response.basket);
61
- }
52
+ await updateQuantityMutation(requestParams)
53
+ .unwrap()
54
+ .then((data) =>
55
+ dispatch(
56
+ basketApi.util.updateQueryData(
57
+ 'getBasket',
58
+ undefined,
59
+ (draftBasket) => {
60
+ Object.assign(draftBasket, data.basket);
61
+ }
62
+ )
62
63
  )
63
64
  );
64
- onBasketUpdate?.(response.basket);
65
- } catch (error) {
66
- console.error('Error updating quantity:', error);
67
- }
68
65
  };
69
66
 
70
67
  const deleteProduct = async (productPk?: number) => {
@@ -18,7 +18,6 @@ import clsx from 'clsx';
18
18
 
19
19
  interface Props {
20
20
  basket: Basket;
21
- onBasketUpdate?: (basket: Basket) => void;
22
21
  }
23
22
 
24
23
  const voucherCodeFormSchema = (t) =>
@@ -28,7 +27,7 @@ const voucherCodeFormSchema = (t) =>
28
27
 
29
28
  export const Summary = (props: Props) => {
30
29
  const { t } = useLocalization();
31
- const { basket, onBasketUpdate } = props;
30
+ const { basket } = props;
32
31
  const router = useRouter();
33
32
  const {
34
33
  register,
@@ -54,7 +53,7 @@ export const Summary = (props: Props) => {
54
53
  const removeVoucherCode = () => {
55
54
  removeVoucherCodeMutation()
56
55
  .unwrap()
57
- .then((basket) => {
56
+ .then((basket) =>
58
57
  dispatch(
59
58
  basketApi.util.updateQueryData(
60
59
  'getBasket',
@@ -63,9 +62,8 @@ export const Summary = (props: Props) => {
63
62
  Object.assign(draftBasket, basket);
64
63
  }
65
64
  )
66
- );
67
- onBasketUpdate?.(basket);
68
- })
65
+ )
66
+ )
69
67
  .catch((error: Error) => {
70
68
  setError('voucherCode', { message: error.data.non_field_errors });
71
69
  });
@@ -76,7 +74,7 @@ export const Summary = (props: Props) => {
76
74
  voucher_code: data.voucherCode
77
75
  })
78
76
  .unwrap()
79
- .then((basket) => {
77
+ .then((basket) =>
80
78
  dispatch(
81
79
  basketApi.util.updateQueryData(
82
80
  'getBasket',
@@ -85,9 +83,8 @@ export const Summary = (props: Props) => {
85
83
  Object.assign(draftBasket, basket);
86
84
  }
87
85
  )
88
- );
89
- onBasketUpdate?.(basket);
90
- })
86
+ )
87
+ )
91
88
  .catch((error: Error) => {
92
89
  setError('voucherCode', { message: error.data.non_field_errors });
93
90
  });
@@ -151,7 +151,13 @@ export default function MiniBasket() {
151
151
  (state) => state.root.miniBasket
152
152
  );
153
153
  const dispatch = useAppDispatch();
154
- const { data: basket, isLoading, isSuccess } = useGetBasketQuery();
154
+ const {
155
+ data: basket,
156
+ isLoading,
157
+ isSuccess
158
+ } = useGetBasketQuery(undefined, {
159
+ skip: !miniBasketOpen
160
+ });
155
161
  const { data: miniBasket } = useGetMiniBasketQuery();
156
162
  const { t } = useLocalization();
157
163
  const { highlightedItem } = useAppSelector((state) => state.root.miniBasket);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akinon/projectzero",
3
- "version": "1.86.0-rc.3",
3
+ "version": "1.86.0",
4
4
  "private": false,
5
5
  "description": "CLI tool to manage your Project Zero Next project",
6
6
  "bin": {
@@ -1,67 +0,0 @@
1
- import { Skeleton, SkeletonWrapper } from 'components';
2
-
3
- export default function Loading() {
4
- return (
5
- <div className="container mx-auto">
6
- <div className="max-w-5xl mx-auto my-5 px-7">
7
- <SkeletonWrapper className="md:mb-7">
8
- <Skeleton className="w-[17.25rem] h-4 lg:w-64" />
9
- </SkeletonWrapper>
10
- </div>
11
- <div className="grid max-w-5xl grid-cols-2 lg:gap-8 mx-auto px-7">
12
- <div className="col-span-2 mb-7 md:mb-0 lg:col-span-1">
13
- <div className="flex gap-1">
14
- <SkeletonWrapper className="hidden md:block md:mb-7">
15
- {Array(5)
16
- .fill(null)
17
- .map((_, index) => (
18
- <Skeleton key={index} className="w-20 h-24 mb-2" />
19
- ))}
20
- </SkeletonWrapper>
21
-
22
- <div className="flex-1">
23
- <SkeletonWrapper className="md:mb-7">
24
- <Skeleton className="w-full h-[30.375rem] md:h-[36.375rem]" />
25
- </SkeletonWrapper>
26
- </div>
27
- </div>
28
- </div>
29
- <div className="flex flex-col items-center col-span-2 lg:col-span-1">
30
- <div className="w-full">
31
- <SkeletonWrapper className="w-full md:mb-7 flex justify-center items-center">
32
- <Skeleton className="w-96 h-16 mb-9" />
33
- <Skeleton className="hidden w-36 h-14 mb-9 md:block" />
34
-
35
- <div className="flex flex-col justify-center items-center mb-9">
36
- <Skeleton className="w-36 h-4 mb-2" />
37
- <div className="flex items-center gap-2">
38
- {Array(3)
39
- .fill(null)
40
- .map((_, index) => (
41
- <Skeleton key={index} className="w-24 h-10" />
42
- ))}
43
- </div>
44
- </div>
45
-
46
- <div className="flex flex-col justify-center items-center mb-4">
47
- <Skeleton className="w-36 h-4 mb-2" />
48
- <div className="flex items-center gap-2">
49
- {Array(5)
50
- .fill(null)
51
- .map((_, index) => (
52
- <Skeleton key={index} className="w-11 h-11" />
53
- ))}
54
- </div>
55
- </div>
56
-
57
- <Skeleton className="hidden w-full h-14 mb-6 md:block" />
58
- <Skeleton className="w-40 h-10 mb-9 md:w-72" />
59
- <Skeleton className="w-24 h-10 mb-7" />
60
- <Skeleton className="w-full h-36" />
61
- </SkeletonWrapper>
62
- </div>
63
- </div>
64
- </div>
65
- </div>
66
- );
67
- }
@@ -1,106 +0,0 @@
1
- 'use client';
2
-
3
- import { useLocalization } from '@akinon/next/hooks';
4
- import { Basket } from '@akinon/next/types';
5
- import { Button, LoaderSpinner, Link } from '@theme/components';
6
- import { BasketItem, Summary } from '@theme/views/basket';
7
- import { ROUTES } from '@theme/routes';
8
- import PluginModule, { Component } from '@akinon/next/components/plugin-module';
9
- import { useEffect, useState } from 'react';
10
- import { pushCartView } from '@theme/utils/gtm';
11
-
12
- interface BasketContentProps {
13
- initialBasket: Basket;
14
- multiBasket: boolean;
15
- }
16
-
17
- export function BasketContent({
18
- initialBasket,
19
- multiBasket
20
- }: BasketContentProps) {
21
- const { t } = useLocalization();
22
- const [basket, setBasket] = useState<Basket>(initialBasket);
23
-
24
- useEffect(() => {
25
- if (basket) {
26
- const products = basket.basketitem_set.map((basketItem) => ({
27
- ...basketItem.product
28
- }));
29
- pushCartView(products);
30
- }
31
- }, [basket]);
32
-
33
- const handleBasketUpdate = (updatedBasket: Basket) => {
34
- setBasket(updatedBasket);
35
- };
36
-
37
- if (!basket) {
38
- return (
39
- <div className="flex justify-center w-full">
40
- <LoaderSpinner />
41
- </div>
42
- );
43
- }
44
-
45
- return (
46
- <div className="max-w-screen-xl p-4 flex flex-col text-primary-800 lg:p-8 xl:flex-row xl:mx-auto">
47
- {basket.basketitem_set && basket.basketitem_set.length > 0 ? (
48
- <>
49
- <div className="flex-1 xl:mr-16">
50
- <div className="flex items-center justify-between py-2 border-b border-gray-200 lg:py-3">
51
- <h2 className="text-xl lg:text-2xl font-light">
52
- {t('basket.my_cart')}
53
- </h2>
54
- <Link
55
- href={ROUTES.HOME}
56
- className="text-xs hover:text-secondary-500"
57
- >
58
- {t('basket.back_to_shopping')}
59
- </Link>
60
- </div>
61
- <ul>
62
- {multiBasket ? (
63
- <PluginModule
64
- component={Component.MultiBasket}
65
- props={{
66
- BasketItem,
67
- onBasketUpdate: handleBasketUpdate
68
- }}
69
- />
70
- ) : (
71
- basket.basketitem_set.map((basketItem, index) => (
72
- <BasketItem
73
- key={index}
74
- basketItem={basketItem}
75
- onBasketUpdate={handleBasketUpdate}
76
- />
77
- ))
78
- )}
79
- </ul>
80
- </div>
81
- <Summary basket={basket} onBasketUpdate={handleBasketUpdate} />
82
- </>
83
- ) : (
84
- <div className="flex flex-col items-center container max-w-screen-sm py-4 px-4 xs:py-6 xs:px-6 sm:py-8 sm:px-8 lg:max-w-screen-xl">
85
- <h1
86
- className="w-full text-xl font-light text-secondary text-center sm:text-2xl"
87
- data-testid="basket-empty"
88
- >
89
- {t('basket.empty.title')}
90
- </h1>
91
-
92
- <div className="w-full text-sm text-black-800 text-center my-4 mb-2 sm:text-base">
93
- <p>{t('basket.empty.content_first')}</p>
94
- <p>{t('basket.empty.content_second')}.</p>
95
- </div>
96
-
97
- <Link href={ROUTES.HOME} passHref>
98
- <Button className="px-10 mt-2" appearance="filled">
99
- {t('basket.empty.button')}
100
- </Button>
101
- </Link>
102
- </div>
103
- )}
104
- </div>
105
- );
106
- }