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