index.tsx 2.43 KB
Newer Older
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import * as React from 'react';
import {translate} from 'react-i18next';
import {Field, reduxForm} from 'redux-form';

// constants
import {PARAMETER_FORM} from 'kpi/constants';

// util
import Validators from 'utilities/Validators';

// ui
import Button from '@material-ui/core/Button';
import {TextField} from 'ui/common/text-field';

class ParameterForm extends React.Component<any, void> {

  public constructor(props: any) {
    super(props);
  }

  public render() {
    const {t, onCancel, error, handleSubmit, submitting, invalid, onDelete, nameDisabled} = this.props;

    return (
      <form onSubmit={ handleSubmit }>
        <div>
          <Field name={ `name` }
                 component={ TextField }
                 type="text"
                 label={ t(`common:label.name`) }
                 validate={ [Validators.required] }
                 disabled={ nameDisabled }
          />
          <Field name={ `title` }
                 component={ TextField }
                 type="text"
                 label={ t(`common:label.title`) }
                 validate={ [Validators.required] }
          />
          <Field name={ `description` }
                 component={ TextField }
                 type="text"
                 label={ t(`kpi.admin.c.parameterForm.description`) }
          />
          <Field name={ `condition` }
                 component={ TextField }
                 type="text"
                 label={ t(`kpi.admin.c.parameterForm.condition`) }
          />
          <Field name={ `entity` }
                 component={ TextField }
                 type="text"
                 label={ t(`kpi.admin.c.parameterForm.entity`) }
                 validate={ [Validators.required] }
          />
        </div>

        { error && <div style={ {color: 'red'} }>{ error }</div> }
59
        <Button variant="contained" type="submit" style={ {marginRight: '1rem', marginTop: '1rem'} } disabled={ submitting || invalid }>{ t('common:action.save') }</Button>
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
60
        { onDelete &&
61
        <Button variant="contained" type="button" style={ {marginRight: '1rem', marginTop: '1rem'} } onClick={ onDelete }>{ t('common:action.delete') }</Button>
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
62
        }
63
        <Button variant="contained" type="button" style={ {marginLeft: '1rem', marginTop: '1rem'} } onClick={ onCancel }>{ t('common:action.cancel') }</Button>
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
64
65
66
67
68
69
70
71
72
      </form>
    );
  }
}

export default translate()(reduxForm({
  form: PARAMETER_FORM,
  enableReinitialize: true,
})(ParameterForm));