Here is the cloned repo I'm working in: https://github.com/mkrul/web-template (yes I'm aware this is using some VERY outdated conventions. I have plans to refactor this but right now I'm just trying to get things working as expected)
I've succeeded in creating a redux thunk that updates the currentUser's deliveryAddress
, however, this change only populates in state after a hard refresh of the page.
https://github.com/mkrul/web-template/blob/main/src/containers/SearchPage/SearchPage.duck.js
Code in question:
export const setDeliveryAddress = address => (dispatch, getState, sdk) => { dispatch(setDeliveryAddressRequest(address)); // Make API call to update the user's delivery address return sdk.currentUser .updateProfile( { publicData: { deliveryAddress: address, }, }, { expand: true } ) .then(() => { dispatch(setDeliveryAddressSuccess()); }) .catch(e => { dispatch(setDeliveryAddressError(storableError(e))); });};
In the redux dev tools, I see the action to SET_DELIVERY_ADDRESS_REQUEST
followed by SET_DELIVERY_ADDRESS_ERROR
. The error response reads that state.currentUser is undefined
. I notice the pattern of returning sdk.currentUser
from elsewhere in this codebase, so I'm not sure why currentUser
wouldn't be initialized here.
The interesting thing is when I hard refresh the page, I do see changes to the deliveryAddress
populate in state. So it's working, but just not immediately as expected.