@evenicanpm/storefront-core 1.0.0-alpha → 1.0.0

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.
Files changed (78) hide show
  1. package/package.json +1 -1
  2. package/src/api-manager/api-manager.config.json +1 -1
  3. package/src/api-manager/datasources/d365/d365-address.datasource.ts +4 -4
  4. package/src/api-manager/datasources/d365/d365-cart.datasource.ts +100 -7
  5. package/src/api-manager/datasources/d365/d365-product.datasource.ts +39 -17
  6. package/src/api-manager/datasources/d365/d365-user.datasource.ts +220 -49
  7. package/src/api-manager/datasources/d365/utils/decode-jwt.ts +2 -2
  8. package/src/api-manager/datasources/e4/e4-cart.datasource.ts +6 -0
  9. package/src/api-manager/datasources/e4/e4-product.datasource.ts +5 -0
  10. package/src/api-manager/datasources/e4/e4-user.datasource.ts +39 -15
  11. package/src/api-manager/datasources/e4/e4.datasource.ts +1 -0
  12. package/src/api-manager/datasources/e4/e4.translator.ts +2 -1
  13. package/src/api-manager/datasources/e4/graphqlRequestSdk.ts +5231 -38282
  14. package/src/api-manager/index.ts +58 -11
  15. package/src/api-manager/lib/get-graphql-client.ts +7 -7
  16. package/src/api-manager/schemas/address.schema.ts +1 -19
  17. package/src/api-manager/schemas/cart.schema.ts +18 -0
  18. package/src/api-manager/schemas/product.schema.ts +7 -0
  19. package/src/api-manager/schemas/user.schema.ts +52 -1
  20. package/src/api-manager/services/address/queries/get-states.ts +1 -1
  21. package/src/api-manager/services/cart/mutations/checkout.ts +16 -1
  22. package/src/api-manager/services/cart/queries/get-cart-lines-inventory.ts +15 -0
  23. package/src/api-manager/services/create-extension-query.ts +26 -0
  24. package/src/api-manager/services/create-mutation.ts +5 -1
  25. package/src/api-manager/services/create-query.ts +0 -1
  26. package/src/api-manager/services/organization/queries/get-channel-configuration.ts +1 -1
  27. package/src/api-manager/services/product/queries/get-product-prices.ts +16 -0
  28. package/src/api-manager/services/product/queries/search-products.ts +1 -0
  29. package/src/api-manager/services/user/mutations/add-to-wishlist.ts +24 -0
  30. package/src/api-manager/services/user/mutations/copy-cart-to-wishlist.ts +23 -0
  31. package/src/api-manager/services/user/mutations/create-wishlist.ts +4 -4
  32. package/src/api-manager/services/user/mutations/delete-wishlist.ts +4 -3
  33. package/src/api-manager/services/user/mutations/remove-from-wishlist.ts +21 -0
  34. package/src/api-manager/services/user/mutations/update-wishlist.ts +23 -0
  35. package/src/api-manager/services/user/queries/get-wishlist-details.ts +11 -4
  36. package/src/api-manager/services/user/queries/get-wishlists.ts +4 -3
  37. package/src/api-manager/types/Datasource.ts +33 -5
  38. package/src/auth/auth-options.ts +2 -2
  39. package/src/auth/msal.ts +9 -9
  40. package/src/auth/next-auth-cookie-manager.ts +5 -3
  41. package/src/auth/providers/aadb2c-provider.ts +3 -4
  42. package/src/cms/endpoints.ts +2 -3
  43. package/src/components/_components/LazyImage.tsx +5 -2
  44. package/src/components/_components/header/components/user.tsx +1 -2
  45. package/src/components/_components/product-cards/product-card-1/components/quantity-buttons.tsx +17 -8
  46. package/src/components/_components/product-cards/product-card-1/product-card-1-wrapper.tsx +304 -0
  47. package/src/components/_components/product-cards/product-card-1/product-card.tsx +16 -55
  48. package/src/components/_components/product-cards/product-card-8/product-card.tsx +80 -60
  49. package/src/components/_components/product-cards/product-card-8/styles/index.ts +10 -0
  50. package/src/components/_components/product-cards/product-card-wishlist/components/hover-actions.tsx +37 -0
  51. package/src/components/_components/product-cards/product-card-wishlist/index.ts +1 -0
  52. package/src/components/_components/product-cards/product-card-wishlist/product-card.tsx +118 -0
  53. package/src/components/_components/product-cards/product-card-wishlist/styles/index.ts +51 -0
  54. package/src/components/_components/products-view/product-view-dialog.tsx +48 -10
  55. package/src/components/_components/products-view/products-grid-view.tsx +31 -17
  56. package/src/components/_components/products-view/products-list-view.tsx +30 -16
  57. package/src/components/_components/search-box/__test__/search-input-category.test.tsx +110 -0
  58. package/src/components/_components/search-box/__test__/search-input.test.tsx +137 -0
  59. package/src/components/_components/search-box/__test__/search-results.json +165 -0
  60. package/src/components/_components/search-box/components/search-result.tsx +66 -12
  61. package/src/components/_components/search-box/search-input-category.tsx +135 -32
  62. package/src/components/_components/search-box/styles/index.ts +2 -0
  63. package/src/components/_components/section-header/section-creator.tsx +1 -0
  64. package/src/components/_components/wishlist/add-to-wishlist-dialog.tsx +161 -0
  65. package/src/components/_components/wishlist/components/create-new-list.tsx +167 -0
  66. package/src/components/_components/wishlist/components/create-wishlist-button.tsx +40 -0
  67. package/src/components/_components/wishlist/components/dashboard-header.tsx +123 -0
  68. package/src/components/_components/wishlist/components/navigation.tsx +87 -0
  69. package/src/components/_components/wishlist/components/no-records.tsx +20 -0
  70. package/src/components/_components/wishlist/components/wishlist-modal-item.tsx +66 -0
  71. package/src/components/_components/wishlist/remove-from-wishlist-dialog.tsx +174 -0
  72. package/src/components/_components/wishlist/styles.ts +61 -0
  73. package/src/components/countries-input.tsx +6 -12
  74. package/src/lib/cart-cookie-handler-constants.ts +8 -0
  75. package/src/lib/cart-cookie-handler.ts +27 -5
  76. package/src/lib/create-graphql-client.ts +1 -2
  77. package/src/lib/product-list-types.ts +41 -0
  78. package/src/config.ts +0 -47
@@ -6,14 +6,10 @@ import Rating from "@mui/material/Rating";
6
6
  // GLOBAL CUSTOM COMPONENTS
7
7
  import LazyImage from "@/components/_components/LazyImage";
8
8
  import { Span } from "@/components/_components/Typography";
9
- import ProductViewDialog from "@/components/_components/products-view/product-view-dialog";
10
9
  // LOCAL CUSTOM HOOK
11
- import useProduct from "../use-product";
12
10
  // LOCAL CUSTOM COMPONENTS
13
- import HoverActions from "./components/hover-actions";
14
11
  import ProductPrice from "../product-price";
15
12
  import ProductTitle from "../product-title";
16
- import DiscountChip from "../discount-chip";
17
13
  import QuantityButtons from "./components/quantity-buttons";
18
14
  // STYLED COMPONENTS
19
15
  import { ImageWrapper, ContentWrapper, StyledBazaarCard } from "./styles/index";
@@ -31,6 +27,11 @@ type Props = {
31
27
  hideRating?: boolean;
32
28
  hoverEffect?: boolean;
33
29
  showProductSize?: boolean;
30
+ wishlistControls?: React.ReactNode;
31
+ quantity: number;
32
+ isLineUpdating: boolean;
33
+ handleIncrementQuantity: () => void;
34
+ handleDecrementQuantity: () => void;
34
35
  };
35
36
  // ========================================================
36
37
 
@@ -45,54 +46,17 @@ export default function ProductCard1({
45
46
  hoverEffect,
46
47
  discount = 5,
47
48
  showProductSize,
49
+ wishlistControls,
50
+ quantity,
51
+ isLineUpdating,
52
+ handleIncrementQuantity,
53
+ handleDecrementQuantity,
48
54
  }: Props) {
49
- const {
50
- isFavorite,
51
- openModal,
52
- cartItem,
53
- toggleDialog,
54
- toggleFavorite,
55
- handleCartAmountChange,
56
- } = useProduct(slug);
57
-
58
- const handleIncrementQuantity = () => {
59
- const product = {
60
- id,
61
- slug,
62
- price,
63
- imgUrl,
64
- name: title,
65
- qty: (cartItem?.Quantity || 0) + 1,
66
- };
67
- product;
68
- handleCartAmountChange();
69
- };
70
-
71
- const handleDecrementQuantity = () => {
72
- const product = {
73
- id,
74
- slug,
75
- price,
76
- imgUrl,
77
- name: title,
78
- qty: (cartItem?.Quantity || 0) - 1,
79
- };
80
- product;
81
- handleCartAmountChange("remove");
82
- };
83
-
84
55
  return (
85
56
  <StyledBazaarCard hoverEffect={hoverEffect}>
86
57
  <ImageWrapper>
87
58
  {/* DISCOUNT PERCENT CHIP IF AVAILABLE */}
88
- <DiscountChip discount={discount} />
89
-
90
- {/* HOVER ACTION ICONS */}
91
- <HoverActions
92
- isFavorite={isFavorite}
93
- toggleView={toggleDialog}
94
- toggleFavorite={toggleFavorite}
95
- />
59
+ {/* <DiscountChip discount={discount} /> */}
96
60
 
97
61
  {/* PRODUCT IMAGE / THUMBNAIL */}
98
62
  <Link href={buildDetailUrl(title, Number(id))}>
@@ -106,13 +70,6 @@ export default function ProductCard1({
106
70
  </Link>
107
71
  </ImageWrapper>
108
72
 
109
- {/* PRODUCT VIEW DIALOG BOX */}
110
- <ProductViewDialog
111
- openDialog={openModal}
112
- handleCloseDialog={toggleDialog}
113
- product={{ title, price, id, slug, imgGroup: [imgUrl, imgUrl] }}
114
- />
115
-
116
73
  <ContentWrapper>
117
74
  <Box flex="1 1 0" minWidth="0px" mr={1}>
118
75
  {/* PRODUCT NAME / TITLE */}
@@ -136,10 +93,14 @@ export default function ProductCard1({
136
93
 
137
94
  {/* PRODUCT QUANTITY HANDLER BUTTONS */}
138
95
  <QuantityButtons
139
- quantity={cartItem?.Quantity || 0}
96
+ quantity={quantity}
140
97
  handleIncrement={handleIncrementQuantity}
141
98
  handleDecrement={handleDecrementQuantity}
99
+ isLineUpdating={isLineUpdating}
142
100
  />
101
+
102
+ {/* WISHLIST CONTROLS: hover actions, delete button */}
103
+ {wishlistControls}
143
104
  </ContentWrapper>
144
105
  </StyledBazaarCard>
145
106
  );
@@ -13,7 +13,9 @@ import useProduct from "../use-product";
13
13
  import LazyImage from "@/components/_components/LazyImage";
14
14
  import { FlexRowCenter } from "@/components/_components/flex-box/index";
15
15
  import { H4, Paragraph, Small } from "@/components/_components/Typography";
16
- import ProductViewDialog from "@/components/_components/products-view/product-view-dialog";
16
+ import ProductViewDialog, {
17
+ ProductInfo,
18
+ } from "@/components/_components/products-view/product-view-dialog";
17
19
  // CUSTOM UTILS LIBRARY FUNCTION
18
20
  import { currency } from "@/lib/lib";
19
21
  // CUSTOM COMPONENTS
@@ -23,45 +25,56 @@ import {
23
25
  CardMedia,
24
26
  FavoriteButton,
25
27
  QuickViewButton,
28
+ QuickViewSmallButton,
26
29
  } from "./styles/index";
27
30
  // CUSTOM DATA MODEL
28
31
  import { Product } from "@/components/_components/bazaar-types";
32
+ import { DialogType } from "@/_components/search-box/search-input-category";
33
+ import { RemoveRedEye } from "@mui/icons-material";
34
+ import buildDetailUrl from "@/lib/build-detail-url";
29
35
 
30
36
  // ==============================================================
31
- type Props = { product: Product };
37
+ type Props = {
38
+ slug: string;
39
+ id: string | number;
40
+ title: string;
41
+ price: number;
42
+ thumbnail: string;
43
+ categories: string[];
44
+ reviews: number;
45
+ rating: number;
46
+ enableWishlistDialog?: boolean;
47
+ enableQuickViewDialog?: boolean;
48
+ openDialog: (
49
+ type: DialogType,
50
+ productId: number,
51
+ productInfo?: ProductInfo,
52
+ ) => void;
53
+ };
32
54
  // ==============================================================
33
-
34
- export default function ProductCard8({ product }: Props) {
35
- const { slug, id, title, price, thumbnail, images, categories, reviews } =
36
- product || {};
55
+ export default function ProductCard8(props: Props) {
56
+ const {
57
+ slug,
58
+ id,
59
+ title,
60
+ price,
61
+ thumbnail,
62
+ categories,
63
+ reviews,
64
+ rating,
65
+ openDialog,
66
+ enableWishlistDialog = true,
67
+ enableQuickViewDialog = true,
68
+ } = props;
37
69
 
38
70
  const {
39
- cartItem,
40
- handleCartAmountChange,
41
- isFavorite,
42
- openModal,
43
- toggleDialog,
44
- toggleFavorite,
71
+ isFavorite, // TODO: always false; need to check if product exists in any of the wishlists?
45
72
  } = useProduct(slug);
46
73
 
47
- // HANDLE ADD TO CART PRODUCT
48
- const handleAddToCart = () => {
49
- const payload = {
50
- id,
51
- slug,
52
- price,
53
- name: title,
54
- imgUrl: thumbnail,
55
- qty: (cartItem?.Quantity || 0) + 1,
56
- };
57
- payload;
58
- handleCartAmountChange();
59
- };
60
-
61
74
  return (
62
75
  <Card>
63
76
  <CardMedia>
64
- <Link href={`/products/${slug}`}>
77
+ <Link href={buildDetailUrl(title, Number(id))}>
65
78
  <LazyImage
66
79
  width={300}
67
80
  height={300}
@@ -70,42 +83,44 @@ export default function ProductCard8({ product }: Props) {
70
83
  src={thumbnail}
71
84
  />
72
85
  </Link>
73
-
74
- {/* ADD TO CART BUTTON */}
75
- <AddToCartButton className="product-actions" onClick={handleAddToCart}>
76
- <AddShoppingCart className="icon" fontSize="small" />
77
- </AddToCartButton>
86
+ {/* */}
87
+ {/* QUICK VIEW BUTTON */}
88
+ {enableQuickViewDialog && (
89
+ <QuickViewSmallButton
90
+ className="product-actions"
91
+ onClick={() =>
92
+ openDialog(DialogType.QuickView, Number(id), {
93
+ id: Number(id),
94
+ title,
95
+ imgGroup: [thumbnail],
96
+ price,
97
+ slug,
98
+ })
99
+ }
100
+ >
101
+ <RemoveRedEye className="icon" fontSize="small" />
102
+ </QuickViewSmallButton>
103
+ )}
78
104
 
79
105
  {/* PRODUCT FAVORITE BUTTON */}
80
- <FavoriteButton className="product-actions" onClick={toggleFavorite}>
81
- {isFavorite ? (
82
- <Favorite className="icon" fontSize="small" color="primary" />
83
- ) : (
84
- <FavoriteBorder className="icon" fontSize="small" />
85
- )}
86
- </FavoriteButton>
87
-
88
- {/* PRODUCT QUICK VIEW BUTTON */}
89
- <Box mx={1} position="relative">
90
- <QuickViewButton
91
- fullWidth
92
- size="large"
93
- variant="contained"
94
- className="product-view-action"
95
- onClick={toggleDialog}
106
+ {enableWishlistDialog && (
107
+ <FavoriteButton
108
+ className="product-actions"
109
+ onClick={() =>
110
+ isFavorite
111
+ ? openDialog(DialogType.RemoveFromWishlist, Number(id))
112
+ : openDialog(DialogType.AddToWishlist, Number(id))
113
+ }
96
114
  >
97
- Quick View
98
- </QuickViewButton>
99
- </Box>
115
+ {isFavorite ? (
116
+ <Favorite className="icon" fontSize="small" color="primary" />
117
+ ) : (
118
+ <FavoriteBorder className="icon" fontSize="small" />
119
+ )}
120
+ </FavoriteButton>
121
+ )}
100
122
  </CardMedia>
101
123
 
102
- {/* PRODUCT VIEW DIALOG BOX */}
103
- <ProductViewDialog
104
- openDialog={openModal}
105
- handleCloseDialog={toggleDialog}
106
- product={{ id, slug, title, price, imgGroup: images ?? [] }}
107
- />
108
-
109
124
  <Box p={1} textAlign="center">
110
125
  {/* PRODUCT CATEGORY */}
111
126
  {categories.length > 0 ? (
@@ -122,9 +137,14 @@ export default function ProductCard8({ product }: Props) {
122
137
 
123
138
  {/* PRODUCT RATING / REVIEW */}
124
139
  <FlexRowCenter gap={1}>
125
- <Rating name="read-only" value={4} readOnly sx={{ fontSize: 16 }} />
140
+ <Rating
141
+ name="read-only"
142
+ value={rating}
143
+ readOnly
144
+ sx={{ fontSize: 16 }}
145
+ />
126
146
  <Small fontWeight={600} color="grey.500">
127
- ({reviews?.length} Reviews)
147
+ ({reviews} Reviews)
128
148
  </Small>
129
149
  </FlexRowCenter>
130
150
  </Box>
@@ -49,3 +49,13 @@ export const QuickViewButton = styled(Button)({
49
49
  position: "absolute",
50
50
  transition: "all 0.3s",
51
51
  });
52
+
53
+ export const QuickViewSmallButton = styled(IconButton)(({ theme }) => ({
54
+ top: 15,
55
+ right: -40,
56
+ position: "absolute",
57
+ backgroundColor: "white",
58
+ transition: "right 0.3s .1s",
59
+ color: theme.palette.text.primary,
60
+ ".icon": { fontSize: 16 },
61
+ }));
@@ -0,0 +1,37 @@
1
+ import IconButton from "@mui/material/IconButton";
2
+ // MUI ICON COMPONENTS
3
+ import Favorite from "@mui/icons-material/Favorite";
4
+ import RemoveRedEye from "@mui/icons-material/RemoveRedEye";
5
+ import FavoriteBorder from "@mui/icons-material/FavoriteBorder";
6
+ // STYLED COMPONENTS
7
+ import { HoverIconWrapper } from "../styles";
8
+
9
+ // ==============================================================
10
+ interface Props {
11
+ isFavorite: boolean;
12
+ toggleView: () => void;
13
+ toggleFavorite: () => void;
14
+ }
15
+ // ==============================================================
16
+
17
+ export default function HoverActions({
18
+ isFavorite,
19
+ toggleFavorite,
20
+ toggleView,
21
+ }: Props) {
22
+ return (
23
+ <HoverIconWrapper className="hover-box">
24
+ <IconButton onClick={toggleView}>
25
+ <RemoveRedEye color="disabled" fontSize="small" />
26
+ </IconButton>
27
+
28
+ <IconButton onClick={toggleFavorite}>
29
+ {isFavorite ? (
30
+ <Favorite color="primary" fontSize="small" />
31
+ ) : (
32
+ <FavoriteBorder fontSize="small" color="disabled" />
33
+ )}
34
+ </IconButton>
35
+ </HoverIconWrapper>
36
+ );
37
+ }
@@ -0,0 +1 @@
1
+ export { default } from "./product-card";
@@ -0,0 +1,118 @@
1
+ "use client";
2
+
3
+ import Link from "next/link";
4
+ import Box from "@mui/material/Box";
5
+ import Rating from "@mui/material/Rating";
6
+ // GLOBAL CUSTOM COMPONENTS
7
+ import ProductViewDialog from "@/_components/products-view/product-view-dialog";
8
+ import { Span } from "@/_components/Typography";
9
+ // LOCAL CUSTOM HOOK
10
+ import useProduct from "../use-product";
11
+ // LOCAL CUSTOM COMPONENTS
12
+ import HoverActions from "./components/hover-actions";
13
+ import ProductPrice from "../product-price";
14
+ import ProductTitle from "../product-title";
15
+ import DiscountChip from "../discount-chip";
16
+ // STYLED COMPONENTS
17
+ import { ImageWrapper, ContentWrapper, StyledBazaarCard } from "./styles";
18
+ import { IconButton } from "@mui/material";
19
+ import { Delete } from "@mui/icons-material";
20
+ import LazyImage from "@/_components/LazyImage";
21
+
22
+ // ========================================================
23
+ type Props = {
24
+ title: string;
25
+ slug: string;
26
+ price: number;
27
+ imgUrl: string;
28
+ rating?: number;
29
+ discount?: number;
30
+ id: string | number;
31
+ hideRating?: boolean;
32
+ hoverEffect?: boolean;
33
+ showProductSize?: boolean;
34
+ lineId: string | undefined;
35
+ handleRemoveProductFromWishlist: (linedId: string | undefined) => void;
36
+ };
37
+ // ========================================================
38
+
39
+ export default function ProductCardWishlist({
40
+ id,
41
+ slug,
42
+ title,
43
+ price,
44
+ imgUrl,
45
+ rating = 5,
46
+ hideRating,
47
+ hoverEffect,
48
+ discount = 5,
49
+ showProductSize,
50
+ lineId,
51
+ handleRemoveProductFromWishlist,
52
+ }: Props) {
53
+ const { isFavorite, openModal, toggleDialog, toggleFavorite } =
54
+ useProduct(slug);
55
+
56
+ return (
57
+ <StyledBazaarCard hoverEffect={hoverEffect}>
58
+ <ImageWrapper>
59
+ {/* DISCOUNT PERCENT CHIP IF AVAILABLE */}
60
+ <DiscountChip discount={discount} />
61
+
62
+ {/* HOVER ACTION ICONS */}
63
+ <HoverActions
64
+ isFavorite={isFavorite}
65
+ toggleView={toggleDialog}
66
+ toggleFavorite={toggleFavorite}
67
+ />
68
+
69
+ {/* PRODUCT IMAGE / THUMBNAIL */}
70
+ <Link href={`/products/${slug}`}>
71
+ <LazyImage
72
+ priority
73
+ src={imgUrl}
74
+ width={500}
75
+ height={500}
76
+ alt={title}
77
+ />
78
+ </Link>
79
+ </ImageWrapper>
80
+
81
+ {/* PRODUCT VIEW DIALOG BOX */}
82
+ <ProductViewDialog
83
+ openDialog={openModal}
84
+ handleCloseDialog={toggleDialog}
85
+ product={{ title, price, id, slug, imgGroup: [imgUrl, imgUrl] }}
86
+ />
87
+
88
+ <ContentWrapper>
89
+ <Box flex="1 1 0" minWidth="0px" mr={1}>
90
+ {/* PRODUCT NAME / TITLE */}
91
+ <ProductTitle title={title} slug={slug} />
92
+
93
+ {/* PRODUCT RATINGS IF AVAILABLE */}
94
+ {!hideRating ? (
95
+ <Rating size="small" value={rating} color="warn" readOnly />
96
+ ) : null}
97
+
98
+ {/* PRODUCT SIZE IF AVAILABLE */}
99
+ {showProductSize ? (
100
+ <Span color="grey.600" mb={1} display="block">
101
+ Liter
102
+ </Span>
103
+ ) : null}
104
+
105
+ {/* PRODUCT PRICE WITH DISCOUNT */}
106
+ <ProductPrice discount={discount} price={price} />
107
+ </Box>
108
+
109
+ {/* PRODUCT QUANTITY HANDLER BUTTONS */}
110
+ <Box display="flex" alignItems="center" gap={1} justifySelf="end">
111
+ <IconButton onClick={() => handleRemoveProductFromWishlist(lineId)}>
112
+ <Delete fontSize="small" color="inherit" />
113
+ </IconButton>
114
+ </Box>
115
+ </ContentWrapper>
116
+ </StyledBazaarCard>
117
+ );
118
+ }
@@ -0,0 +1,51 @@
1
+ import BazaarCard, { Props } from "@/_components/BazaarCard";
2
+ import styled from "@mui/material/styles/styled";
3
+ // GLOBAL CUSTOM COMPONENT
4
+ import React, { ComponentType } from "react";
5
+
6
+ export const StyledBazaarCard: ComponentType<Props> = styled(BazaarCard)({
7
+ height: "100%",
8
+ margin: "auto",
9
+ display: "flex",
10
+ overflow: "hidden",
11
+ borderRadius: "8px",
12
+ position: "relative",
13
+ flexDirection: "column",
14
+ justifyContent: "space-between",
15
+ transition: "all 250ms ease-in-out",
16
+ ":hover": { "& .hover-box": { opacity: 1 } },
17
+ });
18
+
19
+ export const ImageWrapper: ComponentType<React.ComponentProps<"div">> = styled(
20
+ "div",
21
+ )(({ theme }) => ({
22
+ textAlign: "center",
23
+ position: "relative",
24
+ display: "inline-block",
25
+ [theme.breakpoints.down("sm")]: { display: "block" },
26
+ }));
27
+
28
+ export const HoverIconWrapper: ComponentType<React.ComponentProps<"div">> =
29
+ styled("div")({
30
+ zIndex: 2,
31
+ top: "7px",
32
+ opacity: 0,
33
+ right: "15px",
34
+ display: "flex",
35
+ cursor: "pointer",
36
+ position: "absolute",
37
+ flexDirection: "column",
38
+ transition: "all 0.3s ease-in-out",
39
+ });
40
+
41
+ export const ContentWrapper: ComponentType<React.ComponentProps<"div">> =
42
+ styled("div")({
43
+ gap: 8,
44
+ display: "flex",
45
+ padding: "1rem",
46
+ "& .title, & .categories": {
47
+ overflow: "hidden",
48
+ whiteSpace: "nowrap",
49
+ textOverflow: "ellipsis",
50
+ },
51
+ });
@@ -9,20 +9,24 @@ import DialogContent from "@mui/material/DialogContent";
9
9
  import Add from "@mui/icons-material/Add";
10
10
  import Close from "@mui/icons-material/Close";
11
11
  import Remove from "@mui/icons-material/Remove";
12
- // GLOBAL CUSTOM COMPONENTS
13
- import { Carousel } from "@/components/_components/carousel/index";
14
- import BazaarImage from "@/components/_components/BazaarImage";
15
- import FlexBox from "@/components/_components/flex-box/flex-box";
16
- import { H1, H2, H3, H6, Paragraph } from "@/components/_components/Typography";
12
+ // GLOBAL CUSTOM COMPONENT
17
13
  // LOCAL CUSTOM HOOKS
18
- //import useCart from "hooks/useCart";
14
+ import useAddToCart from "@/api-manager/services/cart/mutations/add-to-cart";
15
+ import { useTranslations } from "next-intl";
16
+ import getCart from "@/api-manager/services/cart/queries/get-cart";
19
17
  // CUSTOM UTILS LIBRARY FUNCTION
18
+ import { Carousel } from "../carousel";
19
+ import { useNotification } from "@/components/Notifications/use-notification";
20
+ import BazaarImage from "../BazaarImage";
21
+ import { FlexBox } from "../flex-box";
22
+ import { H2, Paragraph, H1, H6, H3 } from "../Typography";
20
23
  import { currency } from "@/lib/lib";
21
24
 
22
25
  // =====================================================
23
26
  interface Props {
24
27
  product: ProductInfo;
25
28
  openDialog: boolean;
29
+ cartId?: string;
26
30
  handleCloseDialog: () => void;
27
31
  }
28
32
  // =====================================================
@@ -31,7 +35,7 @@ type CartItem = {
31
35
  qty: number;
32
36
  };
33
37
  // =====================================================
34
- type ProductInfo = {
38
+ export type ProductInfo = {
35
39
  id: string | number;
36
40
  title: string;
37
41
  imgGroup: string[];
@@ -50,7 +54,12 @@ type CartDispatch = {
50
54
  // =====================================================
51
55
 
52
56
  export default function ProductViewDialog(props: Props) {
53
- const { product, openDialog, handleCloseDialog } = props;
57
+ const { product, openDialog, cartId, handleCloseDialog } = props;
58
+ const { mutateAsync: addToCart } = useAddToCart();
59
+ const { data: cart } = getCart.useData();
60
+
61
+ const t = useTranslations("ProductViewDialog");
62
+ const { setNotification } = useNotification();
54
63
 
55
64
  //const { state, dispatch } = useCart();
56
65
  const state: { cart: CartItem[] } = {
@@ -73,6 +82,31 @@ export default function ProductViewDialog(props: Props) {
73
82
  });
74
83
  };
75
84
 
85
+ const handleAddToCart = async () => {
86
+ if (!cart) return;
87
+ try {
88
+ await addToCart({
89
+ cartId: cartId,
90
+ version: cart.Version,
91
+ cartLine: [
92
+ {
93
+ ProductId: Number(product.id),
94
+ Quantity: 1,
95
+ },
96
+ ],
97
+ });
98
+ setNotification({
99
+ message: t("addToCartSuccess"),
100
+ severity: "success",
101
+ });
102
+ } catch (error) {
103
+ setNotification({
104
+ message: t("addToCartError"),
105
+ severity: "error",
106
+ });
107
+ }
108
+ };
109
+
76
110
  return (
77
111
  <Dialog
78
112
  open={openDialog}
@@ -133,16 +167,19 @@ export default function ProductViewDialog(props: Props) {
133
167
  {!cartItem?.qty ? (
134
168
  <Button
135
169
  size="large"
170
+ color={"primary"}
136
171
  variant="contained"
137
- onClick={handleCartAmountChange(1)}
172
+ // onClick={handleCartAmountChange(1)}
173
+ onClick={handleAddToCart}
138
174
  sx={{ height: 45, borderRadius: 2 }}
139
175
  >
140
- Add to Cart
176
+ {t("addToCartBtn")}
141
177
  </Button>
142
178
  ) : (
143
179
  <FlexBox alignItems="center">
144
180
  <Button
145
181
  size="small"
182
+ color={"primary"}
146
183
  variant="outlined"
147
184
  sx={{ p: ".6rem", height: 45 }}
148
185
  onClick={handleCartAmountChange(cartItem?.qty - 1)}
@@ -156,6 +193,7 @@ export default function ProductViewDialog(props: Props) {
156
193
 
157
194
  <Button
158
195
  size="small"
196
+ color={"primary"}
159
197
  variant="outlined"
160
198
  sx={{ p: ".6rem", height: 45 }}
161
199
  onClick={handleCartAmountChange(cartItem?.qty + 1)}