@akinon/projectzero 1.102.0 → 1.103.0-rc.81

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 (60) hide show
  1. package/CHANGELOG.md +239 -4
  2. package/app-template/.env.example +1 -0
  3. package/app-template/.github/instructions/routing.instructions.md +603 -0
  4. package/app-template/CHANGELOG.md +5003 -310
  5. package/app-template/README.md +25 -1
  6. package/app-template/package.json +21 -19
  7. package/app-template/public/locales/en/checkout.json +6 -0
  8. package/app-template/public/locales/en/common.json +48 -1
  9. package/app-template/public/locales/tr/checkout.json +6 -0
  10. package/app-template/public/locales/tr/common.json +48 -1
  11. package/app-template/src/app/[commerce]/[locale]/[currency]/basket/page.tsx +9 -82
  12. package/app-template/src/app/[commerce]/[locale]/[currency]/landing-page/[pk]/page.tsx +12 -1
  13. package/app-template/src/app/[commerce]/[locale]/[currency]/product/[pk]/loading.tsx +67 -0
  14. package/app-template/src/app/api/form/[...id]/route.ts +1 -7
  15. package/app-template/src/app/api/image-proxy/route.ts +1 -0
  16. package/app-template/src/app/api/similar-product-list/route.ts +1 -0
  17. package/app-template/src/app/api/similar-products/route.ts +1 -0
  18. package/app-template/src/assets/fonts/pz-icon.css +3 -0
  19. package/app-template/src/components/__tests__/link.test.tsx +2 -0
  20. package/app-template/src/components/accordion.tsx +22 -19
  21. package/app-template/src/components/currency-select.tsx +1 -0
  22. package/app-template/src/components/file-input.tsx +27 -7
  23. package/app-template/src/components/generate-form-fields.tsx +43 -4
  24. package/app-template/src/components/input.tsx +9 -2
  25. package/app-template/src/components/modal.tsx +32 -16
  26. package/app-template/src/components/pagination.tsx +1 -0
  27. package/app-template/src/components/price.tsx +1 -1
  28. package/app-template/src/components/select.tsx +38 -26
  29. package/app-template/src/components/types/index.ts +25 -1
  30. package/app-template/src/hooks/index.ts +2 -0
  31. package/app-template/src/hooks/use-product-cart.ts +77 -0
  32. package/app-template/src/hooks/use-stock-alert.ts +74 -0
  33. package/app-template/src/plugins.js +3 -1
  34. package/app-template/src/settings.js +8 -2
  35. package/app-template/src/types/index.ts +17 -0
  36. package/app-template/src/utils/variant-validation.ts +41 -0
  37. package/app-template/src/views/account/address-form.tsx +8 -4
  38. package/app-template/src/views/account/contact-form.tsx +1 -1
  39. package/app-template/src/views/account/content-header.tsx +2 -2
  40. package/app-template/src/views/account/faq/faq-tabs.tsx +8 -2
  41. package/app-template/src/views/basket/basket-content.tsx +106 -0
  42. package/app-template/src/views/basket/basket-item.tsx +22 -14
  43. package/app-template/src/views/basket/summary.tsx +10 -7
  44. package/app-template/src/views/breadcrumb.tsx +2 -2
  45. package/app-template/src/views/category/category-info.tsx +1 -0
  46. package/app-template/src/views/category/filters/index.tsx +1 -1
  47. package/app-template/src/views/checkout/steps/payment/options/store-credit.tsx +121 -0
  48. package/app-template/src/views/checkout/summary.tsx +10 -0
  49. package/app-template/src/views/guest-login/index.tsx +6 -1
  50. package/app-template/src/views/header/action-menu.tsx +1 -1
  51. package/app-template/src/views/header/search/index.tsx +17 -5
  52. package/app-template/src/views/product/product-actions.tsx +165 -0
  53. package/app-template/src/views/product/product-info.tsx +62 -263
  54. package/app-template/src/views/product/product-share.tsx +56 -0
  55. package/app-template/src/views/product/product-variants.tsx +26 -0
  56. package/app-template/src/views/product/slider.tsx +86 -73
  57. package/app-template/src/widgets/footer-menu.tsx +6 -2
  58. package/commands/plugins.ts +63 -16
  59. package/dist/commands/plugins.js +57 -16
  60. package/package.json +1 -1
@@ -7,6 +7,7 @@ import { useForm } from 'react-hook-form';
7
7
  import { yupResolver } from '@hookform/resolvers/yup';
8
8
  import * as yup from 'yup';
9
9
  import DynamicForm from './dynamic-form';
10
+
10
11
  import {
11
12
  AllFieldClassesType,
12
13
  FieldPropertiesType,
@@ -14,6 +15,7 @@ import {
14
15
  FormPropertiesType,
15
16
  Schema
16
17
  } from '@akinon/next/types';
18
+ import { useLocalization } from '@akinon/next/hooks';
17
19
 
18
20
  export function GenerateFormFields({
19
21
  schema,
@@ -28,8 +30,14 @@ export function GenerateFormFields({
28
30
  formProperties: FormPropertiesType;
29
31
  submitButtonText: string;
30
32
  }) {
33
+ const { t } = useLocalization();
31
34
  const [fields, setFields] = useState([]);
32
35
  const [loading, setIsLoading] = useState(true);
36
+ const [isSubmitting, setIsSubmitting] = useState(false);
37
+ const [submitStatus, setSubmitStatus] = useState<
38
+ 'idle' | 'success' | 'error'
39
+ >('idle');
40
+ const [submitMessage, setSubmitMessage] = useState('');
33
41
 
34
42
  const generateValidationSchema = () => {
35
43
  const schemaObject = {};
@@ -80,6 +88,7 @@ export function GenerateFormFields({
80
88
  const {
81
89
  handleSubmit,
82
90
  register,
91
+ reset,
83
92
  formState: { errors }
84
93
  } = useForm<FormField>({
85
94
  resolver: yupResolver(generateValidationSchema())
@@ -108,6 +117,10 @@ export function GenerateFormFields({
108
117
  }, [schema, fieldProperties]);
109
118
 
110
119
  const onSubmit = async (data) => {
120
+ setIsSubmitting(true);
121
+ setSubmitStatus('idle');
122
+ setSubmitMessage('');
123
+
111
124
  try {
112
125
  const formData = new FormData();
113
126
 
@@ -115,12 +128,25 @@ export function GenerateFormFields({
115
128
  formData.append(key, data[key]);
116
129
  });
117
130
 
118
- fetch(formProperties.actionUrl, {
131
+ const response = await fetch(formProperties.actionUrl, {
119
132
  method: 'POST',
120
133
  body: formData
121
134
  });
135
+
136
+ if (response.ok) {
137
+ setSubmitStatus('success');
138
+ setSubmitMessage(t('common.forms.success'));
139
+ reset();
140
+ } else {
141
+ setSubmitStatus('error');
142
+ setSubmitMessage(t('common.forms.error'));
143
+ }
122
144
  } catch (error) {
123
- console.error('Form submit error:', error);
145
+ console.error(t('common.forms.submit_error'), error);
146
+ setSubmitStatus('error');
147
+ setSubmitMessage(t('common.forms.error'));
148
+ } finally {
149
+ setIsSubmitting(false);
124
150
  }
125
151
  };
126
152
 
@@ -337,9 +363,22 @@ export function GenerateFormFields({
337
363
  <LoaderSpinner />
338
364
  ) : (
339
365
  <>
366
+ {submitStatus === 'success' && (
367
+ <div className="mb-4 p-3 bg-green-100 border border-green-400 text-green-700 rounded">
368
+ {submitMessage}
369
+ </div>
370
+ )}
371
+
372
+ {submitStatus === 'error' && (
373
+ <div className="mb-4 p-3 bg-red-100 border border-red-400 text-red-700 rounded">
374
+ {submitMessage}
375
+ </div>
376
+ )}
377
+
340
378
  {fields.map((field: FormField) => generateField(field))}
341
- <Button type="submit" className="w-full">
342
- {submitButtonText}
379
+
380
+ <Button type="submit" className="w-full" disabled={isSubmitting}>
381
+ {isSubmitting ? t('common.forms.sending') : submitButtonText}
343
382
  </Button>
344
383
  </>
345
384
  )}
@@ -48,7 +48,13 @@ export const Input = forwardRef<
48
48
  props.className
49
49
  );
50
50
 
51
- const inputProps: any = {
51
+ const inputProps: {
52
+ id?: string;
53
+ ref?: Ref<HTMLInputElement>;
54
+ className?: string;
55
+ onFocus?: () => void;
56
+ onBlur?: (event: FocusEvent<HTMLInputElement>) => void;
57
+ } = {
52
58
  id,
53
59
  ref,
54
60
  className: inputClass,
@@ -72,7 +78,8 @@ export const Input = forwardRef<
72
78
  hasFloatingLabel,
73
79
  'mb-2': !hasFloatingLabel,
74
80
  '-translate-y-2 bg-white inline-flex h-auto':
75
- hasFloatingLabel && (focused || hasValue)
81
+ hasFloatingLabel &&
82
+ (focused || hasValue || props.value || props.format)
76
83
  })
77
84
  )}
78
85
  >
@@ -4,16 +4,7 @@ import ReactPortal from './react-portal';
4
4
  import { Icon } from './icon';
5
5
  import { twMerge } from 'tailwind-merge';
6
6
  import { useEffect } from 'react';
7
-
8
- export interface ModalProps {
9
- portalId: string;
10
- children?: React.ReactNode;
11
- open?: boolean;
12
- setOpen?: (open: boolean) => void;
13
- title?: React.ReactNode;
14
- showCloseButton?: React.ReactNode;
15
- className?: string;
16
- }
7
+ import { ModalProps } from '@theme/types';
17
8
 
18
9
  export const Modal = (props: ModalProps) => {
19
10
  const {
@@ -23,7 +14,14 @@ export const Modal = (props: ModalProps) => {
23
14
  setOpen,
24
15
  title = '',
25
16
  showCloseButton = true,
26
- className
17
+ className,
18
+ overlayClassName,
19
+ headerWrapperClassName,
20
+ titleClassName,
21
+ closeButtonClassName,
22
+ iconName = 'close',
23
+ iconSize = 16,
24
+ iconClassName
27
25
  } = props;
28
26
 
29
27
  useEffect(() => {
@@ -38,7 +36,12 @@ export const Modal = (props: ModalProps) => {
38
36
 
39
37
  return (
40
38
  <ReactPortal wrapperId={portalId}>
41
- <div className="fixed top-0 left-0 w-screen h-screen bg-primary bg-opacity-60 z-50" />
39
+ <div
40
+ className={twMerge(
41
+ 'fixed top-0 left-0 w-screen h-screen bg-primary bg-opacity-60 z-50',
42
+ overlayClassName
43
+ )}
44
+ />
42
45
  <section
43
46
  className={twMerge(
44
47
  'fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-50 bg-white',
@@ -46,15 +49,28 @@ export const Modal = (props: ModalProps) => {
46
49
  )}
47
50
  >
48
51
  {(showCloseButton || title) && (
49
- <div className="flex px-6 py-4 border-b border-gray-400">
50
- {title && <h3 className="text-lg font-light">{title}</h3>}
52
+ <div
53
+ className={twMerge(
54
+ 'flex px-6 py-4 border-b border-gray-400',
55
+ headerWrapperClassName
56
+ )}
57
+ >
58
+ {title && (
59
+ <h3 className={twMerge('text-lg font-light', titleClassName)}>
60
+ {title}
61
+ </h3>
62
+ )}
51
63
  {showCloseButton && (
52
64
  <button
53
65
  type="button"
54
66
  onClick={() => setOpen(false)}
55
- className="ml-auto"
67
+ className={twMerge('ml-auto', closeButtonClassName)}
56
68
  >
57
- <Icon name="close" size={16} />
69
+ <Icon
70
+ name={iconName}
71
+ size={iconSize}
72
+ className={iconClassName}
73
+ />
58
74
  </button>
59
75
  )}
60
76
  </div>
@@ -125,6 +125,7 @@ export const Pagination = (props: PaginationProps) => {
125
125
  setPrevPage(1);
126
126
  setNextPage(1);
127
127
  }
128
+ // eslint-disable-next-line react-hooks/exhaustive-deps
128
129
  }, [page]);
129
130
 
130
131
  useEffect(() => {
@@ -56,7 +56,7 @@ export const Price = (props: NumericFormatProps & PriceProps) => {
56
56
 
57
57
  const currentCurrencyDecimalScale = Settings.localization.currencies.find(
58
58
  (currency) => currency.code === currencyCode_
59
- ).decimalScale;
59
+ )?.decimalScale;
60
60
 
61
61
  return (
62
62
  <NumericFormat
@@ -14,14 +14,18 @@ const Select = forwardRef<HTMLSelectElement, SelectProps>((props, ref) => {
14
14
  error,
15
15
  label,
16
16
  required = false,
17
+ labelClassName,
17
18
  ...rest
18
19
  } = props;
19
20
 
20
21
  return (
21
22
  <label
22
- className={clsx('flex flex-col relative text-xs text-gray-800', {
23
- 'pl-7': icon
24
- })}
23
+ className={twMerge(
24
+ clsx('flex flex-col relative text-xs text-gray-800', {
25
+ 'pl-7': icon
26
+ }),
27
+ labelClassName
28
+ )}
25
29
  >
26
30
  {icon && (
27
31
  <Icon
@@ -32,32 +36,40 @@ const Select = forwardRef<HTMLSelectElement, SelectProps>((props, ref) => {
32
36
  )}
33
37
 
34
38
  {label && (
35
- <span className="mb-1">
39
+ <span className={twMerge('mb-1', labelClassName)}>
36
40
  {label} {required && <span className="text-secondary">*</span>}
37
41
  </span>
38
42
  )}
39
- <select
40
- {...rest}
41
- ref={ref}
42
- className={twMerge(
43
- clsx(
44
- 'cursor-pointer truncate h-10 w-40 px-2.5 shrink-0 outline-none',
45
- !borderless &&
46
- 'border border-gray-200 transition-all duration-150 hover:border-primary'
47
- ),
48
- className
49
- )}
50
- >
51
- {options?.map((option) => (
52
- <option
53
- key={option.value}
54
- value={option.value}
55
- className={option.class}
56
- >
57
- {option.label}
58
- </option>
59
- ))}
60
- </select>
43
+ <div className="relative">
44
+ <select
45
+ {...rest}
46
+ ref={ref}
47
+ className={twMerge(
48
+ clsx(
49
+ 'cursor-pointer truncate h-10 w-40 px-2.5 shrink-0 outline-none',
50
+ !borderless &&
51
+ 'border border-gray-200 transition-all duration-150 hover:border-primary',
52
+ 'appearance-none bg-transparent'
53
+ ),
54
+ className
55
+ )}
56
+ >
57
+ {options?.map((option) => (
58
+ <option
59
+ key={option.value}
60
+ value={option.value}
61
+ className={option.class}
62
+ >
63
+ {option.label}
64
+ </option>
65
+ ))}
66
+ </select>
67
+ <div className="pointer-events-none absolute inset-y-0 right-0 flex items-center px-2 text-gray-700">
68
+ <svg className="h-4 w-4 fill-current" viewBox="0 0 20 20">
69
+ <path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z" />
70
+ </svg>
71
+ </div>
72
+ </div>
61
73
  {error && (
62
74
  <span className="mt-1 text-sm text-error">{error.message}</span>
63
75
  )}
@@ -29,7 +29,13 @@ export interface PaginationProps {
29
29
  isLoading?: boolean;
30
30
  }
31
31
 
32
- export type FileInputProps = React.HTMLProps<HTMLInputElement>;
32
+ export interface FileInputProps extends React.HTMLProps<HTMLInputElement> {
33
+ fileClassName?: string;
34
+ fileNameWrapperClassName?: string;
35
+ fileInputClassName?: string;
36
+ onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
37
+ buttonClassName?: string;
38
+ }
33
39
 
34
40
  export type RadioProps = React.HTMLProps<HTMLInputElement>;
35
41
 
@@ -58,6 +64,7 @@ export interface SelectProps extends React.HTMLProps<HTMLSelectElement> {
58
64
  iconSize?: number;
59
65
  error?: FieldError | undefined;
60
66
  required?: boolean;
67
+ labelClassName?: string;
61
68
  }
62
69
  export interface IconProps extends React.ComponentPropsWithRef<'i'> {
63
70
  name: string;
@@ -91,3 +98,20 @@ export interface BadgeProps {
91
98
  children: ReactNode;
92
99
  className?: string;
93
100
  }
101
+
102
+ export type AccordionProps = {
103
+ isCollapse?: boolean;
104
+ collapseClassName?: string;
105
+ title?: string;
106
+ subTitle?: string;
107
+ icons?: string[];
108
+ iconSize?: number;
109
+ iconColor?: string;
110
+ children?: ReactNode;
111
+ headerClassName?: string;
112
+ className?: string;
113
+ titleClassName?: string;
114
+ subTitleClassName?: string;
115
+ dataTestId?: string;
116
+ contentClassName?: string;
117
+ };
@@ -1 +1,3 @@
1
+ export * from './use-contract';
2
+ export * from './use-fav-button';
1
3
  export * from './use-add-product-to-basket';
@@ -0,0 +1,77 @@
1
+ import { useState } from 'react';
2
+ import { useAddProductToBasket } from './index';
3
+ import { pushAddToCart } from '@theme/utils/gtm';
4
+ import { validateVariantSelection } from '../utils/variant-validation';
5
+ import { VariantType } from '@akinon/next/types';
6
+
7
+ interface Product {
8
+ pk: number;
9
+ [key: string]: any;
10
+ }
11
+
12
+ interface UseProductCartProps {
13
+ product: Product;
14
+ variants: VariantType[];
15
+ }
16
+
17
+ interface AddToCartError {
18
+ data?: {
19
+ non_field_errors?: string[];
20
+ [key: string]: string[];
21
+ };
22
+ }
23
+
24
+ export const useProductCart = ({ product, variants }: UseProductCartProps) => {
25
+ const [productError, setProductError] = useState<React.ReactNode | null>(null);
26
+ const [addProduct, { isLoading: isAddToCartLoading }] = useAddProductToBasket();
27
+
28
+ const formatError = (error: AddToCartError) => {
29
+ if (error?.data?.non_field_errors) {
30
+ return error.data.non_field_errors;
31
+ }
32
+
33
+ if (error?.data) {
34
+ return Object.keys(error.data).map(
35
+ (key) => `${key}: ${error.data[key].join(', ')}`
36
+ );
37
+ }
38
+
39
+ return 'An error occurred';
40
+ };
41
+
42
+ const addProductToCart = async () => {
43
+ const validation = validateVariantSelection(variants);
44
+
45
+ if (!validation.isValid) {
46
+ setProductError(validation.errorMessage);
47
+ return false;
48
+ }
49
+
50
+ try {
51
+ await addProduct({
52
+ product: product.pk,
53
+ quantity: 1,
54
+ attributes: {}
55
+ });
56
+
57
+ pushAddToCart(product);
58
+ setProductError(null);
59
+ return true;
60
+ } catch (error) {
61
+ const formattedError = formatError(error as AddToCartError);
62
+ setProductError(formattedError);
63
+ return false;
64
+ }
65
+ };
66
+
67
+ const clearProductError = () => {
68
+ setProductError(null);
69
+ };
70
+
71
+ return {
72
+ addProductToCart,
73
+ productError,
74
+ clearProductError,
75
+ isAddToCartLoading
76
+ };
77
+ };
@@ -0,0 +1,74 @@
1
+ import React, { useState } from 'react';
2
+ import { useAddStockAlertMutation } from '@akinon/next/data/client/wishlist';
3
+ import { Trans } from '@akinon/next/components/trans';
4
+ import { useLocalization } from '@akinon/next/hooks';
5
+
6
+ interface UseStockAlertProps {
7
+ productPk: number;
8
+ userEmail?: string;
9
+ }
10
+
11
+ export const useStockAlert = ({ productPk, userEmail }: UseStockAlertProps) => {
12
+ const { t } = useLocalization();
13
+ const [isModalOpen, setIsModalOpen] = useState(false);
14
+ const [stockAlertResponseMessage, setStockAlertResponseMessage] = useState<React.ReactNode | null>(null);
15
+ const [productError, setProductError] = useState<React.ReactNode | null>(null);
16
+
17
+ const [addStockAlert, { isLoading: isAddToStockAlertLoading }] = useAddStockAlertMutation();
18
+
19
+ const handleSuccess = () => {
20
+ setStockAlertResponseMessage(React.createElement(
21
+ Trans,
22
+ {
23
+ i18nKey: "product.stock_alert.success_description",
24
+ components: {
25
+ Email: React.createElement('span', {}, userEmail)
26
+ }
27
+ }
28
+ ));
29
+ setIsModalOpen(true);
30
+ setProductError(null);
31
+ };
32
+
33
+ const handleError = (err: any) => {
34
+ if (err.status !== 401) {
35
+ setStockAlertResponseMessage(
36
+ t('product.stock_alert.error_description').toString()
37
+ );
38
+ setIsModalOpen(true);
39
+ }
40
+ };
41
+
42
+ const addProductToStockAlertList = async () => {
43
+ try {
44
+ await addStockAlert({
45
+ productPk,
46
+ email: userEmail
47
+ })
48
+ .unwrap()
49
+ .then(handleSuccess)
50
+ .catch(handleError);
51
+ } catch (error: any) {
52
+ setProductError(error?.data?.non_field_errors || null);
53
+ }
54
+ };
55
+
56
+ const closeModal = () => {
57
+ setIsModalOpen(false);
58
+ };
59
+
60
+ const clearError = () => {
61
+ setProductError(null);
62
+ };
63
+
64
+ return {
65
+ addProductToStockAlertList,
66
+ isModalOpen,
67
+ setIsModalOpen,
68
+ stockAlertResponseMessage,
69
+ productError,
70
+ isAddToStockAlertLoading,
71
+ closeModal,
72
+ clearError
73
+ };
74
+ };
@@ -14,5 +14,7 @@ module.exports = [
14
14
  'pz-akifast',
15
15
  'pz-saved-card',
16
16
  'pz-tabby-extension',
17
- 'pz-tamara-extension'
17
+ 'pz-tamara-extension',
18
+ 'pz-hepsipay',
19
+ 'pz-similar-products'
18
20
  ];
@@ -1,6 +1,10 @@
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
+
4
8
  const commerceUrl = encodeURI(process.env.SERVICE_BACKEND_URL ?? 'default');
5
9
 
6
10
  /** @type {import('@akinon/next/types').Settings} */
@@ -14,6 +18,7 @@ module.exports = {
14
18
  { translationKey: 'size', key: 'size' }
15
19
  ],
16
20
  localization: {
21
+ // If there is one locale in the locales array, the default locale will be hidden in the URL.
17
22
  locales: [
18
23
  {
19
24
  label: 'EN',
@@ -41,7 +46,7 @@ module.exports = {
41
46
  }
42
47
  ],
43
48
  defaultLocaleValue: 'en',
44
- localeUrlStrategy: LocaleUrlStrategy.HideDefaultLocale,
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.
45
50
  redirectToDefaultLocale: true,
46
51
  defaultCurrencyCode: 'usd'
47
52
  },
@@ -62,5 +67,6 @@ module.exports = {
62
67
  redis: {
63
68
  defaultExpirationTime: 900 // 15 min
64
69
  },
65
- customNotFoundEnabled: false
70
+ customNotFoundEnabled: false,
71
+ commerceRedirectionIgnoreList: ['/users/reset']
66
72
  };
@@ -125,3 +125,20 @@ export interface SeoProps {
125
125
  ogPriceAmount?: string;
126
126
  ogPriceCurrency?: string;
127
127
  }
128
+
129
+ export interface ModalProps {
130
+ portalId: string;
131
+ children?: React.ReactNode;
132
+ open?: boolean;
133
+ setOpen?: (open: boolean) => void;
134
+ title?: React.ReactNode;
135
+ showCloseButton?: React.ReactNode;
136
+ className?: string;
137
+ overlayClassName?: string;
138
+ headerWrapperClassName?: string;
139
+ titleClassName?: string;
140
+ closeButtonClassName?: string;
141
+ iconName?: string;
142
+ iconSize?: number;
143
+ iconClassName?: string;
144
+ }
@@ -0,0 +1,41 @@
1
+ import React from 'react';
2
+ import { Trans } from '@akinon/next/components/trans';
3
+ import { VariantType } from '@akinon/next/types';
4
+
5
+ export const isVariantSelectionComplete = (variants: VariantType[]): boolean => {
6
+ return variants?.every((variant) =>
7
+ variant?.options.some((opt) => opt.is_selected)
8
+ );
9
+ };
10
+
11
+ export const getUnselectedVariant = (variants: VariantType[]): VariantType | undefined => {
12
+ return variants.find((variant) =>
13
+ variant.options.every((opt) => !opt.is_selected)
14
+ );
15
+ };
16
+
17
+ export const createVariantErrorMessage = (unselectedVariant: VariantType) => {
18
+ const TransComponent = Trans as any;
19
+ return React.createElement(
20
+ TransComponent,
21
+ {
22
+ i18nKey: "product.please_select_variant",
23
+ components: {
24
+ VariantName: React.createElement('span', {}, unselectedVariant.attribute_name)
25
+ }
26
+ }
27
+ );
28
+ };
29
+
30
+ export const validateVariantSelection = (variants: VariantType[]) => {
31
+ const unselectedVariant = getUnselectedVariant(variants);
32
+
33
+ if (unselectedVariant) {
34
+ return {
35
+ isValid: false,
36
+ errorMessage: createVariantErrorMessage(unselectedVariant)
37
+ };
38
+ }
39
+
40
+ return { isValid: true, errorMessage: null };
41
+ };
@@ -259,23 +259,25 @@ export const AddressForm = (props: Props) => {
259
259
  {/* TODO: Fix select and textarea components */}
260
260
 
261
261
  <Select
262
- className="w-full border-gray-500 text-sm mt-2"
262
+ className="w-full border-gray-500 text-sm"
263
263
  options={countryOptions}
264
264
  {...register('country')}
265
265
  error={errors.country}
266
266
  data-testid="address-form-country"
267
267
  label={t('account.address_book.form.country.title')}
268
+ labelClassName="mb-3"
268
269
  required
269
270
  />
270
271
 
271
272
  {city && (
272
273
  <Select
273
- className="w-full border-gray-500 text-sm mt-2"
274
+ className="w-full border-gray-500 text-sm"
274
275
  options={cityOptions}
275
276
  {...register('city')}
276
277
  error={errors.city}
277
278
  data-testid="address-form-city"
278
279
  label={t('account.address_book.form.province.title')}
280
+ labelClassName="mb-3"
279
281
  required
280
282
  />
281
283
  )}
@@ -283,24 +285,26 @@ export const AddressForm = (props: Props) => {
283
285
  <div className="flex gap-4">
284
286
  <div className="flex-1">
285
287
  <Select
286
- className="w-full border-gray-500 text-sm mt-2"
288
+ className="w-full border-gray-500 text-sm"
287
289
  options={townshipOptions}
288
290
  {...register('township')}
289
291
  error={errors.township}
290
292
  data-testid="address-form-township"
291
293
  label={t('account.address_book.form.township.title')}
294
+ labelClassName="mb-3"
292
295
  required
293
296
  />
294
297
  </div>
295
298
  {district && (
296
299
  <div className="flex-1">
297
300
  <Select
298
- className="w-full border-gray-500 text-sm mt-2"
301
+ className="w-full border-gray-500 text-sm"
299
302
  options={districtOptions}
300
303
  {...register('district')}
301
304
  error={errors.district}
302
305
  data-testid="address-form-district"
303
306
  label={t('account.address_book.form.district.title')}
307
+ labelClassName="mb-3"
304
308
  required
305
309
  />
306
310
  </div>