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

3220 testing Redux Store Failing #4216

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
45 changes: 43 additions & 2 deletions packages/peregrine/lib/context/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const getTotalQuantity = items =>

const CartContextProvider = props => {
const { actions, asyncActions, cartState, children } = props;
console.log(cartState,"cartstate");
console.log(actions,"actionns");
console.log(asyncActions,"Async Actions");

// Make deeply nested details easier to retrieve and provide empty defaults
const derivedDetails = useMemo(() => {
Expand All @@ -52,15 +55,53 @@ const CartContextProvider = props => {
[actions, asyncActions]
);


const resetCart = () => {
// actions.reset(); // Dispatch the reset action
//asyncActions.createCart();

//asyncActions.saveCartId()
console.log("Reset Cart function");
};

// const resetCart = () => {
// // Dispatch the saveCartId async action using redux-thunk
// async (dispatch) => {
// try {
// //actions.reset();
// await dispatch(asyncActions.createCart());
// console.log("Reset Cart function");
// } catch (error) {
// console.error("Error resetting cart:", error);
// }
// };
// };

// const resetCart = async () => {
// try {
// const { data } = await fetchCartId();
// console.log(cartState);
// //actions.reset();
// // cartState.cartId=data.cartId
// //const newCartId = data.createEmptyCart;
// //cartState.details.id=data.cartId
// console.log(data.cartId, "This should be the new cart ID value");

// } catch (error) {
// console.error("Error resetting cart:", error);
// }
// };

const contextValue = useMemo(() => {
const derivedCartState = {
...cartState,
isEmpty: isCartEmpty(cartState),
derivedDetails
derivedDetails,
resetCart
};

return [derivedCartState, cartApi];
}, [cartApi, cartState, derivedDetails]);
}, [cartApi, cartState, derivedDetails,resetCart]);

const [fetchCartId] = useMutation(CREATE_CART_MUTATION);
const fetchCartDetails = useAwaitQuery(CART_DETAILS_QUERY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export const useProductFullDetail = props => {

const isSupportedProductType = isSupported(productType);

const [{ cartId }] = useCartContext();
const [{ cartId ,resetCart}] = useCartContext();
const [{ isSignedIn }] = useUserContext();
const { formatMessage } = useIntl();

Expand Down Expand Up @@ -531,6 +531,7 @@ export const useProductFullDetail = props => {
]
);

console.log("working ");
const handleSelectionChange = useCallback(
(optionId, selection) => {
// We must create a new Map here so that React knows that the value
Expand Down Expand Up @@ -570,6 +571,15 @@ export const useProductFullDetail = props => {
addToCartResponseData
]
);
console.log(derivedErrorMessage ,"dervied error message");

// if (derivedErrorMessage){
// resetCart();
// console.log("coming to here");
// //console.log(fetchCartId);
// //const [{ cartId }] = useCartContext();
// //console.log(cartId);
// }

const wishlistItemOptions = useMemo(() => {
const options = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const ProductFullDetail = props => {

// Handle cases where a cart wasn't created properly.
if (
errorMessage.includes('Variable "$cartId" got invalid value null')
errorMessage.includes('Variable "$cartId" got invalid value null') || errorMessage.includes('Could not find a cart with ID')
) {
errors.set('form', [
new Error(
Expand Down
Loading