From c70c8fecf9ebafbc651c4d5c4609e0ef776a9a74 Mon Sep 17 00:00:00 2001 From: Bartosz Herba Date: Wed, 4 May 2022 09:49:19 +0200 Subject: [PATCH] refactor: create wishlist module M2-507 --- packages/theme/components/AppHeader.vue | 9 ++--- .../Header/SearchBar/SearchResults.vue | 3 +- packages/theme/components/LoginModal.vue | 3 +- packages/theme/components/NewProducts.vue | 3 +- packages/theme/composables/index.ts | 2 +- packages/theme/composables/useCart/useCart.ts | 2 +- packages/theme/layouts/default.vue | 10 ++--- .../views/useProductsWithCommonCardProps.ts | 3 +- .../theme/modules/catalog/pages/category.vue | 7 ++-- .../theme/modules/catalog/pages/product.vue | 4 +- .../product/components/ProductsCarousel.vue | 3 +- .../useForgotPassword/useForgotPassword.ts | 8 ++-- .../customer/composables/useUser/useUser.ts | 6 +-- .../composables/useWishlist/helpers.ts | 17 -------- .../components/wishlist}/WishlistSidebar.vue | 22 +++++----- packages/theme/modules/theme/index.ts | 5 +++ .../composables/useWishlist/index.ts | 40 +++++++++---------- .../composables/useWishlist/useWishlist.ts | 17 +++++--- .../wishlist/helpers/findItemOnWishlist.ts | 10 +++++ .../modules/wishlist/helpers/productMatch.ts | 11 +++++ packages/theme/modules/wishlist/index.ts | 5 +++ .../modules/wishlist/store/wishlistStore.ts | 12 ++++++ packages/theme/nuxt.config.js | 2 + packages/theme/stores/customer.ts | 4 +- 24 files changed, 123 insertions(+), 85 deletions(-) delete mode 100644 packages/theme/modules/customer/composables/useWishlist/helpers.ts rename packages/theme/{components => modules/theme/components/wishlist}/WishlistSidebar.vue (94%) create mode 100644 packages/theme/modules/theme/index.ts rename packages/theme/modules/{customer => wishlist}/composables/useWishlist/index.ts (87%) rename packages/theme/modules/{customer => wishlist}/composables/useWishlist/useWishlist.ts (80%) create mode 100644 packages/theme/modules/wishlist/helpers/findItemOnWishlist.ts create mode 100644 packages/theme/modules/wishlist/helpers/productMatch.ts create mode 100644 packages/theme/modules/wishlist/index.ts create mode 100644 packages/theme/modules/wishlist/store/wishlistStore.ts diff --git a/packages/theme/components/AppHeader.vue b/packages/theme/components/AppHeader.vue index 362ee5f32..0c279e337 100644 --- a/packages/theme/components/AppHeader.vue +++ b/packages/theme/components/AppHeader.vue @@ -121,16 +121,15 @@ import { useCart, useUiHelpers, useUiState, - useWishlist, } from '~/composables'; +import useWishlist from '~/modules/wishlist/composables/useWishlist'; import { useUser } from '~/modules/customer/composables/useUser'; - +import { useWishlistStore } from '~/modules/wishlist/store/wishlistStore'; import type { CategoryTree } from '~/modules/GraphQL/types'; import CurrencySelector from '~/components/CurrencySelector.vue'; import HeaderLogo from '~/components/HeaderLogo.vue'; import SvgImage from '~/components/General/SvgImage.vue'; import StoreSwitcher from '~/components/StoreSwitcher.vue'; -import { useCustomerStore } from '~/stores/customer'; export default defineComponent({ components: { @@ -158,10 +157,10 @@ export default defineComponent({ const { loadItemsCount: loadWishlistItemsCount } = useWishlist(); const { categories: categoryList, load: categoriesListLoad } = useCategory(); - const customerStore = useCustomerStore(); + const wishlistStore = useWishlistStore(); const isSearchOpen = ref(false); const result = ref(null); - const wishlistItemsQty = computed(() => customerStore.wishlist?.items_count ?? 0); + const wishlistItemsQty = computed(() => wishlistStore.wishlist?.items_count ?? 0); const wishlistHasProducts = computed(() => wishlistItemsQty.value > 0); const accountIcon = computed(() => (isAuthenticated.value ? 'profile_fill' : 'profile')); diff --git a/packages/theme/components/Header/SearchBar/SearchResults.vue b/packages/theme/components/Header/SearchBar/SearchResults.vue index 2a94dbe80..212fb4a3b 100644 --- a/packages/theme/components/Header/SearchBar/SearchResults.vue +++ b/packages/theme/components/Header/SearchBar/SearchResults.vue @@ -157,8 +157,9 @@ import { import { ref, computed, defineComponent } from '@nuxtjs/composition-api'; import productGetters from '~/modules/catalog/product/getters/productGetters'; import { - useUiHelpers, useImage, useWishlist, + useUiHelpers, useImage, } from '~/composables'; +import useWishlist from '~/modules/wishlist/composables/useWishlist'; import { useUser } from '~/modules/customer/composables/useUser'; import SvgImage from '~/components/General/SvgImage.vue'; diff --git a/packages/theme/components/LoginModal.vue b/packages/theme/components/LoginModal.vue index 53fee5651..3b0f6a2b8 100644 --- a/packages/theme/components/LoginModal.vue +++ b/packages/theme/components/LoginModal.vue @@ -299,8 +299,9 @@ import { import { ValidationProvider, ValidationObserver, extend } from 'vee-validate'; import { required, email } from 'vee-validate/dist/rules'; import { - useUiState, useWishlist, useForgotPassword, useCart, + useUiState, useForgotPassword, useCart, } from '~/composables'; +import useWishlist from '~/modules/wishlist/composables/useWishlist'; import { useUser } from '~/modules/customer/composables/useUser'; import { customerPasswordRegExp, invalidPasswordMsg } from '~/modules/customer/helpers/passwordValidation'; diff --git a/packages/theme/components/NewProducts.vue b/packages/theme/components/NewProducts.vue index 862812e83..76158edf3 100644 --- a/packages/theme/components/NewProducts.vue +++ b/packages/theme/components/NewProducts.vue @@ -65,8 +65,9 @@ import { computed, defineComponent, onMounted, ref, } from '@nuxtjs/composition-api'; import { - useImage, useProduct, useWishlist, + useImage, useProduct, } from '~/composables'; +import useWishlist from '~/modules/wishlist/composables/useWishlist'; import productGetters from '~/modules/catalog/product/getters/productGetters'; import { useUser } from '~/modules/customer/composables/useUser'; import { useAddToCart } from '~/helpers/cart/addToCart'; diff --git a/packages/theme/composables/index.ts b/packages/theme/composables/index.ts index f5fc1d761..859f6c7e5 100644 --- a/packages/theme/composables/index.ts +++ b/packages/theme/composables/index.ts @@ -40,7 +40,7 @@ export * from './useUrlResolver'; export * from '~/modules/customer/composables/useUser'; export * from '~/modules/customer/composables/useUserAddress'; export * from '~/modules/customer/composables/useUserOrder'; -export * from '~/modules/customer/composables/useWishlist'; +export * from '~/modules/wishlist/composables/useWishlist'; export * from './useMagentoConfiguration'; export * from './types'; diff --git a/packages/theme/composables/useCart/useCart.ts b/packages/theme/composables/useCart/useCart.ts index faa8db770..908bc924c 100644 --- a/packages/theme/composables/useCart/useCart.ts +++ b/packages/theme/composables/useCart/useCart.ts @@ -51,7 +51,7 @@ type UseCartIsInCartParams = { */ export interface UseCartInterface { /** Loads the current cart */ - load(params: ComposableFunctionArgs<{ realCart?: boolean }>): Promise; + load(params?: ComposableFunctionArgs<{ realCart?: boolean }>): Promise; /** Updates the global application state with the current total quantity of the cart */ loadTotalQty(): Promise; /** Takes in a `product` and its `quantity` and adds it to the cart */ diff --git a/packages/theme/layouts/default.vue b/packages/theme/layouts/default.vue index 76b02afa3..c57475e03 100644 --- a/packages/theme/layouts/default.vue +++ b/packages/theme/layouts/default.vue @@ -18,15 +18,15 @@ -