Skip to content

Commit 104a15b

Browse files
committed
fix: update ship to different address status on save
1 parent 639f630 commit 104a15b

4 files changed

Lines changed: 19 additions & 6 deletions

File tree

components/composite/StepCustomer/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// import { Address, AddressField } from "@commercelayer/react-components"
22
import classNames from "classnames"
3-
import { Fragment, useContext, useState } from "react"
3+
import { Fragment, useContext, useEffect, useState } from "react"
44
import { useTranslation } from "react-i18next"
55

66
import { AccordionContext } from "components/data/AccordionProvider"
@@ -83,6 +83,10 @@ export const StepCustomer: React.FC<Props> = () => {
8383
!hasSameAddresses
8484
)
8585

86+
useEffect(() => {
87+
setShipToDifferentAddress(!hasSameAddresses)
88+
}, [hasSameAddresses])
89+
8690
const [disabledShipToDifferentAddress, setDisabledShipToDifferentAddress] =
8791
useState(
8892
!!(

components/data/AppProvider/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,15 @@ export async function checkAndSetDefaultAddressForOrder({
173173
}
174174
}
175175

176-
interface IsBillingAddresSameAsShippingAddressProps {
176+
interface IsBillingAddressSameAsShippingAddressProps {
177177
billingAddress: Address | undefined
178178
shippingAddress: Address | undefined
179179
}
180180

181-
function isBillingAddresSameAsShippingAddress({
181+
function isBillingAddressSameAsShippingAddress({
182182
billingAddress,
183183
shippingAddress,
184-
}: IsBillingAddresSameAsShippingAddressProps) {
184+
}: IsBillingAddressSameAsShippingAddressProps) {
185185
if (shippingAddress && billingAddress) {
186186
if (
187187
(shippingAddress.reference === billingAddress.reference &&
@@ -296,7 +296,7 @@ export function calculateAddresses(
296296
customerAddresses: cAddresses,
297297
isGuest: Boolean(order.guest),
298298
}),
299-
hasSameAddresses: isBillingAddresSameAsShippingAddress({
299+
hasSameAddresses: isBillingAddressSameAsShippingAddress({
300300
billingAddress: order.billing_address,
301301
shippingAddress: order.shipping_address,
302302
}),

specs/e2e/customer-addresses.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ test.describe("address on wallet", () => {
290290

291291
await checkoutPage.selectAddressOnBook({ type: "shipping", index: 0 })
292292

293+
await checkoutPage.page.waitForTimeout(1000)
294+
293295
await checkoutPage.save("Customer")
294296

295297
await checkoutPage.clickStep("Customer")
@@ -303,6 +305,8 @@ test.describe("address on wallet", () => {
303305

304306
await checkoutPage.closeNewAddress("billing")
305307
await checkoutPage.selectAddressOnBook({ type: "billing", index: 0 })
308+
await checkoutPage.page.waitForTimeout(1000)
309+
306310
await checkoutPage.save("Customer")
307311

308312
await checkoutPage.clickStep("Customer")
@@ -325,6 +329,11 @@ test.describe("address on wallet", () => {
325329

326330
await checkoutPage.save("Shipping")
327331

332+
await checkoutPage.page.click(
333+
"[data-test-id=stripe_payments] >> text=Credit card",
334+
{ force: true }
335+
)
336+
328337
await checkoutPage.setPayment("stripe")
329338

330339
await checkoutPage.save("Payment")

specs/fixtures/CheckoutPage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export class CheckoutPage {
233233
type: "billing" | "shipping"
234234
index: number
235235
}) {
236-
this.page.click(`[data-cy=customer-${type}-address] >> nth-${index}`)
236+
this.page.click(`[data-cy=customer-${type}-address] >> nth=${index}`)
237237
}
238238

239239
async checkSelectedAddressBook({

0 commit comments

Comments
 (0)