From 86e57a18db651cbc8df0e1b8ce7c46d0c0c4087a Mon Sep 17 00:00:00 2001 From: Jorge Moya Date: Fri, 5 Apr 2024 15:04:54 -0500 Subject: [PATCH] fix(core): pass customer id to shipping mutations (#734) --- .changeset/smart-turtles-raise.md | 5 +++++ .../[locale]/(default)/cart/_components/shipping-info.tsx | 2 +- .../(default)/cart/_components/shipping-options.tsx | 4 ++-- .../client/mutations/add-checkout-shipping-consignments.ts | 6 ++++++ .../client/mutations/select-checkout-shipping-option.ts | 6 ++++++ .../client/mutations/update-checkout-shipping-consigment.ts | 6 ++++++ 6 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 .changeset/smart-turtles-raise.md diff --git a/.changeset/smart-turtles-raise.md b/.changeset/smart-turtles-raise.md new file mode 100644 index 000000000..e193836b4 --- /dev/null +++ b/.changeset/smart-turtles-raise.md @@ -0,0 +1,5 @@ +--- +"@bigcommerce/catalyst-core": patch +--- + +Pass customer id to shipping mutation that were missing. diff --git a/apps/core/app/[locale]/(default)/cart/_components/shipping-info.tsx b/apps/core/app/[locale]/(default)/cart/_components/shipping-info.tsx index f5330efcb..7114644c9 100644 --- a/apps/core/app/[locale]/(default)/cart/_components/shipping-info.tsx +++ b/apps/core/app/[locale]/(default)/cart/_components/shipping-info.tsx @@ -125,7 +125,7 @@ export const ShippingInfo = ({ shippingId: shippingConsignment?.entityId ?? '', }); - if (status === 'error') { + if (status === 'failed') { toast.error(t('errorMessage'), { icon: , }); diff --git a/apps/core/app/[locale]/(default)/cart/_components/shipping-options.tsx b/apps/core/app/[locale]/(default)/cart/_components/shipping-options.tsx index 7f7fce494..836db0029 100644 --- a/apps/core/app/[locale]/(default)/cart/_components/shipping-options.tsx +++ b/apps/core/app/[locale]/(default)/cart/_components/shipping-options.tsx @@ -68,8 +68,8 @@ export const ShippingOptions = ({ const onSubmit = async (formData: FormData) => { const { status } = await submitShippingCosts(formData, checkout.entityId, consignmentEntityId); - if (status === 'error') { - toast.error(t('errorMessage2'), { + if (status === 'failed') { + toast.error(t('errorMessage'), { icon: , }); } diff --git a/apps/core/client/mutations/add-checkout-shipping-consignments.ts b/apps/core/client/mutations/add-checkout-shipping-consignments.ts index 82432cacf..8d2b5e26d 100644 --- a/apps/core/client/mutations/add-checkout-shipping-consignments.ts +++ b/apps/core/client/mutations/add-checkout-shipping-consignments.ts @@ -1,3 +1,5 @@ +import { getSessionCustomerId } from '~/auth'; + import { client } from '..'; import { graphql, VariablesOf } from '../graphql'; @@ -38,6 +40,8 @@ export const addCheckoutShippingConsignments = async ({ lineItems, shouldSaveAddress = false, }: AddCheckoutShippingConsignmentsProps) => { + const customerId = await getSessionCustomerId(); + const response = await client.fetch({ document: ADD_CHECKOUT_SHIPPING_CONSIGNMENTS_MUTATION, variables: { @@ -59,6 +63,8 @@ export const addCheckoutShippingConsignments = async ({ }, }, }, + customerId, + fetchOptions: { cache: 'no-store' }, }); const checkout = response.data.checkout.addCheckoutShippingConsignments?.checkout; diff --git a/apps/core/client/mutations/select-checkout-shipping-option.ts b/apps/core/client/mutations/select-checkout-shipping-option.ts index e18d3ab5d..0791d8daa 100644 --- a/apps/core/client/mutations/select-checkout-shipping-option.ts +++ b/apps/core/client/mutations/select-checkout-shipping-option.ts @@ -1,3 +1,5 @@ +import { getSessionCustomerId } from '~/auth'; + import { client } from '..'; import { graphql } from '../graphql'; @@ -22,6 +24,8 @@ export const selectCheckoutShippingOption = async ({ consignmentEntityId: string; shippingOptionEntityId: string; }) => { + const customerId = await getSessionCustomerId(); + const response = await client.fetch({ document: SELECT_CHECKOUT_SHIPPING_OPTION_MUTATION, variables: { @@ -33,6 +37,8 @@ export const selectCheckoutShippingOption = async ({ }, }, }, + customerId, + fetchOptions: { cache: 'no-store' }, }); const shippingCosts = response.data.checkout.selectCheckoutShippingOption?.checkout; diff --git a/apps/core/client/mutations/update-checkout-shipping-consigment.ts b/apps/core/client/mutations/update-checkout-shipping-consigment.ts index 0c6c02b36..4c452681a 100644 --- a/apps/core/client/mutations/update-checkout-shipping-consigment.ts +++ b/apps/core/client/mutations/update-checkout-shipping-consigment.ts @@ -1,3 +1,5 @@ +import { getSessionCustomerId } from '~/auth'; + import { client } from '..'; import { graphql, VariablesOf } from '../graphql'; @@ -40,6 +42,8 @@ export const updateCheckoutShippingConsignment = async ({ lineItems, shouldSaveAddress = false, }: UpdateCheckoutShippingConsignmentProps) => { + const customerId = await getSessionCustomerId(); + const response = await client.fetch({ document: UPDATE_CHECKOUT_SHIPPING_CONSIGNMENT, variables: { @@ -60,6 +64,8 @@ export const updateCheckoutShippingConsignment = async ({ }, }, }, + customerId, + fetchOptions: { cache: 'no-store' }, }); const checkout = response.data.checkout.updateCheckoutShippingConsignment?.checkout;