/* eslint-disable react/display-name */ import React from 'react'; import { Dialog, Input } from '@ohif/ui'; import RESPONSE from './PROMPT_RESPONSES'; export default function createReportDialogPrompt(UIDialogService) { return new Promise(function(resolve, reject) { let dialogId = undefined; const _handleClose = () => { // Dismiss dialog UIDialogService.dismiss({ id: dialogId }); // Notify of cancel action resolve({ action: RESPONSE.CANCEL, value: undefined }); }; /** * * @param {string} param0.action - value of action performed * @param {string} param0.value - value from input field */ const _handleFormSubmit = ({ action, value }) => { UIDialogService.dismiss({ id: dialogId }); switch (action.id) { case 'save': resolve({ action: RESPONSE.CREATE_REPORT, value: value.label }); break; case 'cancel': resolve({ action: RESPONSE.CANCEL, value: undefined }); break; } }; dialogId = UIDialogService.create({ centralize: true, isDraggable: false, content: Dialog, useLastPosition: false, showOverlay: true, contentProps: { title: 'Provide a name for your report', value: { label: '' }, noCloseButton: true, onClose: _handleClose, actions: [ { id: 'cancel', text: 'Cancel', type: 'primary' }, { id: 'save', text: 'Save', type: 'secondary' }, ], // TODO: Should be on button press... onSubmit: _handleFormSubmit, body: ({ value, setValue }) => { const onChangeHandler = event => { event.persist(); setValue(value => ({ ...value, label: event.target.value })); }; const onKeyPressHandler = event => { if (event.key === 'Enter') { UIDialogService.dismiss({ id: dialogId }); resolve({ action: RESPONSE.CREATE_REPORT, value: value.label }); } }; return (
); }, }, }); }); }