@evenicanpm/storefront-core 1.0.0-alpha → 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/api-manager.config.json +1 -1
- package/src/api-manager/datasources/d365/d365-address.datasource.ts +4 -4
- package/src/api-manager/datasources/d365/d365-cart.datasource.ts +100 -7
- package/src/api-manager/datasources/d365/d365-product.datasource.ts +39 -17
- package/src/api-manager/datasources/d365/d365-user.datasource.ts +220 -68
- package/src/api-manager/datasources/d365/utils/decode-jwt.ts +2 -2
- package/src/api-manager/datasources/e4/e4-cart.datasource.ts +6 -0
- package/src/api-manager/datasources/e4/e4-product.datasource.ts +22 -2
- package/src/api-manager/datasources/e4/e4.datasource.ts +1 -1
- package/src/api-manager/datasources/e4/e4.remaps.ts +24 -0
- package/src/api-manager/datasources/e4/e4.translator.ts +19 -1
- package/src/api-manager/datasources/e4/{e4-user.datasource.ts → user/e4-user.datasource.ts} +41 -19
- 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 +77 -15
- package/src/api-manager/lib/get-graphql-client.ts +7 -7
- package/src/api-manager/schemas/address.schema.ts +1 -19
- package/src/api-manager/schemas/cart.schema.ts +18 -0
- package/src/api-manager/schemas/product.schema.ts +8 -1
- package/src/api-manager/schemas/user.schema.ts +52 -1
- package/src/api-manager/services/address/queries/get-states.ts +1 -1
- package/src/api-manager/services/cart/mutations/checkout.ts +16 -1
- package/src/api-manager/services/cart/queries/get-cart-lines-inventory.ts +15 -0
- package/src/api-manager/services/create-extension-query.ts +26 -0
- package/src/api-manager/services/create-mutation.ts +5 -1
- package/src/api-manager/services/create-query.ts +10 -4
- package/src/api-manager/services/organization/queries/get-channel-configuration.ts +1 -1
- package/src/api-manager/services/product/queries/get-product-prices.ts +16 -0
- package/src/api-manager/services/product/queries/search-products.ts +1 -0
- package/src/api-manager/services/user/mutations/add-to-wishlist.ts +24 -0
- package/src/api-manager/services/user/mutations/copy-cart-to-wishlist.ts +23 -0
- package/src/api-manager/services/user/mutations/create-wishlist.ts +4 -4
- package/src/api-manager/services/user/mutations/delete-wishlist.ts +4 -3
- package/src/api-manager/services/user/mutations/remove-from-wishlist.ts +21 -0
- package/src/api-manager/services/user/mutations/update-wishlist.ts +23 -0
- package/src/api-manager/services/user/queries/get-wishlist-details.ts +11 -4
- package/src/api-manager/services/user/queries/get-wishlists.ts +4 -3
- package/src/api-manager/types/Datasource.ts +42 -14
- package/src/auth/auth-options.ts +2 -2
- package/src/auth/msal.ts +9 -9
- package/src/auth/next-auth-cookie-manager.ts +5 -3
- package/src/auth/providers/aadb2c-provider.ts +3 -4
- package/src/cms/endpoints.ts +2 -3
- package/src/components/Blocks/Components/ProductCarousel/index.tsx +6 -6
- package/src/components/_components/LazyImage.tsx +5 -2
- package/src/components/_components/header/components/user.tsx +1 -2
- 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-cards/product-card-1/components/quantity-buttons.tsx +17 -8
- package/src/components/_components/product-cards/product-card-1/product-card-1-wrapper.tsx +304 -0
- package/src/components/_components/product-cards/product-card-1/product-card.tsx +16 -55
- package/src/components/_components/product-cards/product-card-8/product-card.tsx +80 -60
- package/src/components/_components/product-cards/product-card-8/styles/index.ts +10 -0
- package/src/components/_components/product-cards/product-card-wishlist/components/hover-actions.tsx +37 -0
- package/src/components/_components/product-cards/product-card-wishlist/index.ts +1 -0
- package/src/components/_components/product-cards/product-card-wishlist/product-card.tsx +118 -0
- package/src/components/_components/product-cards/product-card-wishlist/styles/index.ts +51 -0
- 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/products-view/product-view-dialog.tsx +48 -10
- package/src/components/_components/products-view/products-grid-view.tsx +31 -17
- package/src/components/_components/products-view/products-list-view.tsx +30 -16
- package/src/components/_components/search-box/__test__/search-input-category.test.tsx +110 -0
- package/src/components/_components/search-box/__test__/search-input.test.tsx +137 -0
- package/src/components/_components/search-box/__test__/search-results.json +165 -0
- package/src/components/_components/search-box/components/search-result.tsx +66 -12
- package/src/components/_components/search-box/search-input-category.tsx +135 -32
- package/src/components/_components/search-box/styles/index.ts +2 -0
- package/src/components/_components/section-header/section-creator.tsx +1 -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/add-to-wishlist-dialog.tsx +161 -0
- package/src/components/_components/wishlist/components/create-new-list.tsx +167 -0
- package/src/components/_components/wishlist/components/create-wishlist-button.tsx +40 -0
- package/src/components/_components/wishlist/components/dashboard-header.tsx +123 -0
- package/src/components/_components/wishlist/components/navigation.tsx +87 -0
- package/src/components/_components/wishlist/components/no-records.tsx +20 -0
- package/src/components/_components/wishlist/components/wishlist-modal-item.tsx +66 -0
- package/src/components/_components/wishlist/remove-from-wishlist-dialog.tsx +174 -0
- package/src/components/_components/wishlist/styles.ts +61 -0
- 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 +7 -12
- package/src/hooks/use-cart.tsx +82 -0
- package/src/hooks/use-variants.tsx +85 -0
- package/src/lib/cart-cookie-handler-constants.ts +8 -0
- package/src/lib/cart-cookie-handler.ts +27 -5
- package/src/lib/create-graphql-client.ts +1 -2
- package/src/lib/product-list-types.ts +41 -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 -43515
- package/src/config.ts +0 -47
- /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
|
@@ -8,18 +8,50 @@ import CategoryDropdown from "./components/category-dropdown";
|
|
|
8
8
|
// CUSTOM ICON COMPONENT
|
|
9
9
|
import Search from "@/components/_components/icons/search";
|
|
10
10
|
import { useTranslations } from "next-intl";
|
|
11
|
-
import React, { useState } from "react";
|
|
11
|
+
import React, { FormEvent, useState } from "react";
|
|
12
12
|
import getCategories from "@/services/categories/queries/get-categories";
|
|
13
13
|
import searchProducts from "@/services/product/queries/search-products";
|
|
14
14
|
import { INPUT_SX } from "./styles/index";
|
|
15
15
|
import _ from "lodash";
|
|
16
|
+
import ProductViewDialog, {
|
|
17
|
+
ProductInfo,
|
|
18
|
+
} from "../products-view/product-view-dialog";
|
|
19
|
+
import { IconButton } from "@mui/material";
|
|
20
|
+
import { usePathname, useRouter } from "next/navigation";
|
|
21
|
+
import { PageSlug } from "@/lib/page-slugs";
|
|
22
|
+
import { PageKey } from "@/lib/product-list-types";
|
|
23
|
+
import AddToWishlistDialog from "../wishlist/add-to-wishlist-dialog";
|
|
24
|
+
import RemoveFromWishlistDialog from "../wishlist/remove-from-wishlist-dialog";
|
|
25
|
+
import getCart from "@/api-manager/services/cart/queries/get-cart";
|
|
26
|
+
|
|
27
|
+
export enum DialogType {
|
|
28
|
+
AddToWishlist = "addToWishlist",
|
|
29
|
+
RemoveFromWishlist = "removeFromWishlist",
|
|
30
|
+
QuickView = "quickView",
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type DialogState = {
|
|
34
|
+
type: DialogType | null;
|
|
35
|
+
productId: number | null;
|
|
36
|
+
productInfo?: ProductInfo; // for quick view
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
type Props = {
|
|
40
|
+
cartId?: string;
|
|
41
|
+
};
|
|
16
42
|
|
|
17
43
|
export default function SearchInputWithCategory() {
|
|
18
44
|
const t = useTranslations();
|
|
19
|
-
|
|
45
|
+
const { data: cart } = getCart.useData();
|
|
20
46
|
const [resultsOpen, setResultsOpen] = useState(false);
|
|
21
47
|
const [searchText, setSearchText] = React.useState<string>("");
|
|
22
48
|
const [selectedCategory, setSelectedCategory] = React.useState<number>(0);
|
|
49
|
+
const router = useRouter();
|
|
50
|
+
const pathname = usePathname();
|
|
51
|
+
const [dialogState, setDialogState] = useState<DialogState>({
|
|
52
|
+
type: null, // the type of dialog to open (add to/remove from wishlist, quick view)
|
|
53
|
+
productId: null,
|
|
54
|
+
});
|
|
23
55
|
|
|
24
56
|
const { data: resultList } = searchProducts.useData({
|
|
25
57
|
searchText,
|
|
@@ -48,18 +80,29 @@ export default function SearchInputWithCategory() {
|
|
|
48
80
|
|
|
49
81
|
const debounceSearch = _.debounce(handleSearchChange, 500);
|
|
50
82
|
|
|
83
|
+
const handleNavigate = () => {
|
|
84
|
+
if (searchText.trim() === "") {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const url = new URL(PageSlug.ProductList, window.location.origin);
|
|
88
|
+
url.searchParams.set(PageKey.SEARCH, searchText);
|
|
89
|
+
|
|
90
|
+
router.push(url.toString());
|
|
91
|
+
};
|
|
51
92
|
const INPUT_PROPS = {
|
|
52
93
|
startAdornment: (
|
|
53
94
|
<Box
|
|
54
|
-
mr={
|
|
55
|
-
px={
|
|
95
|
+
mr={1}
|
|
96
|
+
px={1}
|
|
56
97
|
display="grid"
|
|
57
98
|
alignItems="center"
|
|
58
99
|
justifyContent="center"
|
|
59
100
|
borderRight="1px solid"
|
|
60
101
|
borderColor="grey.400"
|
|
61
102
|
>
|
|
62
|
-
<
|
|
103
|
+
<IconButton onClick={handleNavigate}>
|
|
104
|
+
<Search sx={{ fontSize: 17, color: "grey.600" }} />
|
|
105
|
+
</IconButton>
|
|
63
106
|
</Box>
|
|
64
107
|
),
|
|
65
108
|
endAdornment: (
|
|
@@ -71,34 +114,94 @@ export default function SearchInputWithCategory() {
|
|
|
71
114
|
),
|
|
72
115
|
};
|
|
73
116
|
|
|
117
|
+
const openDialog = (
|
|
118
|
+
type: DialogType,
|
|
119
|
+
productId: number,
|
|
120
|
+
productInfo?: ProductInfo,
|
|
121
|
+
) => {
|
|
122
|
+
setDialogState({
|
|
123
|
+
type,
|
|
124
|
+
productId,
|
|
125
|
+
productInfo,
|
|
126
|
+
});
|
|
127
|
+
setResultsOpen(false);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
function handleSubmit(event: FormEvent<HTMLFormElement>): void {
|
|
131
|
+
event.preventDefault();
|
|
132
|
+
handleNavigate();
|
|
133
|
+
setResultsOpen(false);
|
|
134
|
+
setSearchText("");
|
|
135
|
+
setSelectedCategory(0);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const handleCloseDialog = () => {
|
|
139
|
+
setDialogState({
|
|
140
|
+
type: null,
|
|
141
|
+
productId: null,
|
|
142
|
+
productInfo: undefined,
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const handleAddRemoveSuccess = () => {
|
|
147
|
+
// Implement
|
|
148
|
+
};
|
|
149
|
+
|
|
74
150
|
return (
|
|
75
|
-
|
|
76
|
-
position="relative"
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
151
|
+
<>
|
|
152
|
+
<Box position="relative" flex="1 1 0" maxWidth="670px" mx="auto">
|
|
153
|
+
<form onSubmit={handleSubmit}>
|
|
154
|
+
<TextField
|
|
155
|
+
fullWidth
|
|
156
|
+
variant="outlined"
|
|
157
|
+
placeholder={t("Search.searchPlaceholder")}
|
|
158
|
+
onChange={debounceSearch}
|
|
159
|
+
InputProps={{ ...INPUT_PROPS, sx: INPUT_SX }}
|
|
160
|
+
onFocus={() => {
|
|
161
|
+
setResultsOpen(true);
|
|
162
|
+
}}
|
|
163
|
+
onBlur={() => {
|
|
164
|
+
setTimeout(() => {
|
|
165
|
+
setResultsOpen(false);
|
|
166
|
+
}, 500);
|
|
167
|
+
}}
|
|
168
|
+
/>
|
|
169
|
+
</form>
|
|
170
|
+
|
|
171
|
+
{resultList && resultList?.length > 0 && resultsOpen ? (
|
|
172
|
+
<SearchResult results={resultList} openDialog={openDialog} />
|
|
173
|
+
) : null}
|
|
174
|
+
</Box>
|
|
175
|
+
{/* Dialog */}
|
|
176
|
+
{dialogState.type === DialogType.AddToWishlist &&
|
|
177
|
+
dialogState.productId && (
|
|
178
|
+
<AddToWishlistDialog
|
|
179
|
+
open={dialogState.type === DialogType.AddToWishlist}
|
|
180
|
+
handleClose={handleCloseDialog}
|
|
181
|
+
productId={dialogState.productId}
|
|
182
|
+
onSuccess={handleAddRemoveSuccess}
|
|
183
|
+
/>
|
|
184
|
+
)}
|
|
185
|
+
{dialogState.type === DialogType.RemoveFromWishlist &&
|
|
186
|
+
dialogState.productId && (
|
|
187
|
+
<RemoveFromWishlistDialog
|
|
188
|
+
open={dialogState.type === DialogType.RemoveFromWishlist}
|
|
189
|
+
handleClose={handleCloseDialog}
|
|
190
|
+
productId={dialogState.productId}
|
|
191
|
+
onSuccess={handleAddRemoveSuccess}
|
|
192
|
+
/>
|
|
193
|
+
)}
|
|
98
194
|
|
|
99
|
-
{
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
195
|
+
{dialogState.type === DialogType.QuickView &&
|
|
196
|
+
dialogState.productId &&
|
|
197
|
+
dialogState.productInfo && (
|
|
198
|
+
<ProductViewDialog
|
|
199
|
+
openDialog={dialogState.type === DialogType.QuickView}
|
|
200
|
+
handleCloseDialog={handleCloseDialog}
|
|
201
|
+
product={dialogState.productInfo}
|
|
202
|
+
cartId={cart.Id}
|
|
203
|
+
/>
|
|
204
|
+
)}
|
|
205
|
+
</>
|
|
103
206
|
);
|
|
104
207
|
}
|
|
@@ -8,7 +8,7 @@ import ArrowRight from "@mui/icons-material/ArrowRight";
|
|
|
8
8
|
// LOCAL CUSTOM COMPONENTS
|
|
9
9
|
import { H2 } from "../Typography";
|
|
10
10
|
import { FlexBetween, FlexBox } from "../flex-box/index";
|
|
11
|
-
import useSettings from "
|
|
11
|
+
import useSettings from "../../../hooks/use-settings";
|
|
12
12
|
|
|
13
13
|
// ===================================================
|
|
14
14
|
interface Props {
|
|
@@ -15,7 +15,7 @@ import { H6 } from "@/components/_components/Typography";
|
|
|
15
15
|
import Scrollbar from "@/components/_components/scrollbar/scrollbar";
|
|
16
16
|
import FlexBox from "@/components/_components/flex-box/flex-box";
|
|
17
17
|
// GLOBAL CUSTOM HOOK
|
|
18
|
-
import useSettings from "@/
|
|
18
|
+
import useSettings from "@/hooks/use-settings";
|
|
19
19
|
// STYLED COMPONENTS
|
|
20
20
|
import {
|
|
21
21
|
BodyWrapper,
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import React, { Fragment } from "react";
|
|
2
|
+
import isFunction from "lodash/isFunction";
|
|
3
|
+
import { useTranslations } from "next-intl";
|
|
4
|
+
import { Grid, Button, Dialog, DialogContent } from "@mui/material";
|
|
5
|
+
import { MdFavorite } from "react-icons/md";
|
|
6
|
+
// Global Custom components
|
|
7
|
+
import DashboardHeader from "./components/dashboard-header";
|
|
8
|
+
import CreateWishlistButton from "./components/create-wishlist-button";
|
|
9
|
+
import WishlistModalItem from "./components/wishlist-modal-item";
|
|
10
|
+
import NoRecords from "./components/no-records";
|
|
11
|
+
// API
|
|
12
|
+
import {
|
|
13
|
+
CopyCartToWishlistInput,
|
|
14
|
+
Wishlist,
|
|
15
|
+
WishlistLinesInput,
|
|
16
|
+
} from "@evenicanpm/storefront-core/src/api-manager/schemas/user.schema";
|
|
17
|
+
import { Cart } from "@evenicanpm/storefront-core/src/api-manager/schemas/cart.schema";
|
|
18
|
+
import useAddToWishlist from "@/api-manager/services/user/mutations/add-to-wishlist";
|
|
19
|
+
import { useNotification } from "@evenicanpm/storefront-core/src/components/Notifications/use-notification";
|
|
20
|
+
import useCopyCartToWishlist from "@/api-manager/services/user/mutations/copy-cart-to-wishlist";
|
|
21
|
+
import { useSession } from "next-auth/react";
|
|
22
|
+
import getWishlists from "@/api-manager/services/user/queries/get-wishlists";
|
|
23
|
+
|
|
24
|
+
interface Props {
|
|
25
|
+
open: boolean;
|
|
26
|
+
handleClose: () => void;
|
|
27
|
+
productId?: number;
|
|
28
|
+
cart?: Cart;
|
|
29
|
+
onSuccess?: () => void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default function AddToWishlistDialog(props: Props) {
|
|
33
|
+
const { data: wishlists, isLoading } = getWishlists.useData();
|
|
34
|
+
|
|
35
|
+
const t = useTranslations("Account.Wishlists");
|
|
36
|
+
const { setNotification } = useNotification();
|
|
37
|
+
|
|
38
|
+
const { mutateAsync: addToWishlist } = useAddToWishlist();
|
|
39
|
+
const { mutateAsync: copyCartToWishlist } = useCopyCartToWishlist();
|
|
40
|
+
|
|
41
|
+
const { data: session } = useSession();
|
|
42
|
+
const isAuthenticated = !!session;
|
|
43
|
+
|
|
44
|
+
const handleClose = () => {
|
|
45
|
+
if (isFunction(props.handleClose)) {
|
|
46
|
+
props.handleClose();
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const handleAddToWishlist = async (wishlistId: string) => {
|
|
51
|
+
if (props.productId) {
|
|
52
|
+
try {
|
|
53
|
+
const wishlistLinesInput: WishlistLinesInput = {
|
|
54
|
+
Id: wishlistId,
|
|
55
|
+
ProductListLines: [],
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
wishlistLinesInput.ProductListLines.push({
|
|
59
|
+
ProductListId: wishlistId,
|
|
60
|
+
ProductId: props.productId,
|
|
61
|
+
Quantity: 1,
|
|
62
|
+
UnitOfMeasure: "ea",
|
|
63
|
+
});
|
|
64
|
+
await addToWishlist(wishlistLinesInput);
|
|
65
|
+
setNotification({
|
|
66
|
+
message: t("wishlistLineAddSuccess"),
|
|
67
|
+
severity: "success",
|
|
68
|
+
});
|
|
69
|
+
if (isFunction(props.onSuccess)) {
|
|
70
|
+
props.onSuccess();
|
|
71
|
+
}
|
|
72
|
+
} catch (error) {
|
|
73
|
+
setNotification({
|
|
74
|
+
message: t("wishlistLineAddFailed"),
|
|
75
|
+
severity: "error",
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
} else if (props.cart) {
|
|
79
|
+
try {
|
|
80
|
+
const copyCartToWishlistInput: CopyCartToWishlistInput = {
|
|
81
|
+
Id: wishlistId,
|
|
82
|
+
CartID: props.cart.Id,
|
|
83
|
+
IsRewrite: false,
|
|
84
|
+
IsQuantityAggregate: true,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
await copyCartToWishlist(copyCartToWishlistInput);
|
|
88
|
+
setNotification({
|
|
89
|
+
message: t("wishlistCartCopySuccess"),
|
|
90
|
+
severity: "success",
|
|
91
|
+
});
|
|
92
|
+
} catch (error) {
|
|
93
|
+
setNotification({
|
|
94
|
+
message: t("wishlistCartCopyFailed"),
|
|
95
|
+
severity: "error",
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<Dialog
|
|
103
|
+
open={props.open}
|
|
104
|
+
onClose={handleClose}
|
|
105
|
+
aria-labelledby="form-dialog-title"
|
|
106
|
+
>
|
|
107
|
+
<DialogContent>
|
|
108
|
+
<Fragment>
|
|
109
|
+
<DashboardHeader
|
|
110
|
+
title="Account.Wishlists.heading"
|
|
111
|
+
Icon={MdFavorite}
|
|
112
|
+
href=""
|
|
113
|
+
buttonText=""
|
|
114
|
+
buttons={
|
|
115
|
+
isAuthenticated && (
|
|
116
|
+
<CreateWishlistButton path="Account.Wishlists.btnCreateNewList" />
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
/>
|
|
120
|
+
{isAuthenticated && !isLoading ? (
|
|
121
|
+
wishlists && wishlists.length > 0 ? (
|
|
122
|
+
wishlists?.map((wishlist: Wishlist) => (
|
|
123
|
+
<WishlistModalItem
|
|
124
|
+
key={wishlist.Id}
|
|
125
|
+
wishlist={wishlist}
|
|
126
|
+
addToWishlist={handleAddToWishlist}
|
|
127
|
+
/>
|
|
128
|
+
))
|
|
129
|
+
) : (
|
|
130
|
+
<NoRecords message="Account.Wishlists.noWishlists" />
|
|
131
|
+
)
|
|
132
|
+
) : (
|
|
133
|
+
<NoRecords message="Account.Wishlists.wishlistAddUnauthenticated" />
|
|
134
|
+
)}
|
|
135
|
+
</Fragment>
|
|
136
|
+
<Grid container spacing={3}>
|
|
137
|
+
<Grid
|
|
138
|
+
item
|
|
139
|
+
sm={12}
|
|
140
|
+
xs={12}
|
|
141
|
+
sx={{
|
|
142
|
+
display: "flex",
|
|
143
|
+
justifyContent: "flex-start",
|
|
144
|
+
gap: 2,
|
|
145
|
+
}}
|
|
146
|
+
>
|
|
147
|
+
<Button
|
|
148
|
+
color="primary"
|
|
149
|
+
variant="outlined"
|
|
150
|
+
size="small"
|
|
151
|
+
onClick={handleClose}
|
|
152
|
+
sx={{ height: 30.75 }}
|
|
153
|
+
>
|
|
154
|
+
{t("btnCancel")}
|
|
155
|
+
</Button>
|
|
156
|
+
</Grid>
|
|
157
|
+
</Grid>
|
|
158
|
+
</DialogContent>
|
|
159
|
+
</Dialog>
|
|
160
|
+
);
|
|
161
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import React, { useEffect } from "react";
|
|
2
|
+
import isFunction from "lodash/isFunction";
|
|
3
|
+
import { useTranslations } from "next-intl";
|
|
4
|
+
import {
|
|
5
|
+
Box,
|
|
6
|
+
Button,
|
|
7
|
+
TextField,
|
|
8
|
+
Dialog,
|
|
9
|
+
DialogContent,
|
|
10
|
+
FormControlLabel,
|
|
11
|
+
Checkbox,
|
|
12
|
+
} from "@mui/material";
|
|
13
|
+
import Grid from "@mui/material/Grid2";
|
|
14
|
+
// Global Custom components
|
|
15
|
+
import { H5 } from "@evenicanpm/storefront-core/src/components/_components/Typography";
|
|
16
|
+
import { useNotification } from "@evenicanpm/storefront-core/src/components/Notifications/use-notification";
|
|
17
|
+
// Forms
|
|
18
|
+
import { useFormik } from "formik";
|
|
19
|
+
import { z } from "zod";
|
|
20
|
+
import { withZodSchema } from "formik-validator-zod";
|
|
21
|
+
// API
|
|
22
|
+
import useCreateWishlist from "@evenicanpm/storefront-core/src/api-manager/services/user/mutations/create-wishlist";
|
|
23
|
+
|
|
24
|
+
interface Props {
|
|
25
|
+
open: boolean;
|
|
26
|
+
handleClose: () => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default function CreateNewList(props: Props) {
|
|
30
|
+
const t = useTranslations("Account.Wishlists");
|
|
31
|
+
const { setNotification } = useNotification();
|
|
32
|
+
|
|
33
|
+
const { mutateAsync: createWishlist } = useCreateWishlist();
|
|
34
|
+
|
|
35
|
+
const FormSchema = z.object({
|
|
36
|
+
Id: z.string(),
|
|
37
|
+
Name: z.string().nonempty(t("Validation.required", { field: t("name") })),
|
|
38
|
+
Comment: z.string().optional(),
|
|
39
|
+
IsPublic: z.boolean().optional(),
|
|
40
|
+
});
|
|
41
|
+
type FormSchemaType = z.infer<typeof FormSchema>;
|
|
42
|
+
|
|
43
|
+
const handleSubmit = async (values: FormSchemaType) => {
|
|
44
|
+
try {
|
|
45
|
+
await createWishlist({ ...values, IsPublic: !values.IsPublic });
|
|
46
|
+
handleClose();
|
|
47
|
+
setNotification({
|
|
48
|
+
message: t("wishlistSuccess"),
|
|
49
|
+
severity: "success",
|
|
50
|
+
});
|
|
51
|
+
} catch (error) {
|
|
52
|
+
setNotification({
|
|
53
|
+
message: t("wishlistFailed"),
|
|
54
|
+
severity: "error",
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const formik = useFormik<FormSchemaType>({
|
|
60
|
+
initialValues: {
|
|
61
|
+
Id: "",
|
|
62
|
+
Name: "",
|
|
63
|
+
Comment: "",
|
|
64
|
+
IsPublic: false,
|
|
65
|
+
},
|
|
66
|
+
onSubmit: handleSubmit,
|
|
67
|
+
validate: withZodSchema(FormSchema),
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// destructure to put in dependency array
|
|
71
|
+
// of use effect instead of whole formik
|
|
72
|
+
const { resetForm } = formik;
|
|
73
|
+
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
if (props.open) {
|
|
76
|
+
resetForm();
|
|
77
|
+
}
|
|
78
|
+
}, [props.open, resetForm]);
|
|
79
|
+
|
|
80
|
+
const handleClose = () => {
|
|
81
|
+
if (isFunction(props.handleClose)) {
|
|
82
|
+
props.handleClose();
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<Dialog
|
|
88
|
+
open={props.open}
|
|
89
|
+
onClose={handleClose}
|
|
90
|
+
aria-labelledby="form-dialog-title"
|
|
91
|
+
>
|
|
92
|
+
<DialogContent>
|
|
93
|
+
<H5 mb={4}>{t("formTitle")}</H5>
|
|
94
|
+
<Box component="form" onSubmit={formik.handleSubmit}>
|
|
95
|
+
<Grid container spacing={3}>
|
|
96
|
+
<Grid size={{ sm: 6, xs: 12 }}>
|
|
97
|
+
<TextField
|
|
98
|
+
name="Name"
|
|
99
|
+
fullWidth
|
|
100
|
+
label={t("name")}
|
|
101
|
+
value={formik.values.Name}
|
|
102
|
+
onChange={formik.handleChange}
|
|
103
|
+
onBlur={formik.handleBlur}
|
|
104
|
+
error={formik.touched.Name && Boolean(formik.errors.Name)}
|
|
105
|
+
helperText={formik.touched.Name && formik.errors.Name}
|
|
106
|
+
required
|
|
107
|
+
/>
|
|
108
|
+
</Grid>
|
|
109
|
+
<Grid size={{ sm: 6, xs: 12 }}>
|
|
110
|
+
<TextField
|
|
111
|
+
name="Comment"
|
|
112
|
+
fullWidth
|
|
113
|
+
label={t("comment")}
|
|
114
|
+
value={formik.values.Comment}
|
|
115
|
+
onChange={formik.handleChange}
|
|
116
|
+
onBlur={formik.handleBlur}
|
|
117
|
+
error={formik.touched.Comment && Boolean(formik.errors.Comment)}
|
|
118
|
+
helperText={formik.touched.Comment && formik.errors.Comment}
|
|
119
|
+
/>
|
|
120
|
+
</Grid>
|
|
121
|
+
<Grid size={{ sm: 6, xs: 12 }}>
|
|
122
|
+
<FormControlLabel
|
|
123
|
+
control={
|
|
124
|
+
<Checkbox
|
|
125
|
+
name="IsPublic"
|
|
126
|
+
checked={formik.values.IsPublic}
|
|
127
|
+
onChange={formik.handleChange}
|
|
128
|
+
onBlur={formik.handleBlur}
|
|
129
|
+
/>
|
|
130
|
+
}
|
|
131
|
+
label={t("private")}
|
|
132
|
+
/>
|
|
133
|
+
</Grid>
|
|
134
|
+
<Grid
|
|
135
|
+
size={{ sm: 6, xs: 12 }}
|
|
136
|
+
sx={{
|
|
137
|
+
display: "flex",
|
|
138
|
+
justifyContent: "flex-end",
|
|
139
|
+
alignItems: "center",
|
|
140
|
+
gap: 2,
|
|
141
|
+
}}
|
|
142
|
+
>
|
|
143
|
+
<Button
|
|
144
|
+
color="primary"
|
|
145
|
+
variant="contained"
|
|
146
|
+
size="small"
|
|
147
|
+
type="submit"
|
|
148
|
+
sx={{ height: 30.75 }}
|
|
149
|
+
>
|
|
150
|
+
{t("btnSave")}
|
|
151
|
+
</Button>
|
|
152
|
+
<Button
|
|
153
|
+
color="primary"
|
|
154
|
+
variant="outlined"
|
|
155
|
+
size="small"
|
|
156
|
+
onClick={handleClose}
|
|
157
|
+
sx={{ height: 30.75 }}
|
|
158
|
+
>
|
|
159
|
+
{t("btnCancel")}
|
|
160
|
+
</Button>
|
|
161
|
+
</Grid>
|
|
162
|
+
</Grid>
|
|
163
|
+
</Box>
|
|
164
|
+
</DialogContent>
|
|
165
|
+
</Dialog>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Button } from "@mui/material";
|
|
5
|
+
import T from "@evenicanpm/storefront-core/src/components/T";
|
|
6
|
+
import CreateNewListDialog from "./create-new-list";
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
path: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const CreateWishlistButton = ({ path }: Props) => {
|
|
13
|
+
const [openCreateListDialog, setOpenCreateListDialog] = useState(false);
|
|
14
|
+
|
|
15
|
+
const handleCloseDialog = () => {
|
|
16
|
+
setOpenCreateListDialog(false);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const handleCreateNewList = () => {
|
|
20
|
+
setOpenCreateListDialog(true);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<>
|
|
25
|
+
<Button
|
|
26
|
+
onClick={handleCreateNewList}
|
|
27
|
+
color="primary"
|
|
28
|
+
sx={{ bgcolor: "primary.light", px: 4 }}
|
|
29
|
+
>
|
|
30
|
+
<T path={path} />
|
|
31
|
+
</Button>
|
|
32
|
+
<CreateNewListDialog
|
|
33
|
+
open={openCreateListDialog}
|
|
34
|
+
handleClose={handleCloseDialog}
|
|
35
|
+
/>
|
|
36
|
+
</>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default CreateWishlistButton;
|