index.tsx 2.24 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
import * as React from 'react';
import {translate} from 'react-i18next';
import {Field, reduxForm} from 'redux-form';

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

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

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

class DimensionForm 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.dimensionForm.description`) }
          />
          <Field name={ `_fullClass` }
                 component={ DimensionTypeSelector }
                 label={ t(`kpi.admin.c.dimensionForm.type`) }
          />
        </div>
        { error && <div style={ {color: 'red'} }>{ error }</div> }
52
        <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
53
        { onDelete &&
54
          <Button variant="contained" type="button" style={ {marginRight: '1rem', marginTop: '1rem'} } onClick={ onDelete }>{ t('common:action.delete') }</Button>
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
55
        }
56
        <Button variant="contained" type="button" style={ {marginLeft: '1rem', marginTop: '1rem'} } onClick={ onCancel }>{ t('common:action.cancel') }</Button>
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
57
58
59
60
61
62
63
64
65
      </form>
    );
  }
}

export default translate()(reduxForm({
  form: DIMENSION_FORM,
  enableReinitialize: true,
})(DimensionForm));