@graphcommerce/magento-cart-shipping-address 2.103.32 → 2.104.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 +11 -0
- package/components/ShippingAddressForm/GetAddresses.graphql +6 -0
- package/components/ShippingAddressForm/SetShippingAddress.graphql +45 -0
- package/{ShippingAddressForm/ShippingAddressForm.graphql → components/ShippingAddressForm/SetShippingBillingAddress.graphql} +1 -1
- package/{ShippingAddressForm → components/ShippingAddressForm}/ShippingAddressForm.tsx +17 -9
- package/{ShippingAddressIdForm → components/ShippingAddressIdForm}/ShippingAddressIdForm.graphql +0 -0
- package/index.ts +2 -2
- package/package.json +10 -10
- package/utils/isSameAddress.ts +36 -0
- package/ShippingAddressForm/GetShippingAddress.graphql +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [2.104.0](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/magento-cart-shipping-address@2.103.33...@graphcommerce/magento-cart-shipping-address@2.104.0) (2021-10-21)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* ability to change shipping address after changing the billing address ([101f11a](https://github.com/ho-nl/m2-pwa/commit/101f11a6472cd6e72e08152cec961df47411f310))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [2.103.1](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/magento-cart-shipping-address@2.103.0...@graphcommerce/magento-cart-shipping-address@2.103.1) (2021-09-27)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @graphcommerce/magento-cart-shipping-address
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
mutation SetShippingAddress(
|
|
2
|
+
$cartId: String!
|
|
3
|
+
$company: String
|
|
4
|
+
$firstname: String!
|
|
5
|
+
$lastname: String!
|
|
6
|
+
$postcode: String!
|
|
7
|
+
$city: String!
|
|
8
|
+
$countryCode: String!
|
|
9
|
+
$regionId: Int
|
|
10
|
+
$street: String!
|
|
11
|
+
$houseNumber: String!
|
|
12
|
+
$addition: String
|
|
13
|
+
$telephone: String = "000 - 000 0000"
|
|
14
|
+
$saveInAddressBook: Boolean!
|
|
15
|
+
$customerNote: String
|
|
16
|
+
) {
|
|
17
|
+
setShippingAddressesOnCart(
|
|
18
|
+
input: {
|
|
19
|
+
cart_id: $cartId
|
|
20
|
+
shipping_addresses: [
|
|
21
|
+
{
|
|
22
|
+
address: {
|
|
23
|
+
company: $company
|
|
24
|
+
firstname: $firstname
|
|
25
|
+
lastname: $lastname
|
|
26
|
+
postcode: $postcode
|
|
27
|
+
city: $city
|
|
28
|
+
country_code: $countryCode
|
|
29
|
+
region_id: $regionId
|
|
30
|
+
street: [$street, $houseNumber, $addition]
|
|
31
|
+
telephone: $telephone
|
|
32
|
+
save_in_address_book: $saveInAddressBook
|
|
33
|
+
}
|
|
34
|
+
customer_notes: $customerNote
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
) {
|
|
39
|
+
cart {
|
|
40
|
+
id
|
|
41
|
+
__typename
|
|
42
|
+
...ShippingAddress
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { useQuery } from '@apollo/client'
|
|
2
2
|
import {
|
|
3
|
+
ApolloCartErrorAlert,
|
|
3
4
|
useCartQuery,
|
|
4
5
|
useFormGqlMutationCart,
|
|
5
|
-
ApolloCartErrorAlert,
|
|
6
6
|
} from '@graphcommerce/magento-cart'
|
|
7
7
|
import { AddressFields, CustomerDocument, NameFields } from '@graphcommerce/magento-customer'
|
|
8
|
-
import {
|
|
8
|
+
import { CountryRegionsDocument, StoreConfigDocument } from '@graphcommerce/magento-store'
|
|
9
9
|
import { Form, FormRow, InputCheckmark } from '@graphcommerce/next-ui'
|
|
10
10
|
import {
|
|
11
11
|
phonePattern,
|
|
@@ -16,16 +16,17 @@ import {
|
|
|
16
16
|
} from '@graphcommerce/react-hook-form'
|
|
17
17
|
import { TextField } from '@material-ui/core'
|
|
18
18
|
import { AnimatePresence } from 'framer-motion'
|
|
19
|
-
import React
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
19
|
+
import React from 'react'
|
|
20
|
+
import { isSameAddress } from '../../utils/isSameAddress'
|
|
21
|
+
import { GetAddressesDocument } from './GetAddresses.gql'
|
|
22
|
+
import { SetShippingAddressDocument } from './SetShippingAddress.gql'
|
|
23
|
+
import { SetShippingBillingAddressDocument } from './SetShippingBillingAddress.gql'
|
|
22
24
|
|
|
23
25
|
export type ShippingAddressFormProps = Pick<UseFormComposeOptions, 'step'>
|
|
24
26
|
|
|
25
27
|
export default function ShippingAddressForm(props: ShippingAddressFormProps) {
|
|
26
28
|
const { step } = props
|
|
27
|
-
const
|
|
28
|
-
const { data: cartQuery } = useCartQuery(GetShippingAddressDocument)
|
|
29
|
+
const { data: cartQuery } = useCartQuery(GetAddressesDocument)
|
|
29
30
|
const { data: config } = useQuery(StoreConfigDocument)
|
|
30
31
|
const { data: countriesData } = useQuery(CountryRegionsDocument)
|
|
31
32
|
const { data: customerQuery } = useQuery(CustomerDocument, { fetchPolicy: 'cache-only' })
|
|
@@ -36,7 +37,14 @@ export default function ShippingAddressForm(props: ShippingAddressFormProps) {
|
|
|
36
37
|
const currentCustomer = customerQuery?.customer
|
|
37
38
|
const currentCountryCode = currentAddress?.country.code ?? shopCountry
|
|
38
39
|
|
|
39
|
-
const
|
|
40
|
+
const shippingAddress = cartQuery?.cart?.shipping_addresses?.[0]
|
|
41
|
+
const billingAddress = cartQuery?.cart?.billing_address
|
|
42
|
+
|
|
43
|
+
const Mutation = isSameAddress(shippingAddress, billingAddress)
|
|
44
|
+
? SetShippingBillingAddressDocument
|
|
45
|
+
: SetShippingAddressDocument
|
|
46
|
+
|
|
47
|
+
const form = useFormGqlMutationCart(Mutation, {
|
|
40
48
|
defaultValues: {
|
|
41
49
|
// todo(paales): change to something more sustainable
|
|
42
50
|
firstname: currentAddress?.firstname ?? currentCustomer?.firstname ?? '',
|
|
@@ -80,7 +88,7 @@ export default function ShippingAddressForm(props: ShippingAddressFormProps) {
|
|
|
80
88
|
const readOnly = formState.isSubmitting && !autoSubmitting
|
|
81
89
|
|
|
82
90
|
return (
|
|
83
|
-
<Form onSubmit={submit} noValidate
|
|
91
|
+
<Form onSubmit={submit} noValidate>
|
|
84
92
|
<AnimatePresence initial={false}>
|
|
85
93
|
<NameFields form={form} key='name' readOnly={readOnly} />
|
|
86
94
|
<AddressFields form={form} key='addressfields' readOnly={readOnly} />
|
package/{ShippingAddressIdForm → components/ShippingAddressIdForm}/ShippingAddressIdForm.graphql
RENAMED
|
File without changes
|
package/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './Api/BillingAddress.gql'
|
|
2
2
|
export * from './Api/ShippingAddress.gql'
|
|
3
3
|
|
|
4
|
-
export * from './ShippingAddressForm/ShippingAddressForm'
|
|
5
|
-
export { default as ShippingAddressForm } from './ShippingAddressForm/ShippingAddressForm'
|
|
4
|
+
export * from './components/ShippingAddressForm/ShippingAddressForm'
|
|
5
|
+
export { default as ShippingAddressForm } from './components/ShippingAddressForm/ShippingAddressForm'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphcommerce/magento-cart-shipping-address",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.104.2",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
6
6
|
"browserslist": [
|
|
@@ -14,20 +14,20 @@
|
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@graphcommerce/browserslist-config-pwa": "^3.0.2",
|
|
17
|
-
"@graphcommerce/eslint-config-pwa": "^3.0
|
|
17
|
+
"@graphcommerce/eslint-config-pwa": "^3.1.0",
|
|
18
18
|
"@graphcommerce/prettier-config-pwa": "^3.0.3",
|
|
19
19
|
"@graphcommerce/typescript-config-pwa": "^3.1.1",
|
|
20
20
|
"@playwright/test": "^1.15.2"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@apollo/client": "^3.4.16",
|
|
24
|
-
"@graphcommerce/graphql": "^2.
|
|
25
|
-
"@graphcommerce/image": "^2.104.
|
|
26
|
-
"@graphcommerce/magento-cart": "^3.2.
|
|
27
|
-
"@graphcommerce/magento-customer": "^3.1.
|
|
28
|
-
"@graphcommerce/magento-store": "^3.0.
|
|
29
|
-
"@graphcommerce/next-ui": "^3.
|
|
30
|
-
"@graphcommerce/react-hook-form": "^2.102.
|
|
24
|
+
"@graphcommerce/graphql": "^2.104.0",
|
|
25
|
+
"@graphcommerce/image": "^2.104.12",
|
|
26
|
+
"@graphcommerce/magento-cart": "^3.2.5",
|
|
27
|
+
"@graphcommerce/magento-customer": "^3.1.8",
|
|
28
|
+
"@graphcommerce/magento-store": "^3.0.30",
|
|
29
|
+
"@graphcommerce/next-ui": "^3.8.1",
|
|
30
|
+
"@graphcommerce/react-hook-form": "^2.102.11",
|
|
31
31
|
"@graphql-typed-document-node/core": "^3.1.0",
|
|
32
32
|
"@material-ui/core": "^4.12.3",
|
|
33
33
|
"@material-ui/lab": "^4.0.0-alpha.60",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"react": "^17.0.2",
|
|
38
38
|
"react-dom": "^17.0.2"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "04a7cc74c49054734b71484e1999af6abfe0ebe2"
|
|
41
41
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { CartAddressFragment } from '@graphcommerce/magento-cart/components/CartAddress/CartAddress.gql'
|
|
2
|
+
|
|
3
|
+
const pluckAddress = ({
|
|
4
|
+
firstname,
|
|
5
|
+
lastname,
|
|
6
|
+
street,
|
|
7
|
+
city,
|
|
8
|
+
country,
|
|
9
|
+
telephone,
|
|
10
|
+
company,
|
|
11
|
+
postcode,
|
|
12
|
+
region,
|
|
13
|
+
}: CartAddressFragment): Omit<CartAddressFragment, '__typename'> => ({
|
|
14
|
+
firstname,
|
|
15
|
+
lastname,
|
|
16
|
+
street,
|
|
17
|
+
city,
|
|
18
|
+
country,
|
|
19
|
+
telephone,
|
|
20
|
+
company,
|
|
21
|
+
postcode,
|
|
22
|
+
region,
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
export function isSameAddress(
|
|
26
|
+
address1: CartAddressFragment | null | undefined,
|
|
27
|
+
address2: CartAddressFragment | null | undefined,
|
|
28
|
+
) {
|
|
29
|
+
// check if both are undefined/null
|
|
30
|
+
if (address1 == address2) return true
|
|
31
|
+
|
|
32
|
+
// one of the thow is undefined/null the other is defined.
|
|
33
|
+
if (!address1 || !address2) return false
|
|
34
|
+
|
|
35
|
+
return JSON.stringify(pluckAddress(address1)) === JSON.stringify(pluckAddress(address2))
|
|
36
|
+
}
|