@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
@@ -0,0 +1,243 @@
1
+ 'use client';
2
+ import React, { useState, useRef, createContext, useContext, useMemo, useEffect, useCallback } from 'react';
3
+ import { getCookie, setCookie, removeCookie, useTranslation, api, isNumeric, cleanObject } from '@weareconceptstudio/core';
4
+ const CartContext = createContext({});
5
+ export const useCart = () => useContext(CartContext);
6
+ export const CartProvider = ({ useUser, children }) => {
7
+ const { selectedLang } = useTranslation();
8
+ const { isLoggedIn, user } = useUser();
9
+ const idramFormRef = useRef(null);
10
+ const [idramForm, setIdramForm] = useState(null);
11
+ const [cartState, setCartState] = useState({
12
+ itemsCount: 0,
13
+ items: [],
14
+ subtotal: 0,
15
+ total: 0,
16
+ loading: true,
17
+ currency: 'AMD',
18
+ shippingCost: '-',
19
+ freeShippingRange: null,
20
+ shippingCostValue: null,
21
+ hasFreeGift: null,
22
+ giftThresholdRemaining: null,
23
+ useBalance: null,
24
+ discount: null,
25
+ appliedPromotions: [],
26
+ });
27
+ const initialCheckoutData = JSON.parse(sessionStorage.getItem('checkoutData') || '{}') || {
28
+ addressId: null,
29
+ useBalance: null,
30
+ note: '',
31
+ paymentType: user?.payment_method || 'cash_on_delivery',
32
+ checkGift: [],
33
+ card_id: null,
34
+ };
35
+ const [checkoutData, setCheckoutData] = useState(initialCheckoutData);
36
+ const checkoutDataRef = useRef(checkoutData);
37
+ useEffect(() => {
38
+ if (typeof window !== 'undefined') {
39
+ sessionStorage.setItem('checkoutData', JSON.stringify(checkoutData));
40
+ }
41
+ checkoutDataRef.current = checkoutData;
42
+ }, [checkoutData]);
43
+ const getCookieItems = () => {
44
+ const cookieCart = getCookie('cart');
45
+ return cookieCart ? JSON.parse(cookieCart) : [];
46
+ };
47
+ const setResourceDecorator = (data) => {
48
+ setCartState((prev) => ({ ...prev, ...data, loading: false }));
49
+ setCheckoutData((prev) => ({ ...prev, useBalance: data.useBalance }));
50
+ };
51
+ const isCheckoutPage = useMemo(() => {
52
+ return window.location.href.includes('checkout');
53
+ }, [window.location.href]);
54
+ const isCartPage = useMemo(() => {
55
+ return window.location.href.includes('cart');
56
+ }, [window.location.href]);
57
+ const cartResourceType = useMemo(() => {
58
+ return isCheckoutPage || isCartPage ? 'cart' : 'cart-summary';
59
+ }, [isCheckoutPage, isCartPage]);
60
+ const getCart = async (params = {}) => {
61
+ let newParams = { ...cleanObject(params), ...cleanObject(checkoutDataRef.current), cartResourceType };
62
+ if (isLoggedIn) {
63
+ const { data } = await api.get({ url: 'cart', lang: selectedLang, params: newParams });
64
+ setResourceDecorator(data);
65
+ }
66
+ else {
67
+ const cookieItems = getCookieItems();
68
+ const { data } = await api.post('guest-cart', { items: cookieItems, ...newParams }, selectedLang);
69
+ setResourceDecorator(data);
70
+ }
71
+ };
72
+ const toggleCartItem = async ({ productId, qty }) => {
73
+ if (qty === 0)
74
+ return deleteCartItem({ productId });
75
+ return isLoggedIn ? customerToggleCartItem({ productId, qty }) : guestToggleCartItem({ productId, qty });
76
+ };
77
+ const guestToggleCartItem = async ({ productId, qty }) => {
78
+ const cookieItems = getCookieItems();
79
+ const existingItem = cookieItems.find((item) => item.productId === productId);
80
+ const items = existingItem
81
+ ? cookieItems.map((item) => (item.productId === productId ? { ...item, qty } : item))
82
+ : [...cookieItems, { productId, qty }];
83
+ setCookie('cart', JSON.stringify(items));
84
+ await getCart();
85
+ return Promise.resolve();
86
+ };
87
+ const customerToggleCartItem = async ({ productId, qty }) => {
88
+ let params = { productId, qty, ...cleanObject(checkoutDataRef.current), cartResourceType };
89
+ const { data } = await api.post('toggle-cart-item', params, selectedLang);
90
+ setResourceDecorator(data);
91
+ };
92
+ const deleteCartItem = async ({ productId }) => {
93
+ let params = { productId, ...cleanObject(checkoutDataRef.current), cartResourceType };
94
+ if (isLoggedIn) {
95
+ const { data } = await api.post('delete-cart-item', params);
96
+ setResourceDecorator(data);
97
+ }
98
+ else {
99
+ const items = getCookieItems().filter((item) => item.productId !== productId);
100
+ setCookie('cart', JSON.stringify(items));
101
+ await getCart();
102
+ }
103
+ };
104
+ const mergeCart = async () => {
105
+ const cookieItems = getCookieItems();
106
+ if (cookieItems.length > 0) {
107
+ removeCookie('cart');
108
+ const { data } = await api.post('merge-cart', { items: cookieItems }, selectedLang);
109
+ setResourceDecorator(data);
110
+ }
111
+ };
112
+ const clearCart = async () => {
113
+ if (isLoggedIn) {
114
+ const { data } = await api.post('clear-cart');
115
+ setResourceDecorator(data);
116
+ }
117
+ else {
118
+ removeCookie('cart');
119
+ await getCart();
120
+ }
121
+ };
122
+ // TODO: make router push func
123
+ const reorder = async (orderId) => {
124
+ const { data } = await api.post('reorder', { orderId });
125
+ setResourceDecorator(data);
126
+ // router.push(getLangPath('cart'));
127
+ };
128
+ //! Has gift from data
129
+ useEffect(() => {
130
+ if (cartState.items.length && !checkoutData.checkGift.length) {
131
+ setCheckoutData((prev) => {
132
+ const checkGift = cartState.items
133
+ .filter((item) => item.is_gift)
134
+ .map((item) => ({
135
+ id: item.product.id,
136
+ qty: item.qty,
137
+ promotionId: item.appliedPromotion.id,
138
+ }));
139
+ return { ...prev, checkGift };
140
+ });
141
+ }
142
+ }, [cartState.items]);
143
+ //! Set gift Select
144
+ const setCheckGift = useCallback(({ promotionId, qty, productId }) => {
145
+ setCheckoutData((prev) => ({
146
+ ...prev,
147
+ checkGift: [
148
+ ...prev.checkGift.map((item) => {
149
+ if (item.promotionId == promotionId && item.id == productId) {
150
+ return { ...item, qty };
151
+ }
152
+ else {
153
+ return { ...item };
154
+ }
155
+ }),
156
+ ],
157
+ }));
158
+ }, []);
159
+ const checkoutBtnDisabled = useMemo(() => {
160
+ let isDisabled = false;
161
+ if (isCheckoutPage && isNumeric(checkoutData.paymentType)) {
162
+ const selectedCard = user?.cards?.find((card) => card.id == checkoutData.paymentType);
163
+ isDisabled = selectedCard.is_expired;
164
+ }
165
+ if (!cartState.itemsCount) {
166
+ isDisabled = true;
167
+ }
168
+ return isDisabled;
169
+ }, [checkoutData.paymentType, user, isCheckoutPage, cartState.itemsCount]);
170
+ const fillCheckoutData = (key, value) => {
171
+ setCheckoutData((prev) => {
172
+ const updatedData = { ...prev, [key]: value };
173
+ sessionStorage.setItem('checkoutData', JSON.stringify(updatedData));
174
+ return updatedData;
175
+ });
176
+ };
177
+ const fillCart = useCallback((key, value) => {
178
+ const updatedData = { ...checkoutData, [key]: value };
179
+ getCart(updatedData);
180
+ }, [checkoutData]);
181
+ const idram = (res) => {
182
+ let lang = selectedLang === 'en' ? 'EN' : selectedLang === 'ru' ? 'RU' : 'AM';
183
+ const idramForm = (React.createElement("form", { action: res.url, method: 'POST', ref: idramFormRef },
184
+ React.createElement("input", { type: 'hidden', name: 'EDP_LANGUAGE', value: lang }),
185
+ Object.keys(res.form).map((i, key) => (React.createElement("input", { key: key, type: 'hidden', name: i, value: res.form[i] })))));
186
+ setIdramForm(idramForm);
187
+ };
188
+ const handleCheckout = async () => {
189
+ let data = cleanObject({ ...checkoutData });
190
+ //! Check gift
191
+ if (data.checkGift) {
192
+ data.checkGift = data.checkGift.filter((item) => item.qty);
193
+ if (!data.checkGift.length)
194
+ delete data.checkGift;
195
+ }
196
+ if (isNumeric(checkoutData.paymentType)) {
197
+ data.paymentType = 'credit_card';
198
+ data.card_id = Number(checkoutData.paymentType);
199
+ }
200
+ if (checkoutData.paymentType == 'credit_card') {
201
+ data.card_id = 0;
202
+ }
203
+ return await api.post('checkout', data).then((res) => {
204
+ if (res.redirect_url) {
205
+ window.location.href = res.redirect_url;
206
+ }
207
+ else if (res.url) {
208
+ idram(res);
209
+ }
210
+ });
211
+ };
212
+ useEffect(() => {
213
+ setCartState((prev) => ({ ...prev, loading: true }));
214
+ getCart(checkoutData);
215
+ if (isLoggedIn)
216
+ mergeCart();
217
+ }, [isCartPage, isCheckoutPage, selectedLang, isLoggedIn]);
218
+ useEffect(() => {
219
+ if (idramFormRef.current) {
220
+ idramFormRef.current.submit();
221
+ }
222
+ }, [idramForm, idramFormRef]);
223
+ return (React.createElement(CartContext.Provider, { value: {
224
+ ...cartState,
225
+ checkoutData,
226
+ getCart,
227
+ setCartState: (data) => setCartState((prev) => ({ ...prev, ...data })),
228
+ toggleCartItem,
229
+ deleteCartItem,
230
+ clearCart,
231
+ reorder,
232
+ mergeCart,
233
+ setCheckoutData,
234
+ fillCheckoutData,
235
+ handleCheckout,
236
+ fillCart,
237
+ setCheckGift,
238
+ checkoutBtnDisabled,
239
+ isCheckoutPage,
240
+ } },
241
+ children,
242
+ idramForm));
243
+ };
@@ -1,14 +1,14 @@
1
1
  import React from 'react';
2
2
  import { useUi } from '@weareconceptstudio/core';
3
- import { useCheckoutContext } from '../../../checkout';
4
3
  import { useAccountContext } from '../../../../AccountProvider';
4
+ import { useCart } from '../../CartProvider';
5
5
  import { skeletonCategoryName, skeletonMenuTitle, skeletonShopUrl, skeletonCategoryNameAdapting } from './icons';
6
6
  import SkeletonItemCart from './SkeletonItem';
7
7
  import SkeletonCartTemplateStyle from './style';
8
8
  const SkeletonCartTemplate = () => {
9
9
  const { winWidth } = useUi();
10
- const { isCheckoutPage } = useCheckoutContext();
11
10
  const { shopUrl } = useAccountContext();
11
+ const { isCheckoutPage } = useCart();
12
12
  return (React.createElement(SkeletonCartTemplateStyle, { className: isCheckoutPage ? 'checkout-style' : '' },
13
13
  React.createElement("div", { className: 'left-bar' },
14
14
  shopUrl ? React.createElement("div", { className: 'wrapper-url' }, skeletonShopUrl) : React.createElement(React.Fragment, null),
@@ -1,6 +1,6 @@
1
1
  import React, { useEffect, useRef } from 'react';
2
2
  import { Page, useTranslation } from '@weareconceptstudio/core';
3
- import { CartItems, EmptyCart } from '..';
3
+ import { CartItems, EmptyCart, useCart } from '..';
4
4
  import { TotalCheckout, AccountButton } from '../../../components';
5
5
  import { useAccountContext } from '../../../AccountProvider';
6
6
  import AccountContainer from '../../../components/AccountContainer';
@@ -14,7 +14,7 @@ import CartTemplateStyle from './style';
14
14
  import SkeletonCartTemplate from './Skeleton';
15
15
  const CartTemplate = ({ children, checkoutUrl = '/checkout/', moreMenu, emptyCartIcon }) => {
16
16
  const { translate } = useTranslation();
17
- const { shopUrl, useCart } = useAccountContext();
17
+ const { shopUrl } = useAccountContext();
18
18
  const { itemsCount, loading, toggleCartItem, deleteCartItem } = useCart();
19
19
  return (React.createElement(Page, { className: 'cart use-account' },
20
20
  React.createElement(AccountContainer, { className: `second-version` },
@@ -1,3 +1,4 @@
1
+ export * from './CartProvider';
1
2
  export { default as EmptyCart } from './EmptyCart';
2
3
  export { default as CartItems } from './CartItems';
3
4
  export { default as CartTemplate } from './CartTemplate';
@@ -1,3 +1,4 @@
1
+ export * from './CartProvider';
1
2
  export { default as EmptyCart } from './EmptyCart';
2
3
  export { default as CartItems } from './CartItems';
3
4
  export { default as CartTemplate } from './CartTemplate';
@@ -13,7 +13,7 @@ const StepReview = () => {
13
13
  return (React.createElement("div", { className: 'step-review' },
14
14
  React.createElement(SelectAddress, null),
15
15
  React.createElement(Payment, { title: 'account.payment_management.payment', onClick: handleSelectPopup }),
16
- React.createElement(CartItems, { smallFontSize: true, className: `checkout-mt`, title: 'account.order_management.orderItems', additionalParameters: {
16
+ React.createElement(CartItems, { isCheckout: true, smallFontSize: true, className: `checkout-mt`, title: 'account.order_management.orderItems', additionalParameters: {
17
17
  remove: false,
18
18
  select: false,
19
19
  horizontalLine: false,
@@ -3,7 +3,7 @@ import { Page } from '@weareconceptstudio/core';
3
3
  import { Sequence, TotalCheckout } from '../../../components';
4
4
  import { useAddressContext } from '../../address';
5
5
  import { useAccountContext } from '../../../AccountProvider';
6
- import { useCheckoutContext } from '../CheckoutProvider';
6
+ import { useCart } from '../../cart';
7
7
  import StepReview from './StepReview';
8
8
  import StepShipping from './StepShipping';
9
9
  import AccountContainer from '../../../components/AccountContainer';
@@ -15,10 +15,9 @@ import SequenceSkeleton from '../../../components/Sequence/Skeleton';
15
15
  import SkeletonAddressSelect from '../../address/SelectAddress/Skeleton';
16
16
  const CheckoutTemplate = () => {
17
17
  const firstStepFormRef = useRef(null);
18
- const { useCart, useUser } = useAccountContext();
18
+ const { useUser } = useAccountContext();
19
19
  const { hasCheckoutAddress, addressLoading } = useAddressContext();
20
- const { handleCheckout } = useCheckoutContext();
21
- const { itemsCount, loading } = useCart();
20
+ const { itemsCount, loading, handleCheckout } = useCart();
22
21
  const { user } = useUser();
23
22
  const checkStep = {
24
23
  isShipping: !hasCheckoutAddress,
@@ -6,12 +6,13 @@ import ThankYouMessageStyle from './style';
6
6
  import { useAccountContext } from '../../../AccountProvider';
7
7
  import { confirmImage } from './icons';
8
8
  import AccountContainer from '../../../components/AccountContainer';
9
+ import { useCart } from '../../cart';
9
10
  const ThankYouTemplate = ({ orderNumber, thankIcon }) => {
10
- const { shopUrl, useCart } = useAccountContext();
11
+ const { shopUrl } = useAccountContext();
11
12
  const { translate } = useTranslation();
12
- const cart = useCart();
13
+ const { clearCart } = useCart();
13
14
  useEffect(() => {
14
- cart.clearCart();
15
+ clearCart();
15
16
  }, []);
16
17
  return (React.createElement(Page, { className: 'thank-you-message use-account' },
17
18
  React.createElement(ThankYouMessageStyle, null,
@@ -1,3 +1,2 @@
1
- export * from './CheckoutProvider';
2
1
  export { default as CheckoutTemplate } from './CheckoutTemplate';
3
2
  export { default as ThankYouTemplate } from './ThankYouTemplate';
@@ -1,3 +1,2 @@
1
- export * from './CheckoutProvider';
2
1
  export { default as CheckoutTemplate } from './CheckoutTemplate';
3
2
  export { default as ThankYouTemplate } from './ThankYouTemplate';
@@ -13,7 +13,7 @@ const Item = memo(({ data }) => {
13
13
  data.is_gift ? React.createElement("div", { className: 'wrapper-gift-icon' }, defaultIconGift) : null,
14
14
  React.createElement(Image, { src: data.product?.image?.src, alt: data.product?.image?.alt })),
15
15
  React.createElement("div", { className: `col-1-right-wrap` },
16
- React.createElement(AccountButton, { disabled: !data.product, btnType: `green-large-text`, className: `ordered-item-title`, text: data.product?.name || data?.product_name, onClick: () => data.product && handleProductClick(data.product) }),
16
+ React.createElement(AccountButton, { disabled: !data.product, btnType: `green-large-text`, className: `ordered-item-title`, text: data.product?.name || data.product_name, onClick: () => data.product && handleProductClick(data.product) }),
17
17
  data.color ? (React.createElement("div", { className: `right-first-item-wrap` },
18
18
  React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color1`, text: `account.general_actions.color` }),
19
19
  "\u00A0",
@@ -26,25 +26,29 @@ const Item = memo(({ data }) => {
26
26
  React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color1`, text: data.product.short_info_2 }))) : null)),
27
27
  React.createElement("div", { className: `col-item tl-col-2` },
28
28
  React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color1`, text: data?.qty })),
29
- React.createElement("div", { className: `col-item tl-col-3 col-item-3 nowrap` }, data.sale_price && !data.is_gift ? (React.createElement("div", null,
29
+ React.createElement("div", { className: `col-item tl-col-3 col-item-3 nowrap` }, (data.sale_price || data.product?.discount) && !data.is_gift ? (React.createElement("div", null,
30
30
  React.createElement(Text, { className: `account-p account-p3 account-font-bold account-secondary-color2 align-right order-sale-price`, text: handlePriceCheckFunc(data.sale_price, currency) }),
31
31
  React.createElement("div", { className: 'wrapper-discount' },
32
- data?.product?.discount ? (React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color2 discount-text` },
32
+ data.product?.discount ? (React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color2 discount-text` },
33
33
  data.product.discount,
34
- data?.product?.discount_type === 'percentage' ? '%' : ` ${currency}`,
34
+ data.product?.discount_type === 'percentage' ? '%' : ` ${currency}`,
35
35
  "\u00A0",
36
36
  React.createElement("span", { className: 'lowercase' }, translate('account.order_balance.discount')))) : null,
37
- React.createElement(Text, { className: `account-p account-p3 account-font-regular account-primary-color2 line-through value align-right order-price1`, text: handlePriceCheckFunc(data.price, currency) })))) : (React.createElement(Text, { className: `account-p account-p3 account-font-bold account-primary-color1 align-right order-sale-price`, text: handlePriceCheckFunc(data.is_gift ? 0 : data.price, currency) }))),
37
+ React.createElement(Text, { className: `account-p account-p3 account-font-regular account-primary-color2 line-through value align-right order-price1`, text: handlePriceCheckFunc(data.price, currency) })))) : (React.createElement(Text, { className: `account-p account-p3 account-font-bold account-primary-color1 align-right order-sale-price` }, data.is_gift ? (React.createElement(React.Fragment, null,
38
+ handlePriceCheckFunc(0, currency),
39
+ React.createElement("span", { className: 'gift-name-text' }, data?.appliedPromotion?.name || 'Karlen'))) : (handlePriceCheckFunc(data.price, currency))))),
38
40
  React.createElement("div", { className: `col-item tl-col-4 col-item-4 nowrap price-block` },
39
41
  React.createElement("div", { className: `col-item-inner-wrap` },
40
- React.createElement("div", { className: `flex-end-wrap` }, data.sale_total && !data.is_gift ? (React.createElement("div", null,
42
+ React.createElement("div", { className: `flex-end-wrap` }, (data.sale_total || data.product?.discount) && !data.is_gift ? (React.createElement("div", null,
41
43
  React.createElement(Text, { className: `account-p account-p3 account-font-bold account-secondary-color2 align-right order-sale-price`, text: handlePriceCheckFunc(data.sale_total, currency) }),
42
44
  React.createElement("div", { className: 'wrapper-discount' },
43
- data?.product?.discount ? (React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color2 discount-text` },
45
+ data.product?.discount ? (React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color2 discount-text` },
44
46
  data.product.discount,
45
- data?.product?.discount_type === 'percentage' ? '%' : ` ${currency}`,
47
+ data.product?.discount_type === 'percentage' ? '%' : ` ${currency}`,
46
48
  "\u00A0",
47
49
  React.createElement("span", { className: 'lowercase' }, translate('account.order_balance.discount')))) : null,
48
- React.createElement(Text, { className: `account-p account-p3 account-font-regular account-primary-color2 line-through value align-right order-price1`, text: handlePriceCheckFunc(data.total, currency) })))) : (React.createElement(Text, { className: `account-p account-p3 account-font-bold account-primary-color1 align-right order-sale-price`, text: `${handlePriceCheckFunc(data.is_gift ? 0 : data.total, currency)}` }))))))));
50
+ React.createElement(Text, { className: `account-p account-p3 account-font-regular account-primary-color2 line-through value align-right order-price1`, text: handlePriceCheckFunc(data.total, currency) })))) : (React.createElement(Text, { className: `account-p account-p3 account-font-bold account-primary-color1 align-right order-sale-price` }, data.is_gift ? (React.createElement(React.Fragment, null,
51
+ handlePriceCheckFunc(0, currency),
52
+ React.createElement("span", { className: 'gift-name-text' }, data?.appliedPromotion?.name || 'Karlen'))) : (handlePriceCheckFunc(data.total, currency))))))))));
49
53
  });
50
54
  export default Item;
@@ -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",
@@ -31,25 +31,29 @@ const ItemMobile = memo(({ data }) => {
31
31
  React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color1`, text: data?.qty })),
32
32
  React.createElement("div", { className: `mobile-price-wrap nowrap` },
33
33
  React.createElement(Text, { className: `account-p account-p3 account-font-medium account-primary-color1`, text: `account.order_balance.price` }),
34
- data.sale_price && !data.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.9",
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';