@akinon/projectzero 1.73.0-rc.9 → 1.73.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.
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
 
3
- import React, { useMemo } from 'react';
3
+ import React, { useMemo, useCallback } from 'react';
4
4
  import { VariantOption, VariantType } from '@akinon/next/types';
5
5
  import { usePathname, useSearchParams } from 'next/navigation';
6
6
  import clsx from 'clsx';
@@ -12,20 +12,23 @@ type VariantProps = {
12
12
  preventDefaultClick?: boolean;
13
13
  } & VariantType;
14
14
 
15
- export const Variant = (props: VariantProps) => {
15
+ export const Variant = ({
16
+ attribute_key,
17
+ attribute_name,
18
+ options,
19
+ preventDefaultClick,
20
+ onChange,
21
+ className
22
+ }: VariantProps) => {
16
23
  const { t } = useLocalization();
17
- const {
18
- attribute_key,
19
- attribute_name,
20
- options,
21
- preventDefaultClick,
22
- onChange
23
- } = props;
24
24
  const router = useRouter();
25
25
  const pathname = usePathname();
26
26
  const searchParams = useSearchParams();
27
27
  // This is a workaround for the fact that we can't use the useSearchParams set method because of this is not implemented in next.js yet. So we have to use the URLSearchParams's set method.
28
- const params = new URLSearchParams(searchParams.toString());
28
+ const params = useMemo(
29
+ () => new URLSearchParams(searchParams.toString()),
30
+ [searchParams]
31
+ );
29
32
 
30
33
  const hasSelected = useMemo(
31
34
  () => options.some((option) => option.is_selected),
@@ -37,22 +40,23 @@ export const Variant = (props: VariantProps) => {
37
40
  [options]
38
41
  );
39
42
 
40
- const handleClick = (option: VariantOption) => {
41
- if (onChange) {
42
- onChange(option);
43
- }
43
+ const handleClick = useCallback(
44
+ (option: VariantOption) => {
45
+ if (onChange) {
46
+ onChange(option);
47
+ }
44
48
 
45
- if (preventDefaultClick) {
46
- return;
47
- }
49
+ if (preventDefaultClick) return;
48
50
 
49
- params.set(attribute_key, option.value);
50
- router.push(`${pathname}?${params.toString()}`);
51
- };
51
+ params.set(attribute_key, option.value);
52
+ router.push(`${pathname}?${params.toString()}`);
53
+ },
54
+ [onChange, preventDefaultClick, params, attribute_key, pathname, router]
55
+ );
52
56
 
53
57
  return (
54
58
  <div
55
- className={clsx('flex flex-col gap-2', props.className)}
59
+ className={clsx('flex flex-col gap-2', className)}
56
60
  data-testid={`product-variant-${attribute_name}`}
57
61
  >
58
62
  <p className="flex gap-2 text-xs leading-4">
@@ -66,30 +70,27 @@ export const Variant = (props: VariantProps) => {
66
70
  className="font-bold"
67
71
  data-testid={`product-variant-${attribute_name}-value`}
68
72
  >
69
- {selectedVariant.value}
73
+ {selectedVariant?.value}
70
74
  </span>
71
75
  )}
72
76
  </p>
73
77
  <div className="flex gap-3 flex-wrap justify-center">
74
78
  {options.map((option, i) => (
75
79
  <button
76
- key={i}
80
+ key={`${i}-${option.value}`}
77
81
  className={clsx(
78
82
  'h-10 px-4 transition-colors duration-200 text-xs',
79
- option.is_selected &&
80
- 'bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground pointer-events-none',
81
- option.is_selectable &&
82
- !option.is_selected &&
83
- 'bg-gray-200 hover:bg-gray-400',
84
- !option.is_selectable &&
85
- !option.is_selected &&
86
- 'border border-gray-300 text-gray-600',
87
- !option.is_selectable &&
88
- !option.is_selectable_without_stock &&
89
- 'border border-gray-300 text-gray-600 cursor-not-allowed',
90
- !option.is_selectable &&
91
- option.is_selected &&
92
- 'border border-dashed border-black bg-white text-gray-600 overflow-hidden relative'
83
+ {
84
+ 'bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground pointer-events-none':
85
+ option.is_selected,
86
+ 'bg-gray-200 hover:bg-gray-400':
87
+ option.is_selectable && !option.is_selected,
88
+ 'border border-gray-300 text-gray-600': !option.is_selectable,
89
+ 'cursor-not-allowed':
90
+ !option.is_selectable && !option.is_selectable_without_stock,
91
+ 'border border-dashed border-black bg-white text-gray-600 overflow-hidden relative':
92
+ !option.is_selectable && option.is_selected
93
+ }
93
94
  )}
94
95
  onClick={() => handleClick(option)}
95
96
  >
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akinon/projectzero",
3
- "version": "1.73.0-rc.9",
3
+ "version": "1.73.0",
4
4
  "private": false,
5
5
  "description": "CLI tool to manage your Project Zero Next project",
6
6
  "bin": {
@@ -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
- }