Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[React Components] update setShippingAddressOnCart to refetch cart details #270

Merged
merged 5 commits into from
May 26, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions react-components/src/components/Checkout/editableForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import MUTATION_SET_BRAINTREE_PAYMENT_METHOD from '../../queries/mutation_set_br
import MUTATION_SET_BILLING_ADDRESS from '../../queries/mutation_set_billing_address.graphql';
import MUTATION_SET_SHIPPING_METHOD from '../../queries/mutation_set_shipping_method.graphql';
import MUTATION_SET_EMAIL from '../../queries/mutation_set_email_on_cart.graphql';
import CART_DETAILS_QUERY from '../../queries/query_cart_details.graphql';
import { useCheckoutState } from './checkoutContext';
import { useUserContext } from '../../context/UserContext';

Expand All @@ -41,7 +42,10 @@ const EditableForm = props => {
const [{ editing, shippingAddress, shippingMethod, paymentMethod, billingAddress }, dispatch] = useCheckoutState();
const { error: countriesError, countries } = useCountries();
const [{ isSignedIn }] = useUserContext();
const [setShippingAddressesOnCart, { data, error }] = useMutation(MUTATION_SET_SHIPPING_ADDRESS);
const [setShippingAddressesOnCart, { data, error }] = useMutation(MUTATION_SET_SHIPPING_ADDRESS, {
refetchQueries: [{ query: CART_DETAILS_QUERY, variables: { cartId } }],
awaitRefetchQueries: true
});

const [setBraintreePaymentMethodOnCart] = useMutation(MUTATION_SET_BRAINTREE_PAYMENT_METHOD);
const [setPaymentMethodOnCart] = useMutation(MUTATION_SET_PAYMENT_METHOD);
Expand All @@ -64,7 +68,15 @@ const EditableForm = props => {

const handleSubmitAddressForm = useCallback(
formValues => {
setShippingAddressesOnCart({ variables: { cartId: cartId, countryCode: 'US', ...formValues } });
setShippingAddressesOnCart({ variables: { cartId: cartId, countryCode: 'US', ...formValues } })
.catch(error => {
dispatch({ type: 'error', error: error.toString() });
})
.finally(() => {
dispatch({ type: 'endLoading' });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The beginLoading and endLoading events are only available via the CartContext, so you need to use cartDispatch here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I updated the events to use cartDispatch here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dabe5651 please make sure you run tests locally first and they pass. CircleCI reports test failures.

});
dispatch({ type: 'beginLoading' });
dispatch({ type: 'endEditing' });
if (!isSignedIn) {
setGuestEmailOnCart({ variables: { cartId: cartId, email: formValues.email } });
}
Expand Down