@weareconceptstudio/account 0.5.9 → 0.6.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.
Files changed (39) hide show
  1. package/dist/AccountProvider.d.ts +1 -2
  2. package/dist/AccountProvider.js +5 -5
  3. package/dist/components/AccountCounter/index.js +2 -5
  4. package/dist/components/TotalCheckout/BalanceComp/index.js +3 -4
  5. package/dist/components/TotalCheckout/CommentComp/index.js +2 -2
  6. package/dist/components/TotalCheckout/FreeShippingComp/index.js +2 -4
  7. package/dist/components/TotalCheckout/GiftComp/index.js +2 -5
  8. package/dist/components/TotalCheckout/PromoCodeComp/index.js +2 -5
  9. package/dist/components/TotalCheckout/index.js +2 -5
  10. package/dist/modules/address/AddressForm/index.js +2 -2
  11. package/dist/modules/address/AddressProvider.js +3 -3
  12. package/dist/modules/cart/CartItems/Item/index.js +16 -21
  13. package/dist/modules/cart/CartItems/ItemMobile/index.js +10 -10
  14. package/dist/modules/cart/CartItems/index.js +4 -5
  15. package/dist/modules/cart/CartItems/style.js +1 -0
  16. package/dist/modules/cart/CartProvider.d.ts +67 -0
  17. package/dist/modules/cart/CartProvider.js +243 -0
  18. package/dist/modules/cart/CartTemplate/Skeleton/index.js +2 -2
  19. package/dist/modules/cart/CartTemplate/index.js +2 -2
  20. package/dist/modules/cart/index.d.ts +1 -0
  21. package/dist/modules/cart/index.js +1 -0
  22. package/dist/modules/checkout/CheckoutTemplate/StepReview/index.js +1 -1
  23. package/dist/modules/checkout/CheckoutTemplate/index.js +3 -4
  24. package/dist/modules/checkout/ThankYouTemplate/index.js +4 -3
  25. package/dist/modules/checkout/index.d.ts +0 -1
  26. package/dist/modules/checkout/index.js +0 -1
  27. package/dist/modules/order/OrderedItems/Item/index.js +13 -9
  28. package/dist/modules/order/OrderedItems/ItemMobile/index.js +13 -9
  29. package/dist/modules/order/OrderedItems/index.js +1 -2
  30. package/dist/modules/order/OrderedItems/style.js +6 -0
  31. package/dist/modules/payment/AddNewCard/index.js +2 -2
  32. package/dist/modules/payment/Card/index.js +2 -2
  33. package/dist/modules/payment/Payment/index.js +4 -4
  34. package/dist/modules/payment/PaymentMethods/index.js +1 -1
  35. package/dist/modules/payment/SelectPaymentMethodPopup/index.js +2 -2
  36. package/dist/modules/payment/SelectedPayment/index.js +2 -2
  37. package/package.json +1 -1
  38. package/dist/modules/checkout/CheckoutProvider.d.ts +0 -5
  39. package/dist/modules/checkout/CheckoutProvider.js +0 -141
@@ -1,5 +1,5 @@
1
1
  export function useAccountContext(): any;
2
- export function AccountProvider({ fontFamily, shopUrl, children, maxQty, currency, addressType, addressFormFields, useUser, useCart, productPopup, productUrlPrefix }: {
2
+ export function AccountProvider({ fontFamily, shopUrl, children, maxQty, currency, addressType, addressFormFields, useUser, productPopup, productUrlPrefix }: {
3
3
  fontFamily?: string;
4
4
  shopUrl?: string;
5
5
  children: any;
@@ -8,7 +8,6 @@ export function AccountProvider({ fontFamily, shopUrl, children, maxQty, currenc
8
8
  addressType: any;
9
9
  addressFormFields: any;
10
10
  useUser: any;
11
- useCart: any;
12
11
  productPopup: any;
13
12
  productUrlPrefix: any;
14
13
  }): React.JSX.Element;
@@ -2,7 +2,7 @@ import React, { createContext, useCallback, useContext, useEffect } from 'react'
2
2
  import { useTranslation, useUi } from '@weareconceptstudio/core';
3
3
  import { ThemeProvider } from 'styled-components';
4
4
  import { AddressProvider } from './modules/address/AddressProvider';
5
- import { CheckoutProvider } from './modules/checkout/CheckoutProvider';
5
+ import { CartProvider } from './modules/cart/CartProvider';
6
6
  //* Translations
7
7
  import translations from './translations';
8
8
  //* Styles
@@ -15,7 +15,7 @@ export const useAccountContext = () => {
15
15
  const context = useContext(AccountContext);
16
16
  return context;
17
17
  };
18
- export const AccountProvider = ({ fontFamily = 'core_Font', shopUrl = '/', children, maxQty = 99, currency, addressType, addressFormFields, useUser, useCart, productPopup, productUrlPrefix }) => {
18
+ export const AccountProvider = ({ fontFamily = 'core_Font', shopUrl = '/', children, maxQty = 99, currency, addressType, addressFormFields, useUser, productPopup, productUrlPrefix }) => {
19
19
  const { addTranslation } = useTranslation();
20
20
  const { openPopup } = useUi();
21
21
  const paymentOptions = [
@@ -51,9 +51,9 @@ export const AccountProvider = ({ fontFamily = 'core_Font', shopUrl = '/', child
51
51
  openPopup(productPopup, { ...product, className: 'popup-product-block' });
52
52
  }
53
53
  }, [productUrlPrefix, productPopup]);
54
- return (React.createElement(AccountContext.Provider, { value: { currency, maxQty, shopUrl, useUser, useCart, handleProductClick, paymentOptions } },
55
- React.createElement(CheckoutProvider, null,
56
- React.createElement(AddressProvider, { useUser: useUser, useCart: useCart, addressType: addressType, addressFormFields: addressFormFields },
54
+ return (React.createElement(AccountContext.Provider, { value: { currency, maxQty, shopUrl, useUser, handleProductClick, paymentOptions } },
55
+ React.createElement(CartProvider, { useUser: useUser },
56
+ React.createElement(AddressProvider, { useUser: useUser, addressType: addressType, addressFormFields: addressFormFields },
57
57
  React.createElement(ThemeProvider, { theme: theme },
58
58
  React.createElement(AccountVariables, { fontFamily: fontFamily }),
59
59
  React.createElement(AccountHelperClass, null),
@@ -1,13 +1,10 @@
1
1
  import React, { useState, useCallback, useEffect } from 'react';
2
2
  import { Text, debounce } from '@weareconceptstudio/core';
3
- import { useAccountContext } from '../../AccountProvider';
4
- import { useCheckoutContext } from '../../modules';
3
+ import { useCart } from '../../modules';
5
4
  //* Style
6
5
  import AccountCounterStyle from './style';
7
6
  const AccountCounter = ({ productId, qty = 1, isGift, maxQty, promotionId }) => {
8
- const { useCart } = useAccountContext();
9
- const { toggleCartItem, items } = useCart();
10
- const { setCheckGift } = useCheckoutContext();
7
+ const { toggleCartItem, items, setCheckGift } = useCart();
11
8
  //! State
12
9
  const [count, setCount] = useState(qty);
13
10
  useEffect(() => {
@@ -2,16 +2,15 @@ import React from 'react';
2
2
  import { Text, CollapseItem, handlePriceCheckFunc, useTranslation } from '@weareconceptstudio/core';
3
3
  import { FormBuilder } from '@weareconceptstudio/form';
4
4
  import { useAccountContext } from '../../../AccountProvider';
5
- import { useCheckoutContext } from '../../../modules';
5
+ import { useCart } from '../../../modules';
6
6
  import AccountButton from '../../AccountButton';
7
7
  import { balanceFields } from './utils';
8
8
  //* Style
9
9
  import BalanceCompStyle from './style';
10
10
  const BalanceComp = () => {
11
11
  const { translate } = useTranslation();
12
- const { useCart, useUser } = useAccountContext();
13
- const { currency, itemsCount, useBalance } = useCart();
14
- const { fillCart } = useCheckoutContext();
12
+ const { useUser } = useAccountContext();
13
+ const { currency, itemsCount, useBalance, fillCart } = useCart();
15
14
  const { user } = useUser();
16
15
  const balance = user?.balance || 0;
17
16
  const handleBalance = (amount) => {
@@ -1,10 +1,10 @@
1
1
  import React from 'react';
2
2
  import { CollapseContainer, CollapseItem, Text } from '@weareconceptstudio/core';
3
3
  import { Input } from '@weareconceptstudio/form';
4
- import { useCheckoutContext } from '../../../modules';
4
+ import { useCart } from '../../../modules';
5
5
  import CommentCompStyle from './style';
6
6
  const CommentComp = ({ isShipping }) => {
7
- const { fillCheckoutData, isCheckoutPage } = useCheckoutContext();
7
+ const { fillCheckoutData, isCheckoutPage } = useCart();
8
8
  return isCheckoutPage && typeof isShipping === 'boolean' && !isShipping ? (React.createElement(CommentCompStyle, { className: 'collapse-distance' },
9
9
  React.createElement(CollapseContainer, null,
10
10
  React.createElement(CollapseItem, { status: 'open', title: React.createElement(React.Fragment, null,
@@ -1,13 +1,11 @@
1
1
  import React, { useEffect, useState } from 'react';
2
2
  import { handlePriceCheckFunc, useTranslation } from '@weareconceptstudio/core';
3
- import { useAccountContext } from '../../../AccountProvider';
4
- import { useCheckoutContext } from '../../../modules';
3
+ import { useCart } from '../../../modules';
5
4
  //* Style
6
5
  import FreeShippingCompStyle from './style';
7
6
  const FreeShippingComp = () => {
8
7
  const { translate } = useTranslation();
9
- const { useCart } = useAccountContext();
10
- const { isCheckoutPage } = useCheckoutContext();
8
+ const { isCheckoutPage } = useCart();
11
9
  const { shippingCostValue, freeShippingRange, shippingCost, items, currency } = useCart();
12
10
  const [freeShow, setFreeShow] = useState(items?.length);
13
11
  useEffect(() => {
@@ -1,14 +1,11 @@
1
1
  import React, { useEffect, useState } from 'react';
2
- import { useCheckoutContext } from '../../../modules';
3
- import { useAccountContext } from '../../../AccountProvider';
4
2
  import { handlePriceCheckFunc, useTranslation } from '@weareconceptstudio/core';
3
+ import { useCart } from '../../../modules';
5
4
  //* Style
6
5
  import GiftCompStyle from './style';
7
6
  const GiftComp = () => {
8
7
  const { translate } = useTranslation();
9
- const { useCart } = useAccountContext();
10
- const { hasFreeGift, giftThresholdRemaining, currency } = useCart();
11
- const { isCheckoutPage } = useCheckoutContext();
8
+ const { hasFreeGift, giftThresholdRemaining, currency, isCheckoutPage } = useCart();
12
9
  const [show, setShow] = useState(true);
13
10
  useEffect(() => {
14
11
  if (hasFreeGift) {
@@ -1,17 +1,14 @@
1
1
  import React, { useMemo } from 'react';
2
2
  import { Text, CollapseItem } from '@weareconceptstudio/core';
3
3
  import { FormBuilder } from '@weareconceptstudio/form';
4
- import { useAccountContext } from '../../../AccountProvider';
5
- import { useCheckoutContext } from '../../../modules';
4
+ import { useCart } from '../../../modules';
6
5
  import AccountButton from '../../AccountButton';
7
6
  import AppliedPromotion from './AppliedPromotion';
8
7
  import { promoCodeFields } from './utils';
9
8
  //* Style
10
9
  import PromoCodeCompStyle from './style';
11
10
  const PromoCodeComp = () => {
12
- const { useCart } = useAccountContext();
13
- const { itemsCount, usePromotion, appliedPromotions } = useCart();
14
- const { fillCart } = useCheckoutContext();
11
+ const { itemsCount, usePromotion, appliedPromotions, fillCart } = useCart();
15
12
  const handlePromotion = (promotion) => {
16
13
  fillCart('usePromotion', promotion);
17
14
  };
@@ -1,7 +1,6 @@
1
1
  import React, { memo } from 'react';
2
2
  import { Text, CollapseContainer, handlePriceCheckFunc, numToLocalString } from '@weareconceptstudio/core';
3
- import { useAccountContext } from '../../AccountProvider';
4
- import { useCheckoutContext } from '../../modules';
3
+ import { useCart } from '../../modules';
5
4
  import AccountButton from '../AccountButton';
6
5
  import FreeShippingComp from './FreeShippingComp';
7
6
  import PromoCodeComp from './PromoCodeComp';
@@ -13,9 +12,7 @@ import TotalCheckoutStyle from './style';
13
12
  //* Skeleton
14
13
  import SkeletonTotalCheckout from './Skeleton';
15
14
  const TotalCheckout = memo(({ isShipping, children, confirmation, buttonProps }) => {
16
- const { useCart } = useAccountContext();
17
- const { checkoutBtnDisabled } = useCheckoutContext();
18
- const { itemsCount, shippingCost, total, subtotal, useBalance, discount, currency, loading } = useCart();
15
+ const { itemsCount, shippingCost, total, subtotal, useBalance, discount, currency, loading, checkoutBtnDisabled } = useCart();
19
16
  return (React.createElement(TotalCheckoutStyle, null,
20
17
  React.createElement("div", { className: `cart-main-wrap` },
21
18
  React.createElement("div", { className: `left-panel-wrap panel` }, children),
@@ -2,7 +2,7 @@ import React, { memo as Memo, useState, useCallback, useMemo } from 'react';
2
2
  import { useUi, Text } from '@weareconceptstudio/core';
3
3
  import { FormBuilder } from '@weareconceptstudio/form';
4
4
  import { useAddressContext } from '../AddressProvider';
5
- import { useCheckoutContext } from '../../checkout';
5
+ import { useCart } from '../../cart';
6
6
  import AccountButton from '../../../components/AccountButton';
7
7
  //* Icons
8
8
  import { CheckboxIcon, CheckboxCheckedIcon } from '../../../utils/icons';
@@ -10,7 +10,7 @@ import { CheckboxIcon, CheckboxCheckedIcon } from '../../../utils/icons';
10
10
  import AddressFormStyle from './style';
11
11
  const AddressForm = Memo(({ title, data, type }) => {
12
12
  const { formFields, createAddress, updateAddress } = useAddressContext();
13
- const { isCheckoutPage } = useCheckoutContext();
13
+ const { isCheckoutPage } = useCart();
14
14
  const { closePopup } = useUi();
15
15
  //! States
16
16
  const [isChecked, setIsChecked] = useState(data?.is_default || false);
@@ -1,6 +1,6 @@
1
- import React, { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
1
+ import React, { createContext, useContext, useEffect, useMemo, useState } from 'react';
2
2
  import { api } from '@weareconceptstudio/core';
3
- import { useCheckoutContext } from '../checkout';
3
+ import { useCart } from '../cart';
4
4
  const AddressContext = createContext(null);
5
5
  export const useAddressContext = () => {
6
6
  const context = useContext(AddressContext);
@@ -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 } = useCheckoutContext();
11
+ const { fillCheckoutData, fillCart, isCheckoutPage } = 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: {} } : {});
@@ -1,14 +1,14 @@
1
- import React, { memo, useCallback, useEffect } from 'react';
1
+ import React, { memo } from 'react';
2
2
  import { handlePriceCheckFunc, Image, Text, useTranslation } from '@weareconceptstudio/core';
3
3
  import { AccountButton, AccountCounter } from '../../../../components';
4
4
  import { useAccountContext } from '../../../../AccountProvider';
5
- import { useCheckoutContext } from '../../../checkout';
5
+ import { useCart } from '../../CartProvider';
6
6
  import { defaultIconGift } from '../util';
7
- const Item = memo(({ data, remove, select, isLast, actions }) => {
8
- const { checkoutData, setCheckGift } = useCheckoutContext();
7
+ const Item = memo(({ data, remove, select, isLast, actions, isCheckout }) => {
8
+ const { checkoutData, setCheckGift } = useCart();
9
9
  const { currency, handleProductClick } = useAccountContext();
10
10
  const { translate } = useTranslation();
11
- return (React.createElement("div", { className: `item-wrap user-select-none` },
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` },
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,42 +27,37 @@ const Item = memo(({ data, remove, select, isLast, actions }) => {
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 ? (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,
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
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,
32
32
  React.createElement(AccountButton, { className: `button-gift`, text: 'account.general_actions.restore', onClick: () => {
33
33
  setCheckGift({ 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
- React.createElement("div", { className: `col-item tl-col-3 col-item-3 nowrap` }, data.product.sale_price && !data.is_gift ? (React.createElement("div", null,
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) }),
37
37
  React.createElement("div", { className: 'wrapper-discount' },
38
38
  data.product.discount ? (React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color2 discount-text` },
39
- data.product.discount,
40
- data.product.discount_type === 'percentage' ? '%' : ` ${currency}`,
39
+ data.product.discount.value,
40
+ data.product.discount.type === 'percentage' ? '%' : ` ${currency}`,
41
41
  "\u00A0",
42
42
  React.createElement("span", { className: 'lowercase' }, translate('account.order_balance.discount')))) : null,
43
43
  React.createElement(Text, { className: `account-p account-p3 account-font-regular account-primary-color2 line-through value align-right cart-price1`, text: handlePriceCheckFunc(data.product.price, currency) })))) : (React.createElement(Text, { className: `account-p account-p3 account-font-bold account-primary-color1 align-right cart-price2` }, data.is_gift ? (React.createElement(React.Fragment, null,
44
44
  handlePriceCheckFunc(0, currency),
45
- React.createElement(Text, { className: 'gift-name-text' }, data.appliedPromotion.name))) : (handlePriceCheckFunc(data.product.price, currency))))),
45
+ React.createElement("span", { className: 'gift-name-text' }, data.appliedPromotion.name))) : (handlePriceCheckFunc(data.product.price, currency))))),
46
46
  React.createElement("div", { className: `col-item tl-col-4 col-item-4 nowrap` },
47
47
  React.createElement("div", { className: `col-item-inner-wrap` },
48
- React.createElement("div", { className: `flex-end-wrap` }, data.sale_total && !data.is_gift ? (React.createElement("div", null,
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
51
  data.product.discount ? (React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color2 discount-text` },
52
- data.product.discount,
53
- data.product.discount_type === 'percentage' ? '%' : ` ${currency}`,
52
+ data.product.discount.value,
53
+ data.product.discount.type === 'percentage' ? '%' : ` ${currency}`,
54
54
  "\u00A0",
55
55
  React.createElement("span", { className: 'lowercase' }, translate('account.order_balance.discount')))) : null,
56
- 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) })))) : (
57
- // <Text
58
- // className={`account-p account-p3 account-font-bold account-primary-color1 align-right cart-total2`}
59
- // text={handlePriceCheckFunc(data.is_gift ? 0 : data.total, currency)}
60
- // />
61
- 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,
56
+ 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,
62
57
  handlePriceCheckFunc(0, currency),
63
- React.createElement(Text, { className: 'gift-name-text' }, data.appliedPromotion.name))) : (handlePriceCheckFunc(data.total, currency))))),
58
+ React.createElement("span", { className: 'gift-name-text' }, data.appliedPromotion.name))) : (handlePriceCheckFunc(data.total, currency))))),
64
59
  React.createElement("div", { className: `favorite-and-remove-wrap` }, remove && !data.is_gift && (React.createElement("div", { className: `remove-btn-wrap` },
65
60
  React.createElement(AccountButton, { btnType: `green-small-text`, className: 'cart-remove-btn', text: 'account.general_actions.remove', onClick: () => actions.delete({ productId: data.product.id }) }))))))),
66
- isLast ? React.createElement("div", { className: 'line' }) : null));
61
+ isLast ? React.createElement("div", { className: 'line' }) : null)) : null;
67
62
  });
68
63
  export default Item;
@@ -2,13 +2,13 @@ import React, { memo } from 'react';
2
2
  import { handlePriceCheckFunc, Image, Text, useTranslation } from '@weareconceptstudio/core';
3
3
  import { AccountButton, AccountCounter } from '../../../../components';
4
4
  import { useAccountContext } from '../../../../AccountProvider';
5
- import { useCheckoutContext } from '../../../checkout';
5
+ import { useCart } from '../../CartProvider';
6
6
  import { defaultIconGift } from '../util';
7
- const ItemMobile = memo(({ data, select }) => {
7
+ const ItemMobile = memo(({ data, select, isCheckout }) => {
8
8
  const { handleProductClick, currency } = useAccountContext();
9
9
  const { translate } = useTranslation();
10
- const { checkoutData, setCheckGift } = useCheckoutContext();
11
- return (React.createElement(React.Fragment, null,
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,
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` },
@@ -27,19 +27,19 @@ const ItemMobile = memo(({ data, select }) => {
27
27
  React.createElement(Text, { className: `account-p account-p3 account-font-regular account-primary-color1`, text: data.size }))) : data.product.short_info_2 ? (React.createElement("div", { className: 'mobile-info-item' },
28
28
  React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color1 mobile-short-info2`, text: data.product.short_info_2 }))) : null,
29
29
  React.createElement("div", { className: `mobile-total-price-wrap flex-box` },
30
- data.sale_total && !data.is_gift ? (React.createElement("div", { className: 'mobile-total-price-flex-block' },
30
+ (data.sale_total || data.product.discount) && !data.is_gift ? (React.createElement("div", { className: 'mobile-total-price-flex-block' },
31
31
  React.createElement(Text, { className: `account-p account-p3 account-font-medium account-secondary-color2 mobile-total-discounted-price`, text: handlePriceCheckFunc(data.sale_total, currency) }),
32
32
  React.createElement("div", { className: 'wrapper-discount' },
33
33
  data.product.discount ? (React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color2 discount-text` },
34
- data.product.discount,
35
- data.product.discount_type === 'percentage' ? '%' : ` ${currency}`,
34
+ data.product.discount.value,
35
+ data.product.discount.type === 'percentage' ? '%' : ` ${currency}`,
36
36
  "\u00A0",
37
37
  React.createElement("span", { className: 'lowercase' }, translate('account.order_balance.discount')))) : null,
38
38
  React.createElement(Text, { className: `account-p account-p3 account-font-regular account-primary-color2 line-through mobile-total-price price-discount`, text: handlePriceCheckFunc(data.total, currency) })))) : (React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color1 mobile-total-price2` }, data.is_gift ? (React.createElement(React.Fragment, null,
39
39
  handlePriceCheckFunc(0, currency),
40
- React.createElement(Text, { className: 'gift-name-text' }, data.appliedPromotion.name))) : (handlePriceCheckFunc(data.total, currency)))),
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 ? (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: () => {
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
43
  setCheckGift({ promotionId: data.appliedPromotion.id, productId: data.product.id, qty: data?.qty });
44
44
  } })))) : (React.createElement("div", { className: `in-block` },
45
45
  React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color1 mobile-quantity-with-symbol2` },
@@ -47,6 +47,6 @@ const ItemMobile = memo(({ data, select }) => {
47
47
  ":"),
48
48
  "\u00A0",
49
49
  React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color1 mobile-quantity2`, text: data?.qty }))))))),
50
- React.createElement("div", { className: 'line' })));
50
+ React.createElement("div", { className: 'line' }))) : null;
51
51
  });
52
52
  export default ItemMobile;
@@ -1,15 +1,14 @@
1
1
  import React, { memo, useMemo } from 'react';
2
2
  import { Text, useUi } from '@weareconceptstudio/core';
3
+ import { useCart } from '../CartProvider';
3
4
  //* Components
4
5
  import Item from './Item';
5
6
  import ItemMobile from './ItemMobile';
6
7
  import { AccountButton } from '../../../components';
7
- import { useAccountContext } from '../../../AccountProvider';
8
8
  //* Style
9
9
  import CartItemsStyle from './style';
10
- const CartItems = memo(({ className, title, smallFontSize, additionalParameters, actions }) => {
10
+ const CartItems = memo(({ className, title, smallFontSize, additionalParameters, actions, isCheckout = false }) => {
11
11
  const { winWidth } = useUi();
12
- const { useCart } = useAccountContext();
13
12
  const { items } = useCart();
14
13
  //! Store
15
14
  const itemsStore = useMemo(() => {
@@ -25,11 +24,11 @@ const CartItems = memo(({ className, title, smallFontSize, additionalParameters,
25
24
  React.createElement(Text, { className: `account-p account-p3 account-font-bold account-primary-color1 nowrap align-right`, text: `account.order_balance.total` }))),
26
25
  React.createElement("div", { className: `items-wrap` }, items?.length > 0
27
26
  ? items.map((item, index) => {
28
- return (React.createElement(Item, { key: index, data: item, actions: actions, isLast: items.length - 1 == index, select: additionalParameters.select, remove: additionalParameters.remove }));
27
+ return (React.createElement(Item, { key: index, data: item, actions: actions, isCheckout: isCheckout, isLast: items.length - 1 == index, select: additionalParameters.select, remove: additionalParameters.remove }));
29
28
  })
30
29
  : null))) : (React.createElement("div", { className: `mobile-cart-items-table-wrap` }, items?.length > 0
31
30
  ? items.map((item, index) => {
32
- return (React.createElement(ItemMobile, { key: index, data: item, select: additionalParameters.select }));
31
+ return (React.createElement(ItemMobile, { key: index, data: item, isCheckout: isCheckout, select: additionalParameters.select }));
33
32
  })
34
33
  : null));
35
34
  }, [winWidth, items, additionalParameters, actions]);
@@ -294,6 +294,7 @@ const CartItemsStyle = styled.section `
294
294
  }
295
295
 
296
296
  .gift-name-text {
297
+ display: block;
297
298
  color: var(--pink1000);
298
299
  white-space: pre-wrap;
299
300
  }
@@ -0,0 +1,67 @@
1
+ import React, { ReactNode } from 'react';
2
+ interface CartItem {
3
+ productId: number;
4
+ qty: number;
5
+ }
6
+ interface CheckoutData {
7
+ addressId: number | null;
8
+ useBalance: boolean | null;
9
+ note: string;
10
+ paymentType: string;
11
+ checkGift: {
12
+ id: number;
13
+ qty: number;
14
+ promotionId: number;
15
+ }[];
16
+ card_id: number | null;
17
+ }
18
+ interface CartState {
19
+ itemsCount: number;
20
+ items: any[];
21
+ subtotal: number;
22
+ total: number;
23
+ loading: boolean;
24
+ currency: string;
25
+ shippingCost: string;
26
+ freeShippingRange: number | null;
27
+ shippingCostValue: number | null;
28
+ hasFreeGift: boolean | null;
29
+ giftThresholdRemaining: number | null;
30
+ useBalance: boolean | null;
31
+ discount: number | null;
32
+ usePromotion?: string | null;
33
+ appliedPromotions: any[];
34
+ }
35
+ interface CartContextType extends CartState {
36
+ getCart: (params?: Record<string, any>) => Promise<void>;
37
+ setCartState: (data: Partial<CartState>) => void;
38
+ toggleCartItem: ({ productId, qty }: CartItem) => Promise<void>;
39
+ deleteCartItem: ({ productId }: {
40
+ productId: number;
41
+ }) => Promise<void>;
42
+ clearCart: () => Promise<void>;
43
+ reorder: (orderId: number) => Promise<void>;
44
+ mergeCart: () => Promise<void>;
45
+ checkoutData: CheckoutData;
46
+ setCheckoutData: React.Dispatch<React.SetStateAction<CheckoutData>>;
47
+ fillCheckoutData: (key: string, value: any) => void;
48
+ handleCheckout: () => Promise<void>;
49
+ fillCart: (key: string, value: any) => void;
50
+ setCheckGift: ({ promotionId, qty, productId }: {
51
+ promotionId: number;
52
+ qty: number;
53
+ productId: number;
54
+ }) => void;
55
+ checkoutBtnDisabled: boolean;
56
+ isCheckoutPage: boolean;
57
+ }
58
+ export declare const useCart: () => CartContextType;
59
+ interface CartProviderProps {
60
+ useUser: () => {
61
+ user: any;
62
+ isLoggedIn: boolean;
63
+ };
64
+ children: ReactNode;
65
+ }
66
+ export declare const CartProvider: React.FC<CartProviderProps>;
67
+ export {};