@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
@@ -12,7 +12,7 @@ const ItemMobile = memo(({ data }) => {
12
12
  data.is_gift ? React.createElement("div", { className: 'wrapper-gift-icon' }, defaultIconGift) : null,
13
13
  React.createElement(Image, { src: data.product?.image?.src, alt: data.product?.image?.alt })),
14
14
  React.createElement("div", { className: `mobile-info-wrap` },
15
- React.createElement(AccountButton, { disabled: !data.product, btnType: `green-large-text`, className: `ordered-item-mobile-title`, text: data.product?.name || data?.product_name, onClick: () => data.product && handleProductClick(data.product) }),
15
+ React.createElement(AccountButton, { disabled: !data.product, btnType: `green-large-text`, className: `ordered-item-mobile-title`, text: data.product?.name || data.product_name, onClick: () => data.product && handleProductClick(data.product) }),
16
16
  data.color ? (React.createElement("div", { className: `mobile-info-item` },
17
17
  React.createElement(Text, { className: `account-p account-p3 account-font-bold account-primary-color1`, text: `account.general_actions.color` }),
18
18
  "\u00A0",
@@ -28,28 +28,32 @@ const ItemMobile = memo(({ data }) => {
28
28
  translate('account.order_balance.quantity'),
29
29
  ":"),
30
30
  "\u00A0",
31
- React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color1`, text: data.qty })),
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.is_gift ? (React.createElement(React.Fragment, null,
34
+ (data.sale_price || data.product?.discount) && !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` },
37
+ data.product?.discount ? (React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color2 discount-text-mobile` },
38
38
  data.product.discount,
39
- data?.product?.discount_type === 'percentage' ? '%' : ` ${currency}`,
39
+ data.product?.discount_type === 'percentage' ? '%' : ` ${currency}`,
40
40
  "\u00A0",
41
41
  React.createElement("span", { className: 'lowercase' }, translate('account.order_balance.discount')))) : null,
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`, text: handlePriceCheckFunc(data.is_gift ? 0 : data.price, currency) }))),
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
+ handlePriceCheckFunc(0, currency),
44
+ React.createElement("span", { className: 'gift-name-text' }, data?.appliedPromotion?.name || 'Karlen'))) : (handlePriceCheckFunc(data.price, currency))))),
43
45
  React.createElement("div", { className: `mobile-total-price-wrap nowrap` },
44
46
  React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color1`, text: `account.order_balance.total` }),
45
- data.sale_total && !data.is_gift ? (React.createElement(React.Fragment, null,
47
+ (data.sale_total || data.product?.discount) && !data.is_gift ? (React.createElement(React.Fragment, null,
46
48
  React.createElement(Text, { className: `account-p account-p3 account-font-medium account-secondary-color2 sale-total`, text: handlePriceCheckFunc(data.sale_total, currency) }),
47
49
  React.createElement("div", { className: 'wrapper-discount' },
48
- data?.product?.discount ? (React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color2 discount-text-mobile` },
50
+ data.product?.discount ? (React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color2 discount-text-mobile` },
49
51
  data.product.discount,
50
- data?.product?.discount_type === 'percentage' ? '%' : ` ${currency}`,
52
+ data.product?.discount_type === 'percentage' ? '%' : ` ${currency}`,
51
53
  "\u00A0",
52
54
  React.createElement("span", { className: 'lowercase' }, translate('account.order_balance.discount')))) : null,
53
- 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) })))))));
55
+ 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
+ handlePriceCheckFunc(0, currency),
57
+ React.createElement("span", { className: 'gift-name-text' }, data?.appliedPromotion?.name || 'Karlen'))) : (handlePriceCheckFunc(data.total, currency)))))))));
54
58
  });
55
59
  export default ItemMobile;
@@ -1,13 +1,12 @@
1
1
  import React, { useMemo } from 'react';
2
2
  import { Text, useUi } from '@weareconceptstudio/core';
3
- import { useAccountContext } from '../../../AccountProvider';
3
+ import { useCart } from '../../cart';
4
4
  import { AccountButton } from '../../../components';
5
5
  import Item from './Item';
6
6
  import ItemMobile from './ItemMobile';
7
7
  import OrderedItemsStyle from './style';
8
8
  const OrderedItems = ({ data: items, dataId }) => {
9
9
  const { winWidth } = useUi();
10
- const { useCart } = useAccountContext();
11
10
  const cartContext = useCart();
12
11
  //! Store order items
13
12
  const storeOrderedItems = useMemo(() => {
@@ -373,6 +373,12 @@ const OrderedItemsStyle = styled.div `
373
373
  column-gap: var(--sp1x);
374
374
  }
375
375
 
376
+ .gift-name-text {
377
+ display: block;
378
+ color: var(--pink1000);
379
+ white-space: pre-wrap;
380
+ }
381
+
376
382
  @media only screen and (max-width: ${(props) => props.theme.account.mediaQuery.account_DesktopSizeXLMin}) and (min-width: ${(props) => props.theme.account.mediaQuery.account_DesktopSizeL}) {
377
383
  --account_orderItemsMarginTop: var(--sp11x);
378
384
  --account_spaceLineMarginTop: var(--sp2x);
@@ -1,11 +1,11 @@
1
1
  import React from 'react';
2
2
  import { Text, api, useTranslation } from '@weareconceptstudio/core';
3
- import { useCheckoutContext } from '../../checkout';
3
+ import { useCart } from '../../cart';
4
4
  import { popupCardSVG } from '../icons';
5
5
  //* Style
6
6
  import AddNewCardStyle from './style';
7
7
  const AddNewCard = ({ className }) => {
8
- const { isCheckoutPage } = useCheckoutContext();
8
+ const { isCheckoutPage } = useCart();
9
9
  const { translate } = useTranslation();
10
10
  const handleNewCard = async () => {
11
11
  return await api.post('add-card', { backUrl: `${window.location.href}`, isCheckout: isCheckoutPage }).then((res) => {
@@ -1,15 +1,15 @@
1
1
  import React, { useCallback } from 'react';
2
2
  import { Text, useUi } from '@weareconceptstudio/core';
3
3
  import { mastercardSVG, visaSVG } from '../icons';
4
+ import { useCart } from '../../cart';
4
5
  //* Components
5
6
  import WarningMessageForPopup from '../../../components/WarningMessageForPopup';
6
7
  import AccountButton from '../../../components/AccountButton';
7
8
  //* Style
8
9
  import CardStyle from './style';
9
- import { useCheckoutContext } from '../../checkout';
10
10
  const Card = ({ cardOption, className, selectedPayment, setSelectedPayment, deleteCard }) => {
11
11
  const { openPopup } = useUi();
12
- const { isCheckoutPage } = useCheckoutContext();
12
+ const { isCheckoutPage } = useCart();
13
13
  //! Handle Popups
14
14
  const handleDeletePopup = useCallback(() => {
15
15
  openPopup(React.createElement(WarningMessageForPopup, { isDelete: true, title: 'account.payment_management.deleteCardMessage', description: 'account.payment_management.confirmDeleteCard', onRemove: () => deleteCard(cardOption.id) }), {
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { Text } from '@weareconceptstudio/core';
3
- import { useCheckoutContext } from '../../checkout';
3
+ import { useCart } from '../../cart';
4
4
  //* Components
5
5
  import AccountButton from '../../../components/AccountButton';
6
6
  import PaymentMethods from '../PaymentMethods';
@@ -10,7 +10,7 @@ import PaymentStyle from './style';
10
10
  import { useAccountContext } from '../../../AccountProvider';
11
11
  const Payment = ({ title, onClick, className }) => {
12
12
  const { useUser } = useAccountContext();
13
- const { checkoutData, fillCheckoutData } = useCheckoutContext();
13
+ const { checkoutData, fillCheckoutData } = useCart();
14
14
  const { user } = useUser();
15
15
  const setSelectedPayment = (value) => {
16
16
  fillCheckoutData('paymentType', value);
@@ -18,7 +18,7 @@ const Payment = ({ title, onClick, className }) => {
18
18
  return (React.createElement(PaymentStyle, { className: `item-container ${className || ''}` },
19
19
  React.createElement("div", { className: `change-payment-wrap` },
20
20
  React.createElement(Text, { className: `account-p account-p2 account-font-bold account-primary-color1`, text: title }),
21
- user.payment_method && (React.createElement(AccountButton, { onClick: onClick, btnType: `green-small-text`, text: `account.general_actions.change` }))),
22
- user.payment_method ? (React.createElement(SelectedPayment, null)) : (React.createElement(PaymentMethods, { selectedPayment: checkoutData.paymentType, setSelectedPayment: setSelectedPayment }))));
21
+ user?.payment_method && (React.createElement(AccountButton, { onClick: onClick, btnType: `green-small-text`, text: `account.general_actions.change` }))),
22
+ user?.payment_method ? (React.createElement(SelectedPayment, null)) : (React.createElement(PaymentMethods, { selectedPayment: checkoutData.paymentType, setSelectedPayment: setSelectedPayment }))));
23
23
  };
24
24
  export default Payment;
@@ -8,7 +8,7 @@ const PaymentMethods = ({ className, selectedPayment, setSelectedPayment }) => {
8
8
  const { paymentOptions, useUser } = useAccountContext();
9
9
  const { user } = useUser();
10
10
  const paymentMethods = useMemo(() => {
11
- return !!user.payment_method ? paymentOptions : [{ label: 'Card', value: 'credit_card' }, ...paymentOptions];
11
+ return !!user?.payment_method ? paymentOptions : [{ label: 'Card', value: 'credit_card' }, ...paymentOptions];
12
12
  }, [user, paymentOptions]);
13
13
  return (React.createElement(PaymentMethodsStyle, { className: `payment-item-container ${className || ''}` }, paymentMethods.map((item, index) => (React.createElement(PaymentMethodItem, { key: index, item: item, selectedPayment: selectedPayment, setSelectedPayment: setSelectedPayment })))));
14
14
  };
@@ -1,6 +1,6 @@
1
1
  import React, { useState } from 'react';
2
2
  import { useUi, Text } from '@weareconceptstudio/core';
3
- import { useCheckoutContext } from '../../checkout';
3
+ import { useCart } from '../../cart';
4
4
  //* Components
5
5
  import AccountButton from '../../../components/AccountButton';
6
6
  import PaymentWrap from '../PaymentWrap';
@@ -8,7 +8,7 @@ import PaymentWrap from '../PaymentWrap';
8
8
  import SelectPaymentMethodPopupStyle from './style';
9
9
  const SelectPaymentMethodPopup = () => {
10
10
  const { closePopup } = useUi();
11
- const { checkoutData, fillCheckoutData } = useCheckoutContext();
11
+ const { checkoutData, fillCheckoutData } = useCart();
12
12
  const [selectedPayment, setSelectedPayment] = useState(checkoutData.paymentType);
13
13
  const handlePaymentMethodChangeSubmit = () => {
14
14
  fillCheckoutData('paymentType', selectedPayment);
@@ -2,10 +2,10 @@ import React, { useMemo } from 'react';
2
2
  import { isNumeric } from '@weareconceptstudio/core';
3
3
  import PaymentMethodItem from '../PaymentMethodItem';
4
4
  import { useAccountContext } from '../../../AccountProvider';
5
- import { useCheckoutContext } from '../../checkout';
5
+ import { useCart } from '../../cart';
6
6
  const SelectedPayment = () => {
7
7
  const { paymentOptions, useUser } = useAccountContext();
8
- const { checkoutData } = useCheckoutContext();
8
+ const { checkoutData } = useCart();
9
9
  const { user } = useUser();
10
10
  const isCardType = useMemo(() => {
11
11
  return isNumeric(checkoutData.paymentType);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weareconceptstudio/account",
3
- "version": "0.5.8",
3
+ "version": "0.6.0",
4
4
  "description": "Concept Studio Account",
5
5
  "author": "Concept Studio",
6
6
  "license": "ISC",
@@ -1,5 +0,0 @@
1
- export function useCheckoutContext(): any;
2
- export function CheckoutProvider({ children }: {
3
- children: any;
4
- }): React.JSX.Element;
5
- import React from 'react';
@@ -1,132 +0,0 @@
1
- import React, { createContext, useContext, useState, useRef, useEffect, useCallback, useMemo } from 'react';
2
- import { api, useTranslation, isNumeric } from '@weareconceptstudio/core';
3
- import { useAccountContext } from '../../AccountProvider';
4
- const CheckoutContext = createContext(null);
5
- export const useCheckoutContext = () => {
6
- const context = useContext(CheckoutContext);
7
- return context;
8
- };
9
- export const CheckoutProvider = ({ children }) => {
10
- const { selectedLang } = useTranslation();
11
- const { useCart, useUser } = useAccountContext();
12
- const { getCart, setCart, itemsCount, mergeCart, items } = useCart();
13
- const { user, isLoggedIn } = useUser();
14
- const form = useRef();
15
- const [checkoutData, setCheckoutData] = useState({
16
- addressId: null,
17
- useBalance: null,
18
- note: '',
19
- paymentType: user?.payment_method || 'cash_on_delivery',
20
- checkGift: {},
21
- });
22
- const [idramForm, setIdramForm] = useState();
23
- //! Has gift from data
24
- useMemo(() => {
25
- items.length &&
26
- setCheckoutData((prev) => {
27
- const checkGift = {};
28
- items?.forEach((item) => {
29
- if (item.is_gift) {
30
- const productId = item.product.id * -1;
31
- checkGift[productId] = (checkGift[productId] || 0) + item.qty;
32
- }
33
- });
34
- return { ...prev, checkGift };
35
- });
36
- }, [items]);
37
- //! Set gift Select
38
- const setCheckGift = useCallback(({ productId, qty } = {}) => {
39
- setCheckoutData((prev) => ({ ...prev, checkGift: { ...prev.checkGift, [productId]: qty } }));
40
- }, []);
41
- const isCheckoutPage = useMemo(() => {
42
- return window.location.href.includes('checkout');
43
- }, [window.location.href]);
44
- const isCartPage = useMemo(() => {
45
- return window.location.href.includes('cart');
46
- }, [window.location.href]);
47
- const checkoutBtnDisabled = useMemo(() => {
48
- let isDisabled = false;
49
- if (isCheckoutPage && isNumeric(checkoutData.paymentType)) {
50
- const selectedCard = user?.cards?.find((card) => card.id == checkoutData.paymentType);
51
- isDisabled = selectedCard.is_expired;
52
- }
53
- if (!itemsCount) {
54
- isDisabled = true;
55
- }
56
- return isDisabled;
57
- }, [checkoutData.paymentType, user, isCheckoutPage, itemsCount]);
58
- const fillCheckoutData = (key, value) => {
59
- setCheckoutData((prev) => ({
60
- ...prev,
61
- [key]: value,
62
- }));
63
- };
64
- const fillCart = useCallback((key, value) => {
65
- setCheckoutData((prev) => {
66
- const updatedData = { ...prev, [key]: value };
67
- getCart(updatedData);
68
- return updatedData;
69
- });
70
- }, [checkoutData]);
71
- const handleCheckout = async () => {
72
- let data = { ...checkoutData };
73
- //! Check gift
74
- if (data.checkGift) {
75
- data.checkGift = Object.entries(data.checkGift)
76
- .filter(([key, value]) => value)
77
- .map(([key, value]) => ({
78
- id: key,
79
- qty: value,
80
- }));
81
- if (!data.checkGift.length) {
82
- delete data.checkGift;
83
- }
84
- }
85
- if (isNumeric(checkoutData.paymentType)) {
86
- data.paymentType = 'credit_card';
87
- data.card_id = Number(checkoutData.paymentType);
88
- }
89
- if (checkoutData.paymentType == 'credit_card') {
90
- data.card_id = 0;
91
- }
92
- return await api.post('checkout', data).then((res) => {
93
- if (res.redirect_url) {
94
- window.location.href = res.redirect_url;
95
- }
96
- else if (res.url) {
97
- idram(res);
98
- }
99
- });
100
- };
101
- const idram = (res) => {
102
- let lang = selectedLang === 'en' ? 'EN' : selectedLang === 'ru' ? 'RU' : 'AM';
103
- const idramForm = (React.createElement("form", { action: res.url, method: 'POST', ref: form },
104
- React.createElement("input", { type: 'hidden', name: 'EDP_LANGUAGE', value: lang }),
105
- Object.keys(res.form).map((i, key) => (React.createElement("input", { key: key, type: 'hidden', name: i, value: res.form[i] })))));
106
- setIdramForm(idramForm);
107
- };
108
- useEffect(() => {
109
- if (form.current) {
110
- form.current.submit();
111
- }
112
- }, [idramForm, form]);
113
- useEffect(() => {
114
- setCart((prev) => ({ ...prev, loading: true }));
115
- getCart(checkoutData);
116
- if (isLoggedIn) {
117
- mergeCart();
118
- }
119
- }, [isCartPage, isCheckoutPage, selectedLang, isLoggedIn]);
120
- return (React.createElement(CheckoutContext.Provider, { value: {
121
- checkoutData,
122
- setCheckoutData,
123
- fillCheckoutData,
124
- handleCheckout,
125
- fillCart,
126
- setCheckGift,
127
- checkoutBtnDisabled,
128
- isCheckoutPage,
129
- } },
130
- children,
131
- idramForm));
132
- };