@evenicanpm/storefront-core 2.1.0 → 2.3.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.
- package/package.json +9 -4
- package/src/api-manager/README.md +52 -27
- package/src/api-manager/datasources/d365/d365-cart.datasource.ts +166 -17
- package/src/api-manager/datasources/d365/d365-invoice.datasource.ts +100 -0
- package/src/api-manager/datasources/d365/d365-order.datasource.ts +75 -18
- package/src/api-manager/datasources/d365/d365-product.datasource.ts +19 -1
- package/src/api-manager/datasources/d365/d365-user.datasource.ts +96 -22
- package/src/api-manager/datasources/d365/d365.datasource.ts +3 -0
- package/src/api-manager/datasources/d365/utils/get-context-cookie.ts +14 -5
- package/src/api-manager/datasources/e4/e4.datasource.ts +9 -0
- package/src/api-manager/datasources/e4/middleware.ts +35 -0
- package/src/api-manager/datasources/e4/order/e4-order.datasource.ts +7 -4
- package/src/api-manager/datasources/e4/user/e4-user.datasource.ts +4 -0
- package/src/api-manager/index.ts +54 -3
- package/src/api-manager/lib/get-graphql-client.ts +13 -6
- package/src/api-manager/schemas/cart.schema.ts +10 -1
- package/src/api-manager/schemas/invoice.schema.ts +55 -0
- package/src/api-manager/schemas/order.schema.ts +13 -1
- package/src/api-manager/schemas/user.schema.ts +8 -0
- package/src/api-manager/services/create-query.ts +5 -56
- package/src/api-manager/services/invoice/queries/get-invoice-details.ts +18 -0
- package/src/api-manager/services/invoice/queries/get-invoices.ts +18 -0
- package/src/api-manager/services/order/queries/get-order-details.ts +1 -1
- package/src/api-manager/services/order/queries/get-orders.ts +6 -3
- package/src/api-manager/services/user/queries/get-customer-balance.ts +20 -0
- package/src/api-manager/types/Datasource.ts +21 -2
- package/src/auth/better-auth.ts +89 -0
- package/src/auth/signout.ts +5 -34
- package/src/cms/blocks/block-manager.tsx +18 -3
- package/src/cms/blocks/components/cta-banner.tsx +65 -0
- package/src/cms/blocks/components/hero-image.tsx +83 -0
- package/src/cms/blocks/index.tsx +2 -0
- package/src/cms/blocks/interfaces.ts +20 -0
- package/src/cms/draft-mode-badge.tsx +26 -0
- package/src/cms/queries.ts +81 -0
- package/src/components/flex-box/flex-box.tsx +2 -0
- package/src/components/header/__tests__/header.test.tsx +9 -2
- package/src/components/header/__tests__/user.test.tsx +34 -19
- package/src/components/header/components/user.tsx +70 -29
- package/src/components/mini-cart/mini-cart.tsx +3 -3
- package/src/components/wishlist-dialogs/add-to-wishlist/compound/add-to-wishlist-dialog.tsx +3 -1
- package/src/components/wishlist-dialogs/add-to-wishlist/compound/wishlist-dialog-header.tsx +4 -1
- package/src/hooks/use-nextauth-session.ts +10 -14
- package/src/pages/account/account-navigation.tsx +88 -60
- package/src/pages/account/account-routes.ts +52 -0
- package/src/pages/account/orders/order-history-filter-types.tsx +26 -0
- package/src/pages/account/orders/order-history-filters-panel.tsx +375 -0
- package/src/pages/account/orders/order-history-header.tsx +54 -0
- package/src/pages/account/orders/order-history-pagination.tsx +55 -0
- package/src/pages/account/orders/order-history-root.tsx +125 -0
- package/src/pages/account/orders/order-history-row.tsx +110 -0
- package/src/pages/account/orders/order-history-search-and-filter.tsx +449 -0
- package/src/pages/account/orders/order-history-search-bar.tsx +84 -0
- package/src/pages/account/orders/order-history-search-dropdown.tsx +53 -0
- package/src/pages/account/orders/order-history-sort.tsx +90 -0
- package/src/pages/account/orders/order-history-table.tsx +54 -0
- package/src/pages/account/orders/order-row.tsx +2 -2
- package/src/pages/account/orders/orders-drop-down-handler.tsx +19 -0
- package/src/pages/account/table-header.tsx +20 -0
- package/src/pages/account/wishlist/wishlist-item.tsx +1 -1
- package/src/pages/blog/blog-card.tsx +9 -3
- package/src/pages/blog/blog-detail-view.tsx +150 -0
- package/src/pages/blog/blog-list-view.tsx +59 -0
- package/src/pages/cart/__tests__/checkout-form.test.tsx +4 -2
- package/src/pages/cart/estimate-shipping.tsx +6 -5
- package/src/pages/checkout/checkout-alt-form/checkout-form.tsx +43 -21
- package/src/pages/checkout/checkout-alt-form/steps/payment/payment-details.tsx +144 -19
- package/src/pages/cms-page-view.tsx +53 -0
- package/src/pages/quickorder/order-upload.tsx +12 -6
- package/src/pages/quickorder/quick-order.tsx +25 -20
- package/src/api-manager/datasources/d365/utils/decode-jwt.ts +0 -10
- package/src/auth/auth-options.test.ts +0 -70
- package/src/auth/auth-options.ts +0 -101
- package/src/auth/next-auth-cookie-manager.ts +0 -87
- package/src/auth/providers/aadb2c-provider.ts +0 -32
- package/src/auth/providers/authentik-provider.ts +0 -24
- package/src/auth/providers/entra-external-id-provider.ts +0 -50
- package/src/auth/providers/index.ts +0 -16
- package/src/auth/providers/keycloak-provider.ts +0 -22
- package/src/auth/refresh-token.ts +0 -132
- package/src/auth/types/next-auth.d.ts +0 -38
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export enum FilterSourceType {
|
|
2
|
+
Origin = "Origin",
|
|
3
|
+
CreatedDate = "CreatedDate",
|
|
4
|
+
OrderStatus = "OrderStatus",
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface OriginFilter {
|
|
8
|
+
sourceType: FilterSourceType.Origin;
|
|
9
|
+
label: string;
|
|
10
|
+
value: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface CreatedDateFilter {
|
|
14
|
+
sourceType: FilterSourceType.CreatedDate;
|
|
15
|
+
label: string;
|
|
16
|
+
startValue?: string;
|
|
17
|
+
endValue?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface OrderStatusFilter {
|
|
21
|
+
sourceType: FilterSourceType.OrderStatus;
|
|
22
|
+
label: string;
|
|
23
|
+
value: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type FilterOption = OriginFilter | CreatedDateFilter | OrderStatusFilter;
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import { SalesStatus } from "@msdyn365-commerce/retail-proxy";
|
|
2
|
+
import { KeyboardArrowRight } from "@mui/icons-material";
|
|
3
|
+
import {
|
|
4
|
+
Box,
|
|
5
|
+
Button,
|
|
6
|
+
Checkbox,
|
|
7
|
+
Divider,
|
|
8
|
+
FormControlLabel,
|
|
9
|
+
FormGroup,
|
|
10
|
+
Radio,
|
|
11
|
+
RadioGroup,
|
|
12
|
+
TextField,
|
|
13
|
+
Typography,
|
|
14
|
+
} from "@mui/material";
|
|
15
|
+
import { useTranslations } from "next-intl";
|
|
16
|
+
import { useState } from "react";
|
|
17
|
+
import { HiX } from "react-icons/hi";
|
|
18
|
+
import {
|
|
19
|
+
type CreatedDateFilter,
|
|
20
|
+
type FilterOption,
|
|
21
|
+
FilterSourceType,
|
|
22
|
+
type OrderStatusFilter,
|
|
23
|
+
} from "./order-history-filter-types";
|
|
24
|
+
import { useOrdersSearchAndFilter } from "./order-history-search-and-filter";
|
|
25
|
+
|
|
26
|
+
const createdDateOptions: CreatedDateFilter[] = [
|
|
27
|
+
{
|
|
28
|
+
sourceType: FilterSourceType.CreatedDate,
|
|
29
|
+
label: "Last 7 days",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
sourceType: FilterSourceType.CreatedDate,
|
|
33
|
+
label: "Last 30 days",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
sourceType: FilterSourceType.CreatedDate,
|
|
37
|
+
label: "Last 3 months",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
sourceType: FilterSourceType.CreatedDate,
|
|
41
|
+
label: "Last 6 months",
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
sourceType: FilterSourceType.CreatedDate,
|
|
45
|
+
label: "Custom Dates",
|
|
46
|
+
startValue: "",
|
|
47
|
+
endValue: "",
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
const orderStatusOptions: OrderStatusFilter[] = [
|
|
52
|
+
{
|
|
53
|
+
sourceType: FilterSourceType.OrderStatus,
|
|
54
|
+
label: "Created",
|
|
55
|
+
value: SalesStatus.Created,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
sourceType: FilterSourceType.OrderStatus,
|
|
59
|
+
label: "Processing",
|
|
60
|
+
value: SalesStatus.Processing,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
sourceType: FilterSourceType.OrderStatus,
|
|
64
|
+
label: "Delivered",
|
|
65
|
+
value: SalesStatus.Delivered,
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
sourceType: FilterSourceType.OrderStatus,
|
|
69
|
+
label: "Invoiced",
|
|
70
|
+
value: SalesStatus.Invoiced,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
sourceType: FilterSourceType.OrderStatus,
|
|
74
|
+
label: "Cancelled",
|
|
75
|
+
value: SalesStatus.Canceled,
|
|
76
|
+
},
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
const OrdersFilterPanel = ({ children }: { children: React.ReactNode }) => {
|
|
80
|
+
const {
|
|
81
|
+
selectedOrigins,
|
|
82
|
+
handleSelectOrigin,
|
|
83
|
+
createdDate,
|
|
84
|
+
handleSelectCreatedDate,
|
|
85
|
+
orderStatus,
|
|
86
|
+
handleSelectOrderStatus,
|
|
87
|
+
} = useOrdersSearchAndFilter();
|
|
88
|
+
const [open, setOpen] = useState(false);
|
|
89
|
+
const t = useTranslations("Account.Orders");
|
|
90
|
+
|
|
91
|
+
const handleToggle = () => setOpen((prev) => !prev);
|
|
92
|
+
|
|
93
|
+
const activeFilters: FilterOption[] = [];
|
|
94
|
+
selectedOrigins.forEach((origin) => {
|
|
95
|
+
activeFilters.push(origin);
|
|
96
|
+
});
|
|
97
|
+
if (createdDate) {
|
|
98
|
+
activeFilters.push(createdDate);
|
|
99
|
+
}
|
|
100
|
+
if (orderStatus) {
|
|
101
|
+
activeFilters.push(orderStatus);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const handleRemoveActiveFilter = (filter: FilterOption) => {
|
|
105
|
+
switch (filter.sourceType) {
|
|
106
|
+
case FilterSourceType.Origin:
|
|
107
|
+
handleSelectOrigin(filter);
|
|
108
|
+
break;
|
|
109
|
+
case FilterSourceType.CreatedDate:
|
|
110
|
+
handleSelectCreatedDate(undefined);
|
|
111
|
+
break;
|
|
112
|
+
case FilterSourceType.OrderStatus:
|
|
113
|
+
handleSelectOrderStatus(undefined);
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const handleClearAllFilters = () => {
|
|
119
|
+
selectedOrigins.forEach((origin) => {
|
|
120
|
+
handleSelectOrigin(origin);
|
|
121
|
+
});
|
|
122
|
+
handleSelectCreatedDate(undefined);
|
|
123
|
+
handleSelectOrderStatus(undefined);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
<Box
|
|
128
|
+
sx={{
|
|
129
|
+
border: "1px solid #eee",
|
|
130
|
+
borderRadius: 2,
|
|
131
|
+
bgcolor: "#fff",
|
|
132
|
+
mb: 3,
|
|
133
|
+
mt: 2,
|
|
134
|
+
flex: "1 1 0",
|
|
135
|
+
}}
|
|
136
|
+
>
|
|
137
|
+
<Box display="flex" sx={{ pt: 1, pl: 1 }}>
|
|
138
|
+
<Button
|
|
139
|
+
onClick={handleToggle}
|
|
140
|
+
sx={{ textTransform: "none", mb: 1, mr: 1, ml: 1 }}
|
|
141
|
+
>
|
|
142
|
+
<Typography sx={{ marginRight: 1, fontWeight: 600 }}>
|
|
143
|
+
{t("filterBtn")}
|
|
144
|
+
</Typography>
|
|
145
|
+
|
|
146
|
+
<KeyboardArrowRight
|
|
147
|
+
fontSize="small"
|
|
148
|
+
color="inherit"
|
|
149
|
+
sx={{
|
|
150
|
+
transform: open ? "rotate(90deg)" : "rotate(0deg)", // 0deg = right, 90deg = down
|
|
151
|
+
transition: "transform 0.3s ease",
|
|
152
|
+
transformOrigin: "center",
|
|
153
|
+
}}
|
|
154
|
+
/>
|
|
155
|
+
</Button>
|
|
156
|
+
<Box>
|
|
157
|
+
{activeFilters.length > 0 &&
|
|
158
|
+
activeFilters.map((filter, index) => (
|
|
159
|
+
<Box
|
|
160
|
+
key={index}
|
|
161
|
+
sx={{
|
|
162
|
+
display: "inline-flex",
|
|
163
|
+
alignItems: "center",
|
|
164
|
+
backgroundColor: "#f0f0f0",
|
|
165
|
+
borderRadius: 4,
|
|
166
|
+
px: 1.5,
|
|
167
|
+
py: 0.75,
|
|
168
|
+
mr: 1,
|
|
169
|
+
mb: 1,
|
|
170
|
+
cursor: "pointer",
|
|
171
|
+
|
|
172
|
+
"&:hover": {
|
|
173
|
+
boxShadow: "0 2px 6px rgba(0, 0, 0, 0.15)",
|
|
174
|
+
},
|
|
175
|
+
}}
|
|
176
|
+
onClick={() => handleRemoveActiveFilter(filter)}
|
|
177
|
+
>
|
|
178
|
+
<Typography mr={1}>{filter.label}</Typography>
|
|
179
|
+
<HiX />
|
|
180
|
+
</Box>
|
|
181
|
+
))}
|
|
182
|
+
</Box>
|
|
183
|
+
{activeFilters.length > 0 && (
|
|
184
|
+
<Typography
|
|
185
|
+
sx={{
|
|
186
|
+
cursor: "pointer",
|
|
187
|
+
mx: 1,
|
|
188
|
+
my: 1,
|
|
189
|
+
minWidth: "60px",
|
|
190
|
+
textDecoration: "underline",
|
|
191
|
+
}}
|
|
192
|
+
onClick={handleClearAllFilters}
|
|
193
|
+
>
|
|
194
|
+
{t("clearAllBtn")}
|
|
195
|
+
</Typography>
|
|
196
|
+
)}
|
|
197
|
+
</Box>
|
|
198
|
+
|
|
199
|
+
{open && (
|
|
200
|
+
<>
|
|
201
|
+
<Box
|
|
202
|
+
display="flex"
|
|
203
|
+
gap={4}
|
|
204
|
+
p={3}
|
|
205
|
+
sx={{
|
|
206
|
+
border: "1px solid #e0e0e0",
|
|
207
|
+
borderRadius: 2,
|
|
208
|
+
bgcolor: "#fff",
|
|
209
|
+
mb: 2,
|
|
210
|
+
}}
|
|
211
|
+
>
|
|
212
|
+
{children}
|
|
213
|
+
</Box>
|
|
214
|
+
|
|
215
|
+
{/* Done Button */}
|
|
216
|
+
<Box textAlign="right" pr={2} pb={2}>
|
|
217
|
+
<Button
|
|
218
|
+
variant="contained"
|
|
219
|
+
color="primary"
|
|
220
|
+
onClick={handleToggle}
|
|
221
|
+
sx={{ borderRadius: "24px", textTransform: "none" }}
|
|
222
|
+
>
|
|
223
|
+
{t("doneBtn")}
|
|
224
|
+
</Button>
|
|
225
|
+
</Box>
|
|
226
|
+
</>
|
|
227
|
+
)}
|
|
228
|
+
</Box>
|
|
229
|
+
);
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
const OriginsFilterList = () => {
|
|
233
|
+
const { originOptions, selectedOrigins, handleSelectOrigin } =
|
|
234
|
+
useOrdersSearchAndFilter();
|
|
235
|
+
const t = useTranslations("Account.Orders");
|
|
236
|
+
|
|
237
|
+
return (
|
|
238
|
+
<Box>
|
|
239
|
+
<Typography fontWeight={600} mb={1}>
|
|
240
|
+
{t("originHeader")}
|
|
241
|
+
</Typography>
|
|
242
|
+
<Divider />
|
|
243
|
+
<FormGroup
|
|
244
|
+
sx={{
|
|
245
|
+
maxHeight: "400px",
|
|
246
|
+
overflowY: "auto",
|
|
247
|
+
flexWrap: "nowrap",
|
|
248
|
+
}}
|
|
249
|
+
>
|
|
250
|
+
{originOptions.map((originOption, index) => (
|
|
251
|
+
<FormControlLabel
|
|
252
|
+
key={index}
|
|
253
|
+
control={
|
|
254
|
+
<Checkbox
|
|
255
|
+
checked={selectedOrigins.some(
|
|
256
|
+
(o) => o.value === originOption.value,
|
|
257
|
+
)}
|
|
258
|
+
onChange={() => handleSelectOrigin(originOption)}
|
|
259
|
+
/>
|
|
260
|
+
}
|
|
261
|
+
label={originOption.label}
|
|
262
|
+
/>
|
|
263
|
+
))}
|
|
264
|
+
</FormGroup>
|
|
265
|
+
</Box>
|
|
266
|
+
);
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
const CreatedDateFilterList = () => {
|
|
270
|
+
const { createdDate, handleSelectCreatedDate } = useOrdersSearchAndFilter();
|
|
271
|
+
const t = useTranslations("Account.Orders");
|
|
272
|
+
|
|
273
|
+
return (
|
|
274
|
+
<Box sx={{ minWidth: "155px" }}>
|
|
275
|
+
<Typography fontWeight={600} mb={1}>
|
|
276
|
+
{t("createdDateHeader")}
|
|
277
|
+
</Typography>
|
|
278
|
+
<Divider />
|
|
279
|
+
<RadioGroup value={createdDate?.label ?? ""}>
|
|
280
|
+
{createdDateOptions.map((createdDateOption, index) => (
|
|
281
|
+
<div key={index}>
|
|
282
|
+
<FormControlLabel
|
|
283
|
+
key={createdDateOption.label}
|
|
284
|
+
value={createdDateOption.label}
|
|
285
|
+
control={
|
|
286
|
+
<Radio
|
|
287
|
+
onClick={() => {
|
|
288
|
+
handleSelectCreatedDate(createdDateOption);
|
|
289
|
+
}}
|
|
290
|
+
/>
|
|
291
|
+
}
|
|
292
|
+
label={createdDateOption.label}
|
|
293
|
+
/>
|
|
294
|
+
{createdDateOption.label === "Custom Dates" &&
|
|
295
|
+
createdDate &&
|
|
296
|
+
createdDate.label === "Custom Dates" && (
|
|
297
|
+
<Box mt={1} display="flex" flexDirection="column" gap={2}>
|
|
298
|
+
<TextField
|
|
299
|
+
label="From"
|
|
300
|
+
type="date"
|
|
301
|
+
value={createdDate?.startValue || ""}
|
|
302
|
+
onChange={(e) =>
|
|
303
|
+
handleSelectCreatedDate(
|
|
304
|
+
{ ...createdDate, startValue: e.target.value },
|
|
305
|
+
false,
|
|
306
|
+
)
|
|
307
|
+
}
|
|
308
|
+
slotProps={{
|
|
309
|
+
inputLabel: {
|
|
310
|
+
shrink: true,
|
|
311
|
+
},
|
|
312
|
+
}}
|
|
313
|
+
variant="outlined"
|
|
314
|
+
/>
|
|
315
|
+
<TextField
|
|
316
|
+
label="To"
|
|
317
|
+
type="date"
|
|
318
|
+
value={createdDate?.endValue || ""}
|
|
319
|
+
onChange={(e) =>
|
|
320
|
+
handleSelectCreatedDate(
|
|
321
|
+
{ ...createdDate, endValue: e.target.value },
|
|
322
|
+
false,
|
|
323
|
+
)
|
|
324
|
+
}
|
|
325
|
+
slotProps={{
|
|
326
|
+
inputLabel: {
|
|
327
|
+
shrink: true,
|
|
328
|
+
},
|
|
329
|
+
}}
|
|
330
|
+
variant="outlined"
|
|
331
|
+
/>
|
|
332
|
+
</Box>
|
|
333
|
+
)}
|
|
334
|
+
</div>
|
|
335
|
+
))}
|
|
336
|
+
</RadioGroup>
|
|
337
|
+
</Box>
|
|
338
|
+
);
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
const OrderStatusFilterList = () => {
|
|
342
|
+
const { orderStatus, handleSelectOrderStatus } = useOrdersSearchAndFilter();
|
|
343
|
+
const t = useTranslations("Account.Orders");
|
|
344
|
+
|
|
345
|
+
return (
|
|
346
|
+
<Box>
|
|
347
|
+
<Typography fontWeight={600} mb={1}>
|
|
348
|
+
{t("orderStatusHeader")}
|
|
349
|
+
</Typography>
|
|
350
|
+
<Divider />
|
|
351
|
+
<RadioGroup value={orderStatus?.value ?? -1}>
|
|
352
|
+
{orderStatusOptions.map((orderStatusOption) => (
|
|
353
|
+
<FormControlLabel
|
|
354
|
+
key={orderStatusOption.label}
|
|
355
|
+
value={orderStatusOption.value}
|
|
356
|
+
control={
|
|
357
|
+
<Radio
|
|
358
|
+
onClick={() => {
|
|
359
|
+
handleSelectOrderStatus(orderStatusOption);
|
|
360
|
+
}}
|
|
361
|
+
/>
|
|
362
|
+
}
|
|
363
|
+
label={orderStatusOption.label}
|
|
364
|
+
/>
|
|
365
|
+
))}
|
|
366
|
+
</RadioGroup>
|
|
367
|
+
</Box>
|
|
368
|
+
);
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
OrdersFilterPanel.Origins = OriginsFilterList;
|
|
372
|
+
OrdersFilterPanel.CreatedDate = CreatedDateFilterList;
|
|
373
|
+
OrdersFilterPanel.OrderStatus = OrderStatusFilterList;
|
|
374
|
+
|
|
375
|
+
export default OrdersFilterPanel;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// GLOBAL CUSTOM COMPONENT
|
|
2
|
+
import { Paragraph } from "@evenicanpm/storefront-core/src/components/Typography";
|
|
3
|
+
// CUSTOM UTILS LIBRARY FUNCTION;
|
|
4
|
+
import TableHeader from "@evenicanpm/storefront-core/src/pages/account/table-header";
|
|
5
|
+
import Box from "@mui/material/Box";
|
|
6
|
+
import { useTranslations } from "next-intl";
|
|
7
|
+
import { createContext } from "react";
|
|
8
|
+
|
|
9
|
+
export const OrderHistoryTableHeaderContext =
|
|
10
|
+
createContext<undefined>(undefined);
|
|
11
|
+
|
|
12
|
+
const OrderHistoryTableHeader = ({
|
|
13
|
+
children,
|
|
14
|
+
}: {
|
|
15
|
+
children: React.ReactNode;
|
|
16
|
+
}) => {
|
|
17
|
+
return (
|
|
18
|
+
<OrderHistoryTableHeaderContext.Provider value={undefined}>
|
|
19
|
+
<Box>
|
|
20
|
+
<TableHeader sx={{ gridTemplateColumns: "2fr 1fr 1fr 1fr 1fr" }}>
|
|
21
|
+
{children}
|
|
22
|
+
</TableHeader>
|
|
23
|
+
</Box>
|
|
24
|
+
</OrderHistoryTableHeaderContext.Provider>
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
OrderHistoryTableHeader.OrderNumber = () => {
|
|
29
|
+
const t = useTranslations("Account.Orders");
|
|
30
|
+
return <Paragraph ellipsis>{t("orderNumberHeader")}</Paragraph>;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
OrderHistoryTableHeader.OrderStatus = () => {
|
|
34
|
+
const t = useTranslations("Account.Orders");
|
|
35
|
+
return <Box textAlign="center">{t("orderStatusHeader")}</Box>;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
OrderHistoryTableHeader.TransactionDate = () => {
|
|
39
|
+
const t = useTranslations("Account.Orders");
|
|
40
|
+
return (
|
|
41
|
+
<Paragraph textAlign={{ sm: "center", xs: "left" }}>
|
|
42
|
+
{t("transactionDateHeader")}
|
|
43
|
+
</Paragraph>
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
OrderHistoryTableHeader.TransactionAmount = () => {
|
|
48
|
+
const t = useTranslations("Account.Orders");
|
|
49
|
+
return (
|
|
50
|
+
<Paragraph textAlign="center">{t("transactionAmountHeader")}</Paragraph>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export default OrderHistoryTableHeader;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Typography } from "@mui/material";
|
|
2
|
+
import MuiPagination from "@mui/material/Pagination";
|
|
3
|
+
import { Box } from "@mui/system";
|
|
4
|
+
import { useTranslations } from "next-intl";
|
|
5
|
+
import type { ChangeEvent } from "react";
|
|
6
|
+
import { PAGE_SIZE, useOrderHistory } from "./order-history-root";
|
|
7
|
+
|
|
8
|
+
const OrdersPagination = ({ children }: { children: React.ReactNode }) => {
|
|
9
|
+
return (
|
|
10
|
+
<Box sx={{ display: "flex", justifyContent: "space-between" }}>
|
|
11
|
+
{children}
|
|
12
|
+
</Box>
|
|
13
|
+
);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const ResultNumber = () => {
|
|
17
|
+
const { pageNumber, orders } = useOrderHistory();
|
|
18
|
+
const t = useTranslations("Account.Orders");
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<Typography color="grey.600">
|
|
22
|
+
{t("showingRange", {
|
|
23
|
+
start: (pageNumber - 1) * PAGE_SIZE,
|
|
24
|
+
end: (pageNumber - 1) * PAGE_SIZE + orders.length,
|
|
25
|
+
total: 500,
|
|
26
|
+
})}
|
|
27
|
+
</Typography>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const PaginationControl = () => {
|
|
32
|
+
const { pageNumber, setPageNumber } = useOrderHistory();
|
|
33
|
+
|
|
34
|
+
const handleMuiPaginationChange = (
|
|
35
|
+
_event: ChangeEvent<unknown>,
|
|
36
|
+
newPage: number,
|
|
37
|
+
) => {
|
|
38
|
+
setPageNumber(newPage);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<MuiPagination
|
|
43
|
+
color="primary"
|
|
44
|
+
variant="outlined"
|
|
45
|
+
count={25}
|
|
46
|
+
page={pageNumber}
|
|
47
|
+
onChange={handleMuiPaginationChange}
|
|
48
|
+
/>
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
OrdersPagination.ResultNumber = ResultNumber;
|
|
53
|
+
OrdersPagination.PaginationControl = PaginationControl;
|
|
54
|
+
|
|
55
|
+
export default OrdersPagination;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { SalesOrder } from "@evenicanpm/storefront-core/src/api-manager/schemas/order.schema";
|
|
2
|
+
import getOrders from "@evenicanpm/storefront-core/src/api-manager/services/order/queries/get-orders";
|
|
3
|
+
import type {
|
|
4
|
+
OrderSearchCriteria,
|
|
5
|
+
SortColumn,
|
|
6
|
+
} from "@msdyn365-commerce/retail-proxy";
|
|
7
|
+
import { createContext, useContext, useMemo, useState } from "react";
|
|
8
|
+
import OrdersSearchAndFilter from "./order-history-search-and-filter";
|
|
9
|
+
import OrdersSort from "./order-history-sort";
|
|
10
|
+
import OrderHistoryTable from "./order-history-table";
|
|
11
|
+
|
|
12
|
+
export const PAGE_SIZE = 10;
|
|
13
|
+
|
|
14
|
+
export type OrderHistoryContextType = {
|
|
15
|
+
orderSearchCriteria: OrderSearchCriteria;
|
|
16
|
+
setOrderSearchCriteria: (criteria: OrderSearchCriteria) => void;
|
|
17
|
+
sortColumn: SortColumn;
|
|
18
|
+
setSortColumn: (sort: SortColumn) => void;
|
|
19
|
+
pageNumber: number;
|
|
20
|
+
setPageNumber: (page: number) => void;
|
|
21
|
+
orders: SalesOrder[];
|
|
22
|
+
isLoading: boolean;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const OrderHistoryContext = createContext<
|
|
26
|
+
OrderHistoryContextType | undefined
|
|
27
|
+
>(undefined);
|
|
28
|
+
|
|
29
|
+
export const useOrderHistory = () => {
|
|
30
|
+
const context = useContext(OrderHistoryContext);
|
|
31
|
+
if (!context) {
|
|
32
|
+
throw new Error("Context must be used within a OrderHistoryProvider");
|
|
33
|
+
}
|
|
34
|
+
return context;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const OrderHistory = ({ children }: { children: React.ReactNode }) => {
|
|
38
|
+
const [orderSearchCriteria, setOrderSearchCriteria] =
|
|
39
|
+
useState<OrderSearchCriteria>({});
|
|
40
|
+
const [pageNumber, setPageNumber] = useState<number>(1);
|
|
41
|
+
const [sortColumn, setSortColumn] = useState<SortColumn>({
|
|
42
|
+
ColumnName: "CREATEDDATETIME",
|
|
43
|
+
IsDescending: true,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const { data: orders, isLoading } = getOrders.useData({
|
|
47
|
+
orderSearchCriteria,
|
|
48
|
+
paging: {
|
|
49
|
+
Top: PAGE_SIZE,
|
|
50
|
+
Skip: (pageNumber - 1) * PAGE_SIZE,
|
|
51
|
+
},
|
|
52
|
+
sort: sortColumn,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const value = useMemo(
|
|
56
|
+
() => ({
|
|
57
|
+
orderSearchCriteria,
|
|
58
|
+
setOrderSearchCriteria,
|
|
59
|
+
sortColumn,
|
|
60
|
+
setSortColumn,
|
|
61
|
+
pageNumber,
|
|
62
|
+
setPageNumber,
|
|
63
|
+
orders: orders ?? [],
|
|
64
|
+
isLoading,
|
|
65
|
+
}),
|
|
66
|
+
[orderSearchCriteria, sortColumn, pageNumber, orders, isLoading],
|
|
67
|
+
);
|
|
68
|
+
return (
|
|
69
|
+
<OrderHistoryContext.Provider value={value}>
|
|
70
|
+
{children}
|
|
71
|
+
</OrderHistoryContext.Provider>
|
|
72
|
+
);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
OrderHistory.SearchAndFilter = OrdersSearchAndFilter;
|
|
76
|
+
|
|
77
|
+
OrderHistory.Sort = () => {
|
|
78
|
+
const { setSortColumn } = useOrderHistory();
|
|
79
|
+
return <OrdersSort setSortColumn={setSortColumn} />;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
OrderHistory.Table = OrderHistoryTable;
|
|
83
|
+
|
|
84
|
+
// OrderHistory.Table = () => {
|
|
85
|
+
// const { orders, isLoading } = useOrderHistory();
|
|
86
|
+
|
|
87
|
+
// return (
|
|
88
|
+
// <OrderHistoryTable>
|
|
89
|
+
// <OrderHistoryTable.Header>
|
|
90
|
+
// <OrderHistoryTable.Header.OrderNumber />
|
|
91
|
+
// <OrderHistoryTable.Header.OrderStatus />
|
|
92
|
+
// <OrderHistoryTable.Header.TransactionDate />
|
|
93
|
+
// <OrderHistoryTable.Header.TransactionAmount />
|
|
94
|
+
// </OrderHistoryTable.Header>
|
|
95
|
+
|
|
96
|
+
// {!isLoading ? (
|
|
97
|
+
// orders && orders.length > 0 ? (
|
|
98
|
+
// <Fragment>
|
|
99
|
+
// {orders.map((order: SalesOrder) => (
|
|
100
|
+
// <OrderHistoryTable.Row order={order} key={order.RecordId}>
|
|
101
|
+
// <OrderHistoryTable.Row.OrderNumber />
|
|
102
|
+
// <OrderHistoryTable.Row.OrderStatus />
|
|
103
|
+
// <OrderHistoryTable.Row.TransactionDate />
|
|
104
|
+
// <OrderHistoryTable.Row.TransactionAmount />
|
|
105
|
+
// <OrderHistoryTable.Row.DetailsIcon />
|
|
106
|
+
// </OrderHistoryTable.Row>
|
|
107
|
+
// ))}
|
|
108
|
+
// <OrderHistoryTable.Pagination>
|
|
109
|
+
// <OrderHistoryTable.Pagination.ResultNumber />
|
|
110
|
+
// <OrderHistoryTable.Pagination.PaginationControl />
|
|
111
|
+
// </OrderHistoryTable.Pagination>
|
|
112
|
+
// </Fragment>
|
|
113
|
+
// ) : (
|
|
114
|
+
// <NoRecords message="Account.Orders.noOrders" />
|
|
115
|
+
// )
|
|
116
|
+
// ) : (
|
|
117
|
+
// <Box sx={{ display: "flex", justifyContent: "center", mt: 2 }}>
|
|
118
|
+
// <CircularProgress size={30} />
|
|
119
|
+
// </Box>
|
|
120
|
+
// )}
|
|
121
|
+
// </OrderHistoryTable>
|
|
122
|
+
// );
|
|
123
|
+
// };
|
|
124
|
+
|
|
125
|
+
export default OrderHistory;
|