@graphcommerce/magento-cart-pickup 3.0.35 → 3.1.1

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 CHANGED
@@ -1,5 +1,39 @@
1
1
  # Change Log
2
2
 
3
+ ## 3.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`01f1588c9`](https://github.com/graphcommerce-org/graphcommerce/commit/01f1588c9200bb39dd61146e260bfa2b32060612)]:
8
+ - @graphcommerce/graphql@3.4.3
9
+ - @graphcommerce/magento-store@4.2.19
10
+ - @graphcommerce/magento-cart-shipping-method@3.5.1
11
+
12
+ ## 3.1.0
13
+
14
+ ### Minor Changes
15
+
16
+ - [#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
17
+
18
+ ### Patch Changes
19
+
20
+ - 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)]:
21
+ - @graphcommerce/graphql@3.4.2
22
+ - @graphcommerce/react-hook-form@3.3.1
23
+ - @graphcommerce/magento-cart-shipping-method@3.5.0
24
+ - @graphcommerce/next-ui@4.14.0
25
+ - @graphcommerce/magento-store@4.2.18
26
+
27
+ ## 3.0.36
28
+
29
+ ### Patch Changes
30
+
31
+ - Updated dependencies [[`4b8c0a3ef`](https://github.com/graphcommerce-org/graphcommerce/commit/4b8c0a3efa163bc7e4e590f1c251a2a78e000a81), [`18054c441`](https://github.com/graphcommerce-org/graphcommerce/commit/18054c441962ba750bed3acc39ab46c8d3a341ce), [`c5c539c44`](https://github.com/graphcommerce-org/graphcommerce/commit/c5c539c44eeac524cd62ce649e132d2e00333794), [`6f69bc54c`](https://github.com/graphcommerce-org/graphcommerce/commit/6f69bc54c6e0224452817c532ae58d9c332b61ea), [`21886d6fa`](https://github.com/graphcommerce-org/graphcommerce/commit/21886d6fa64a48d9e932bfaf8d138c9b13c36e43)]:
32
+ - @graphcommerce/magento-cart-shipping-method@3.4.0
33
+ - @graphcommerce/graphql@3.4.1
34
+ - @graphcommerce/next-ui@4.13.1
35
+ - @graphcommerce/magento-store@4.2.17
36
+
3
37
  ## 3.0.35
4
38
 
5
39
  ### 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.0.35",
5
+ "version": "3.1.1",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -12,22 +12,22 @@
12
12
  }
13
13
  },
14
14
  "devDependencies": {
15
- "@graphcommerce/eslint-config-pwa": "^4.1.8",
15
+ "@graphcommerce/eslint-config-pwa": "^4.1.9",
16
16
  "@graphcommerce/prettier-config-pwa": "^4.0.6",
17
- "@graphcommerce/typescript-config-pwa": "^4.0.3",
17
+ "@graphcommerce/typescript-config-pwa": "^4.0.4",
18
18
  "@playwright/test": "^1.21.1"
19
19
  },
20
20
  "dependencies": {
21
- "@graphcommerce/graphql": "3.4.0",
21
+ "@graphcommerce/graphql": "3.4.3",
22
22
  "@graphcommerce/image": "3.1.7",
23
- "@graphcommerce/magento-cart-shipping-method": "3.3.1",
24
- "@graphcommerce/magento-store": "4.2.16",
25
- "@graphcommerce/next-ui": "4.13.0",
26
- "@graphcommerce/react-hook-form": "3.3.0"
23
+ "@graphcommerce/magento-cart-shipping-method": "3.5.1",
24
+ "@graphcommerce/magento-store": "4.2.19",
25
+ "@graphcommerce/next-ui": "4.14.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
- }