/** * 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 type { TerminalProductOrder } from '@finos/legend-server-marketplace'; import type { OrdersStore } from '../../stores/orders/OrderStore.js'; import { getProcessInstanceId } from '../../stores/orders/OrderHelpers.js'; interface CancelOrderDialogProps { open: boolean; onClose: () => void; order: TerminalProductOrder; orderStore: OrdersStore; } export const CancelOrderDialog: React.FC = 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 = (): void => { if (!isLoading) { setCancellationReason(''); onClose(); } }; const handleConfirm = async (): Promise => { 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 ( Cancel Order Are you sure you want to cancel this order? Order ID: {order.order_id} Vendor: {order.vendor_name} Order Type: {order.order_type} 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" /> ); }, );