Skip to content

Commit

Permalink
- Address PR feedback
Browse files Browse the repository at this point in the history
- Update test snaps after mainline merge
  • Loading branch information
tjwiebell committed Feb 5, 2020
1 parent b033585 commit 23e9cb5
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ export const useShippingForm = props => {
[fetchStates]
);

/**
* When the zip value is changed, go ahead and manually wipe out that
* portion of the cache, which will cause the components subscribed to
* that state to re-render. Ideally we would send a mutation to clear the
* shipping address set on the cart, to keep those states in sync, but the
* GraphQL API does not currently supported clearing addresses.
*/
const handleZipChange = useCallback(
zip => {
if (zip !== selectedValues.zip) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const useShippingMethods = props => {
);

const [isShowingForm, setIsShowingForm] = useState(false);
const showForm = () => setIsShowingForm(true);

useEffect(() => {
if (cartId) {
Expand All @@ -26,12 +27,7 @@ export const useShippingMethods = props => {
}, [cartId, fetchShippingMethods]);

useEffect(() => {
if (
data &&
data.cart &&
data.cart.shipping_addresses &&
data.cart.shipping_addresses.length
) {
if (data && data.cart.shipping_addresses.length) {
setIsShowingForm(true);
}
}, [data]);
Expand Down Expand Up @@ -76,7 +72,7 @@ export const useShippingMethods = props => {
isShowingForm,
selectedShippingFields,
selectedShippingMethod,
setIsShowingForm,
shippingMethods: formattedShippingMethods
shippingMethods: formattedShippingMethods,
showForm
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Array [
</h3>,
<form
className="root"
onKeyDown={[Function]}
onReset={[Function]}
onSubmit={[Function]}
>
Expand Down Expand Up @@ -185,6 +186,7 @@ Array [
</h3>,
<form
className="root"
onKeyDown={[Function]}
onReset={[Function]}
onSubmit={[Function]}
>
Expand Down Expand Up @@ -375,6 +377,7 @@ Array [
</h3>,
<form
className="root"
onKeyDown={[Function]}
onReset={[Function]}
onSubmit={[Function]}
>
Expand Down Expand Up @@ -607,6 +610,7 @@ Array [
</h3>,
<form
className="root"
onKeyDown={[Function]}
onReset={[Function]}
onSubmit={[Function]}
>
Expand Down Expand Up @@ -828,6 +832,7 @@ Array [
</h3>,
<form
className="root"
onKeyDown={[Function]}
onReset={[Function]}
onSubmit={[Function]}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ exports[`renders address form and methods with address set 1`] = `
Shipping Methods
</h3>
<form
onKeyDown={[Function]}
onReset={[Function]}
onSubmit={[Function]}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

exports[`automatically selects first option when none selected 1`] = `
<form
onKeyDown={[Function]}
onReset={[Function]}
onSubmit={[Function]}
>
Expand Down Expand Up @@ -69,6 +70,7 @@ exports[`automatically selects first option when none selected 1`] = `

exports[`renders list of shipping methods 1`] = `
<form
onKeyDown={[Function]}
onReset={[Function]}
onSubmit={[Function]}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const ShippingMethods = props => {
isShowingForm,
selectedShippingFields,
selectedShippingMethod,
setIsShowingForm,
shippingMethods
shippingMethods,
showForm
} = useShippingMethods({
getShippingMethodsQuery: GET_SHIPPING_METHODS
});
Expand Down Expand Up @@ -56,7 +56,7 @@ const ShippingMethods = props => {
classes={{ root_lowPriority: classes.estimateLink }}
priority="low"
type="button"
onClick={() => setIsShowingForm(true)}
onClick={showForm}
>
I want to estimate my shipping
</Button>
Expand Down

0 comments on commit 23e9cb5

Please sign in to comment.