import React, { useState } from 'react'; import { Button, Form, ModalBody, ModalFooter, ModalHeader, TextArea } from '@carbon/react'; import { useTranslation } from 'react-i18next'; import styles from './reject-order-dialog.scss'; import { type Result } from '../../work-list/work-list.resource'; import { showNotification, showSnackbar } from '@openmrs/esm-framework'; import { mutate } from 'swr'; import { updateOrder } from '../pick-imaging-order/add-to-worklist-dialog.resource'; import capitalize from 'lodash-es/capitalize'; interface RejectOrderModalProps { order: Result; closeModal: () => void; } const RejectOrderModal: React.FC = ({ order, closeModal }) => { const { t } = useTranslation(); const [notes, setNotes] = useState(''); const rejectOrder = async (event) => { event.preventDefault(); const payload = { fulfillerStatus: 'DECLINED', fulfillerComment: notes, }; updateOrder(order.uuid, payload).then( () => { showSnackbar({ isLowContrast: true, title: t('rejectOrder', 'Rejected Order'), kind: 'success', subtitle: t( 'successfullyRejected', `You have successfully rejected an Order with OrderNumber {{orderNumber}} `, { orderNumber: order.orderNumber }, ), }); closeModal(); mutate((key) => typeof key === 'string' && key.startsWith('/ws/rest/v1/order'), undefined, { revalidate: true, }); }, (err) => { showNotification({ title: t(`errorRejecting order', 'Error Rejecting a order`), kind: 'error', critical: true, description: err?.message, }); }, ); }; const orderName = capitalize(order?.concept?.display); const orderNumber = order?.orderNumber; return (

{t('rejectImagingOrder', 'Reject Imaging Order')}

{t('confirmationRejectMessages', `Do you want to reject this order: {{orderName}} - {{orderNumber}}?`, { orderName, orderNumber, })}