Skip to content

Commit

Permalink
chore: refactor CustomerReviews settings (#1462)
Browse files Browse the repository at this point in the history
## Description
Removed the dependency on useCustomerReviews in the Core project to
improve module separation.

## References
### Jira-link:
https://virtocommerce.atlassian.net/browse/VCST-2281
### Artifact URL:

https://vc3prerelease.blob.core.windows.net/packages/vc-theme-b2b-vue-2.10.0-pr-1462-3cad-3cada9ea.zip
  • Loading branch information
NaMax66 authored Nov 26, 2024
1 parent 5752c7b commit 3ec8642
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
2 changes: 0 additions & 2 deletions client-app/modules/customer-reviews/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export const MODULE_ID = "VirtoCommerce.CustomerReviews";
export const ENABLED_KEY = "CustomerReviews.CustomerReviewsEnabled";
export const ENABLED_FOR_ANONYMOUS = "CustomerReviews.CustomerReviewsEnabledForAnonymous";
export const ENABLED_FOR_PURCHASED_ORDER = "CustomerReviews.CanSubmitReviewWhenHasOrder";

export const PAGE_SIZE = 5;
export const MAX_RATING = 5;
6 changes: 1 addition & 5 deletions client-app/modules/customer-reviews/useCustomerReviews.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { isDefined } from "@vueuse/core";
import { computed, readonly, ref } from "vue";
import { useModuleSettings } from "@/core/composables/useModuleSettings";
import { Logger } from "@/core/utilities";
import { getCustomerReviews } from "./api/graphql";
import { createReview } from "./api/graphql/mutations/createReview";
import { canLeaveFeedback } from "./api/graphql/queries/canLeaveFeedback";
import { ENABLED_KEY, MODULE_ID, PAGE_SIZE } from "./constants";
import { PAGE_SIZE } from "./constants";
import type { CustomerReview, ReviewValidationErrorType } from "./api/graphql/types";
import type { Ref } from "vue";

export function useCustomerReviews() {
const { isEnabled } = useModuleSettings(MODULE_ID);

const fetching: Ref<boolean> = ref(false);
const itemsPerPage: Ref<number> = ref(PAGE_SIZE);
const pagesCount: Ref<number> = ref(0);
Expand Down Expand Up @@ -74,7 +71,6 @@ export function useCustomerReviews() {
}

return {
enabled: computed(() => isEnabled(ENABLED_KEY)),
reviews: computed(() => reviews.value),
fetching: readonly(fetching),
itemsPerPage: readonly(itemsPerPage),
Expand Down
10 changes: 8 additions & 2 deletions client-app/pages/product.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ import { useI18n } from "vue-i18n";
import _productTemplate from "@/config/product.json";
import { useBreadcrumbs, useGoogleAnalytics, usePageHead } from "@/core/composables";
import { useHistoricalEvents } from "@/core/composables/useHistoricalEvents";
import { useModuleSettings } from "@/core/composables/useModuleSettings";
import { BREAKPOINTS } from "@/core/constants";
import { SortDirection } from "@/core/enums";
import { globals } from "@/core/globals";
Expand All @@ -129,7 +130,10 @@ import {
getFilterExpressionForAvailableIn,
getFilterExpressionForInStock,
} from "@/core/utilities";
import { useCustomerReviews } from "@/modules/customer-reviews/useCustomerReviews";
import {
MODULE_ID as CUSTOMER_REVIEWS_MODULE_ID,
ENABLED_KEY as CUSTOMER_REVIEWS_ENABLED_KEY,
} from "@/modules/customer-reviews/constants";
import {
useProduct,
useRelatedProducts,
Expand Down Expand Up @@ -192,7 +196,9 @@ const {
});
const { relatedProducts, fetchRelatedProducts } = useRelatedProducts();
const { recommendedProducts, fetchRecommendedProducts } = useRecommendedProducts();
const { enabled: productReviewsEnabled } = useCustomerReviews();
const { isEnabled } = useModuleSettings(CUSTOMER_REVIEWS_MODULE_ID);
const productReviewsEnabled = isEnabled(CUSTOMER_REVIEWS_ENABLED_KEY);
const ga = useGoogleAnalytics();
const { catalogBreadcrumb } = useCategory();
Expand Down
10 changes: 8 additions & 2 deletions client-app/shared/catalog/components/display-products.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@
<script setup lang="ts">
import { useBreakpoints } from "@vueuse/core";
import { computed } from "vue";
import { useModuleSettings } from "@/core/composables/useModuleSettings";
import { BREAKPOINTS, DEFAULT_PAGE_SIZE } from "@/core/constants";
import { useCustomerReviews } from "@/modules/customer-reviews/useCustomerReviews";
import {
MODULE_ID as CUSTOMER_REVIEWS_MODULE_ID,
ENABLED_KEY as CUSTOMER_REVIEWS_ENABLED_KEY,
} from "@/modules/customer-reviews/constants";
import ProductCardGrid from "./product-card-grid.vue";
import ProductCardList from "./product-card-list.vue";
import ProductSkeletonGrid from "./product-skeleton-grid.vue";
Expand Down Expand Up @@ -67,7 +71,9 @@ const props = withDefaults(defineProps<IProps>(), {
});
const breakpoints = useBreakpoints(BREAKPOINTS);
const { enabled: productReviewsEnabled } = useCustomerReviews();
const { isEnabled } = useModuleSettings(CUSTOMER_REVIEWS_MODULE_ID);
const productReviewsEnabled = isEnabled(CUSTOMER_REVIEWS_ENABLED_KEY);
const skeletonComponent = computed(() => (props.viewMode === "list" ? ProductSkeletonList : ProductSkeletonGrid));
const cardComponent = computed(() => (props.viewMode === "list" ? ProductCardList : ProductCardGrid));
Expand Down
9 changes: 7 additions & 2 deletions client-app/shared/catalog/components/product/properties.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@
<script setup lang="ts">
import { computed, inject } from "vue";
import { PropertyType } from "@/core/api/graphql/types";
import { useModuleSettings } from "@/core/composables/useModuleSettings";
import { configInjectionKey } from "@/core/injection-keys";
import { getPropertiesGroupedByName } from "@/core/utilities";
import { useCustomerReviews } from "@/modules/customer-reviews/useCustomerReviews";
import {
MODULE_ID as CUSTOMER_REVIEWS_MODULE_ID,
ENABLED_KEY as CUSTOMER_REVIEWS_ENABLED_KEY,
} from "@/modules/customer-reviews/constants";
import { ProductTitledBlock, Vendor } from "@/shared/catalog";
import type { Product } from "@/core/api/graphql/types";
import ProductRating from "@/modules/customer-reviews/components/product-rating.vue";
Expand All @@ -51,7 +55,8 @@ const props = defineProps<IProps>();
const config = inject(configInjectionKey, {});
const { enabled: productReviewsEnabled } = useCustomerReviews();
const { isEnabled } = useModuleSettings(CUSTOMER_REVIEWS_MODULE_ID);
const productReviewsEnabled = isEnabled(CUSTOMER_REVIEWS_ENABLED_KEY);
const properties = computed(() =>
Object.values(getPropertiesGroupedByName(props.product.properties ?? [], PropertyType.Product)),
Expand Down

0 comments on commit 3ec8642

Please sign in to comment.