Skip to content

Commit

Permalink
fix: Force include resources to order query
Browse files Browse the repository at this point in the history
  • Loading branch information
acasazza committed Nov 29, 2021
1 parent 11127db commit 14daa83
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 13 deletions.
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@
"v8-to-istanbul": "^8.1.0"
},
"peerDependencies": {
"react": "^17.0.2",
"react-dom": "^17.0.2"
"react": "^17.0.2"
}
}
7 changes: 5 additions & 2 deletions src/components/BillingAddressContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ const BillingAddressContainer: FunctionComponent<Props> = (props) => {
const { shipToDifferentAddress, setCloneAddress } = useContext(AddressContext)
useEffect(() => {
if (!include?.includes('billing_address')) {
addResourceToInclude({ newResource: 'billing_address' })
addResourceToInclude({
newResource: 'billing_address',
resourcesIncluded: include,
})
}
if (order && config) {
setBillingCustomerAddressId({
Expand All @@ -47,7 +50,7 @@ const BillingAddressContainer: FunctionComponent<Props> = (props) => {
payload: {},
})
}
}, [order])
}, [order, include])
const contextValue = {
...state,
setBillingAddress: async (
Expand Down
5 changes: 4 additions & 1 deletion src/components/BillingAddressForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ const BillingAddressForm: FunctionComponent<BillingAddressFormProps> = (
const ref = useRef<HTMLFormElement>(null)
useEffect(() => {
if (!include?.includes('billing_address')) {
addResourceToInclude({ newResource: 'billing_address' })
addResourceToInclude({
newResource: 'billing_address',
resourcesIncluded: include,
})
}
if (!isEmpty(errors)) {
const formErrors: BaseError[] = []
Expand Down
3 changes: 2 additions & 1 deletion src/components/CustomerContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const CustomerContainer: FunctionComponent<CustomerContainer> = (props) => {
) {
addResourceToInclude({
newResource: 'available_customer_payment_sources.payment_source',
resourcesIncluded: include,
})
}
if (config.accessToken && isEmpty(state.addresses) && !isGuest) {
Expand All @@ -54,7 +55,7 @@ const CustomerContainer: FunctionComponent<CustomerContainer> = (props) => {
return () => {
dispatch({ type: 'setCustomerEmail', payload: {} })
}
}, [config.accessToken, order, isGuest])
}, [config.accessToken, order, isGuest, include])
const contextValue = {
isGuest,
...state,
Expand Down
1 change: 1 addition & 0 deletions src/components/LineItemsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const LineItemsContainer: FunctionComponent<LineItemsContainer> = (props) => {
if (!include?.includes('line_items.line_item_options.sku_option')) {
addResourceToInclude({
newResource: 'line_items.line_item_options.sku_option',
resourcesIncluded: include,
})
} else if (!isEmpty(order) && order?.line_items) {
dispatch({
Expand Down
1 change: 1 addition & 0 deletions src/components/OrderContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const OrderContainer: FunctionComponent<OrderContainerProps> = (props) => {
setLocalOrder,
deleteLocalOrder,
} = useContext(OrderStorageContext)
console.log(`children`, state.include)
useEffect(() => {
if (config.accessToken) {
const localOrder = persistKey ? getLocalOrder(persistKey) : orderId
Expand Down
3 changes: 2 additions & 1 deletion src/components/PaymentMethodsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const PaymentMethodsContainer: FunctionComponent<PaymentMethodsContainerProps> =
'payment_source',
'payment_method',
],
resourcesIncluded: include,
})
}

Expand All @@ -68,7 +69,7 @@ const PaymentMethodsContainer: FunctionComponent<PaymentMethodsContainerProps> =
payload: { paymentSource: order?.payment_source },
})
}
}, [order, credentials])
}, [order, credentials, include])
const contextValue = useMemo(() => {
return {
...state,
Expand Down
15 changes: 12 additions & 3 deletions src/components/PlaceOrderContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,22 @@ const PlaceOrderContainer: FunctionComponent<PlaceOrderContainerProps> = (
const config = useContext(CommerceLayerContext)
useEffect(() => {
if (!include?.includes('shipments.shipping_method')) {
addResourceToInclude({ newResource: 'shipments.shipping_method' })
addResourceToInclude({
newResource: 'shipments.shipping_method',
resourcesIncluded: include,
})
}
if (!include?.includes('billing_address')) {
addResourceToInclude({ newResource: 'billing_address' })
addResourceToInclude({
newResource: 'billing_address',
resourcesIncluded: include,
})
}
if (!include?.includes('shipping_address')) {
addResourceToInclude({ newResource: 'shipping_address' })
addResourceToInclude({
newResource: 'shipping_address',
resourcesIncluded: include,
})
}
if (order) {
placeOrderPermitted({
Expand Down
3 changes: 2 additions & 1 deletion src/components/ShipmentsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ const ShipmentsContainer: FunctionComponent<ShipmentsContainerProps> = (
'shipments.stock_transfers',
'shipments.stock_location',
],
resourcesIncluded: include,
})
}
// TODO: Get shipments
if (order && !isEmpty(config)) {
getShipments({ order, dispatch, config })
}
}, [order])
}, [order, include])
const contextValue = {
...state,
setShipmentErrors: (errors: BaseError[]) =>
Expand Down

0 comments on commit 14daa83

Please sign in to comment.