@graphcommerce/magento-cart-pickup 3.0.36 → 3.1.2
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/CHANGELOG.md +33 -0
- package/components/PickupLocationActionCard.tsx +66 -0
- package/components/PickupLocationSelector.tsx +120 -0
- package/graphql/GetPickupLocationsForProducts.graphql +32 -0
- package/graphql/PickupLocationItems.graphql +26 -0
- package/graphql/SetPickupLocationOnCart.graphql +24 -0
- package/index.ts +1 -1
- package/package.json +7 -7
- package/PickupLocationForm/PickupLocationForm.graphql +0 -13
- package/PickupLocationsQuery/PickupLocationsQuery.graphql +0 -21
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 3.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`e167992df`](https://github.com/graphcommerce-org/graphcommerce/commit/e167992dfdc6964a392af719667f8a188626ab1b), [`9c2504b4e`](https://github.com/graphcommerce-org/graphcommerce/commit/9c2504b4ed75f41d3003c4d3339814010e85e37e)]:
|
|
8
|
+
- @graphcommerce/next-ui@4.15.0
|
|
9
|
+
- @graphcommerce/magento-cart-shipping-method@3.5.2
|
|
10
|
+
- @graphcommerce/magento-store@4.2.20
|
|
11
|
+
|
|
12
|
+
## 3.1.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [[`01f1588c9`](https://github.com/graphcommerce-org/graphcommerce/commit/01f1588c9200bb39dd61146e260bfa2b32060612)]:
|
|
17
|
+
- @graphcommerce/graphql@3.4.3
|
|
18
|
+
- @graphcommerce/magento-store@4.2.19
|
|
19
|
+
- @graphcommerce/magento-cart-shipping-method@3.5.1
|
|
20
|
+
|
|
21
|
+
## 3.1.0
|
|
22
|
+
|
|
23
|
+
### Minor Changes
|
|
24
|
+
|
|
25
|
+
- [#1553](https://github.com/graphcommerce-org/graphcommerce/pull/1553) [`db5d485a2`](https://github.com/graphcommerce-org/graphcommerce/commit/db5d485a23b6b90cfabc9a1320d3c05acbaeb8e2) Thanks [@NickdeK](https://github.com/NickdeK)! - Pickup in store functionality added to checkout
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- Updated dependencies [[`1afc6a547`](https://github.com/graphcommerce-org/graphcommerce/commit/1afc6a5473d6e31f47b5d0188801803b31865290), [`4a4579bb2`](https://github.com/graphcommerce-org/graphcommerce/commit/4a4579bb2f7da378f3fcc504405caf2560dc10f6), [`db5d485a2`](https://github.com/graphcommerce-org/graphcommerce/commit/db5d485a23b6b90cfabc9a1320d3c05acbaeb8e2), [`afcd8e4bf`](https://github.com/graphcommerce-org/graphcommerce/commit/afcd8e4bfb7010da4d5faeed85b61991ed7975f4), [`02e1988e5`](https://github.com/graphcommerce-org/graphcommerce/commit/02e1988e5f361c6f66ae30d3bbee38ef2ac062df), [`323fdee4b`](https://github.com/graphcommerce-org/graphcommerce/commit/323fdee4b15ae23e0e84dd0588cb2c6446dcfd50)]:
|
|
30
|
+
- @graphcommerce/graphql@3.4.2
|
|
31
|
+
- @graphcommerce/react-hook-form@3.3.1
|
|
32
|
+
- @graphcommerce/magento-cart-shipping-method@3.5.0
|
|
33
|
+
- @graphcommerce/next-ui@4.14.0
|
|
34
|
+
- @graphcommerce/magento-store@4.2.18
|
|
35
|
+
|
|
3
36
|
## 3.0.36
|
|
4
37
|
|
|
5
38
|
### Patch Changes
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { ActionCard, ActionCardItemRenderProps } from '@graphcommerce/next-ui'
|
|
2
|
+
import { Trans } from '@lingui/react'
|
|
3
|
+
import { Box, Button } from '@mui/material'
|
|
4
|
+
import { GetPickupLocationsForProductsQuery } from '../graphql/GetPickupLocationsForProducts.gql'
|
|
5
|
+
|
|
6
|
+
export type Location = NonNullable<
|
|
7
|
+
NonNullable<NonNullable<GetPickupLocationsForProductsQuery['pickupLocations']>['items']>[number]
|
|
8
|
+
>
|
|
9
|
+
|
|
10
|
+
export function PickupLocationActionCard(props: ActionCardItemRenderProps<Location>) {
|
|
11
|
+
const { onReset, name, contact_name, street, postcode, city, description, ...cardProps } = props
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<ActionCard
|
|
15
|
+
{...cardProps}
|
|
16
|
+
title={
|
|
17
|
+
<>
|
|
18
|
+
{name} {contact_name}
|
|
19
|
+
</>
|
|
20
|
+
}
|
|
21
|
+
details={
|
|
22
|
+
<>
|
|
23
|
+
<div>{`${street}, ${postcode} ${city}`}</div>
|
|
24
|
+
{cardProps.selected && description && (
|
|
25
|
+
// eslint-disable-next-line react/no-danger
|
|
26
|
+
<Box
|
|
27
|
+
dangerouslySetInnerHTML={{ __html: description }}
|
|
28
|
+
sx={(theme) => ({
|
|
29
|
+
'& table': {
|
|
30
|
+
border: '0 transparent',
|
|
31
|
+
width: 'auto!important',
|
|
32
|
+
maxWidth: '100%',
|
|
33
|
+
|
|
34
|
+
'& td': {
|
|
35
|
+
width: 'auto!important',
|
|
36
|
+
padding: `0 ${theme.spacings.xl}`,
|
|
37
|
+
|
|
38
|
+
'&:first-of-type': {
|
|
39
|
+
paddingLeft: 0,
|
|
40
|
+
},
|
|
41
|
+
'&:last-of-child': {
|
|
42
|
+
paddingRight: 0,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
'& p': {
|
|
47
|
+
margin: 0,
|
|
48
|
+
},
|
|
49
|
+
})}
|
|
50
|
+
/>
|
|
51
|
+
)}
|
|
52
|
+
</>
|
|
53
|
+
}
|
|
54
|
+
action={
|
|
55
|
+
<Button disableRipple variant='inline' color='secondary'>
|
|
56
|
+
<Trans id='Select' />
|
|
57
|
+
</Button>
|
|
58
|
+
}
|
|
59
|
+
reset={
|
|
60
|
+
<Button disableRipple variant='inline' color='secondary' onClick={onReset}>
|
|
61
|
+
<Trans id='Change' />
|
|
62
|
+
</Button>
|
|
63
|
+
}
|
|
64
|
+
/>
|
|
65
|
+
)
|
|
66
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ApolloErrorAlert,
|
|
3
|
+
useFormAutoSubmit,
|
|
4
|
+
useFormCompose,
|
|
5
|
+
UseFormComposeOptions,
|
|
6
|
+
} from '@graphcommerce/ecommerce-ui'
|
|
7
|
+
import { useLazyQuery, useQuery } from '@graphcommerce/graphql'
|
|
8
|
+
import { ProductInfoInput } from '@graphcommerce/graphql-mesh'
|
|
9
|
+
import { useShippingMethod } from '@graphcommerce/magento-cart-shipping-method'
|
|
10
|
+
import { GetShippingMethodsDocument } from '@graphcommerce/magento-cart-shipping-method/components/ShippingMethodForm/GetShippingMethods.gql'
|
|
11
|
+
import { useCartQuery, useFormGqlMutationCart } from '@graphcommerce/magento-cart/hooks'
|
|
12
|
+
import { ActionCardItemBase, ActionCardListForm, FormRow } from '@graphcommerce/next-ui'
|
|
13
|
+
import { Trans } from '@lingui/react'
|
|
14
|
+
import { debounce, TextField } from '@mui/material'
|
|
15
|
+
import { useCallback, useEffect, useMemo } from 'react'
|
|
16
|
+
import { GetPickupLocationsForProductsDocument } from '../graphql/GetPickupLocationsForProducts.gql'
|
|
17
|
+
import {
|
|
18
|
+
SetPickupLocationOnCartDocument,
|
|
19
|
+
SetPickupLocationOnCartMutation,
|
|
20
|
+
SetPickupLocationOnCartMutationVariables,
|
|
21
|
+
} from '../graphql/SetPickupLocationOnCart.gql'
|
|
22
|
+
import { PickupLocationActionCard, Location } from './PickupLocationActionCard'
|
|
23
|
+
|
|
24
|
+
type PickupProps = Pick<UseFormComposeOptions, 'step'>
|
|
25
|
+
|
|
26
|
+
function nonNullable<T>(value: T): value is NonNullable<T> {
|
|
27
|
+
return value !== null && value !== undefined
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function PickupLocationSelector(props: PickupProps) {
|
|
31
|
+
const { step } = props
|
|
32
|
+
const currentShippingMethod = useShippingMethod()
|
|
33
|
+
|
|
34
|
+
const availableMethods = useCartQuery(GetShippingMethodsDocument, { fetchPolicy: 'cache-only' })
|
|
35
|
+
const productInput = (availableMethods.data?.cart?.items ?? [])?.map<ProductInfoInput>((i) =>
|
|
36
|
+
i?.__typename === 'ConfigurableCartItem'
|
|
37
|
+
? { sku: i.configured_variant.sku ?? '' }
|
|
38
|
+
: { sku: i?.product.sku ?? '' },
|
|
39
|
+
)
|
|
40
|
+
const shippingAddress = availableMethods.data?.cart?.shipping_addresses?.[0]
|
|
41
|
+
|
|
42
|
+
const isAvailable = currentShippingMethod === 'instore-pickup' && productInput.length > 0
|
|
43
|
+
|
|
44
|
+
const form = useFormGqlMutationCart<
|
|
45
|
+
SetPickupLocationOnCartMutation,
|
|
46
|
+
SetPickupLocationOnCartMutationVariables & { searchTerm?: string }
|
|
47
|
+
>(SetPickupLocationOnCartDocument, {
|
|
48
|
+
mode: 'onChange',
|
|
49
|
+
defaultValues: {
|
|
50
|
+
searchTerm: shippingAddress?.pickup_location_code
|
|
51
|
+
? undefined
|
|
52
|
+
: shippingAddress?.postcode ?? undefined,
|
|
53
|
+
pickupLocationCode: shippingAddress?.pickup_location_code ?? undefined,
|
|
54
|
+
},
|
|
55
|
+
onBeforeSubmit: ({ cartId, pickupLocationCode }) => ({
|
|
56
|
+
cartId,
|
|
57
|
+
pickupLocationCode,
|
|
58
|
+
pickupLocationAddress: {
|
|
59
|
+
firstname: shippingAddress?.firstname ?? '',
|
|
60
|
+
lastname: shippingAddress?.lastname ?? '',
|
|
61
|
+
city: '_',
|
|
62
|
+
country_code: shippingAddress?.country.code ?? '',
|
|
63
|
+
street: ['_'],
|
|
64
|
+
telephone: shippingAddress?.telephone ?? '_',
|
|
65
|
+
postcode: '_',
|
|
66
|
+
},
|
|
67
|
+
}),
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
const { control, handleSubmit, muiRegister } = form
|
|
71
|
+
const submit = handleSubmit(() => {})
|
|
72
|
+
|
|
73
|
+
useFormCompose({ form, step, submit, key: 'PickupLocationForm' })
|
|
74
|
+
|
|
75
|
+
const searchTerm = form.watch('searchTerm') ?? ''
|
|
76
|
+
const locationsQuery = useQuery(GetPickupLocationsForProductsDocument, {
|
|
77
|
+
variables: {
|
|
78
|
+
productInput,
|
|
79
|
+
searchTerm: `${searchTerm.length < 4 ? '' : searchTerm}:${shippingAddress?.country.code}`,
|
|
80
|
+
},
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
const locationData = locationsQuery.data ?? locationsQuery.previousData
|
|
84
|
+
const locations = useMemo(
|
|
85
|
+
() => (locationData?.pickupLocations?.items ?? []).filter(nonNullable),
|
|
86
|
+
[locationData?.pickupLocations?.items],
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
const selected = form.watch('pickupLocationCode')
|
|
90
|
+
|
|
91
|
+
// What to do when shippingForm is pickup but there aren't any available pickup locations?
|
|
92
|
+
if (!isAvailable) return null
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<form onSubmit={submit} noValidate>
|
|
96
|
+
{!selected && (
|
|
97
|
+
<FormRow>
|
|
98
|
+
<TextField
|
|
99
|
+
label={<Trans id='Zip code or city' />}
|
|
100
|
+
type='text'
|
|
101
|
+
{...muiRegister('searchTerm', { required: false, minLength: 4 })}
|
|
102
|
+
/>
|
|
103
|
+
</FormRow>
|
|
104
|
+
)}
|
|
105
|
+
|
|
106
|
+
<ActionCardListForm<Location & ActionCardItemBase>
|
|
107
|
+
control={control}
|
|
108
|
+
name='pickupLocationCode'
|
|
109
|
+
errorMessage='Please select a pickup location'
|
|
110
|
+
items={locations.map((location) => ({
|
|
111
|
+
...location,
|
|
112
|
+
value: String(location?.pickup_location_code),
|
|
113
|
+
}))}
|
|
114
|
+
render={PickupLocationActionCard}
|
|
115
|
+
/>
|
|
116
|
+
|
|
117
|
+
<ApolloErrorAlert error={availableMethods.error} />
|
|
118
|
+
</form>
|
|
119
|
+
)
|
|
120
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
query GetPickupLocationsForProducts(
|
|
2
|
+
$searchTerm: String!
|
|
3
|
+
$radiusKm: Int = 100
|
|
4
|
+
$productInput: [ProductInfoInput!]!
|
|
5
|
+
$currentPage: Int = 1
|
|
6
|
+
) {
|
|
7
|
+
pickupLocations(
|
|
8
|
+
area: { search_term: $searchTerm, radius: $radiusKm }
|
|
9
|
+
sort: { distance: ASC }
|
|
10
|
+
productsInfo: $productInput
|
|
11
|
+
pageSize: 20
|
|
12
|
+
currentPage: $currentPage
|
|
13
|
+
) {
|
|
14
|
+
items {
|
|
15
|
+
city
|
|
16
|
+
pickup_location_code
|
|
17
|
+
contact_name
|
|
18
|
+
country_id
|
|
19
|
+
description
|
|
20
|
+
email
|
|
21
|
+
fax
|
|
22
|
+
latitude
|
|
23
|
+
longitude
|
|
24
|
+
name
|
|
25
|
+
phone
|
|
26
|
+
postcode
|
|
27
|
+
region
|
|
28
|
+
region_id
|
|
29
|
+
street
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
fragment PickupLocationitems on Cart @inject(into: ["AvailableShippingMethods"]) {
|
|
2
|
+
items {
|
|
3
|
+
__typename
|
|
4
|
+
uid
|
|
5
|
+
... on ConfigurableCartItem {
|
|
6
|
+
configured_variant {
|
|
7
|
+
uid
|
|
8
|
+
sku
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
product {
|
|
12
|
+
uid
|
|
13
|
+
sku
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
shipping_addresses {
|
|
17
|
+
pickup_location_code
|
|
18
|
+
firstname
|
|
19
|
+
lastname
|
|
20
|
+
telephone
|
|
21
|
+
postcode
|
|
22
|
+
country {
|
|
23
|
+
code
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
mutation SetPickupLocationOnCart(
|
|
2
|
+
$cartId: String!
|
|
3
|
+
$pickupLocationCode: String!
|
|
4
|
+
$pickupLocationAddress: CartAddressInput!
|
|
5
|
+
) {
|
|
6
|
+
setShippingAddressesOnCart(
|
|
7
|
+
input: {
|
|
8
|
+
cart_id: $cartId
|
|
9
|
+
shipping_addresses: {
|
|
10
|
+
pickup_location_code: $pickupLocationCode
|
|
11
|
+
address: $pickupLocationAddress
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
) {
|
|
15
|
+
cart {
|
|
16
|
+
id
|
|
17
|
+
__typename
|
|
18
|
+
...ShippingAddress
|
|
19
|
+
shipping_addresses {
|
|
20
|
+
pickup_location_code
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
package/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './components/PickupLocationSelector'
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/magento-cart-pickup",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "3.
|
|
5
|
+
"version": "3.1.2",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -18,16 +18,16 @@
|
|
|
18
18
|
"@playwright/test": "^1.21.1"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@graphcommerce/graphql": "3.4.
|
|
21
|
+
"@graphcommerce/graphql": "3.4.3",
|
|
22
22
|
"@graphcommerce/image": "3.1.7",
|
|
23
|
-
"@graphcommerce/magento-cart-shipping-method": "3.
|
|
24
|
-
"@graphcommerce/magento-store": "4.2.
|
|
25
|
-
"@graphcommerce/next-ui": "4.
|
|
26
|
-
"@graphcommerce/react-hook-form": "3.3.
|
|
23
|
+
"@graphcommerce/magento-cart-shipping-method": "3.5.2",
|
|
24
|
+
"@graphcommerce/magento-store": "4.2.20",
|
|
25
|
+
"@graphcommerce/next-ui": "4.15.0",
|
|
26
|
+
"@graphcommerce/react-hook-form": "3.3.1"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@lingui/react": "^3.13.2",
|
|
30
29
|
"@lingui/core": "^3.13.2",
|
|
30
|
+
"@lingui/react": "^3.13.2",
|
|
31
31
|
"@mui/material": "5.5.3",
|
|
32
32
|
"framer-motion": "^6.2.4",
|
|
33
33
|
"next": "^12.1.2",
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
mutation PickupLocationForm($cartId: String!, $pickupLocationCode: String!) {
|
|
2
|
-
setShippingAddressesOnCart(
|
|
3
|
-
input: { cart_id: $cartId, shipping_addresses: [{ pickup_location_code: $pickupLocationCode }] }
|
|
4
|
-
) {
|
|
5
|
-
cart {
|
|
6
|
-
shipping_addresses {
|
|
7
|
-
...CartAddress
|
|
8
|
-
pickup_location_code
|
|
9
|
-
}
|
|
10
|
-
...ShippingAddress
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
query PickupLocationsQuery($searchTerm: String!) {
|
|
2
|
-
pickupLocations(area: { search_term: $searchTerm, radius: 100 }, pageSize: 1000) {
|
|
3
|
-
items {
|
|
4
|
-
city
|
|
5
|
-
pickup_location_code
|
|
6
|
-
contact_name
|
|
7
|
-
country_id
|
|
8
|
-
description
|
|
9
|
-
email
|
|
10
|
-
fax
|
|
11
|
-
latitude
|
|
12
|
-
longitude
|
|
13
|
-
name
|
|
14
|
-
phone
|
|
15
|
-
postcode
|
|
16
|
-
region
|
|
17
|
-
region_id
|
|
18
|
-
street
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|