@finos/legend-application-marketplace
Version:
Legend Marketplace application core
52 lines • 4.25 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/**
* Copyright (c) 2025-present, Goldman Sachs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React, { useState } from 'react';
import { observer } from 'mobx-react-lite';
import { flowResult } from 'mobx';
import { Dialog, DialogTitle, DialogContent, DialogActions, Button, TextField, Typography, Box, CircularProgress, } from '@mui/material';
import { WarningIcon } from '@finos/legend-art';
import { getProcessInstanceId } from '../../stores/orders/OrderHelpers.js';
export const CancelOrderDialog = observer(({ open, onClose, order, orderStore }) => {
const [cancellationReason, setCancellationReason] = useState('');
const isLoading = orderStore.cancelOrderState.isInProgress;
const trimmedReason = cancellationReason.trim();
const isReasonValid = trimmedReason.length > 0;
const handleClose = () => {
if (!isLoading) {
setCancellationReason('');
onClose();
}
};
const handleConfirm = async () => {
if (!isReasonValid) {
return;
}
const processInstanceId = getProcessInstanceId(order);
if (!processInstanceId) {
return;
}
const success = await flowResult(orderStore.cancelOrder(order.order_id, processInstanceId, trimmedReason));
if (success) {
handleClose();
}
};
return (_jsxs(Dialog, { open: open, onClose: handleClose, maxWidth: "sm", fullWidth: true, className: "legend-marketplace-cancel-order-dialog", children: [_jsx(DialogTitle, { children: _jsxs(Box, { className: "legend-marketplace-cancel-order-dialog__title", children: [_jsx(WarningIcon, { className: "legend-marketplace-cancel-order-dialog__warning-icon" }), _jsx(Typography, { variant: "h6", children: "Cancel Order" })] }) }), _jsx(DialogContent, { children: _jsxs(Box, { className: "legend-marketplace-cancel-order-dialog__content", children: [_jsx(Typography, { className: "legend-marketplace-cancel-order-dialog__message", children: "Are you sure you want to cancel this order?" }), _jsxs(Box, { className: "legend-marketplace-cancel-order-dialog__order-info", children: [_jsxs(Typography, { variant: "body2", children: [_jsx("strong", { children: "Order ID:" }), " ", order.order_id] }), _jsxs(Typography, { variant: "body2", children: [_jsx("strong", { children: "Vendor:" }), " ", order.vendor_name] }), _jsxs(Typography, { variant: "body2", children: [_jsx("strong", { children: "Order Type:" }), " ", order.order_type] })] }), _jsx(TextField, { autoFocus: true, margin: "dense", label: "Cancellation Reason", placeholder: "Please provide a reason for canceling this order...", fullWidth: true, multiline: true, rows: 4, value: cancellationReason, onChange: (e) => setCancellationReason(e.target.value), disabled: isLoading, required: true, helperText: "Required: Please explain why you are canceling this order", error: cancellationReason.length > 0 && !isReasonValid, className: "legend-marketplace-cancel-order-dialog__text-field" })] }) }), _jsxs(DialogActions, { className: "legend-marketplace-cancel-order-dialog__actions", children: [_jsx(Button, { onClick: handleClose, disabled: isLoading, variant: "text", color: "inherit", children: "Cancel" }), _jsx(Button, { onClick: () => {
// eslint-disable-next-line no-void
void handleConfirm();
}, disabled: isLoading || !isReasonValid, variant: "contained", color: "error", startIcon: isLoading ? _jsx(CircularProgress, { size: 16 }) : undefined, children: isLoading ? 'Canceling...' : 'Confirm Cancellation' })] })] }));
});
//# sourceMappingURL=CancelOrderDialog.js.map