@weareconceptstudio/account 0.6.1 → 0.6.3

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.
@@ -4,7 +4,7 @@ import { useCart } from '../../modules';
4
4
  //* Style
5
5
  import AccountCounterStyle from './style';
6
6
  const AccountCounter = ({ productId, qty = 1, isGift, maxQty, promotionId }) => {
7
- const { toggleCartItem, items, setCheckGift } = useCart();
7
+ const { toggleCartItem, items, setGifts } = useCart();
8
8
  //! State
9
9
  const [count, setCount] = useState(qty);
10
10
  useEffect(() => {
@@ -21,7 +21,7 @@ const AccountCounter = ({ productId, qty = 1, isGift, maxQty, promotionId }) =>
21
21
  e.stopPropagation();
22
22
  const newCount = type == 'inc' ? count + 1 : count - 1;
23
23
  setCount(newCount);
24
- isGift ? setCheckGift({ promotionId, qty: newCount, productId }) : debouncedUpdateCartServer(newCount);
24
+ isGift ? setGifts({ promotionId, qty: newCount, productId }) : debouncedUpdateCartServer(newCount);
25
25
  };
26
26
  return (React.createElement(AccountCounterStyle, { onClick: (e) => e.stopPropagation(), className: `counter-block ${count == 0 ? 'opacity-zero pointer-none' : ''}` },
27
27
  React.createElement("div", { className: 'counter' },
@@ -6,6 +6,5 @@ export declare const balanceFields: {
6
6
  };
7
7
  fieldProps: {
8
8
  placeholder: string;
9
- type: string;
10
9
  };
11
10
  }[];
@@ -1,13 +1,12 @@
1
1
  export const balanceFields = [
2
2
  {
3
- fieldType: 'input',
3
+ fieldType: 'number',
4
4
  labelProps: {
5
5
  name: 'balance',
6
6
  errorKey: 'account.balance_promotions.balance',
7
7
  },
8
8
  fieldProps: {
9
9
  placeholder: 'account.balance_promotions.balancePlaceholder',
10
- type: 'number',
11
10
  },
12
11
  },
13
12
  ];
@@ -1,5 +1,7 @@
1
1
  export default AppliedPromotion;
2
- declare function AppliedPromotion({ name }: {
2
+ declare function AppliedPromotion({ name, onClick, isExcluded }: {
3
3
  name: any;
4
+ onClick: any;
5
+ isExcluded?: boolean;
4
6
  }): React.JSX.Element;
5
7
  import React from 'react';
@@ -1,11 +1,8 @@
1
1
  import React from 'react';
2
2
  import { Text } from '@weareconceptstudio/core';
3
- const AppliedPromotion = ({ name }) => {
3
+ const AppliedPromotion = ({ name, onClick, isExcluded = false }) => {
4
4
  return (React.createElement("div", { className: `promo-code-success-block` },
5
5
  React.createElement(Text, { className: 'account-p account-p4 account-primary-color2 account-font-medium promo-code-success-text' }, name),
6
- React.createElement(Text, { text: 'account.general_actions.remove', className: 'account-p account-p4 account-primary-color2 account-font-medium promo-code-remove-text', onClick: () => {
7
- // promotionHandler(null);
8
- // setDisable(false);
9
- } })));
6
+ React.createElement(Text, { text: isExcluded ? 'account.general_actions.restore' : 'account.general_actions.remove', className: 'account-p account-p4 account-primary-color2 account-font-medium promo-code-remove-text', onClick: onClick })));
10
7
  };
11
8
  export default AppliedPromotion;
@@ -8,16 +8,13 @@ import { promoCodeFields } from './utils';
8
8
  //* Style
9
9
  import PromoCodeCompStyle from './style';
10
10
  const PromoCodeComp = () => {
11
- const { itemsCount, usePromotion, appliedPromotions, fillCart } = useCart();
12
- const handlePromotion = (promotion) => {
13
- fillCart('usePromotion', promotion);
14
- };
11
+ const { itemsCount, appliedPromotions, fillCart, togglePromotion, checkoutData } = useCart();
15
12
  const onFinish = (values) => {
16
- handlePromotion(values.promo_code);
13
+ fillCart('promotion_code', values?.promo_code || null);
17
14
  };
18
15
  const promotions = useMemo(() => {
19
- return appliedPromotions?.map((promotion, index) => (React.createElement(AppliedPromotion, { key: index, ...promotion })));
20
- }, [appliedPromotions]);
16
+ return appliedPromotions?.map((promotion) => (React.createElement(AppliedPromotion, { key: promotion.id, ...promotion, isExcluded: checkoutData?.excludedPromotions?.includes(promotion.id), onClick: () => (promotion.is_manual ? onFinish(null) : togglePromotion({ promotionId: promotion.id })) })));
17
+ }, [appliedPromotions, checkoutData.excludedPromotions]);
21
18
  return (React.createElement(PromoCodeCompStyle, { className: `collapse-distance ${itemsCount ? '' : 'disable'}` },
22
19
  React.createElement(CollapseItem, { status: appliedPromotions?.length ? 'open' : 'close', title: React.createElement(React.Fragment, null,
23
20
  React.createElement("div", { className: 'inner-wrapper-icon' },
@@ -26,9 +23,9 @@ const PromoCodeComp = () => {
26
23
  React.createElement("path", { d: 'M6 12L6 0', stroke: 'black', strokeWidth: '2' }))),
27
24
  React.createElement(Text, { className: 'account-p account-p4 account-primary-color1 account-font-medium promo-code-text', text: 'account.balance_promotions.gotPromotionCode' })), description: React.createElement(React.Fragment, null,
28
25
  promotions,
29
- usePromotion ? (React.createElement(AppliedPromotion, { name: usePromotion, onClick: () => handlePromotion(null) })) : (React.createElement(FormBuilder, { onSubmit: onFinish, fields: promoCodeFields, className: `promo-code-block`, formOptions: {
26
+ !checkoutData.promotion_code ? (React.createElement(FormBuilder, { onSubmit: onFinish, fields: promoCodeFields, className: `promo-code-block`, formOptions: {
30
27
  className: 'promo-code-container',
31
28
  } },
32
- React.createElement(AccountButton, { type: 'submit', btnType: `promo-code-version`, text: `account.general_actions.add` })))) })));
29
+ React.createElement(AccountButton, { type: 'submit', btnType: `promo-code-version`, text: `account.general_actions.add` }))) : null) })));
33
30
  };
34
31
  export default PromoCodeComp;
@@ -8,7 +8,7 @@ export const useAddressContext = () => {
8
8
  };
9
9
  export const AddressProvider = ({ addressType, addressFormFields = [], useUser, children }) => {
10
10
  const { isLoggedIn } = useUser();
11
- const { fillCheckoutData, fillCart, isCheckoutPage } = useCart();
11
+ const { fillCheckoutData, fillCart, isCheckoutPage, checkoutData } = useCart();
12
12
  const [addressLoading, setAddressLoading] = useState(false);
13
13
  const [addresses, setAddresses] = useState(addressType ? { billing: [], shipping: [] } : []);
14
14
  const [selectedAddresses, setSelectedAddresses] = useState(addressType ? { billing: {}, shipping: {} } : {});
@@ -35,6 +35,14 @@ export const AddressProvider = ({ addressType, addressFormFields = [], useUser,
35
35
  });
36
36
  }
37
37
  }, [isLoggedIn]);
38
+ useEffect(() => {
39
+ if (checkoutData?.addressId) {
40
+ let storageSelectedAddress = addresses.find((item) => item.id == checkoutData.addressId);
41
+ if (storageSelectedAddress) {
42
+ setSelectedAddresses(storageSelectedAddress);
43
+ }
44
+ }
45
+ }, [checkoutData?.addressId, addresses]);
38
46
  const createAddress = async ({ data, type }) => {
39
47
  return await api.post('addresses', data).then((res) => {
40
48
  if (addressType) {
@@ -5,10 +5,10 @@ import { useAccountContext } from '../../../../AccountProvider';
5
5
  import { useCart } from '../../CartProvider';
6
6
  import { defaultIconGift } from '../util';
7
7
  const Item = memo(({ data, remove, select, isLast, actions, isCheckout }) => {
8
- const { checkoutData, setCheckGift } = useCart();
8
+ const { checkoutData, setGifts } = useCart();
9
9
  const { currency, handleProductClick } = useAccountContext();
10
10
  const { translate } = useTranslation();
11
- return !isCheckout || checkoutData.checkGift.find((item) => item.promotionId == data.appliedPromotion?.id && item.id == data.product.id)?.qty !== 0 ? (React.createElement("div", { className: `item-wrap user-select-none` },
11
+ return !isCheckout || checkoutData.gifts.find((item) => item.promotionId == data.appliedPromotion?.id && item.productId == data.product.id)?.qty !== 0 ? (React.createElement("div", { className: `item-wrap user-select-none` },
12
12
  React.createElement("div", { className: 'line' }),
13
13
  React.createElement("div", { className: `item-inner-wrapper` },
14
14
  React.createElement("div", { className: `col-item tl-col-1 col-item-1` },
@@ -27,10 +27,10 @@ const Item = memo(({ data, remove, select, isLast, actions, isCheckout }) => {
27
27
  "\u00A0",
28
28
  React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color1`, text: data.size }))) : data.product.short_info_2 ? (React.createElement("div", { className: `right-second-item-wrap` },
29
29
  React.createElement(Text, { className: `account-p account-p3 account-font-bold account-primary-color1`, text: data.product.short_info_2 }))) : null)),
30
- React.createElement("div", { className: `col-item tl-col-2` }, select && !data.is_gift ? (React.createElement("div", { className: `select-and-out-of-stock-wrap` }, !data.product.out_of_stock ? (React.createElement(AccountCounter, { productId: data.product.id })) : (React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color1`, text: 'account.general_actions.outOfStock' })))) : data.is_gift && !isCheckout ? (React.createElement("div", { className: 'wrapper-gift-button' }, checkoutData.checkGift.find((item) => item.promotionId == data.appliedPromotion.id && item.id == data.product.id)?.qty !== 0 ? (React.createElement(React.Fragment, null,
31
- React.createElement(AccountCounter, { maxQty: data?.qty, productId: data.product.id, promotionId: data.appliedPromotion.id, isGift: data.is_gift, qty: checkoutData.checkGift.find((item) => item.promotionId == data.appliedPromotion.id && item.id == data.product.id)?.qty }))) : (React.createElement(React.Fragment, null,
30
+ React.createElement("div", { className: `col-item tl-col-2` }, select && !data.is_gift ? (React.createElement("div", { className: `select-and-out-of-stock-wrap` }, !data.product.out_of_stock ? (React.createElement(AccountCounter, { productId: data.product.id })) : (React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color1`, text: 'account.general_actions.outOfStock' })))) : data.is_gift && !isCheckout ? (React.createElement("div", { className: 'wrapper-gift-button' }, checkoutData.gifts.find((item) => item.promotionId == data.appliedPromotion.id && item.productId == data.product.id)?.qty !== 0 ? (React.createElement(React.Fragment, null,
31
+ React.createElement(AccountCounter, { maxQty: data?.qty, productId: data.product.id, promotionId: data.appliedPromotion.id, isGift: data.is_gift, qty: checkoutData.gifts.find((item) => item.promotionId == data.appliedPromotion.id && item.productId == data.product.id)?.qty }))) : (React.createElement(React.Fragment, null,
32
32
  React.createElement(AccountButton, { className: `button-gift`, text: 'account.general_actions.restore', onClick: () => {
33
- setCheckGift({ promotionId: data.appliedPromotion.id, productId: data.product.id, qty: data?.qty });
33
+ setGifts({ promotionId: data.appliedPromotion.id, productId: data.product.id, qty: data?.qty });
34
34
  } }))))) : (React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color1`, text: data?.qty }))),
35
35
  React.createElement("div", { className: `col-item tl-col-3 col-item-3 nowrap` }, (data.product.sale_price || data.product.discount) && !data.is_gift ? (React.createElement("div", null,
36
36
  React.createElement(Text, { className: `account-p account-p3 account-font-bold account-secondary-color2 align-right cart-sale-price`, text: handlePriceCheckFunc(data.product.sale_price, currency) }),
@@ -48,11 +48,6 @@ const Item = memo(({ data, remove, select, isLast, actions, isCheckout }) => {
48
48
  React.createElement("div", { className: `flex-end-wrap` }, (data.sale_total || data.product.discount) && !data.is_gift ? (React.createElement("div", null,
49
49
  React.createElement(Text, { className: `account-p account-p3 account-font-bold account-secondary-color2 align-right cart-sale-total`, text: handlePriceCheckFunc(data.sale_total, currency) }),
50
50
  React.createElement("div", { className: 'wrapper-discount' },
51
- data.product.discount ? (React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color2 discount-text` },
52
- data.product.discount.value,
53
- data.product.discount.type === 'percentage' ? '%' : ` ${currency}`,
54
- "\u00A0",
55
- React.createElement("span", { className: 'lowercase' }, translate('account.order_balance.discount')))) : null,
56
51
  React.createElement(Text, { className: `account-p account-p3 account-font-regular account-primary-color2 line-through value align-right cart-total1`, text: handlePriceCheckFunc(data.total, currency) })))) : (React.createElement(Text, { className: `account-p account-p3 account-font-bold account-primary-color1 align-right cart-total2` }, data.is_gift ? (React.createElement(React.Fragment, null,
57
52
  handlePriceCheckFunc(0, currency),
58
53
  React.createElement("span", { className: 'gift-name-text' }, data.appliedPromotion.name))) : (handlePriceCheckFunc(data.total, currency))))),
@@ -7,8 +7,8 @@ import { defaultIconGift } from '../util';
7
7
  const ItemMobile = memo(({ data, select, isCheckout }) => {
8
8
  const { handleProductClick, currency } = useAccountContext();
9
9
  const { translate } = useTranslation();
10
- const { checkoutData, setCheckGift } = useCart();
11
- return !isCheckout || checkoutData.checkGift.find((item) => item.promotionId == data.appliedPromotion?.id && item.id == data.product.id)?.qty !== 0 ? (React.createElement(React.Fragment, null,
10
+ const { checkoutData, setGifts } = useCart();
11
+ return !isCheckout || checkoutData.gifts.find((item) => item.promotionId == data.appliedPromotion?.id && item.productId == data.product.id)?.qty !== 0 ? (React.createElement(React.Fragment, null,
12
12
  React.createElement("div", { className: `mobile-cart-item-wrap user-select-none` },
13
13
  React.createElement("div", { className: `mobile-cart-item-inner-wrap` },
14
14
  React.createElement("div", { className: `mobile-image-wrap` },
@@ -39,9 +39,7 @@ const ItemMobile = memo(({ data, select, isCheckout }) => {
39
39
  handlePriceCheckFunc(0, currency),
40
40
  React.createElement("span", { className: 'gift-name-text' }, data.appliedPromotion.name))) : (handlePriceCheckFunc(data.total, currency)))),
41
41
  select && !data.is_gift ? (React.createElement("div", { className: `inner-container` }, !data.product.out_of_stock ? (React.createElement(AccountCounter, { productId: data.product.id })) : (React.createElement("div", { className: `in-block` },
42
- React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color1`, text: 'account.general_actions.outOfStock' }))))) : data.is_gift && !isCheckout ? (React.createElement("div", { className: 'wrapper-gift-button' }, checkoutData.checkGift.find((item) => item.promotionId == data.appliedPromotion.id && item.id == data.product.id)?.qty !== 0 ? (React.createElement(AccountCounter, { maxQty: data?.qty, productId: data.product.id, promotionId: data.appliedPromotion.id, isGift: data.is_gift, qty: checkoutData.checkGift.find((item) => item.promotionId == data.appliedPromotion.id && item.id == data.product.id)?.qty })) : (React.createElement(AccountButton, { className: `capitalize button-gift`, text: 'account.general_actions.restore', onClick: () => {
43
- setCheckGift({ promotionId: data.appliedPromotion.id, productId: data.product.id, qty: data?.qty });
44
- } })))) : (React.createElement("div", { className: `in-block` },
42
+ React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color1`, text: 'account.general_actions.outOfStock' }))))) : data.is_gift && !isCheckout ? (React.createElement("div", { className: 'wrapper-gift-button' }, checkoutData.gifts.find((item) => item.promotionId == data.appliedPromotion.id && item.productId == data.product.id)?.qty !== 0 ? (React.createElement(AccountCounter, { maxQty: data?.qty, productId: data.product.id, promotionId: data.appliedPromotion.id, isGift: data.is_gift, qty: checkoutData.gifts.find((item) => item.promotionId == data.appliedPromotion.id && item.productId == data.product.id)?.qty })) : (React.createElement(AccountButton, { className: `capitalize button-gift`, text: 'account.general_actions.restore', onClick: () => setGifts({ promotionId: data.appliedPromotion.id, productId: data.product.id, qty: data?.qty }) })))) : (React.createElement("div", { className: `in-block` },
45
43
  React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color1 mobile-quantity-with-symbol2` },
46
44
  translate('account.order_balance.quantity'),
47
45
  ":"),
@@ -5,15 +5,17 @@ interface CartItem {
5
5
  }
6
6
  interface CheckoutData {
7
7
  addressId: number | null;
8
- useBalance: boolean | null;
8
+ useBalance: number | string | null;
9
9
  note: string;
10
10
  paymentType: string;
11
- checkGift: {
12
- id: number;
13
- qty: number;
11
+ gifts: {
12
+ productId: number;
14
13
  promotionId: number;
14
+ qty: number;
15
15
  }[];
16
16
  card_id: number | null;
17
+ excludedPromotions: any[];
18
+ promotion_code: string | null;
17
19
  }
18
20
  interface CartState {
19
21
  itemsCount: number;
@@ -27,10 +29,10 @@ interface CartState {
27
29
  shippingCostValue: number | null;
28
30
  hasFreeGift: boolean | null;
29
31
  giftThresholdRemaining: number | null;
30
- useBalance: boolean | null;
32
+ useBalance: number | string | null;
31
33
  discount: number | null;
32
- usePromotion?: string | null;
33
34
  appliedPromotions: any[];
35
+ promotion_code: string | null;
34
36
  }
35
37
  interface CartContextType extends CartState {
36
38
  getCart: (params?: Record<string, any>) => Promise<void>;
@@ -47,11 +49,14 @@ interface CartContextType extends CartState {
47
49
  fillCheckoutData: (key: string, value: any) => void;
48
50
  handleCheckout: () => Promise<void>;
49
51
  fillCart: (key: string, value: any) => void;
50
- setCheckGift: ({ promotionId, qty, productId }: {
52
+ setGifts: ({ promotionId, qty, productId }: {
51
53
  promotionId: number;
52
54
  qty: number;
53
55
  productId: number;
54
56
  }) => void;
57
+ togglePromotion: ({ promotionId }: {
58
+ promotionId: any;
59
+ }) => void;
55
60
  checkoutBtnDisabled: boolean;
56
61
  isCheckoutPage: boolean;
57
62
  }
@@ -21,6 +21,7 @@ export const CartProvider = ({ useUser, children }) => {
21
21
  hasFreeGift: null,
22
22
  giftThresholdRemaining: null,
23
23
  useBalance: null,
24
+ promotion_code: null,
24
25
  discount: null,
25
26
  appliedPromotions: [],
26
27
  });
@@ -29,8 +30,10 @@ export const CartProvider = ({ useUser, children }) => {
29
30
  useBalance: null,
30
31
  note: '',
31
32
  paymentType: user?.payment_method || 'cash_on_delivery',
32
- checkGift: [],
33
+ gifts: [],
33
34
  card_id: null,
35
+ excludedPromotions: [],
36
+ promotion_code: null
34
37
  };
35
38
  const [checkoutData, setCheckoutData] = useState(initialCheckoutData);
36
39
  const checkoutDataRef = useRef(checkoutData);
@@ -45,8 +48,16 @@ export const CartProvider = ({ useUser, children }) => {
45
48
  return cookieCart ? JSON.parse(cookieCart) : [];
46
49
  };
47
50
  const setResourceDecorator = (data) => {
48
- setCartState((prev) => ({ ...prev, ...data, loading: false }));
49
- setCheckoutData((prev) => ({ ...prev, useBalance: data.useBalance }));
51
+ setCartState((prev) => ({
52
+ ...prev,
53
+ ...data,
54
+ loading: false
55
+ }));
56
+ setCheckoutData((prev) => ({
57
+ ...prev,
58
+ useBalance: data.useBalance,
59
+ promotion_code: data.promotion_code
60
+ }));
50
61
  };
51
62
  const isCheckoutPage = useMemo(() => {
52
63
  return window.location.href.includes('checkout');
@@ -58,7 +69,7 @@ export const CartProvider = ({ useUser, children }) => {
58
69
  return isCheckoutPage || isCartPage ? 'cart' : 'cart-summary';
59
70
  }, [isCheckoutPage, isCartPage]);
60
71
  const getCart = async (params = {}) => {
61
- let newParams = { ...cleanObject(params), ...cleanObject(checkoutDataRef.current), cartResourceType };
72
+ let newParams = { ...cleanObject(checkoutDataRef.current), ...params, cartResourceType };
62
73
  if (isLoggedIn) {
63
74
  const { data } = await api.get({ url: 'cart', lang: selectedLang, params: newParams });
64
75
  setResourceDecorator(data);
@@ -110,6 +121,7 @@ export const CartProvider = ({ useUser, children }) => {
110
121
  }
111
122
  };
112
123
  const clearCart = async () => {
124
+ sessionStorage.clear();
113
125
  if (isLoggedIn) {
114
126
  const { data } = await api.post('clear-cart');
115
127
  setResourceDecorator(data);
@@ -119,34 +131,33 @@ export const CartProvider = ({ useUser, children }) => {
119
131
  await getCart();
120
132
  }
121
133
  };
122
- // TODO: make router push func
123
134
  const reorder = async (orderId) => {
124
135
  const { data } = await api.post('reorder', { orderId });
125
136
  setResourceDecorator(data);
126
- // router.push(getLangPath('cart'));
137
+ window.location.href = `/${selectedLang}/cart`;
127
138
  };
128
139
  //! Has gift from data
129
140
  useEffect(() => {
130
- if (cartState.items.length && !checkoutData.checkGift.length) {
141
+ if (cartState.items.length && !checkoutData.gifts?.length) {
131
142
  setCheckoutData((prev) => {
132
- const checkGift = cartState.items
143
+ const gifts = cartState.items
133
144
  .filter((item) => item.is_gift)
134
145
  .map((item) => ({
135
- id: item.product.id,
136
- qty: item.qty,
146
+ productId: item.product.id,
137
147
  promotionId: item.appliedPromotion.id,
148
+ qty: item.qty,
138
149
  }));
139
- return { ...prev, checkGift };
150
+ return { ...prev, gifts };
140
151
  });
141
152
  }
142
153
  }, [cartState.items]);
143
154
  //! Set gift Select
144
- const setCheckGift = useCallback(({ promotionId, qty, productId }) => {
155
+ const setGifts = useCallback(({ promotionId, qty, productId }) => {
145
156
  setCheckoutData((prev) => ({
146
157
  ...prev,
147
- checkGift: [
148
- ...prev.checkGift.map((item) => {
149
- if (item.promotionId == promotionId && item.id == productId) {
158
+ gifts: [
159
+ ...prev.gifts.map((item) => {
160
+ if (item.promotionId == promotionId && item.productId == productId) {
150
161
  return { ...item, qty };
151
162
  }
152
163
  else {
@@ -156,6 +167,21 @@ export const CartProvider = ({ useUser, children }) => {
156
167
  ],
157
168
  }));
158
169
  }, []);
170
+ const togglePromotion = ({ promotionId }) => {
171
+ setCheckoutData((prev) => {
172
+ const excludedPromotions = prev.excludedPromotions;
173
+ const index = excludedPromotions.indexOf(promotionId);
174
+ if (index > -1) {
175
+ excludedPromotions.splice(index, 1);
176
+ }
177
+ else {
178
+ excludedPromotions.push(promotionId);
179
+ }
180
+ const updatedData = { ...prev, excludedPromotions };
181
+ getCart(updatedData);
182
+ return updatedData;
183
+ });
184
+ };
159
185
  const checkoutBtnDisabled = useMemo(() => {
160
186
  let isDisabled = false;
161
187
  if (isCheckoutPage && isNumeric(checkoutData.paymentType)) {
@@ -188,11 +214,8 @@ export const CartProvider = ({ useUser, children }) => {
188
214
  const handleCheckout = async () => {
189
215
  let data = cleanObject({ ...checkoutData });
190
216
  //! Check gift
191
- if (data.checkGift) {
192
- data.checkGift = data.checkGift.filter((item) => item.qty);
193
- if (!data.checkGift.length)
194
- delete data.checkGift;
195
- }
217
+ if (!data.gifts.length)
218
+ delete data.gifts;
196
219
  if (isNumeric(checkoutData.paymentType)) {
197
220
  data.paymentType = 'credit_card';
198
221
  data.card_id = Number(checkoutData.paymentType);
@@ -234,7 +257,8 @@ export const CartProvider = ({ useUser, children }) => {
234
257
  fillCheckoutData,
235
258
  handleCheckout,
236
259
  fillCart,
237
- setCheckGift,
260
+ setGifts,
261
+ togglePromotion,
238
262
  checkoutBtnDisabled,
239
263
  isCheckoutPage,
240
264
  } },
@@ -7,6 +7,7 @@ import { useAccountContext } from '../../../AccountProvider';
7
7
  import { confirmImage } from './icons';
8
8
  import AccountContainer from '../../../components/AccountContainer';
9
9
  import { useCart } from '../../cart';
10
+ // TODO: maybe need change order number translate
10
11
  const ThankYouTemplate = ({ orderNumber, thankIcon }) => {
11
12
  const { shopUrl } = useAccountContext();
12
13
  const { translate } = useTranslation();
@@ -26,29 +26,22 @@ const Item = memo(({ data }) => {
26
26
  React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color1`, text: data.product.short_info_2 }))) : null)),
27
27
  React.createElement("div", { className: `col-item tl-col-2` },
28
28
  React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color1`, text: data?.qty })),
29
- React.createElement("div", { className: `col-item tl-col-3 col-item-3 nowrap` }, (data.sale_price || data.product?.discount) && !data.is_gift ? (React.createElement("div", null,
29
+ React.createElement("div", { className: `col-item tl-col-3 col-item-3 nowrap` }, data.sale_price && !data.is_gift ? (React.createElement("div", null,
30
30
  React.createElement(Text, { className: `account-p account-p3 account-font-bold account-secondary-color2 align-right order-sale-price`, text: handlePriceCheckFunc(data.sale_price, currency) }),
31
31
  React.createElement("div", { className: 'wrapper-discount' },
32
- data.product?.discount ? (React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color2 discount-text` },
33
- data.product.discount,
34
- data.product?.discount_type === 'percentage' ? '%' : ` ${currency}`,
32
+ data.appliedPromotion ? (React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color2 discount-text` },
33
+ data.appliedPromotion.value,
34
+ data.appliedPromotion.type === 'percentage' ? '%' : ` ${currency}`,
35
35
  "\u00A0",
36
36
  React.createElement("span", { className: 'lowercase' }, translate('account.order_balance.discount')))) : null,
37
37
  React.createElement(Text, { className: `account-p account-p3 account-font-regular account-primary-color2 line-through value align-right order-price1`, text: handlePriceCheckFunc(data.price, currency) })))) : (React.createElement(Text, { className: `account-p account-p3 account-font-bold account-primary-color1 align-right order-sale-price` }, data.is_gift ? (React.createElement(React.Fragment, null,
38
38
  handlePriceCheckFunc(0, currency),
39
- React.createElement("span", { className: 'gift-name-text' }, data?.appliedPromotion?.name || 'Karlen'))) : (handlePriceCheckFunc(data.price, currency))))),
39
+ React.createElement("span", { className: 'gift-name-text' }, data?.appliedPromotion?.name))) : (handlePriceCheckFunc(data.price, currency))))),
40
40
  React.createElement("div", { className: `col-item tl-col-4 col-item-4 nowrap price-block` },
41
41
  React.createElement("div", { className: `col-item-inner-wrap` },
42
- React.createElement("div", { className: `flex-end-wrap` }, (data.sale_total || data.product?.discount) && !data.is_gift ? (React.createElement("div", null,
42
+ React.createElement("div", { className: `flex-end-wrap` }, data.sale_total && !data.is_gift ? (React.createElement("div", null,
43
43
  React.createElement(Text, { className: `account-p account-p3 account-font-bold account-secondary-color2 align-right order-sale-price`, text: handlePriceCheckFunc(data.sale_total, currency) }),
44
44
  React.createElement("div", { className: 'wrapper-discount' },
45
- data.product?.discount ? (React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color2 discount-text` },
46
- data.product.discount,
47
- data.product?.discount_type === 'percentage' ? '%' : ` ${currency}`,
48
- "\u00A0",
49
- React.createElement("span", { className: 'lowercase' }, translate('account.order_balance.discount')))) : null,
50
- React.createElement(Text, { className: `account-p account-p3 account-font-regular account-primary-color2 line-through value align-right order-price1`, text: handlePriceCheckFunc(data.total, currency) })))) : (React.createElement(Text, { className: `account-p account-p3 account-font-bold account-primary-color1 align-right order-sale-price` }, data.is_gift ? (React.createElement(React.Fragment, null,
51
- handlePriceCheckFunc(0, currency),
52
- React.createElement("span", { className: 'gift-name-text' }, data?.appliedPromotion?.name || 'Karlen'))) : (handlePriceCheckFunc(data.total, currency))))))))));
45
+ React.createElement(Text, { className: `account-p account-p3 account-font-regular account-primary-color2 line-through value align-right order-price1`, text: handlePriceCheckFunc(data.total, currency) })))) : (React.createElement(Text, { className: `account-p account-p3 account-font-bold account-primary-color1 align-right order-sale-price` }, handlePriceCheckFunc(data.total, currency)))))))));
53
46
  });
54
47
  export default Item;
@@ -31,27 +31,22 @@ const ItemMobile = memo(({ data }) => {
31
31
  React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color1`, text: data?.qty })),
32
32
  React.createElement("div", { className: `mobile-price-wrap nowrap` },
33
33
  React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color1`, text: `account.order_balance.price` }),
34
- (data.sale_price || data.product?.discount) && !data.is_gift ? (React.createElement(React.Fragment, null,
34
+ data.sale_price && !data.is_gift ? (React.createElement(React.Fragment, null,
35
35
  React.createElement(Text, { className: `account-p account-p3 account-font-medium account-secondary-color2 sale-price`, text: handlePriceCheckFunc(data.sale_price, currency) }),
36
36
  React.createElement("div", { className: 'wrapper-discount' },
37
- data.product?.discount ? (React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color2 discount-text-mobile` },
38
- data.product.discount,
39
- data.product?.discount_type === 'percentage' ? '%' : ` ${currency}`,
37
+ data.appliedPromotion ? (React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color2 discount-text-mobile` },
38
+ data.appliedPromotion.value,
39
+ data.appliedPromotion.type === 'percentage' ? '%' : ` ${currency}`,
40
40
  "\u00A0",
41
41
  React.createElement("span", { className: 'lowercase' }, translate('account.order_balance.discount')))) : null,
42
42
  React.createElement(Text, { className: `account-p account-p3 account-font-regular account-primary-color2 line-through price1`, text: handlePriceCheckFunc(data.price, currency) })))) : (React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color1 price2` }, data.is_gift ? (React.createElement(React.Fragment, null,
43
43
  handlePriceCheckFunc(0, currency),
44
- React.createElement("span", { className: 'gift-name-text' }, data?.appliedPromotion?.name || 'Karlen'))) : (handlePriceCheckFunc(data.price, currency))))),
44
+ React.createElement("span", { className: 'gift-name-text' }, data?.appliedPromotion?.name))) : (handlePriceCheckFunc(data.price, currency))))),
45
45
  React.createElement("div", { className: `mobile-total-price-wrap nowrap` },
46
46
  React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color1`, text: `account.order_balance.total` }),
47
- (data.sale_total || data.product?.discount) && !data.is_gift ? (React.createElement(React.Fragment, null,
47
+ data.sale_total && !data.is_gift ? (React.createElement(React.Fragment, null,
48
48
  React.createElement(Text, { className: `account-p account-p3 account-font-medium account-secondary-color2 sale-total`, text: handlePriceCheckFunc(data.sale_total, currency) }),
49
49
  React.createElement("div", { className: 'wrapper-discount' },
50
- data.product?.discount ? (React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color2 discount-text-mobile` },
51
- data.product.discount,
52
- data.product?.discount_type === 'percentage' ? '%' : ` ${currency}`,
53
- "\u00A0",
54
- React.createElement("span", { className: 'lowercase' }, translate('account.order_balance.discount')))) : null,
55
50
  React.createElement(Text, { className: `account-p account-p3 account-font-regular account-primary-color2 line-through total1`, text: handlePriceCheckFunc(data.total, currency) })))) : (React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color1 total2`, text: handlePriceCheckFunc(data.is_gift ? 0 : data.total, currency) }, data.is_gift ? (React.createElement(React.Fragment, null,
56
51
  handlePriceCheckFunc(0, currency),
57
52
  React.createElement("span", { className: 'gift-name-text' }, data?.appliedPromotion?.name || 'Karlen'))) : (handlePriceCheckFunc(data.total, currency)))))))));
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@weareconceptstudio/account",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "Concept Studio Account",
5
5
  "author": "Concept Studio",
6
6
  "license": "ISC",
7
7
  "main": "dist/index.js",
8
+ "sideEffects": false,
8
9
  "files": [
9
10
  "dist"
10
11
  ],