@finos/legend-application-marketplace 0.1.50 → 0.1.52
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/lib/__lib__/LegendMarketplaceAppEvent.d.ts +2 -1
- package/lib/__lib__/LegendMarketplaceAppEvent.d.ts.map +1 -1
- package/lib/__lib__/LegendMarketplaceAppEvent.js +1 -0
- package/lib/__lib__/LegendMarketplaceAppEvent.js.map +1 -1
- package/lib/application/LegendMarketplaceApplicationPlugin.d.ts +5 -1
- package/lib/application/LegendMarketplaceApplicationPlugin.d.ts.map +1 -1
- package/lib/application/LegendMarketplaceApplicationPlugin.js.map +1 -1
- package/lib/components/AddToCart/RecommendedAddOnsModal.d.ts.map +1 -1
- package/lib/components/AddToCart/RecommendedAddOnsModal.js +32 -6
- package/lib/components/AddToCart/RecommendedAddOnsModal.js.map +1 -1
- package/lib/components/AddToCart/RecommendedItemsCard.d.ts +0 -1
- package/lib/components/AddToCart/RecommendedItemsCard.d.ts.map +1 -1
- package/lib/components/AddToCart/RecommendedItemsCard.js +12 -17
- package/lib/components/AddToCart/RecommendedItemsCard.js.map +1 -1
- package/lib/components/ProviderCard/LegendMarketplaceTerminalCard.d.ts.map +1 -1
- package/lib/components/ProviderCard/LegendMarketplaceTerminalCard.js +2 -2
- package/lib/components/ProviderCard/LegendMarketplaceTerminalCard.js.map +1 -1
- package/lib/components/orders/CancelOrderDialog.d.ts +27 -0
- package/lib/components/orders/CancelOrderDialog.d.ts.map +1 -0
- package/lib/components/orders/CancelOrderDialog.js +52 -0
- package/lib/components/orders/CancelOrderDialog.js.map +1 -0
- package/lib/components/orders/ProgressTracker.d.ts +23 -0
- package/lib/components/orders/ProgressTracker.d.ts.map +1 -0
- package/lib/components/orders/ProgressTracker.js +116 -0
- package/lib/components/orders/ProgressTracker.js.map +1 -0
- package/lib/index.css +2 -2
- package/lib/index.css.map +1 -1
- package/lib/package.json +1 -1
- package/lib/pages/Profile/LegendMarketplaceYourOrders.d.ts.map +1 -1
- package/lib/pages/Profile/LegendMarketplaceYourOrders.js +43 -36
- package/lib/pages/Profile/LegendMarketplaceYourOrders.js.map +1 -1
- package/lib/pages/TerminalsAddons/LegendMarketplaceTerminalsAddons.d.ts.map +1 -1
- package/lib/pages/TerminalsAddons/LegendMarketplaceTerminalsAddons.js +42 -18
- package/lib/pages/TerminalsAddons/LegendMarketplaceTerminalsAddons.js.map +1 -1
- package/lib/stores/LegendMarketPlaceVendorDataStore.d.ts +10 -4
- package/lib/stores/LegendMarketPlaceVendorDataStore.d.ts.map +1 -1
- package/lib/stores/LegendMarketPlaceVendorDataStore.js +82 -49
- package/lib/stores/LegendMarketPlaceVendorDataStore.js.map +1 -1
- package/lib/stores/cart/CartStore.d.ts.map +1 -1
- package/lib/stores/cart/CartStore.js +2 -1
- package/lib/stores/cart/CartStore.js.map +1 -1
- package/lib/stores/orders/OrderHelpers.d.ts +49 -0
- package/lib/stores/orders/OrderHelpers.d.ts.map +1 -0
- package/lib/stores/orders/OrderHelpers.js +134 -0
- package/lib/stores/orders/OrderHelpers.js.map +1 -0
- package/lib/stores/orders/OrderStore.d.ts +2 -0
- package/lib/stores/orders/OrderStore.d.ts.map +1 -1
- package/lib/stores/orders/OrderStore.js +31 -0
- package/lib/stores/orders/OrderStore.js.map +1 -1
- package/package.json +7 -7
- package/src/__lib__/LegendMarketplaceAppEvent.ts +1 -0
- package/src/application/LegendMarketplaceApplicationPlugin.ts +6 -0
- package/src/components/AddToCart/RecommendedAddOnsModal.tsx +145 -17
- package/src/components/AddToCart/RecommendedItemsCard.tsx +32 -62
- package/src/components/ProviderCard/LegendMarketplaceTerminalCard.tsx +18 -2
- package/src/components/orders/CancelOrderDialog.tsx +157 -0
- package/src/components/orders/ProgressTracker.tsx +266 -0
- package/src/pages/Profile/LegendMarketplaceYourOrders.tsx +227 -230
- package/src/pages/TerminalsAddons/LegendMarketplaceTerminalsAddons.tsx +140 -17
- package/src/stores/LegendMarketPlaceVendorDataStore.tsx +114 -84
- package/src/stores/cart/CartStore.ts +2 -1
- package/src/stores/orders/OrderHelpers.ts +167 -0
- package/src/stores/orders/OrderStore.ts +51 -0
- package/tsconfig.json +3 -0
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { observer } from 'mobx-react-lite';
|
|
18
|
+
import { useMemo, useState } from 'react';
|
|
18
19
|
import {
|
|
19
20
|
Dialog,
|
|
20
21
|
DialogTitle,
|
|
@@ -22,15 +23,24 @@ import {
|
|
|
22
23
|
DialogActions,
|
|
23
24
|
Button,
|
|
24
25
|
Typography,
|
|
25
|
-
Grid,
|
|
26
26
|
Box,
|
|
27
27
|
IconButton,
|
|
28
|
+
TextField,
|
|
29
|
+
InputAdornment,
|
|
30
|
+
Select,
|
|
31
|
+
MenuItem,
|
|
32
|
+
FormControl,
|
|
33
|
+
InputLabel,
|
|
34
|
+
type SelectChangeEvent,
|
|
28
35
|
} from '@mui/material';
|
|
29
36
|
import {
|
|
30
37
|
CloseIcon,
|
|
31
38
|
CheckCircleIcon,
|
|
32
39
|
ArrowRightIcon,
|
|
33
40
|
WarningIcon,
|
|
41
|
+
SearchIcon,
|
|
42
|
+
ArrowUpIcon,
|
|
43
|
+
ArrowDownIcon,
|
|
34
44
|
} from '@finos/legend-art';
|
|
35
45
|
import {
|
|
36
46
|
TerminalItemType,
|
|
@@ -58,8 +68,34 @@ export const RecommendedAddOnsModal = observer(
|
|
|
58
68
|
onViewCart,
|
|
59
69
|
} = props;
|
|
60
70
|
|
|
71
|
+
const [searchTerm, setSearchTerm] = useState('');
|
|
72
|
+
const [sortOrder, setSortOrder] = useState<'asc' | 'desc' | ''>('');
|
|
73
|
+
|
|
74
|
+
const filteredAndSortedItems = useMemo(() => {
|
|
75
|
+
let items = [...recommendedItems];
|
|
76
|
+
|
|
77
|
+
if (searchTerm) {
|
|
78
|
+
const search = searchTerm.toLowerCase();
|
|
79
|
+
items = items.filter(
|
|
80
|
+
(item) =>
|
|
81
|
+
item.productName.toLowerCase().includes(search) ||
|
|
82
|
+
item.providerName.toLowerCase().includes(search),
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (sortOrder) {
|
|
87
|
+
items.sort((a, b) =>
|
|
88
|
+
sortOrder === 'asc' ? a.price - b.price : b.price - a.price,
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return items;
|
|
93
|
+
}, [recommendedItems, searchTerm, sortOrder]);
|
|
94
|
+
|
|
61
95
|
const closeModal = () => {
|
|
62
96
|
setShowModal(false);
|
|
97
|
+
setSearchTerm('');
|
|
98
|
+
setSortOrder('');
|
|
63
99
|
};
|
|
64
100
|
|
|
65
101
|
const handleViewCart = () => {
|
|
@@ -67,6 +103,12 @@ export const RecommendedAddOnsModal = observer(
|
|
|
67
103
|
closeModal();
|
|
68
104
|
};
|
|
69
105
|
|
|
106
|
+
const handleSortChange = (
|
|
107
|
+
event: SelectChangeEvent<'asc' | 'desc' | ''>,
|
|
108
|
+
) => {
|
|
109
|
+
setSortOrder(event.target.value);
|
|
110
|
+
};
|
|
111
|
+
|
|
70
112
|
if (!showModal) {
|
|
71
113
|
return null;
|
|
72
114
|
}
|
|
@@ -119,8 +161,10 @@ export const RecommendedAddOnsModal = observer(
|
|
|
119
161
|
className="recommended-addons-modal__section-title"
|
|
120
162
|
>
|
|
121
163
|
{terminal?.terminalItemType === TerminalItemType.TERMINAL
|
|
122
|
-
?
|
|
123
|
-
:
|
|
164
|
+
? `Recommended Add-Ons for ${terminal.providerName}`
|
|
165
|
+
: terminal
|
|
166
|
+
? `Recommended Terminals for ${terminal.providerName}`
|
|
167
|
+
: ''}
|
|
124
168
|
</Typography>
|
|
125
169
|
<Typography
|
|
126
170
|
variant="body2"
|
|
@@ -141,24 +185,108 @@ export const RecommendedAddOnsModal = observer(
|
|
|
141
185
|
</Typography>
|
|
142
186
|
</Box>
|
|
143
187
|
) : (
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
<
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
188
|
+
<>
|
|
189
|
+
<Box className="recommended-addons-modal__filter-controls">
|
|
190
|
+
<TextField
|
|
191
|
+
size="medium"
|
|
192
|
+
placeholder="Search any service..."
|
|
193
|
+
value={searchTerm}
|
|
194
|
+
onChange={(e) => setSearchTerm(e.target.value)}
|
|
195
|
+
className="recommended-addons-modal__search-field"
|
|
196
|
+
slotProps={{
|
|
197
|
+
input: {
|
|
198
|
+
endAdornment: (
|
|
199
|
+
<InputAdornment position="end">
|
|
200
|
+
<SearchIcon />
|
|
201
|
+
</InputAdornment>
|
|
202
|
+
),
|
|
203
|
+
},
|
|
204
|
+
}}
|
|
205
|
+
/>
|
|
206
|
+
<FormControl
|
|
207
|
+
size="medium"
|
|
208
|
+
className="recommended-addons-modal__sort-select"
|
|
209
|
+
sx={{ minWidth: 180 }}
|
|
210
|
+
>
|
|
211
|
+
<InputLabel
|
|
212
|
+
id="recommended-addons-sort-label"
|
|
213
|
+
sx={{ fontSize: '1rem' }}
|
|
214
|
+
>
|
|
215
|
+
Sort by Price
|
|
216
|
+
</InputLabel>
|
|
217
|
+
<Select
|
|
218
|
+
labelId="recommended-addons-sort-label"
|
|
219
|
+
value={sortOrder}
|
|
220
|
+
label="Sort by Price"
|
|
221
|
+
onChange={handleSortChange}
|
|
222
|
+
sx={{ fontSize: '1rem' }}
|
|
223
|
+
>
|
|
224
|
+
<MenuItem value="" sx={{ fontSize: '1rem' }}>
|
|
225
|
+
<em>None</em>
|
|
226
|
+
</MenuItem>
|
|
227
|
+
<MenuItem value="asc" sx={{ fontSize: '1rem' }}>
|
|
228
|
+
<Box display="flex" alignItems="center">
|
|
229
|
+
<ArrowUpIcon fontSize="small" />
|
|
230
|
+
<Typography sx={{ ml: 0.5, fontSize: '1rem' }}>
|
|
231
|
+
Low to High
|
|
232
|
+
</Typography>
|
|
233
|
+
</Box>
|
|
234
|
+
</MenuItem>
|
|
235
|
+
<MenuItem value="desc" sx={{ fontSize: '1rem' }}>
|
|
236
|
+
<Box display="flex" alignItems="center">
|
|
237
|
+
<ArrowDownIcon fontSize="small" />
|
|
238
|
+
<Typography sx={{ ml: 0.5, fontSize: '1rem' }}>
|
|
239
|
+
High to Low
|
|
240
|
+
</Typography>
|
|
241
|
+
</Box>
|
|
242
|
+
</MenuItem>
|
|
243
|
+
</Select>
|
|
244
|
+
</FormControl>
|
|
245
|
+
</Box>
|
|
246
|
+
|
|
247
|
+
{filteredAndSortedItems.length === 0 ? (
|
|
248
|
+
<Box className="recommended-addons-modal__empty-state">
|
|
249
|
+
<Typography variant="body1">
|
|
250
|
+
No items match your search criteria.
|
|
251
|
+
</Typography>
|
|
252
|
+
</Box>
|
|
253
|
+
) : (
|
|
254
|
+
<Box className="recommended-addons-modal__list">
|
|
255
|
+
<Box className="recommended-addons-modal__list-header">
|
|
256
|
+
<Typography
|
|
257
|
+
variant="subtitle2"
|
|
258
|
+
className="recommended-addons-modal__header-name"
|
|
259
|
+
>
|
|
260
|
+
Product Name
|
|
261
|
+
</Typography>
|
|
262
|
+
<Typography
|
|
263
|
+
variant="subtitle2"
|
|
264
|
+
className="recommended-addons-modal__header-provider"
|
|
265
|
+
>
|
|
266
|
+
Provider
|
|
267
|
+
</Typography>
|
|
268
|
+
<Typography
|
|
269
|
+
variant="subtitle2"
|
|
270
|
+
className="recommended-addons-modal__header-price"
|
|
271
|
+
>
|
|
272
|
+
Price
|
|
273
|
+
</Typography>
|
|
274
|
+
<Typography
|
|
275
|
+
variant="subtitle2"
|
|
276
|
+
className="recommended-addons-modal__header-action"
|
|
277
|
+
>
|
|
278
|
+
Action
|
|
279
|
+
</Typography>
|
|
280
|
+
</Box>
|
|
281
|
+
{filteredAndSortedItems.map((item) => (
|
|
154
282
|
<RecommendedItemsCard
|
|
155
283
|
key={item.id}
|
|
156
284
|
recommendedItem={item}
|
|
157
285
|
/>
|
|
158
|
-
)}
|
|
159
|
-
</
|
|
160
|
-
)
|
|
161
|
-
|
|
286
|
+
))}
|
|
287
|
+
</Box>
|
|
288
|
+
)}
|
|
289
|
+
</>
|
|
162
290
|
)}
|
|
163
291
|
</DialogContent>
|
|
164
292
|
|
|
@@ -16,16 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
import { clsx, PlusIcon } from '@finos/legend-art';
|
|
18
18
|
import type { TerminalResult } from '@finos/legend-server-marketplace';
|
|
19
|
-
import {
|
|
20
|
-
Box,
|
|
21
|
-
Button,
|
|
22
|
-
Card,
|
|
23
|
-
CardActions,
|
|
24
|
-
CardContent,
|
|
25
|
-
Chip,
|
|
26
|
-
CircularProgress,
|
|
27
|
-
Typography,
|
|
28
|
-
} from '@mui/material';
|
|
19
|
+
import { Box, Button, CircularProgress, Typography } from '@mui/material';
|
|
29
20
|
import { flowResult } from 'mobx';
|
|
30
21
|
import { useState } from 'react';
|
|
31
22
|
import { assertErrorThrown } from '@finos/legend-shared';
|
|
@@ -33,12 +24,11 @@ import { toastManager } from '../Toast/CartToast.js';
|
|
|
33
24
|
import { useLegendMarketplaceBaseStore } from '../../application/providers/LegendMarketplaceFrameworkProvider.js';
|
|
34
25
|
|
|
35
26
|
interface RecommendedItemsCardProps {
|
|
36
|
-
vendorProfileId?: number;
|
|
37
27
|
recommendedItem: TerminalResult;
|
|
38
28
|
}
|
|
39
29
|
|
|
40
30
|
export const RecommendedItemsCard = (props: RecommendedItemsCardProps) => {
|
|
41
|
-
const {
|
|
31
|
+
const { recommendedItem } = props;
|
|
42
32
|
const legendMarketplaceBaseStore = useLegendMarketplaceBaseStore();
|
|
43
33
|
const [isAddingToCart, setIsAddingToCart] = useState(false);
|
|
44
34
|
const [inCart, setInCart] = useState(false);
|
|
@@ -47,9 +37,6 @@ export const RecommendedItemsCard = (props: RecommendedItemsCardProps) => {
|
|
|
47
37
|
setIsAddingToCart(true);
|
|
48
38
|
const cartItemRequest =
|
|
49
39
|
legendMarketplaceBaseStore.cartStore.providerToCartRequest(addon);
|
|
50
|
-
if (vendorProfileId) {
|
|
51
|
-
cartItemRequest.vendorProfileId = vendorProfileId;
|
|
52
|
-
}
|
|
53
40
|
|
|
54
41
|
flowResult(
|
|
55
42
|
legendMarketplaceBaseStore.cartStore.addToCartWithAPI(cartItemRequest),
|
|
@@ -70,62 +57,45 @@ export const RecommendedItemsCard = (props: RecommendedItemsCardProps) => {
|
|
|
70
57
|
};
|
|
71
58
|
|
|
72
59
|
return (
|
|
73
|
-
<
|
|
74
|
-
<
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
<Box className="recommended-addons-modal__card-footer">
|
|
97
|
-
<Typography
|
|
98
|
-
variant="body2"
|
|
99
|
-
className={clsx('recommended-addons-modal__price', {
|
|
100
|
-
'recommended-addons-modal__price__free':
|
|
101
|
-
recommendedItem.price === 0,
|
|
60
|
+
<Box className="recommended-addons-modal__list-item">
|
|
61
|
+
<Typography
|
|
62
|
+
variant="body1"
|
|
63
|
+
className="recommended-addons-modal__item-name"
|
|
64
|
+
>
|
|
65
|
+
{recommendedItem.productName}
|
|
66
|
+
</Typography>
|
|
67
|
+
<Typography
|
|
68
|
+
variant="body2"
|
|
69
|
+
className="recommended-addons-modal__item-provider"
|
|
70
|
+
>
|
|
71
|
+
{recommendedItem.providerName}
|
|
72
|
+
</Typography>
|
|
73
|
+
<Typography
|
|
74
|
+
variant="body2"
|
|
75
|
+
className="recommended-addons-modal__item-price"
|
|
76
|
+
>
|
|
77
|
+
{recommendedItem.price === 0
|
|
78
|
+
? 'Free'
|
|
79
|
+
: recommendedItem.price.toLocaleString('en-US', {
|
|
80
|
+
style: 'currency',
|
|
81
|
+
currency: 'USD',
|
|
82
|
+
maximumFractionDigits: 2,
|
|
102
83
|
})}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
? 'Free'
|
|
106
|
-
: recommendedItem.price.toLocaleString('en-US', {
|
|
107
|
-
style: 'currency',
|
|
108
|
-
currency: 'USD',
|
|
109
|
-
maximumFractionDigits: 2,
|
|
110
|
-
})}
|
|
111
|
-
</Typography>
|
|
112
|
-
</Box>
|
|
113
|
-
</CardContent>
|
|
114
|
-
|
|
115
|
-
<CardActions className="recommended-addons-modal__card-actions">
|
|
84
|
+
</Typography>
|
|
85
|
+
<Box className="recommended-addons-modal__item-action">
|
|
116
86
|
<Button
|
|
117
87
|
variant={inCart ? 'outlined' : 'contained'}
|
|
118
88
|
onClick={() => handleAddAddonToCart(recommendedItem)}
|
|
119
89
|
disabled={inCart || isAddingToCart}
|
|
120
|
-
|
|
90
|
+
size="small"
|
|
121
91
|
className={clsx('recommended-addons-modal__add-btn', {
|
|
122
|
-
'recommended-addons-modal__add-
|
|
92
|
+
'recommended-addons-modal__add-btn--added': inCart,
|
|
123
93
|
})}
|
|
124
94
|
>
|
|
125
95
|
{isAddingToCart ? (
|
|
126
96
|
<>
|
|
127
97
|
Adding...
|
|
128
|
-
<CircularProgress size={
|
|
98
|
+
<CircularProgress size={14} />
|
|
129
99
|
</>
|
|
130
100
|
) : inCart ? (
|
|
131
101
|
'Added to Cart'
|
|
@@ -136,7 +106,7 @@ export const RecommendedItemsCard = (props: RecommendedItemsCardProps) => {
|
|
|
136
106
|
</>
|
|
137
107
|
)}
|
|
138
108
|
</Button>
|
|
139
|
-
</
|
|
140
|
-
</
|
|
109
|
+
</Box>
|
|
110
|
+
</Box>
|
|
141
111
|
);
|
|
142
112
|
};
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
CardMedia,
|
|
26
26
|
Chip,
|
|
27
27
|
CircularProgress,
|
|
28
|
+
Typography,
|
|
28
29
|
} from '@mui/material';
|
|
29
30
|
import type { TerminalResult } from '@finos/legend-server-marketplace';
|
|
30
31
|
import { CheckCircleIcon, ShoppingCartIcon } from '@finos/legend-art';
|
|
@@ -104,10 +105,25 @@ export const LegendMarketplaceTerminalCard = observer(
|
|
|
104
105
|
image={getImageUrl()}
|
|
105
106
|
alt="data asset"
|
|
106
107
|
/>
|
|
108
|
+
{terminalResult.category && (
|
|
109
|
+
<Chip
|
|
110
|
+
label={terminalResult.category}
|
|
111
|
+
className="legend-marketplace-terminal-card__category-chip"
|
|
112
|
+
/>
|
|
113
|
+
)}
|
|
107
114
|
<CardContent className="legend-marketplace-terminal-card__content">
|
|
108
|
-
<
|
|
115
|
+
<Typography
|
|
116
|
+
variant="subtitle2"
|
|
117
|
+
className="legend-marketplace-terminal-card__provider"
|
|
118
|
+
>
|
|
119
|
+
{terminalResult.providerName}
|
|
120
|
+
</Typography>
|
|
121
|
+
<Typography
|
|
122
|
+
variant="h6"
|
|
123
|
+
className="legend-marketplace-terminal-card__title"
|
|
124
|
+
>
|
|
109
125
|
{terminalResult.productName}
|
|
110
|
-
</
|
|
126
|
+
</Typography>
|
|
111
127
|
</CardContent>
|
|
112
128
|
</CardActionArea>
|
|
113
129
|
<CardActions className="legend-marketplace-terminal-card__action-buttons">
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025-present, Goldman Sachs
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import React, { useState } from 'react';
|
|
18
|
+
import { observer } from 'mobx-react-lite';
|
|
19
|
+
import { flowResult } from 'mobx';
|
|
20
|
+
import {
|
|
21
|
+
Dialog,
|
|
22
|
+
DialogTitle,
|
|
23
|
+
DialogContent,
|
|
24
|
+
DialogActions,
|
|
25
|
+
Button,
|
|
26
|
+
TextField,
|
|
27
|
+
Typography,
|
|
28
|
+
Box,
|
|
29
|
+
CircularProgress,
|
|
30
|
+
} from '@mui/material';
|
|
31
|
+
import { WarningIcon } from '@finos/legend-art';
|
|
32
|
+
import type { TerminalProductOrder } from '@finos/legend-server-marketplace';
|
|
33
|
+
import type { OrdersStore } from '../../stores/orders/OrderStore.js';
|
|
34
|
+
import { getProcessInstanceId } from '../../stores/orders/OrderHelpers.js';
|
|
35
|
+
|
|
36
|
+
interface CancelOrderDialogProps {
|
|
37
|
+
open: boolean;
|
|
38
|
+
onClose: () => void;
|
|
39
|
+
order: TerminalProductOrder;
|
|
40
|
+
orderStore: OrdersStore;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const CancelOrderDialog: React.FC<CancelOrderDialogProps> = observer(
|
|
44
|
+
({ open, onClose, order, orderStore }) => {
|
|
45
|
+
const [cancellationReason, setCancellationReason] = useState('');
|
|
46
|
+
|
|
47
|
+
const isLoading = orderStore.cancelOrderState.isInProgress;
|
|
48
|
+
const trimmedReason = cancellationReason.trim();
|
|
49
|
+
const isReasonValid = trimmedReason.length > 0;
|
|
50
|
+
|
|
51
|
+
const handleClose = (): void => {
|
|
52
|
+
if (!isLoading) {
|
|
53
|
+
setCancellationReason('');
|
|
54
|
+
onClose();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const handleConfirm = async (): Promise<void> => {
|
|
59
|
+
if (!isReasonValid) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const processInstanceId = getProcessInstanceId(order);
|
|
64
|
+
if (!processInstanceId) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const success = await flowResult(
|
|
69
|
+
orderStore.cancelOrder(
|
|
70
|
+
order.order_id,
|
|
71
|
+
processInstanceId,
|
|
72
|
+
trimmedReason,
|
|
73
|
+
),
|
|
74
|
+
);
|
|
75
|
+
if (success) {
|
|
76
|
+
handleClose();
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<Dialog
|
|
82
|
+
open={open}
|
|
83
|
+
onClose={handleClose}
|
|
84
|
+
maxWidth="sm"
|
|
85
|
+
fullWidth={true}
|
|
86
|
+
className="legend-marketplace-cancel-order-dialog"
|
|
87
|
+
>
|
|
88
|
+
<DialogTitle>
|
|
89
|
+
<Box className="legend-marketplace-cancel-order-dialog__title">
|
|
90
|
+
<WarningIcon className="legend-marketplace-cancel-order-dialog__warning-icon" />
|
|
91
|
+
<Typography variant="h6">Cancel Order</Typography>
|
|
92
|
+
</Box>
|
|
93
|
+
</DialogTitle>
|
|
94
|
+
|
|
95
|
+
<DialogContent>
|
|
96
|
+
<Box className="legend-marketplace-cancel-order-dialog__content">
|
|
97
|
+
<Typography className="legend-marketplace-cancel-order-dialog__message">
|
|
98
|
+
Are you sure you want to cancel this order?
|
|
99
|
+
</Typography>
|
|
100
|
+
|
|
101
|
+
<Box className="legend-marketplace-cancel-order-dialog__order-info">
|
|
102
|
+
<Typography variant="body2">
|
|
103
|
+
<strong>Order ID:</strong> {order.order_id}
|
|
104
|
+
</Typography>
|
|
105
|
+
<Typography variant="body2">
|
|
106
|
+
<strong>Vendor:</strong> {order.vendor_name}
|
|
107
|
+
</Typography>
|
|
108
|
+
<Typography variant="body2">
|
|
109
|
+
<strong>Order Type:</strong> {order.order_type}
|
|
110
|
+
</Typography>
|
|
111
|
+
</Box>
|
|
112
|
+
|
|
113
|
+
<TextField
|
|
114
|
+
autoFocus={true}
|
|
115
|
+
margin="dense"
|
|
116
|
+
label="Cancellation Reason"
|
|
117
|
+
placeholder="Please provide a reason for canceling this order..."
|
|
118
|
+
fullWidth={true}
|
|
119
|
+
multiline={true}
|
|
120
|
+
rows={4}
|
|
121
|
+
value={cancellationReason}
|
|
122
|
+
onChange={(e) => setCancellationReason(e.target.value)}
|
|
123
|
+
disabled={isLoading}
|
|
124
|
+
required={true}
|
|
125
|
+
helperText="Required: Please explain why you are canceling this order"
|
|
126
|
+
error={cancellationReason.length > 0 && !isReasonValid}
|
|
127
|
+
className="legend-marketplace-cancel-order-dialog__text-field"
|
|
128
|
+
/>
|
|
129
|
+
</Box>
|
|
130
|
+
</DialogContent>
|
|
131
|
+
|
|
132
|
+
<DialogActions className="legend-marketplace-cancel-order-dialog__actions">
|
|
133
|
+
<Button
|
|
134
|
+
onClick={handleClose}
|
|
135
|
+
disabled={isLoading}
|
|
136
|
+
variant="text"
|
|
137
|
+
color="inherit"
|
|
138
|
+
>
|
|
139
|
+
Cancel
|
|
140
|
+
</Button>
|
|
141
|
+
<Button
|
|
142
|
+
onClick={() => {
|
|
143
|
+
// eslint-disable-next-line no-void
|
|
144
|
+
void handleConfirm();
|
|
145
|
+
}}
|
|
146
|
+
disabled={isLoading || !isReasonValid}
|
|
147
|
+
variant="contained"
|
|
148
|
+
color="error"
|
|
149
|
+
startIcon={isLoading ? <CircularProgress size={16} /> : undefined}
|
|
150
|
+
>
|
|
151
|
+
{isLoading ? 'Canceling...' : 'Confirm Cancellation'}
|
|
152
|
+
</Button>
|
|
153
|
+
</DialogActions>
|
|
154
|
+
</Dialog>
|
|
155
|
+
);
|
|
156
|
+
},
|
|
157
|
+
);
|