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

fix: cart refreshing issues #1507

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions client-app/core/api/graphql/cart/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export const FULL_CART_MUTATION_NAMES = [
OperationNames.Mutation.AddOrUpdateCartPayment,
OperationNames.Mutation.AddOrUpdateCartShipment,
OperationNames.Mutation.ChangeCartComment,
OperationNames.Mutation.ChangeCartConfiguredItem,
OperationNames.Mutation.ChangeFullCartItemQuantity,
OperationNames.Mutation.ChangeFullCartItemsQuantity,
OperationNames.Mutation.ChangePurchaseOrderNumber,
OperationNames.Mutation.ClearCart,
OperationNames.Mutation.RejectGiftItems,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import { useApolloClient } from "@vue/apollo-composable";
import { useCartMutationVariables } from "@/core/api/graphql/cart/composables";
import { useMutation } from "@/core/api/graphql/composables";
import { AddBulkItemsCartDocument, OperationNames } from "@/core/api/graphql/types";
import { filterActiveQueryNames } from "@/core/api/graphql/utils";
import { AddBulkItemsCartDocument } from "@/core/api/graphql/types";
import type { BulkCartType, InputNewBulkItemType, CartIdFragment } from "@/core/api/graphql/types";
import type { MaybeRef } from "vue";

export function useAddBulkItemsCartMutation(cart?: MaybeRef<CartIdFragment | undefined>) {
const { client } = useApolloClient();
return useMutation(
AddBulkItemsCartDocument,
useCartMutationVariables(cart, {
refetchQueries: () => filterActiveQueryNames(client, [OperationNames.Query.GetFullCart]),
}),
);
return useMutation(AddBulkItemsCartDocument, useCartMutationVariables(cart));
}

/** @deprecated Use {@link useAddBulkItemsCartMutation} instead. */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import { useApolloClient } from "@vue/apollo-composable";
import { useCartMutationVariables } from "@/core/api/graphql/cart/composables";
import { useMutation } from "@/core/api/graphql/composables";
import { AddItemDocument, OperationNames } from "@/core/api/graphql/types";
import { filterActiveQueryNames } from "@/core/api/graphql/utils";
import { AddItemDocument } from "@/core/api/graphql/types";
import type { CartType, CartIdFragment } from "@/core/api/graphql/types";
import type { MaybeRef } from "vue";

export function useAddItemToCartMutation(cart?: MaybeRef<CartIdFragment | undefined>) {
const { client } = useApolloClient();
return useMutation(
AddItemDocument,
useCartMutationVariables(cart, {
refetchQueries: () => filterActiveQueryNames(client, [OperationNames.Query.GetFullCart]),
}),
);
return useMutation(AddItemDocument, useCartMutationVariables(cart));
}

/** @deprecated Use {@link useAddItemToCartMutation} instead. */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import { useApolloClient } from "@vue/apollo-composable";
import { useCartMutationVariables } from "@/core/api/graphql/cart/composables";
import { useMutation } from "@/core/api/graphql/composables";
import { AddItemsCartDocument, OperationNames } from "@/core/api/graphql/types";
import { filterActiveQueryNames } from "@/core/api/graphql/utils";
import { AddItemsCartDocument } from "@/core/api/graphql/types";
import type { CartType, InputNewCartItemType, CartIdFragment } from "@/core/api/graphql/types";
import type { MaybeRef } from "vue";

export function useAddItemsCartMutation(cart?: MaybeRef<CartIdFragment | undefined>) {
const { client } = useApolloClient();
return useMutation(
AddItemsCartDocument,
useCartMutationVariables(cart, {
refetchQueries: () => filterActiveQueryNames(client, [OperationNames.Query.GetFullCart]),
}),
);
return useMutation(AddItemsCartDocument, useCartMutationVariables(cart));
}

/** @deprecated Use {@link useAddItemsCartMutation} instead. */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import { useApolloClient } from "@vue/apollo-composable";
import { useCartMutationVariables } from "@/core/api/graphql/cart/composables";
import { useMutation } from "@/core/api/graphql/composables";
import { ChangeShortCartItemQuantityDocument, OperationNames } from "@/core/api/graphql/types";
import { filterActiveQueryNames } from "@/core/api/graphql/utils";
import { ChangeShortCartItemQuantityDocument } from "@/core/api/graphql/types";
import type { CartIdFragment } from "@/core/api/graphql/types";
import type { MaybeRef } from "vue";

export function useChangeShortCartItemQuantityMutation(cart?: MaybeRef<CartIdFragment | undefined>) {
const { client } = useApolloClient();
return useMutation(
ChangeShortCartItemQuantityDocument,
useCartMutationVariables(cart, {
refetchQueries: () => filterActiveQueryNames(client, [OperationNames.Query.GetFullCart]),
}),
);
return useMutation(ChangeShortCartItemQuantityDocument, useCartMutationVariables(cart));
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { useQuery } from "@vue/apollo-composable";
import { computed } from "vue";
import { useRoute } from "vue-router";
import { useCartQueryVariables } from "@/core/api/graphql/cart/composables";
import { GetShortCartDocument } from "@/core/api/graphql/types";

export function useGetShortCartQuery() {
const route = useRoute();
const isCartPage = computed(() => route.name === "Cart");
return useQuery(GetShortCartDocument, useCartQueryVariables(), {
notifyOnNetworkStatusChange: true,
fetchPolicy: isCartPage.value ? "cache-only" : "cache-first",
fetchPolicy: "cache-first",
});
}
34 changes: 18 additions & 16 deletions client-app/pages/cart.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
<template>
<VcLoaderOverlay v-if="loading" no-bg />

<VcEmptyPage
v-else-if="!cart?.items?.length"
:title="$t('pages.cart.title')"
:description="$t('pages.cart.empty_cart_description')"
image="/static/images/errors/emptyCart.webp"
mobile-image="/static/images/errors/emptyCartMobile.webp"
:breadcrumbs="breadcrumbs"
>
<template #actions>
<VcButton :to="{ name: 'Catalog' }" size="lg">
{{ $t("common.buttons.continue_shopping") }}
</VcButton>
</template>
</VcEmptyPage>
<template v-if="!cart?.items?.length">
<VcLoaderOverlay v-if="loading" no-bg />

<VcEmptyPage
v-else
:title="$t('pages.cart.title')"
:description="$t('pages.cart.empty_cart_description')"
image="/static/images/errors/emptyCart.webp"
mobile-image="/static/images/errors/emptyCartMobile.webp"
:breadcrumbs="breadcrumbs"
>
<template #actions>
<VcButton :to="{ name: 'Catalog' }" size="lg">
{{ $t("common.buttons.continue_shopping") }}
</VcButton>
</template>
</VcEmptyPage>
</template>

<VcContainer v-else class="relative z-0 max-lg:pb-12">
<VcLoaderOverlay :visible="isCartLoked" fixed-spinner />
Expand Down
9 changes: 6 additions & 3 deletions client-app/shared/cart/composables/useCart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,12 @@ export function _useFullCart() {
await _changeItemQuantity({ command: { lineItemId, quantity } });
}

const { mutate: _changeItemsQuantity, loading: changeItemsQuantityLoading } =
useChangeFullCartItemsQuantityMutation(cart);
const { add, overflowed: changeItemQuantityBatchedOverflowed } = useMutationBatcher(_changeItemsQuantity, {
const { mutate: _changeItemsQuantity } = useChangeFullCartItemsQuantityMutation(cart);
const {
add,
overflowed: changeItemQuantityBatchedOverflowed,
loading: changeItemsQuantityLoading,
} = useMutationBatcher(_changeItemsQuantity, {
mergeStrategy: getMergeStrategyUniqueBy("lineItemId"),
});
async function changeItemQuantityBatched(lineItemId: string, quantity: number): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@ function onValidationUpdate(validation: { isValid: true } | { isValid: false; er
}

watch(countInCart, (newCount) => {
quantity.value = newCount || 1;
quantity.value = newCount || product.value.minQuantity || 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was it a bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was a not related to the task bug, which I spotted during testing my changes, decided to fix it at once in that PR

});
</script>
Loading