Created
November 28, 2021 14:21
-
-
Save BrianJenney/e12193cddd68b661df10282f79985281 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import apiClient from './apiClient'; | |
import ShoppingCart from './ShoppingCart'; | |
const ShoppingCartContainer = ({apiClient}) => { | |
const [errorMessage, setErrorMessage] = useState(null) | |
const isLoggedIn = useSelector((state) => state.account.isLoggedIn); | |
const urlToUse = isLoggedIn ? 'https://api/customercheckout' : 'https://api/guestcheckout'; | |
const addToCartFunction = async (items) => { | |
const { data, errors } = await apiClient(urlToUse, {items}); | |
if(errors){ | |
setErrorMessage('Oops, something went wrong...') | |
} | |
} | |
return( | |
<ShoppingCart | |
errorMessage={errorMessage} | |
addToCartFunction={addToCartFunction} | |
/> | |
) | |
} | |
ShoppingCartContainer.defaultProps = { | |
apiClient | |
} | |
// Now our shopping cart is much simpler to test as well as the container | |
const ShoppingCart = ({addToCartFunction, isLoggedIn, errorMessage}) => { | |
return ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment