@riosst100/pwa-marketplace 3.0.1 → 3.0.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/package.json +1 -1
- package/src/componentOverrideMapping.js +1 -0
- package/src/components/OrderDetail/components/itemsOrdered.js +6 -1
- package/src/components/RMAPage/components/productItem.css +15 -0
- package/src/components/RMAPage/components/productItem.js +43 -13
- package/src/components/RMAPage/components/productItem.module.css +15 -0
- package/src/overwrites/peregrine/lib/talons/CartPage/useCartPage.js +121 -0
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
module.exports = componentOverrideMapping = {
|
|
2
2
|
['@magento/peregrine/lib/talons/Header/useCartTrigger.js']: '@riosst100/pwa-marketplace/src/overwrites/peregrine/lib/talons/Header/useCartTrigger.js',
|
|
3
|
+
['@magento/peregrine/lib/talons/CartPage/useCartPage.js']: '@riosst100/pwa-marketplace/src/overwrites/peregrine/lib/talons/CartPage/useCartPage.js',
|
|
3
4
|
[`@magento/venia-ui/lib/components/CartPage/PriceSummary/priceSummary.js`]: '@riosst100/pwa-marketplace/src/overwrites/venia-ui/lib/components/CartPage/PriceSummary/priceSummary.js',
|
|
4
5
|
[`@magento/peregrine/lib/talons/CartPage/PriceSummary/priceSummaryFragments.gql.js`]: '@riosst100/pwa-marketplace/src/overwrites/peregrine/lib/talons/CartPage/PriceSummary/priceSummaryFragments.gql.js',
|
|
5
6
|
[`@magento/venia-ui/lib/components/Adapter/adapter.js`]: '@riosst100/pwa-marketplace/src/overwrites/venia-ui/lib/components/Adapter/adapter.js',
|
|
@@ -11,6 +11,11 @@ const ItemsOrdered = ({ order }) => {
|
|
|
11
11
|
const tax = order?.total?.total_tax?.value || 0;
|
|
12
12
|
const grandTotal = order?.total?.grand_total?.value || 0;
|
|
13
13
|
|
|
14
|
+
const itemLink = useMemo(
|
|
15
|
+
() => resourceUrl(`/${urlKey}${urlSuffix || ''}`),
|
|
16
|
+
[urlKey, urlSuffix]
|
|
17
|
+
);
|
|
18
|
+
|
|
14
19
|
return (
|
|
15
20
|
<>
|
|
16
21
|
<div className='rounded-md border border-gray-100 pb-4'>
|
|
@@ -29,7 +34,7 @@ const ItemsOrdered = ({ order }) => {
|
|
|
29
34
|
{items.map((item, idx) => (
|
|
30
35
|
<tr key={item.id || idx} className='border-b border-gray-150'>
|
|
31
36
|
<td className="col name text-left align-top py-3 px-2.5" data-th="Product Name">
|
|
32
|
-
<
|
|
37
|
+
<Link to={itemLink} className="product name product-item-name">{item.product_name}</Link>
|
|
33
38
|
{item.selected_options && item.selected_options.length > 0 && (
|
|
34
39
|
<dl className="item-options">
|
|
35
40
|
{item.selected_options.map((opt, i) => (
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
.quantityLabel {
|
|
2
|
+
composes: font-medium from global;
|
|
3
|
+
composes: leading-normal from global;
|
|
4
|
+
composes: mb-sm from global;
|
|
5
|
+
composes: pt-xs from global;
|
|
6
|
+
composes: text-colorDefault from global;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.quantityRoot {
|
|
10
|
+
composes: root from '@magento/venia-ui/lib/components/QuantityStepper/quantityStepper.module.css';
|
|
11
|
+
grid-template-columns: auto 4rem auto;
|
|
12
|
+
composes: justify-start from global;
|
|
13
|
+
composes: px-xs from global;
|
|
14
|
+
composes: py-0 from global;
|
|
15
|
+
}
|
|
@@ -4,7 +4,9 @@ import { Link } from 'react-router-dom';
|
|
|
4
4
|
import Select from '@riosst100/pwa-marketplace/src/components/commons/Select';
|
|
5
5
|
import TextField from '@riosst100/pwa-marketplace/src/components/commons/Textfield';
|
|
6
6
|
import Checkbox from '@riosst100/pwa-marketplace/src/components/commons/Checkbox';
|
|
7
|
-
|
|
7
|
+
import QuantityStepper from '@magento/venia-ui/lib/components/QuantityStepper';
|
|
8
|
+
import defaultClasses from './productItem.module.css';
|
|
9
|
+
import { useStyle } from '@magento/venia-ui/lib/classify';
|
|
8
10
|
|
|
9
11
|
const productItem = (props) => {
|
|
10
12
|
const {
|
|
@@ -41,6 +43,8 @@ const productItem = (props) => {
|
|
|
41
43
|
// Input change handler with qty_requested validation
|
|
42
44
|
const handleFieldChange = (field, value) => {
|
|
43
45
|
if (field === 'qty_requested' && item && item.quantity_ordered) {
|
|
46
|
+
console.log('value',value)
|
|
47
|
+
console.log('item.quantity_ordered',item.quantity_ordered)
|
|
44
48
|
if (value > item.quantity_ordered) {
|
|
45
49
|
value = item.quantity_ordered;
|
|
46
50
|
}
|
|
@@ -51,6 +55,8 @@ const productItem = (props) => {
|
|
|
51
55
|
if (onItemChange) onItemChange(field, value);
|
|
52
56
|
};
|
|
53
57
|
|
|
58
|
+
const classes = useStyle(defaultClasses, props.classes);
|
|
59
|
+
|
|
54
60
|
return (
|
|
55
61
|
<>
|
|
56
62
|
<div className='item flex flex-col lg_flex-row justify-between border border-gray-100 rounded-md p-4'>
|
|
@@ -102,23 +108,47 @@ const productItem = (props) => {
|
|
|
102
108
|
<p className='mb-1'>
|
|
103
109
|
Qty Return
|
|
104
110
|
</p>
|
|
105
|
-
<
|
|
111
|
+
<QuantityStepper
|
|
112
|
+
classes={{
|
|
113
|
+
root: classes.quantityRoot
|
|
114
|
+
}}
|
|
115
|
+
initialValue={item.quantity_ordered}
|
|
116
|
+
// itemId={item.id}
|
|
117
|
+
/>
|
|
118
|
+
{/* <TextField
|
|
119
|
+
type="number"
|
|
106
120
|
value={
|
|
107
|
-
itemState.qty_requested
|
|
108
|
-
|
|
109
|
-
|
|
121
|
+
itemState.qty_requested !== undefined
|
|
122
|
+
? String(itemState.qty_requested)
|
|
123
|
+
: ''
|
|
110
124
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
125
|
+
min={1}
|
|
126
|
+
max={item.quantity_ordered}
|
|
127
|
+
onChange={(e) => {
|
|
128
|
+
let val = e.target.value;
|
|
129
|
+
|
|
130
|
+
// Jika kosong
|
|
131
|
+
if (val === '') {
|
|
132
|
+
handleFieldChange('qty_requested', '');
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
val = parseFloat(val);
|
|
137
|
+
|
|
138
|
+
if (isNaN(val)) {
|
|
139
|
+
handleFieldChange('qty_requested', '');
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// batas maksimum
|
|
114
144
|
if (val > item.quantity_ordered) val = item.quantity_ordered;
|
|
115
|
-
|
|
145
|
+
|
|
146
|
+
// batas minimum
|
|
147
|
+
if (val < 1) val = 1;
|
|
148
|
+
|
|
116
149
|
handleFieldChange('qty_requested', val);
|
|
117
150
|
}}
|
|
118
|
-
|
|
119
|
-
min={1}
|
|
120
|
-
max={item.quantity_ordered}
|
|
121
|
-
/>
|
|
151
|
+
/> */}
|
|
122
152
|
</div>
|
|
123
153
|
<div className='flex flex-col mb-2.5'>
|
|
124
154
|
<p className='mb-1'>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
.quantityLabel {
|
|
2
|
+
composes: font-medium from global;
|
|
3
|
+
composes: leading-normal from global;
|
|
4
|
+
composes: mb-sm from global;
|
|
5
|
+
composes: pt-xs from global;
|
|
6
|
+
composes: text-colorDefault from global;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.quantityRoot {
|
|
10
|
+
composes: root from '@magento/venia-ui/lib/components/QuantityStepper/quantityStepper.module.css';
|
|
11
|
+
grid-template-columns: auto 4rem auto;
|
|
12
|
+
composes: justify-start from global;
|
|
13
|
+
composes: px-xs from global;
|
|
14
|
+
composes: py-0 from global;
|
|
15
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { useLazyQuery } from '@apollo/client';
|
|
3
|
+
|
|
4
|
+
import { useCartContext } from '@magento/peregrine/lib/context/cart';
|
|
5
|
+
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
6
|
+
import DEFAULT_OPERATIONS from '@magento/peregrine/lib/talons/CartPage/cartPage.gql';
|
|
7
|
+
import { useEventingContext } from '@magento/peregrine/lib/context/eventing';
|
|
8
|
+
import { useUserContext } from '@magento/peregrine/lib/context/user';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* This talon contains logic for a cart page component.
|
|
12
|
+
* It performs effects and returns prop data for rendering the component.
|
|
13
|
+
*
|
|
14
|
+
* This talon performs the following effects:
|
|
15
|
+
*
|
|
16
|
+
* - Manages the updating state of the cart while cart details data is being fetched
|
|
17
|
+
*
|
|
18
|
+
* @function
|
|
19
|
+
*
|
|
20
|
+
* @param {Object} props
|
|
21
|
+
* @param {CartPageQueries} props.queries GraphQL queries
|
|
22
|
+
*
|
|
23
|
+
* @returns {CartPageTalonProps}
|
|
24
|
+
*
|
|
25
|
+
* @example <caption>Importing into your project</caption>
|
|
26
|
+
* import { useCartPage } from '@magento/peregrine/lib/talons/CartPage/useCartPage';
|
|
27
|
+
*/
|
|
28
|
+
export const useCartPage = (props = {}) => {
|
|
29
|
+
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
30
|
+
const { getCartDetailsQuery } = operations;
|
|
31
|
+
|
|
32
|
+
const [{ cartId }] = useCartContext();
|
|
33
|
+
const [{ isSignedIn }] = useUserContext();
|
|
34
|
+
|
|
35
|
+
const [isProceedToCheckout, setIsProceedToCheckout] = useState(false);
|
|
36
|
+
|
|
37
|
+
const [isCartUpdating, setIsCartUpdating] = useState(false);
|
|
38
|
+
const [wishlistSuccessProps, setWishlistSuccessProps] = useState(null);
|
|
39
|
+
|
|
40
|
+
const [fetchCartDetails, { called, data, loading }] = useLazyQuery(
|
|
41
|
+
getCartDetailsQuery,
|
|
42
|
+
{
|
|
43
|
+
fetchPolicy: 'cache-and-network',
|
|
44
|
+
nextFetchPolicy: 'cache-first',
|
|
45
|
+
errorPolicy: 'all'
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const hasItems = !!data?.cart?.total_quantity;
|
|
50
|
+
const shouldShowLoadingIndicator = called && loading && !hasItems;
|
|
51
|
+
|
|
52
|
+
const cartItems = useMemo(() => {
|
|
53
|
+
return data?.cart?.items || [];
|
|
54
|
+
}, [data]);
|
|
55
|
+
|
|
56
|
+
const onAddToWishlistSuccess = useCallback(successToastProps => {
|
|
57
|
+
setWishlistSuccessProps(successToastProps);
|
|
58
|
+
}, []);
|
|
59
|
+
|
|
60
|
+
const [, { dispatch }] = useEventingContext();
|
|
61
|
+
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (!called && cartId) {
|
|
64
|
+
fetchCartDetails({ variables: { cartId } });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Let the cart page know it is updating while we're waiting on network data.
|
|
68
|
+
setIsCartUpdating(loading);
|
|
69
|
+
}, [fetchCartDetails, called, cartId, loading]);
|
|
70
|
+
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (called && cartId && !loading) {
|
|
73
|
+
dispatch({
|
|
74
|
+
type: 'CART_PAGE_VIEW',
|
|
75
|
+
payload: {
|
|
76
|
+
cart_id: cartId,
|
|
77
|
+
products: cartItems
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}, [called, cartItems, cartId, loading, dispatch]);
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
cartItems,
|
|
85
|
+
hasItems,
|
|
86
|
+
isCartUpdating,
|
|
87
|
+
isGuestCheckout: !isSignedIn,
|
|
88
|
+
fetchCartDetails,
|
|
89
|
+
onAddToWishlistSuccess,
|
|
90
|
+
setIsCartUpdating,
|
|
91
|
+
shouldShowLoadingIndicator,
|
|
92
|
+
wishlistSuccessProps,
|
|
93
|
+
isProceedToCheckout,
|
|
94
|
+
setIsProceedToCheckout
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/** JSDoc type definitions */
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* GraphQL formatted string queries used in this talon.
|
|
102
|
+
*
|
|
103
|
+
* @typedef {Object} CartPageQueries
|
|
104
|
+
*
|
|
105
|
+
* @property {GraphQLAST} getCartDetailsQuery Query for getting the cart details.
|
|
106
|
+
*
|
|
107
|
+
* @see [cartPage.gql.js]{@link https://github.com/magento/pwa-studio/blob/develop/packages/venia-ui/lib/components/CartPage/cartPage.gql.js}
|
|
108
|
+
* for queries used in Venia
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Props data to use when rendering a cart page component.
|
|
113
|
+
*
|
|
114
|
+
* @typedef {Object} CartPageTalonProps
|
|
115
|
+
*
|
|
116
|
+
* @property {Array<Object>} cartItems An array of item objects in the cart.
|
|
117
|
+
* @property {boolean} hasItems True if the cart has items. False otherwise.
|
|
118
|
+
* @property {boolean} isCartUpdating True if the cart is updating. False otherwise.
|
|
119
|
+
* @property {function} setIsCartUpdating Callback function for setting the updating state of the cart page.
|
|
120
|
+
* @property {boolean} shouldShowLoadingIndicator True if the loading indicator should be rendered. False otherwise.
|
|
121
|
+
*/
|