/** * * PopUpForm * */ import React from 'react'; import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap'; import { FormattedMessage } from 'react-intl'; import PropTypes from 'prop-types'; import { capitalize, get, findIndex, isArray, isObject, includes, map, tail, take, takeRight } from 'lodash'; // Translations import en from 'translations/en.json'; import Input from 'components/Input'; import styles from './styles.scss'; class PopUpForm extends React.Component { // eslint-disable-line react/prefer-stateless-function state = { enabled: false }; handleChange = (e) => { this.setState({ enabled: e.target.value }); this.props.onChange(e); } renderForm = () => { const { dataToEdit, settingType, values } = this.props; const form = Object.keys(values.options || values || {}).reduce((acc, current) => { const path = settingType === 'email-templates' ? ['options', current] : [ current ]; const name = settingType === 'email-templates' ? 'options.' : ''; if (isObject(get(values, path)) && !isArray(get(values, path))) { return Object.keys(get(values, path, {})) .reduce((acc, curr) => { acc.push(`${name}${current}.${curr}`); return acc; }, []).concat(acc); } else if (current !== 'icon' && current !== 'scope'){ acc.push(`${name}${current}`); } return acc; }, []); if (settingType === 'providers') { return (
{form.length > 1 ? (
) : ''} {map(tail(form), (value, key) => ( ))}
); } return (
{map(take(form, 3), (value, key) => ( ))}
{map(takeRight(form, 2), (value) => ( ))}
); } render() { const { display } = this.props.values; const { actionType, dataToEdit, settingType } = this.props; let header = {dataToEdit}; if (actionType) { header = {capitalize(dataToEdit)} }} />; } if (display && en[display]) { header = ; } return (
{header}
{this.renderForm()}
); } } PopUpForm.contextTypes = { unsetDataToEdit: PropTypes.func.isRequired, }; PopUpForm.defaultProps = { settingType: 'providers', // showLoader: false, }; PopUpForm.propTypes = { actionType: PropTypes.string.isRequired, dataToEdit: PropTypes.string.isRequired, didCheckErrors: PropTypes.bool.isRequired, formErrors: PropTypes.array.isRequired, isOpen: PropTypes.bool.isRequired, onChange: PropTypes.func.isRequired, onSubmit: PropTypes.func.isRequired, settingType: PropTypes.string, // showLoader: PropTypes.bool, values: PropTypes.object.isRequired, }; export default PopUpForm;