@weareconceptstudio/account 0.5.8 → 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 (47) hide show
  1. package/dist/AccountProvider.d.ts +1 -2
  2. package/dist/AccountProvider.js +5 -5
  3. package/dist/components/AccountCounter/index.d.ts +2 -1
  4. package/dist/components/AccountCounter/index.js +5 -8
  5. package/dist/components/TotalCheckout/BalanceComp/index.js +3 -4
  6. package/dist/components/TotalCheckout/CommentComp/index.js +2 -2
  7. package/dist/components/TotalCheckout/FreeShippingComp/index.js +2 -4
  8. package/dist/components/TotalCheckout/GiftComp/index.js +2 -5
  9. package/dist/components/TotalCheckout/PromoCodeComp/index.js +2 -5
  10. package/dist/components/TotalCheckout/index.js +4 -9
  11. package/dist/components/TotalCheckout/style.js +12 -3
  12. package/dist/modules/address/AddressForm/index.js +2 -2
  13. package/dist/modules/address/AddressProvider.js +3 -3
  14. package/dist/modules/cart/CartItems/Item/index.js +22 -18
  15. package/dist/modules/cart/CartItems/ItemMobile/index.js +15 -13
  16. package/dist/modules/cart/CartItems/index.js +11 -19
  17. package/dist/modules/cart/CartItems/style.js +6 -0
  18. package/dist/modules/cart/CartProvider.d.ts +67 -0
  19. package/dist/modules/cart/CartProvider.js +243 -0
  20. package/dist/modules/cart/CartTemplate/Skeleton/index.d.ts +1 -3
  21. package/dist/modules/cart/CartTemplate/Skeleton/index.js +5 -3
  22. package/dist/modules/cart/CartTemplate/index.js +9 -15
  23. package/dist/modules/cart/CartTemplate/style.js +23 -0
  24. package/dist/modules/cart/EmptyCart/index.d.ts +1 -2
  25. package/dist/modules/cart/EmptyCart/index.js +5 -3
  26. package/dist/modules/cart/index.d.ts +1 -0
  27. package/dist/modules/cart/index.js +1 -0
  28. package/dist/modules/checkout/CheckoutTemplate/StepReview/index.d.ts +1 -3
  29. package/dist/modules/checkout/CheckoutTemplate/StepReview/index.js +2 -2
  30. package/dist/modules/checkout/CheckoutTemplate/index.js +9 -16
  31. package/dist/modules/checkout/CheckoutTemplate/style.js +23 -0
  32. package/dist/modules/checkout/ThankYouTemplate/index.js +4 -3
  33. package/dist/modules/checkout/index.d.ts +0 -1
  34. package/dist/modules/checkout/index.js +0 -1
  35. package/dist/modules/order/OrderedItems/Item/index.js +14 -10
  36. package/dist/modules/order/OrderedItems/ItemMobile/index.js +14 -10
  37. package/dist/modules/order/OrderedItems/index.js +1 -2
  38. package/dist/modules/order/OrderedItems/style.js +6 -0
  39. package/dist/modules/payment/AddNewCard/index.js +2 -2
  40. package/dist/modules/payment/Card/index.js +2 -2
  41. package/dist/modules/payment/Payment/index.js +4 -4
  42. package/dist/modules/payment/PaymentMethods/index.js +1 -1
  43. package/dist/modules/payment/SelectPaymentMethodPopup/index.js +2 -2
  44. package/dist/modules/payment/SelectedPayment/index.js +2 -2
  45. package/package.json +1 -1
  46. package/dist/modules/checkout/CheckoutProvider.d.ts +0 -5
  47. package/dist/modules/checkout/CheckoutProvider.js +0 -132
@@ -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,8 +1,9 @@
1
1
  export default AccountCounter;
2
- declare function AccountCounter({ productId, qty, isGift, maxQty }: {
2
+ declare function AccountCounter({ productId, qty, isGift, maxQty, promotionId }: {
3
3
  productId: any;
4
4
  qty?: number;
5
5
  isGift: any;
6
6
  maxQty: any;
7
+ promotionId: any;
7
8
  }): React.JSX.Element;
8
9
  import React from 'react';
@@ -1,17 +1,14 @@
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
- const AccountCounter = ({ productId, qty = 1, isGift, maxQty }) => {
8
- const { useCart } = useAccountContext();
9
- const { toggleCartItem, items } = useCart();
10
- const { setCheckGift } = useCheckoutContext();
6
+ const AccountCounter = ({ productId, qty = 1, isGift, maxQty, promotionId }) => {
7
+ const { toggleCartItem, items, setCheckGift } = useCart();
11
8
  //! State
12
9
  const [count, setCount] = useState(qty);
13
10
  useEffect(() => {
14
- setCount(items.find((item) => item.product.id == productId && !item.is_gift)?.qty || qty);
11
+ setCount(items.find((item) => item.product.id == productId && item.promotionId == promotionId && !item.is_gift)?.qty || qty);
15
12
  }, [items]);
16
13
  const updateCartServer = useCallback((quantity) => {
17
14
  toggleCartItem({
@@ -24,7 +21,7 @@ const AccountCounter = ({ productId, qty = 1, isGift, maxQty }) => {
24
21
  e.stopPropagation();
25
22
  const newCount = type == 'inc' ? count + 1 : count - 1;
26
23
  setCount(newCount);
27
- isGift ? setCheckGift({ productId, qty: newCount }) : debouncedUpdateCartServer(newCount);
24
+ isGift ? setCheckGift({ promotionId, qty: newCount, productId }) : debouncedUpdateCartServer(newCount);
28
25
  };
29
26
  return (React.createElement(AccountCounterStyle, { onClick: (e) => e.stopPropagation(), className: `counter-block ${count == 0 ? 'opacity-zero pointer-none' : ''}` },
30
27
  React.createElement("div", { className: 'counter' },
@@ -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 { useAddressContext, 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';
@@ -12,16 +11,12 @@ import GiftComp from './GiftComp';
12
11
  import TotalCheckoutStyle from './style';
13
12
  //* Skeleton
14
13
  import SkeletonTotalCheckout from './Skeleton';
15
- const TotalCheckout = memo(({ isShipping, children, confirmation, buttonProps, loading }) => {
16
- const { useCart, useUser } = useAccountContext();
17
- const { checkoutBtnDisabled } = useCheckoutContext();
18
- const { addressLoading } = useAddressContext();
19
- const { user } = useUser();
20
- const { itemsCount, shippingCost, total, subtotal, useBalance, discount, currency } = useCart();
14
+ const TotalCheckout = memo(({ isShipping, children, confirmation, buttonProps }) => {
15
+ const { itemsCount, shippingCost, total, subtotal, useBalance, discount, currency, loading, checkoutBtnDisabled } = useCart();
21
16
  return (React.createElement(TotalCheckoutStyle, null,
22
17
  React.createElement("div", { className: `cart-main-wrap` },
23
18
  React.createElement("div", { className: `left-panel-wrap panel` }, children),
24
- React.createElement("div", { className: `right-panel-wrap panel ${confirmation ? 'display-none-wrap' : ''}` }, !confirmation && !addressLoading && !loading ? (React.createElement("div", { className: `max-width-wrapper sticky-wrap` },
19
+ React.createElement("div", { className: `right-panel-wrap panel ${confirmation ? 'display-none-wrap' : ''}` }, !confirmation && !loading ? (React.createElement("div", { className: `max-width-wrapper sticky-wrap` },
25
20
  React.createElement("div", { className: 'panel-block' },
26
21
  React.createElement(Text, { className: `account-p account-p2 account-font-bold account-primary-color1 sticky-wrap-title`, text: `account.cart_checkout.orderSummary` }),
27
22
  React.createElement("div", { className: `od-line` }),
@@ -200,12 +200,12 @@ const TotalCheckoutStyle = styled.section `
200
200
  }
201
201
 
202
202
  /* //! Scroll logic */
203
- --account_rightPanelScrollSize: var(--sp50x);
203
+ --account_rightPanelScrollSize: var(--sp70x);
204
204
 
205
205
  .scroll-block {
206
206
  overflow-x: hidden;
207
207
  overflow-y: auto;
208
- max-height: calc(100vh - var(--account_rightPanelScrollSize));
208
+ max-height: calc(100dvh - var(--account_rightPanelScrollSize));
209
209
 
210
210
  scrollbar-width: none;
211
211
  -ms-overflow-style: none;
@@ -232,6 +232,9 @@ const TotalCheckoutStyle = styled.section `
232
232
  /* //! Collapse Sizes */
233
233
  --account_collapseLargeDistance: var(--sp4x);
234
234
  --account_collapseSmallDistance: var(--sp3x);
235
+
236
+ /* //! Scroll logic */
237
+ --account_rightPanelScrollSize: var(--sp55x);
235
238
  }
236
239
 
237
240
  @media only screen and (max-width: ${(props) => props.theme.account.mediaQuery.account_DesktopSizeLMin}) and (min-width: ${(props) => props.theme.account.mediaQuery.account_DesktopSizeM}) {
@@ -251,6 +254,9 @@ const TotalCheckoutStyle = styled.section `
251
254
  /* //! Collapse Sizes */
252
255
  --account_collapseLargeDistance: var(--sp3x);
253
256
  --account_collapseSmallDistance: var(--sp3x);
257
+
258
+ /* //! Scroll logic */
259
+ --account_rightPanelScrollSize: var(--sp55x);
254
260
  }
255
261
 
256
262
  @media only screen and (max-width: ${(props) => props.theme.account.mediaQuery.account_DesktopSizeMMin}) and (min-width: ${(props) => props.theme.account.mediaQuery.account_DesktopSizeS}) {
@@ -270,6 +276,9 @@ const TotalCheckoutStyle = styled.section `
270
276
  /* //! Collapse Sizes */
271
277
  --account_collapseLargeDistance: var(--sp4x);
272
278
  --account_collapseSmallDistance: var(--sp3x);
279
+
280
+ /* //! Scroll logic */
281
+ --account_rightPanelScrollSize: var(--sp50x);
273
282
  }
274
283
 
275
284
  @media only screen and (max-width: ${(props) => props.theme.account.mediaQuery.account_DesktopSizeSMin}) and (min-width: ${(props) => props.theme.account.mediaQuery.account_DesktopSizeXS}) {
@@ -291,7 +300,7 @@ const TotalCheckoutStyle = styled.section `
291
300
  --account_collapseSmallDistance: var(--sp3x);
292
301
 
293
302
  /* //! Scroll logic */
294
- --account_rightPanelScrollSize: var(--sp45x);
303
+ --account_rightPanelScrollSize: var(--sp50x);
295
304
  }
296
305
 
297
306
  @media only screen and (max-width: ${(props) => props.theme.account.mediaQuery.account_DesktopSizeXSMin}) and (min-width: ${(props) => props.theme.account.mediaQuery.account_TabletSize}) {
@@ -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,33 +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[data.product.id * -1] !== 0 ? (React.createElement(React.Fragment, null,
31
- React.createElement(AccountCounter, { maxQty: data.qty, productId: data.product.id * -1, isGift: data.is_gift, qty: checkoutData.checkGift[data.product.id * -1] || data.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.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,
32
32
  React.createElement(AccountButton, { className: `button-gift`, text: 'account.general_actions.restore', onClick: () => {
33
- setCheckGift({ productId: data.product.id * -1, qty: data.qty });
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,
33
+ setCheckGift({ promotionId: data.appliedPromotion.id, productId: data.product.id, qty: data?.qty });
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.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
- 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`, text: handlePriceCheckFunc(data.is_gift ? 0 : data.product.price, currency) }))),
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
+ handlePriceCheckFunc(0, currency),
45
+ React.createElement("span", { className: 'gift-name-text' }, data.appliedPromotion.name))) : (handlePriceCheckFunc(data.product.price, currency))))),
44
46
  React.createElement("div", { className: `col-item tl-col-4 col-item-4 nowrap` },
45
47
  React.createElement("div", { className: `col-item-inner-wrap` },
46
- 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,
47
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) }),
48
50
  React.createElement("div", { className: 'wrapper-discount' },
49
51
  data.product.discount ? (React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color2 discount-text` },
50
- data.product.discount,
51
- data.product.discount_type === 'percentage' ? '%' : ` ${currency}`,
52
+ data.product.discount.value,
53
+ data.product.discount.type === 'percentage' ? '%' : ` ${currency}`,
52
54
  "\u00A0",
53
55
  React.createElement("span", { className: 'lowercase' }, translate('account.order_balance.discount')))) : null,
54
- 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`, text: handlePriceCheckFunc(data.is_gift ? 0 : data.total, currency) }))),
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,
57
+ handlePriceCheckFunc(0, currency),
58
+ React.createElement("span", { className: 'gift-name-text' }, data.appliedPromotion.name))) : (handlePriceCheckFunc(data.total, currency))))),
55
59
  React.createElement("div", { className: `favorite-and-remove-wrap` }, remove && !data.is_gift && (React.createElement("div", { className: `remove-btn-wrap` },
56
60
  React.createElement(AccountButton, { btnType: `green-small-text`, className: 'cart-remove-btn', text: 'account.general_actions.remove', onClick: () => actions.delete({ productId: data.product.id }) }))))))),
57
- isLast ? React.createElement("div", { className: 'line' }) : null));
61
+ isLast ? React.createElement("div", { className: 'line' }) : null)) : null;
58
62
  });
59
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,24 +27,26 @@ 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
- 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`, text: handlePriceCheckFunc(data.is_gift ? 0 : data.total, currency) })),
39
- select ? (React.createElement("div", { className: `inner-container` }, !data.product.out_of_stock && !data.is_gift ? (React.createElement(AccountCounter, { productId: data.product.id })) : data.is_gift ? (React.createElement("div", { className: 'wrapper-gift-button' }, checkoutData.checkGift[data.product.id * -1] !== 0 ? (React.createElement(AccountCounter, { maxQty: data.qty, productId: data.product.id * -1, isGift: data.is_gift, qty: checkoutData.checkGift[data.product.id * -1] || data.qty })) : (React.createElement(AccountButton, { className: `capitalize button-gift`, text: 'account.general_actions.restore', onClick: () => {
40
- setCheckGift({ productId: data.product.id * -1, qty: data.qty });
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
+ handlePriceCheckFunc(0, currency),
40
+ React.createElement("span", { className: 'gift-name-text' }, data.appliedPromotion.name))) : (handlePriceCheckFunc(data.total, currency)))),
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 });
41
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' }))))) : (React.createElement("div", { className: `in-block` },
43
45
  React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color1 mobile-quantity-with-symbol2` },
44
46
  translate('account.order_balance.quantity'),
45
47
  ":"),
46
48
  "\u00A0",
47
- React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color1 mobile-quantity2`, text: data.qty }))))))),
48
- React.createElement("div", { className: 'line' })));
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' }))) : null;
49
51
  });
50
52
  export default ItemMobile;
@@ -1,23 +1,15 @@
1
- import React, { memo, useEffect, useMemo } from 'react';
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
8
  //* Style
8
9
  import CartItemsStyle from './style';
9
- const CartItems = memo(({ data, className, title, smallFontSize, additionalParameters, actions }) => {
10
+ const CartItems = memo(({ className, title, smallFontSize, additionalParameters, actions, isCheckout = false }) => {
10
11
  const { winWidth } = useUi();
11
- data = data?.reduce((acc, item) => {
12
- const existingItem = acc.find((i) => item.is_gift && i.product.id === item.product.id);
13
- if (existingItem) {
14
- existingItem.qty += item.qty;
15
- }
16
- else {
17
- acc.push({ ...item });
18
- }
19
- return acc;
20
- }, []);
12
+ const { items } = useCart();
21
13
  //! Store
22
14
  const itemsStore = useMemo(() => {
23
15
  return winWidth >= 768 ? (React.createElement("div", { className: `cart-items-table-wrap` },
@@ -30,16 +22,16 @@ const CartItems = memo(({ data, className, title, smallFontSize, additionalParam
30
22
  React.createElement(Text, { className: `account-p account-p3 account-font-bold account-primary-color1 nowrap align-right`, text: `account.order_balance.price` })),
31
23
  React.createElement("div", { className: `title-wrap tl-col-4 title-item` },
32
24
  React.createElement(Text, { className: `account-p account-p3 account-font-bold account-primary-color1 nowrap align-right`, text: `account.order_balance.total` }))),
33
- React.createElement("div", { className: `items-wrap` }, data?.length > 0
34
- ? data.map((item, index) => {
35
- return (React.createElement(Item, { key: index, data: item, actions: actions, isLast: data.length - 1 == index, select: additionalParameters.select, remove: additionalParameters.remove }));
25
+ React.createElement("div", { className: `items-wrap` }, items?.length > 0
26
+ ? items.map((item, index) => {
27
+ return (React.createElement(Item, { key: index, data: item, actions: actions, isCheckout: isCheckout, isLast: items.length - 1 == index, select: additionalParameters.select, remove: additionalParameters.remove }));
36
28
  })
37
- : null))) : (React.createElement("div", { className: `mobile-cart-items-table-wrap` }, data?.length > 0
38
- ? data.map((item, index) => {
39
- return (React.createElement(ItemMobile, { key: index, data: item, select: additionalParameters.select }));
29
+ : null))) : (React.createElement("div", { className: `mobile-cart-items-table-wrap` }, items?.length > 0
30
+ ? items.map((item, index) => {
31
+ return (React.createElement(ItemMobile, { key: index, data: item, isCheckout: isCheckout, select: additionalParameters.select }));
40
32
  })
41
33
  : null));
42
- }, [winWidth, data, additionalParameters, actions]);
34
+ }, [winWidth, items, additionalParameters, actions]);
43
35
  return (React.createElement(CartItemsStyle, { className: className || '' },
44
36
  additionalParameters.edit.list ? (React.createElement("div", { className: `title-edit-wrapper` },
45
37
  React.createElement(Text, { className: `account-p ${smallFontSize ? 'account-p2' : 'account-p1'} account-font-bold account-primary-color1 cart-items-title2-version`, text: title }),
@@ -293,6 +293,12 @@ const CartItemsStyle = styled.section `
293
293
  }
294
294
  }
295
295
 
296
+ .gift-name-text {
297
+ display: block;
298
+ color: var(--pink1000);
299
+ white-space: pre-wrap;
300
+ }
301
+
296
302
  @keyframes opacityShow {
297
303
  0% {
298
304
  opacity: 0;
@@ -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 {};