import React, { useState } from 'react'; import { Button, Form, ModalBody, ModalFooter, ModalHeader, Checkbox, TextInput } from '@carbon/react'; import { useTranslation } from 'react-i18next'; import styles from './add-to-worklist-dialog.scss'; import { showNotification, showSnackbar } from '@openmrs/esm-framework'; import { updateOrder } from './add-to-worklist-dialog.resource'; import { type Result } from '../../work-list/work-list.resource'; import { mutate } from 'swr'; import capitalize from 'lodash-es/capitalize'; interface AddImagingToWorkListModalProps { queueId; order: Result; closeModal: () => void; } const AddImagingToWorkListModal: React.FC = ({ order, closeModal }) => { const { t } = useTranslation(); const [isReferredChecked, setIsReferredChecked] = useState(false); const [referredLocation, setReferredLocation] = useState(''); const pickImagingOrder = async (event) => { event.preventDefault(); const body = { fulfillerComment: '', fulfillerStatus: isReferredChecked ? 'EXCEPTION' : 'IN_PROGRESS', }; try { const response = await updateOrder(order.uuid, body); if (response.ok) { showSnackbar({ isLowContrast: true, title: t('pickedAnOrder', 'Picked an order'), kind: 'success', subtitle: t('pickSuccessfully', 'You have successfully picked an Order'), }); mutate((key) => typeof key === 'string' && key.startsWith('/ws/rest/v1/order'), undefined, { revalidate: true, }); closeModal(); } } catch (error) { showNotification({ title: t(`errorPicking an order', 'Error Picking an Order`), kind: 'error', critical: true, description: error?.message, }); } }; const handleCheckboxChange = () => { setIsReferredChecked(!isReferredChecked); }; const orderName = capitalize(order?.concept?.display); const orderNumber = order?.orderNumber; return (

{t('pickRequest', 'Pick Request')}

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

{isReferredChecked && ( setReferredLocation(e.target.value)} /> )}
); }; export default AddImagingToWorkListModal;