@evenicanpm/storefront-core 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/src/api-manager/datasources/d365/d365-address.datasource.ts +1 -1
- package/src/api-manager/datasources/d365/d365-user.datasource.ts +0 -19
- package/src/api-manager/datasources/e4/e4-cart.datasource.ts +2 -2
- package/src/api-manager/datasources/e4/e4-product.datasource.ts +19 -4
- package/src/api-manager/datasources/e4/e4.datasource.ts +1 -2
- package/src/api-manager/datasources/e4/e4.remaps.ts +24 -0
- package/src/api-manager/datasources/e4/e4.translator.ts +17 -0
- package/src/api-manager/datasources/e4/{e4-user.datasource.ts → user/e4-user.datasource.ts} +5 -7
- package/src/api-manager/datasources/e4/user/e4-user.remaps.ts +4 -0
- package/src/api-manager/datasources/e4/user/e4-user.translator.ts +10 -0
- package/src/api-manager/index.ts +21 -6
- package/src/api-manager/schemas/product.schema.ts +1 -1
- package/src/api-manager/services/address/queries/get-states.ts +1 -1
- package/src/api-manager/services/create-query.ts +10 -3
- package/src/api-manager/types/Datasource.ts +9 -9
- package/src/components/Blocks/Components/ProductCarousel/index.tsx +6 -6
- package/src/components/_components/navbar/category-based-menu/components/categories.tsx +1 -1
- package/src/components/_components/navbar/mega-menu/mega-menu.tsx +1 -1
- package/src/components/_components/navbar/nav-list/nav-item-child.tsx +2 -2
- package/src/components/_components/product-dimensions/product-dimensions.tsx +114 -0
- package/src/components/_components/product-quantity-buttons/product-quantity-buttons.tsx +88 -0
- package/src/components/_components/section-header/section-header.tsx +1 -1
- package/src/components/_components/settings/setting.tsx +1 -1
- package/src/components/_components/wishlist-modal/TODO.md +10 -0
- package/src/components/_components/wishlist-modal/add-to-wishlist-button.tsx +68 -0
- package/src/components/_components/wishlist-modal/add-to-wishlist-dialog.tsx +161 -0
- package/src/components/_components/wishlist-modal/remove-from-wishlist-dialog.tsx +174 -0
- package/src/components/_components/wishlist-modal/wishlist-modal-item.tsx +65 -0
- package/src/components/countries-input.tsx +1 -0
- package/src/hooks/use-cart.tsx +82 -0
- package/src/hooks/use-variants.tsx +85 -0
- package/src/pages/account/addresses/address-form.tsx +289 -0
- package/src/pages/account/addresses/address-item.tsx +104 -0
- package/src/pages/account/dashboard-header.tsx +123 -0
- package/src/pages/account/navigation.tsx +84 -0
- package/src/pages/account/no-records.tsx +20 -0
- package/src/pages/account/orders/icons/delivery.tsx +14 -0
- package/src/pages/account/orders/icons/package-box.tsx +13 -0
- package/src/pages/account/orders/icons/truck-filled.tsx +14 -0
- package/src/pages/account/orders/order-progress.tsx +111 -0
- package/src/pages/account/orders/order-row.tsx +61 -0
- package/src/pages/account/orders/order-summary.tsx +83 -0
- package/src/pages/account/orders/ordered-products.tsx +114 -0
- package/src/pages/account/profile/profile-button.test.tsx +59 -0
- package/src/pages/account/profile/profile-button.tsx +50 -0
- package/src/pages/account/profile/user-info.tsx +59 -0
- package/src/pages/account/styles.ts +32 -0
- package/src/pages/account/table-row.tsx +19 -0
- package/src/pages/account/wishlist/create-new-list.tsx +167 -0
- package/src/pages/account/wishlist/create-wishlist-button.tsx +40 -0
- package/src/pages/account/wishlist/wishlist-item.tsx +82 -0
- package/src/pages/blog/pagination.tsx +38 -0
- package/src/pages/cart/cart-item.tsx +312 -0
- package/src/pages/cart/checkout-form.tsx +122 -0
- package/src/pages/cart/coupon-entry.tsx +90 -0
- package/src/pages/cart/estimate-shipping.tsx +183 -0
- package/src/pages/cart/wrapper.tsx +30 -0
- package/src/pages/checkout/checkout-alt-form/address-card.tsx +73 -0
- package/src/pages/checkout/checkout-alt-form/checkout-form.tsx +133 -0
- package/src/pages/checkout/checkout-alt-form/checkout-step.tsx +120 -0
- package/src/pages/checkout/checkout-alt-form/customer-information.tsx +94 -0
- package/src/pages/checkout/checkout-alt-form/delivery-address.tsx +170 -0
- package/src/pages/checkout/checkout-alt-form/delivery-date.tsx +114 -0
- package/src/pages/checkout/checkout-alt-form/delivery-options.tsx +186 -0
- package/src/pages/checkout/checkout-alt-form/edit-address-form.tsx +130 -0
- package/src/pages/checkout/checkout-alt-form/heading.tsx +50 -0
- package/src/pages/checkout/checkout-alt-form/index.ts +1 -0
- package/src/pages/checkout/checkout-alt-form/new-address-form.tsx +294 -0
- package/src/pages/checkout/checkout-alt-form/node.tsx +9 -0
- package/src/pages/checkout/checkout-alt-form/payment-details.tsx +344 -0
- package/src/pages/checkout/checkout-alt-form/safe-card-preview-data.tsx +36 -0
- package/src/pages/checkout/checkout-alt-form/types.ts +20 -0
- package/src/pages/checkout/checkout-alt-summary/cart-item.tsx +39 -0
- package/src/pages/checkout/checkout-alt-summary/checkout-alt-summary.tsx +40 -0
- package/src/pages/checkout/checkout-alt-summary/index.ts +1 -0
- package/src/pages/checkout/checkout-alt-summary/list-item.tsx +31 -0
- package/src/pages/confirmation/address.tsx +22 -0
- package/src/pages/confirmation/confirmation-summary.tsx +52 -0
- package/src/pages/confirmation/ordered-products.tsx +108 -0
- package/src/pages/product-details/available-shops.tsx +48 -0
- package/src/pages/product-details/bopis/find-in-store-button.tsx +63 -0
- package/src/pages/product-details/bopis/find-in-store-modal.tsx +257 -0
- package/src/pages/product-details/bopis/pickup-option-select.tsx +127 -0
- package/src/pages/product-details/bopis/search-header.tsx +69 -0
- package/src/pages/product-details/checkbox-label.tsx +20 -0
- package/src/pages/product-details/currency.ts +64 -0
- package/src/pages/product-details/frequently-bought.tsx +90 -0
- package/src/pages/product-details/frequently-product-card.tsx +60 -0
- package/src/pages/product-details/product-comment.tsx +44 -0
- package/src/pages/product-details/product-description.tsx +22 -0
- package/src/pages/product-details/product-filter-card.tsx +257 -0
- package/src/pages/product-details/product-intro/product-intro-images.tsx +87 -0
- package/src/pages/product-details/product-intro/product-intro.tsx +250 -0
- package/src/pages/product-details/product-review.tsx +131 -0
- package/src/pages/product-details/product-tabs.tsx +51 -0
- package/src/pages/product-details/related-products.tsx +42 -0
- package/src/pages/product-details/types.ts +11 -0
- package/src/pages/product-list/breadcrumbs.tsx +39 -0
- package/src/pages/product-list/checkbox-label.tsx +20 -0
- package/src/pages/product-list/facet-group.tsx +125 -0
- package/src/pages/product-list/facet.tsx +36 -0
- package/src/pages/product-list/list-filter.tsx +40 -0
- package/src/pages/product-list/pagination.tsx +80 -0
- package/src/pages/product-list/product-list-context.tsx +302 -0
- package/src/pages/product-list/product-list-state.ts +187 -0
- package/src/pages/product-list/product-rating.tsx +16 -0
- package/src/pages/product-list/quick-view-dialog-content.tsx +205 -0
- package/src/pages/product-list/quick-view-dialog.tsx +54 -0
- package/src/pages/product-list/range-filter.tsx +125 -0
- package/src/pages/product-list/scrollbar.tsx +38 -0
- package/src/pages/product-list/search-bar.tsx +162 -0
- package/src/pages/product-list/selected-facets.tsx +80 -0
- package/src/pages/product-list/side-nav.tsx +49 -0
- package/src/pages/product-list/swatch.tsx +80 -0
- package/src/pages/product-list/types.ts +18 -0
- package/src/pages/product-list/use-product-list.ts +12 -0
- package/src/pages/product-list/useCategoryFilter.tsx +26 -0
- package/src/pages/product-list/utils/facet-helpers.ts +5 -0
- package/src/pages/product-list/utils/generate-breadcrumbs.ts +30 -0
- package/src/pages/product-list/utils/getCategoryFilterFromSlug.ts +153 -0
- package/src/pages/product-list/utils/product-list-helper.ts +111 -0
- package/src/pages/product-list/utils/product-list-types.ts +41 -0
- package/src/pages/product-list/utils/search-for-category.ts +76 -0
- package/src/pages/product-list/utils/sort-options.ts +44 -0
- package/src/pages/product-list/utils/use-previous-refiners.ts +14 -0
- package/src/pages/quickorder/order-upload.tsx +150 -0
- package/src/pages/quickorder/quick-order-form.tsx +343 -0
- package/src/pages/quickorder/quick-order-row.tsx +144 -0
- package/tsconfig.json +1 -0
- package/src/api-manager/datasources/e4/graphqlRequestSdk.ts +0 -10464
- /package/src/{components/_components/hooks/useOverflowDetect.ts → hooks/use-overflow-detect.ts} +0 -0
- /package/src/{components/_components/hooks/useSettings.ts → hooks/use-settings.ts} +0 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ProductRefiner,
|
|
3
|
+
ProductRefinerValue,
|
|
4
|
+
} from "@msdyn365-commerce/retail-proxy";
|
|
5
|
+
import React from "react";
|
|
6
|
+
import FacetGroup from "./facet-group";
|
|
7
|
+
import { Box, Divider } from "@mui/material";
|
|
8
|
+
|
|
9
|
+
type Props = {
|
|
10
|
+
facets: ProductRefiner[];
|
|
11
|
+
selectedRefiners: ProductRefinerValue[];
|
|
12
|
+
handleRefinerSelect(refiner: ProductRefinerValue): void;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default function Facet({
|
|
16
|
+
facets,
|
|
17
|
+
selectedRefiners,
|
|
18
|
+
handleRefinerSelect,
|
|
19
|
+
}: Props) {
|
|
20
|
+
return (
|
|
21
|
+
<div>
|
|
22
|
+
{facets.map((facetGroup, index) => {
|
|
23
|
+
return (
|
|
24
|
+
<Box key={facetGroup.KeyName}>
|
|
25
|
+
<FacetGroup
|
|
26
|
+
facet={facetGroup}
|
|
27
|
+
selectedRefiners={selectedRefiners}
|
|
28
|
+
handleRefinerSelect={handleRefinerSelect}
|
|
29
|
+
/>
|
|
30
|
+
{index < facets.length - 1 && <Divider />}
|
|
31
|
+
</Box>
|
|
32
|
+
);
|
|
33
|
+
})}
|
|
34
|
+
</div>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ProductRefinerValue } from "@msdyn365-commerce/retail-proxy";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import CheckboxLabel from "./checkbox-label";
|
|
4
|
+
import { FlexBetween, FlexBox } from "@/components/_components/flex-box";
|
|
5
|
+
import { Span } from "@/components/_components/Typography";
|
|
6
|
+
import { RenderedFacetProps } from "./facet-group";
|
|
7
|
+
|
|
8
|
+
type Props = RenderedFacetProps & NonNullable<unknown>;
|
|
9
|
+
|
|
10
|
+
const generateKey = (f: ProductRefinerValue) => {
|
|
11
|
+
return `${f.LeftValueBoundString}-${f.RefinerRecordId}`;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default function ListFilter({
|
|
15
|
+
facet,
|
|
16
|
+
handleRefinerSelect,
|
|
17
|
+
isRefinerSelected,
|
|
18
|
+
}: Props) {
|
|
19
|
+
const createFacetLabel = (f: ProductRefinerValue) => {
|
|
20
|
+
const label = f.LeftValueBoundLocalizedString || f.LeftValueBoundString;
|
|
21
|
+
return (
|
|
22
|
+
<FlexBetween>
|
|
23
|
+
<Span>{label}</Span>
|
|
24
|
+
<Span ml={2}>({f.Count})</Span>
|
|
25
|
+
</FlexBetween>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
return (
|
|
29
|
+
<FlexBox flexDirection="column" pl={1}>
|
|
30
|
+
{facet.Values?.map((f) => (
|
|
31
|
+
<CheckboxLabel
|
|
32
|
+
key={generateKey(f)}
|
|
33
|
+
label={createFacetLabel(f)}
|
|
34
|
+
checked={isRefinerSelected(f)}
|
|
35
|
+
onChange={() => handleRefinerSelect(f)}
|
|
36
|
+
/>
|
|
37
|
+
))}
|
|
38
|
+
</FlexBox>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { ChangeEvent } from "react";
|
|
3
|
+
import MuiPagination, { PaginationProps } from "@mui/material/Pagination";
|
|
4
|
+
import { Span } from "@/components/_components/Typography";
|
|
5
|
+
import { useTranslations } from "next-intl";
|
|
6
|
+
|
|
7
|
+
export interface PageInfo {
|
|
8
|
+
top?: number;
|
|
9
|
+
skip?: number;
|
|
10
|
+
search?: string;
|
|
11
|
+
sort?: string;
|
|
12
|
+
sortDesc?: boolean;
|
|
13
|
+
startCursor?: string;
|
|
14
|
+
endCursor?: string;
|
|
15
|
+
hasNextPage?: boolean;
|
|
16
|
+
hasPreviousPage?: boolean;
|
|
17
|
+
currentPage?: number;
|
|
18
|
+
after?: string;
|
|
19
|
+
before?: string;
|
|
20
|
+
// filter?: any;
|
|
21
|
+
}
|
|
22
|
+
interface Props extends PaginationProps {
|
|
23
|
+
recordCount: number;
|
|
24
|
+
pageInfo: PageInfo;
|
|
25
|
+
handleChange: (filter: PageInfo) => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const Pagination = ({ recordCount, pageInfo, handleChange, page }: Props) => {
|
|
29
|
+
const t = useTranslations("ProductList");
|
|
30
|
+
|
|
31
|
+
const newPageInfo = {
|
|
32
|
+
...pageInfo,
|
|
33
|
+
top: pageInfo.top ?? 20,
|
|
34
|
+
skip: pageInfo.skip ?? 0,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// Calculate showing range
|
|
38
|
+
const start = recordCount === 0 ? 0 : newPageInfo.skip + 1;
|
|
39
|
+
const end = Math.min(newPageInfo.skip + newPageInfo.top, recordCount);
|
|
40
|
+
const showingText = t("showingRange", {
|
|
41
|
+
start,
|
|
42
|
+
end,
|
|
43
|
+
total: recordCount,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Calculate page count
|
|
47
|
+
let newCount = Math.floor(recordCount / newPageInfo.top);
|
|
48
|
+
if (recordCount === 0) {
|
|
49
|
+
newCount = 1;
|
|
50
|
+
} else if (recordCount % newPageInfo.top !== 0) {
|
|
51
|
+
newCount += 1;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const handleMuiPaginationChange = (
|
|
55
|
+
_event: ChangeEvent<unknown>,
|
|
56
|
+
newPage: number,
|
|
57
|
+
) => {
|
|
58
|
+
const skip = newPageInfo.top * (newPage - 1);
|
|
59
|
+
handleChange({
|
|
60
|
+
...newPageInfo,
|
|
61
|
+
currentPage: newPage,
|
|
62
|
+
skip,
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<>
|
|
68
|
+
<Span color="grey.600">{showingText}</Span>
|
|
69
|
+
<MuiPagination
|
|
70
|
+
color="primary"
|
|
71
|
+
variant="outlined"
|
|
72
|
+
count={newCount}
|
|
73
|
+
page={page}
|
|
74
|
+
onChange={handleMuiPaginationChange}
|
|
75
|
+
/>
|
|
76
|
+
</>
|
|
77
|
+
);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export default Pagination;
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SearchByCriteriaInput,
|
|
3
|
+
SearchByCriteriaResponse,
|
|
4
|
+
ProductPrice,
|
|
5
|
+
} from "@/api-manager/schemas/product.schema";
|
|
6
|
+
import { parseAsInteger, parseAsString, useQueryState } from "nuqs";
|
|
7
|
+
import React, { createContext, useMemo, useCallback } from "react";
|
|
8
|
+
import {
|
|
9
|
+
PageKey,
|
|
10
|
+
ProductListParamHandlers,
|
|
11
|
+
SortOption,
|
|
12
|
+
ViewMode,
|
|
13
|
+
} from "./utils/product-list-types";
|
|
14
|
+
import {
|
|
15
|
+
ProductRefinerSource,
|
|
16
|
+
ProductRefinerValue,
|
|
17
|
+
} from "@msdyn365-commerce/retail-proxy";
|
|
18
|
+
import {
|
|
19
|
+
areRefinersEqual,
|
|
20
|
+
convertRefinerToParameter,
|
|
21
|
+
} from "@/lib/refiner-utils";
|
|
22
|
+
import getProductList from "@/api-manager/services/product/queries/get-product-list";
|
|
23
|
+
import getSortOptions from "./utils/sort-options";
|
|
24
|
+
import { usePathname, useSearchParams } from "next/navigation";
|
|
25
|
+
import {
|
|
26
|
+
buildInitialState,
|
|
27
|
+
calculatePage,
|
|
28
|
+
calculateSkip,
|
|
29
|
+
getDefaultValueByPageKey,
|
|
30
|
+
getSelectedSortOption,
|
|
31
|
+
} from "./utils/product-list-helper";
|
|
32
|
+
import getProductPrices from "@/api-manager/services/product/queries/get-product-prices";
|
|
33
|
+
export type ProductListContextType = {
|
|
34
|
+
productData: SearchByCriteriaResponse;
|
|
35
|
+
isLoading: boolean;
|
|
36
|
+
paramHandlers: ProductListParamHandlers;
|
|
37
|
+
view: ViewMode;
|
|
38
|
+
sortOptions: SortOption[];
|
|
39
|
+
selectedSort: string;
|
|
40
|
+
itemsPerPage: number;
|
|
41
|
+
page: number;
|
|
42
|
+
skip: number;
|
|
43
|
+
selectedRefiners: ProductRefinerValue[];
|
|
44
|
+
searchTerm: string;
|
|
45
|
+
productPrices: ProductPrice[];
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const ProductListContext = createContext<
|
|
49
|
+
ProductListContextType | undefined
|
|
50
|
+
>(undefined);
|
|
51
|
+
|
|
52
|
+
const ProductListProvider = ({ children }: { children: React.ReactNode }) => {
|
|
53
|
+
const pathname = usePathname();
|
|
54
|
+
const searchParams = useSearchParams();
|
|
55
|
+
const [topParameter, setTopParameter] = useQueryState(
|
|
56
|
+
PageKey.TOP,
|
|
57
|
+
parseAsInteger
|
|
58
|
+
.withDefault(getDefaultValueByPageKey(PageKey.TOP) as number)
|
|
59
|
+
.withOptions({ clearOnDefault: true }),
|
|
60
|
+
);
|
|
61
|
+
const [pageParameter, setPageParameter] = useQueryState(
|
|
62
|
+
PageKey.PAGE,
|
|
63
|
+
parseAsInteger
|
|
64
|
+
.withDefault(getDefaultValueByPageKey(PageKey.PAGE) as number)
|
|
65
|
+
.withOptions({ clearOnDefault: true }),
|
|
66
|
+
);
|
|
67
|
+
const [refinerParameter, setRefinerParameter] = useQueryState(
|
|
68
|
+
PageKey.REFINEMENT,
|
|
69
|
+
parseAsString
|
|
70
|
+
.withDefault(getDefaultValueByPageKey(PageKey.REFINEMENT) as string)
|
|
71
|
+
.withOptions({ clearOnDefault: true }),
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const [viewParameter, setViewParameter] = useQueryState(
|
|
75
|
+
PageKey.VIEW,
|
|
76
|
+
parseAsString
|
|
77
|
+
.withDefault(getDefaultValueByPageKey(PageKey.VIEW) as string)
|
|
78
|
+
.withOptions({ clearOnDefault: true }),
|
|
79
|
+
);
|
|
80
|
+
const [sortParameter, setSortParameter] = useQueryState(
|
|
81
|
+
PageKey.SORT,
|
|
82
|
+
parseAsString
|
|
83
|
+
.withDefault(
|
|
84
|
+
getSelectedSortOption(
|
|
85
|
+
getSortOptions(),
|
|
86
|
+
!!searchParams.get(PageKey.SEARCH),
|
|
87
|
+
)?.code,
|
|
88
|
+
)
|
|
89
|
+
.withOptions({ clearOnDefault: true }),
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const [searchParameter, setSearchParameter] = useQueryState(
|
|
93
|
+
PageKey.SEARCH,
|
|
94
|
+
parseAsString
|
|
95
|
+
.withDefault(getDefaultValueByPageKey(PageKey.SEARCH) as string)
|
|
96
|
+
.withOptions({ clearOnDefault: true }),
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
const initialState = buildInitialState(
|
|
100
|
+
pathname.split("/"),
|
|
101
|
+
topParameter,
|
|
102
|
+
pageParameter,
|
|
103
|
+
sortParameter,
|
|
104
|
+
refinerParameter,
|
|
105
|
+
searchParameter,
|
|
106
|
+
);
|
|
107
|
+
const [inputParams, setInputParams] =
|
|
108
|
+
React.useState<SearchByCriteriaInput>(initialState);
|
|
109
|
+
|
|
110
|
+
const { data, isLoading } = getProductList.useData(inputParams);
|
|
111
|
+
const { data: productPrices } = getProductPrices.useSuspenseData({
|
|
112
|
+
productIds: data?.products.map((product) => product.RecordId) || [],
|
|
113
|
+
});
|
|
114
|
+
const handleRefinerChange = useCallback(
|
|
115
|
+
(refiner: ProductRefinerValue) => {
|
|
116
|
+
const newInputParams = { ...inputParams };
|
|
117
|
+
const refiners = newInputParams.searchState.refinement;
|
|
118
|
+
const priceIndex = ProductRefinerSource.Price;
|
|
119
|
+
const idx = refiners.findIndex((r) => areRefinersEqual(r, refiner));
|
|
120
|
+
if (refiner.RefinerSourceValue === priceIndex) {
|
|
121
|
+
const priceRefiner = refiners[idx];
|
|
122
|
+
if (idx > -1) {
|
|
123
|
+
if (
|
|
124
|
+
priceRefiner.LeftValueBoundString ===
|
|
125
|
+
refiner.LeftValueBoundString &&
|
|
126
|
+
priceRefiner.RightValueBoundString === refiner.RightValueBoundString
|
|
127
|
+
) {
|
|
128
|
+
refiners.splice(idx, 1);
|
|
129
|
+
} else {
|
|
130
|
+
priceRefiner.LeftValueBoundString = refiner.LeftValueBoundString;
|
|
131
|
+
priceRefiner.RightValueBoundString = refiner.RightValueBoundString;
|
|
132
|
+
}
|
|
133
|
+
} else {
|
|
134
|
+
refiners.push(refiner);
|
|
135
|
+
}
|
|
136
|
+
} else {
|
|
137
|
+
if (idx > -1) {
|
|
138
|
+
refiners.splice(idx, 1);
|
|
139
|
+
} else {
|
|
140
|
+
refiners.push(refiner);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
setInputParams(newInputParams);
|
|
145
|
+
},
|
|
146
|
+
[inputParams, setInputParams],
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
const handlePageChange = useCallback(
|
|
150
|
+
(page: number) => {
|
|
151
|
+
const updatedInputParams = { ...inputParams };
|
|
152
|
+
const calculationSkip = calculateSkip(page, topParameter);
|
|
153
|
+
let paging = updatedInputParams.searchState.queryResultSettings.Paging;
|
|
154
|
+
paging = paging || {};
|
|
155
|
+
paging.Skip = calculationSkip;
|
|
156
|
+
setInputParams(updatedInputParams);
|
|
157
|
+
},
|
|
158
|
+
[inputParams, topParameter, setInputParams],
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
const handlePerPageChange = useCallback(
|
|
162
|
+
(newValue: number) => {
|
|
163
|
+
const updatedInputParams = { ...inputParams };
|
|
164
|
+
let paging = updatedInputParams.searchState.queryResultSettings.Paging;
|
|
165
|
+
paging = paging || {};
|
|
166
|
+
paging.Top = newValue;
|
|
167
|
+
setInputParams(updatedInputParams);
|
|
168
|
+
},
|
|
169
|
+
[inputParams, setInputParams],
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
const handleViewChange = useCallback(
|
|
173
|
+
(viewMode: ViewMode) => {
|
|
174
|
+
setViewParameter(viewMode);
|
|
175
|
+
},
|
|
176
|
+
[setViewParameter],
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
const handleSortChange = useCallback(
|
|
180
|
+
(sort: SortOption) => {
|
|
181
|
+
const updatedInputParams = { ...inputParams };
|
|
182
|
+
const sortOption = getSortOptions().find((s) => s.code === sort.code);
|
|
183
|
+
if (!sortOption) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
let sorting = updatedInputParams.searchState.queryResultSettings.Sorting;
|
|
187
|
+
sorting = sorting || {};
|
|
188
|
+
sorting.Columns = [
|
|
189
|
+
{ ColumnName: sortOption.field, IsDescending: sortOption.isDescending },
|
|
190
|
+
];
|
|
191
|
+
setInputParams(updatedInputParams);
|
|
192
|
+
},
|
|
193
|
+
[inputParams, setInputParams],
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
const handleSearchChange = useCallback(
|
|
197
|
+
(searchTerm: string) => {
|
|
198
|
+
const updatedInputParams = { ...inputParams };
|
|
199
|
+
updatedInputParams.searchState.searchTerm = searchTerm;
|
|
200
|
+
setInputParams(updatedInputParams);
|
|
201
|
+
},
|
|
202
|
+
[inputParams, setInputParams],
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
const handleRefinersClear = useCallback(() => {
|
|
206
|
+
const updatedInputParams = { ...inputParams };
|
|
207
|
+
updatedInputParams.searchState.refinement = [];
|
|
208
|
+
setInputParams(updatedInputParams);
|
|
209
|
+
}, [inputParams, setInputParams]);
|
|
210
|
+
|
|
211
|
+
const paramHandlers = useMemo(
|
|
212
|
+
() => ({
|
|
213
|
+
handlePageChange,
|
|
214
|
+
handlePerPageChange,
|
|
215
|
+
handleRefinerChange,
|
|
216
|
+
handleViewChange,
|
|
217
|
+
handleSortChange,
|
|
218
|
+
handleSearchChange,
|
|
219
|
+
handleRefinersClear,
|
|
220
|
+
}),
|
|
221
|
+
[
|
|
222
|
+
handlePageChange,
|
|
223
|
+
handlePerPageChange,
|
|
224
|
+
handleRefinerChange,
|
|
225
|
+
handleViewChange,
|
|
226
|
+
handleSortChange,
|
|
227
|
+
handleSearchChange,
|
|
228
|
+
handleRefinersClear,
|
|
229
|
+
],
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
React.useEffect(() => {
|
|
233
|
+
const sortObj =
|
|
234
|
+
inputParams.searchState.queryResultSettings.Sorting?.Columns?.[0];
|
|
235
|
+
let sortCode = "";
|
|
236
|
+
if (sortObj) {
|
|
237
|
+
sortCode =
|
|
238
|
+
getSortOptions().find(
|
|
239
|
+
(s) =>
|
|
240
|
+
s.field === sortObj.ColumnName &&
|
|
241
|
+
s.isDescending === sortObj.IsDescending,
|
|
242
|
+
)?.code || "";
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
setTopParameter(
|
|
246
|
+
inputParams.searchState.queryResultSettings.Paging?.Top || 20,
|
|
247
|
+
);
|
|
248
|
+
setPageParameter(
|
|
249
|
+
calculatePage(inputParams.searchState.queryResultSettings),
|
|
250
|
+
);
|
|
251
|
+
setRefinerParameter(
|
|
252
|
+
inputParams.searchState.refinement
|
|
253
|
+
.map((r) => convertRefinerToParameter(r))
|
|
254
|
+
.join("||"),
|
|
255
|
+
);
|
|
256
|
+
setSortParameter(sortCode);
|
|
257
|
+
setSearchParameter(inputParams.searchState.searchTerm || "");
|
|
258
|
+
}, [
|
|
259
|
+
inputParams,
|
|
260
|
+
setPageParameter,
|
|
261
|
+
setRefinerParameter,
|
|
262
|
+
setSearchParameter,
|
|
263
|
+
setSortParameter,
|
|
264
|
+
setTopParameter,
|
|
265
|
+
]);
|
|
266
|
+
|
|
267
|
+
const value = useMemo(
|
|
268
|
+
() => ({
|
|
269
|
+
productData: data as SearchByCriteriaResponse,
|
|
270
|
+
isLoading,
|
|
271
|
+
paramHandlers,
|
|
272
|
+
view: viewParameter as ViewMode,
|
|
273
|
+
sortOptions: getSortOptions(),
|
|
274
|
+
selectedSort: sortParameter,
|
|
275
|
+
itemsPerPage: topParameter,
|
|
276
|
+
page: pageParameter,
|
|
277
|
+
skip: calculateSkip(pageParameter, topParameter),
|
|
278
|
+
selectedRefiners: inputParams.searchState.refinement,
|
|
279
|
+
searchTerm: searchParameter,
|
|
280
|
+
productPrices: productPrices,
|
|
281
|
+
}),
|
|
282
|
+
[
|
|
283
|
+
data,
|
|
284
|
+
isLoading,
|
|
285
|
+
paramHandlers,
|
|
286
|
+
viewParameter,
|
|
287
|
+
sortParameter,
|
|
288
|
+
topParameter,
|
|
289
|
+
pageParameter,
|
|
290
|
+
inputParams.searchState.refinement,
|
|
291
|
+
searchParameter,
|
|
292
|
+
productPrices,
|
|
293
|
+
],
|
|
294
|
+
);
|
|
295
|
+
return (
|
|
296
|
+
<ProductListContext.Provider value={value}>
|
|
297
|
+
{children}
|
|
298
|
+
</ProductListContext.Provider>
|
|
299
|
+
);
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
export default ProductListProvider;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { SearchByCriteriaInput } from "@/api-manager/schemas/product.schema";
|
|
2
|
+
import { parseAsInteger, parseAsString, useQueryState } from "nuqs";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import {
|
|
5
|
+
PageKey,
|
|
6
|
+
ProductListParamHandlers,
|
|
7
|
+
ViewMode,
|
|
8
|
+
} from "./utils/product-list-types";
|
|
9
|
+
import {
|
|
10
|
+
IQueryResultSettings,
|
|
11
|
+
ProductRefinerValue,
|
|
12
|
+
} from "@msdyn365-commerce/retail-proxy";
|
|
13
|
+
import {
|
|
14
|
+
areRefinersEqual,
|
|
15
|
+
convertParameterToRefiner,
|
|
16
|
+
convertRefinerToParameter,
|
|
17
|
+
} from "@/lib/refiner-utils";
|
|
18
|
+
import getProductList from "@/api-manager/services/product/queries/get-product-list";
|
|
19
|
+
import { SortOption } from "./types";
|
|
20
|
+
import getSortOptions from "./utils/sort-options";
|
|
21
|
+
|
|
22
|
+
const calculatePage = (searchState: IQueryResultSettings) => {
|
|
23
|
+
const skip = searchState.Paging?.Skip ?? 0;
|
|
24
|
+
const top = searchState.Paging?.Top ?? 20;
|
|
25
|
+
return skip === 0 ? 1 : skip / top + 1;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const calculateSkip = (page: number, top: number) => (page - 1) * top;
|
|
29
|
+
|
|
30
|
+
const useProductListState = () => {
|
|
31
|
+
const [topParameter, setTopParameter] = useQueryState(
|
|
32
|
+
PageKey.TOP,
|
|
33
|
+
parseAsInteger.withDefault(20),
|
|
34
|
+
);
|
|
35
|
+
const [pageParameter, setPageParameter] = useQueryState(
|
|
36
|
+
PageKey.PAGE,
|
|
37
|
+
parseAsInteger.withDefault(1),
|
|
38
|
+
);
|
|
39
|
+
const [refinerParameter, setRefinerParameter] = useQueryState(
|
|
40
|
+
PageKey.REFINEMENT,
|
|
41
|
+
parseAsString,
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const [viewParameter, setViewParameter] = useQueryState(
|
|
45
|
+
PageKey.VIEW,
|
|
46
|
+
parseAsString.withDefault("grid"),
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const [sortParameter, setSortParameter] = useQueryState(
|
|
50
|
+
PageKey.SORT,
|
|
51
|
+
parseAsString,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const [searchParameter, setSearchParameter] = useQueryState(
|
|
55
|
+
PageKey.SEARCH,
|
|
56
|
+
parseAsString,
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const buildInitialState = () => {
|
|
60
|
+
const state: SearchByCriteriaInput = {
|
|
61
|
+
searchState: {
|
|
62
|
+
queryResultSettings: {
|
|
63
|
+
Paging: {
|
|
64
|
+
Top: topParameter,
|
|
65
|
+
Skip: calculateSkip(pageParameter, topParameter),
|
|
66
|
+
},
|
|
67
|
+
Sorting: {
|
|
68
|
+
Columns:
|
|
69
|
+
(sortParameter && [
|
|
70
|
+
{ ColumnName: sortParameter, IsDescending: false },
|
|
71
|
+
]) ||
|
|
72
|
+
[],
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
refinement: refinerParameter
|
|
76
|
+
? refinerParameter
|
|
77
|
+
.split("||")
|
|
78
|
+
.map((r) => convertParameterToRefiner(r))
|
|
79
|
+
: [],
|
|
80
|
+
searchTerm: searchParameter || undefined,
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
return state;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const [inputParams, setInputParams] =
|
|
87
|
+
React.useState<SearchByCriteriaInput>(buildInitialState());
|
|
88
|
+
|
|
89
|
+
const { data } = getProductList.useData(inputParams);
|
|
90
|
+
|
|
91
|
+
const handleRefinerChange = (refiner: ProductRefinerValue) => {
|
|
92
|
+
const newInputParams = { ...inputParams };
|
|
93
|
+
const refiners = newInputParams.searchState.refinement;
|
|
94
|
+
const idx = refiners.findIndex((r) => areRefinersEqual(r, refiner));
|
|
95
|
+
if (idx > -1) {
|
|
96
|
+
refiners.splice(idx, 1);
|
|
97
|
+
} else {
|
|
98
|
+
refiners.push(refiner);
|
|
99
|
+
}
|
|
100
|
+
setInputParams(newInputParams);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const handlePageChange = (page: number) => {
|
|
104
|
+
const updatedInputParams = { ...inputParams };
|
|
105
|
+
const calculationSkip = calculateSkip(page, topParameter);
|
|
106
|
+
let paging = updatedInputParams.searchState.queryResultSettings.Paging;
|
|
107
|
+
paging = paging || {};
|
|
108
|
+
paging.Skip = calculationSkip;
|
|
109
|
+
setInputParams(updatedInputParams);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const handlePerPageChange = (newValue: number) => {
|
|
113
|
+
const updatedInputParams = { ...inputParams };
|
|
114
|
+
let paging = updatedInputParams.searchState.queryResultSettings.Paging;
|
|
115
|
+
paging = paging || {};
|
|
116
|
+
paging.Top = newValue;
|
|
117
|
+
setInputParams(updatedInputParams);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const handleViewChange = (viewMode: ViewMode) => {
|
|
121
|
+
setViewParameter(viewMode);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const handleSortChange = (sort: SortOption) => {
|
|
125
|
+
const updatedInputParams = { ...inputParams };
|
|
126
|
+
let sorting = updatedInputParams.searchState.queryResultSettings.Sorting;
|
|
127
|
+
sorting = sorting || {};
|
|
128
|
+
sorting.Columns = [
|
|
129
|
+
{ ColumnName: sort.field, IsDescending: sort.isDescending },
|
|
130
|
+
];
|
|
131
|
+
setInputParams(updatedInputParams);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const handleSearchChange = (searchTerm: string) => {
|
|
135
|
+
const updatedInputParams = { ...inputParams };
|
|
136
|
+
updatedInputParams.searchState.searchTerm = searchTerm;
|
|
137
|
+
setInputParams(updatedInputParams);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const paramHandlers: ProductListParamHandlers = {
|
|
141
|
+
handlePageChange,
|
|
142
|
+
handlePerPageChange,
|
|
143
|
+
handleRefinerChange,
|
|
144
|
+
handleViewChange,
|
|
145
|
+
handleSortChange,
|
|
146
|
+
handleSearchChange,
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
React.useEffect(() => {
|
|
150
|
+
setTopParameter(
|
|
151
|
+
inputParams.searchState.queryResultSettings.Paging?.Top || 20,
|
|
152
|
+
);
|
|
153
|
+
setPageParameter(
|
|
154
|
+
calculatePage(inputParams.searchState.queryResultSettings),
|
|
155
|
+
);
|
|
156
|
+
setRefinerParameter(
|
|
157
|
+
inputParams.searchState.refinement
|
|
158
|
+
.map((r) => convertRefinerToParameter(r))
|
|
159
|
+
.join("||"),
|
|
160
|
+
);
|
|
161
|
+
setSortParameter(
|
|
162
|
+
inputParams.searchState.queryResultSettings.Sorting?.Columns?.[0]
|
|
163
|
+
.ColumnName || "",
|
|
164
|
+
);
|
|
165
|
+
setSearchParameter(inputParams.searchState.searchTerm || "");
|
|
166
|
+
}, [
|
|
167
|
+
inputParams,
|
|
168
|
+
setTopParameter,
|
|
169
|
+
setPageParameter,
|
|
170
|
+
setRefinerParameter,
|
|
171
|
+
setSortParameter,
|
|
172
|
+
setSearchParameter,
|
|
173
|
+
]);
|
|
174
|
+
|
|
175
|
+
return {
|
|
176
|
+
productData: data,
|
|
177
|
+
paramHandlers,
|
|
178
|
+
viewMode: viewParameter as ViewMode,
|
|
179
|
+
sortOptions: getSortOptions(),
|
|
180
|
+
selectedSort: sortParameter,
|
|
181
|
+
top: topParameter,
|
|
182
|
+
page: pageParameter,
|
|
183
|
+
skip: calculateSkip(pageParameter, topParameter),
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
export default useProductListState;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Rating from "@mui/material/Rating";
|
|
2
|
+
import { BoxProps } from "@mui/material/Box";
|
|
3
|
+
import { Box, Typography } from "@mui/material";
|
|
4
|
+
|
|
5
|
+
interface Props extends BoxProps {
|
|
6
|
+
rating: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default function ProductRating({ rating = 0, ...props }: Props) {
|
|
10
|
+
return (
|
|
11
|
+
<Box display="flex" gap={1} alignItems="center" {...props}>
|
|
12
|
+
<Rating size="small" value={rating} color="warn" readOnly />
|
|
13
|
+
<Typography color="grey.600">({rating})</Typography>
|
|
14
|
+
</Box>
|
|
15
|
+
);
|
|
16
|
+
}
|