|
|
@ -10,12 +10,26 @@ interface ModalWrapperProps extends ModalDialogProps { |
|
|
|
const ModalWrapper = (props: ModalWrapperProps) => { |
|
|
|
const ModalWrapper = (props: ModalWrapperProps) => { |
|
|
|
const [state, setState] = useState<ModalDialogProps>() |
|
|
|
const [state, setState] = useState<ModalDialogProps>() |
|
|
|
const ref = useRef() |
|
|
|
const ref = useRef() |
|
|
|
|
|
|
|
const formRef = useRef() |
|
|
|
const data = useRef() |
|
|
|
const data = useRef() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getFormData = () => { |
|
|
|
|
|
|
|
if (formRef.current) { |
|
|
|
|
|
|
|
const formData = new FormData(formRef.current) |
|
|
|
|
|
|
|
const data = {} |
|
|
|
|
|
|
|
for (const pair of formData.entries()) { |
|
|
|
|
|
|
|
data[pair[0]] = pair[1] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return data |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const onFinishPrompt = async () => { |
|
|
|
const onFinishPrompt = async () => { |
|
|
|
if (ref.current === undefined) { |
|
|
|
if (ref.current === undefined && formRef.current === undefined) { |
|
|
|
onOkFn() |
|
|
|
onOkFn() |
|
|
|
} else { |
|
|
|
} else if (formRef.current) { |
|
|
|
|
|
|
|
(props.okFn) ? props.okFn(getFormData()) : props.resolve(getFormData()) |
|
|
|
|
|
|
|
} else if(ref.current) { |
|
|
|
// @ts-ignore: Object is possibly 'null'.
|
|
|
|
// @ts-ignore: Object is possibly 'null'.
|
|
|
|
(props.okFn) ? props.okFn(ref.current.value) : props.resolve(ref.current.value) |
|
|
|
(props.okFn) ? props.okFn(ref.current.value) : props.resolve(ref.current.value) |
|
|
|
} |
|
|
|
} |
|
|
@ -43,7 +57,27 @@ const ModalWrapper = (props: ModalWrapperProps) => { |
|
|
|
<> |
|
|
|
<> |
|
|
|
{props.message} |
|
|
|
{props.message} |
|
|
|
<input onChange={onInputChanged} type={props.modalType === ModalTypes.password ? 'password' : 'text'} defaultValue={defaultValue} data-id="modalDialogCustomPromp" ref={ref} className="form-control" /> |
|
|
|
<input onChange={onInputChanged} type={props.modalType === ModalTypes.password ? 'password' : 'text'} defaultValue={defaultValue} data-id="modalDialogCustomPromp" ref={ref} className="form-control" /> |
|
|
|
{!validation.valid && <span className='text-warning'>{validation.message}</span>} |
|
|
|
{validation && !validation.valid && <span className='text-warning'>{validation.message}</span>} |
|
|
|
|
|
|
|
</> |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const onFormChanged = () => { |
|
|
|
|
|
|
|
if (props.validationFn) { |
|
|
|
|
|
|
|
const validation = props.validationFn(getFormData()) |
|
|
|
|
|
|
|
setState(prevState => { |
|
|
|
|
|
|
|
return { ...prevState, message: createForm(validation), validation } |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const createForm = (validation: ValidationResult) => { |
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
|
|
<> |
|
|
|
|
|
|
|
<form onChange={onFormChanged} ref={formRef}> |
|
|
|
|
|
|
|
{props.message} |
|
|
|
|
|
|
|
</form> |
|
|
|
|
|
|
|
{validation && !validation.valid && <span className='text-warning'>{validation.message}</span>} |
|
|
|
</> |
|
|
|
</> |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
@ -61,6 +95,14 @@ const ModalWrapper = (props: ModalWrapperProps) => { |
|
|
|
message: createModalMessage(props.defaultValue, { valid: true }) |
|
|
|
message: createModalMessage(props.defaultValue, { valid: true }) |
|
|
|
}) |
|
|
|
}) |
|
|
|
break |
|
|
|
break |
|
|
|
|
|
|
|
case ModalTypes.form: |
|
|
|
|
|
|
|
setState({ |
|
|
|
|
|
|
|
...props, |
|
|
|
|
|
|
|
okFn: onFinishPrompt, |
|
|
|
|
|
|
|
cancelFn: onCancelFn, |
|
|
|
|
|
|
|
message: createForm({ valid: true }) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
break |
|
|
|
default: |
|
|
|
default: |
|
|
|
setState({ |
|
|
|
setState({ |
|
|
|
...props, |
|
|
|
...props, |
|
|
|