FolderForm.tsx 1.76 KB
Newer Older
Maxym Borodenko's avatar
Maxym Borodenko committed
1
import * as React from 'react';
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
2
import { translate } from 'react-i18next';
Maxym Borodenko's avatar
Maxym Borodenko committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import {Field, reduxForm} from 'redux-form';
import {TextField} from 'ui/common/text-field';
import Validators from 'utilities/Validators';
import Button from '@material-ui/core/Button';
import {EDIT_FOLDER_FORM} from 'repository/constants';

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

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

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

    return (
      <form onSubmit={ handleSubmit }>
        { edit ?
          <div>
            <Field name={ `title` }
              component={ TextField }
              type="text"
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
25
              label={ t(`common:label.title`) }
Maxym Borodenko's avatar
Maxym Borodenko committed
26
27
28
29
            />
            <Field name={ `description` }
              component={ TextField }
              type="text"
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
30
              label={ t(`common:label.description`) }
Maxym Borodenko's avatar
Maxym Borodenko committed
31
32
33
34
35
36
            />
          </div>
          :
          <Field name={ `name` }
            component={ TextField }
            type="text"
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
37
            label={ t(`repository.admin.c.folderForm.form.name`) }
Maxym Borodenko's avatar
Maxym Borodenko committed
38
39
40
41
42
43
            disabled={ edit }
            validate={ [ Validators.required ] }
          />
        }

        { error && <div style={ { color: 'red' } }>{ error }</div> }
44
45
        <Button variant="contained" type="submit" style={ { marginRight: '1rem', marginTop: '1rem' } } disabled={ submitting || invalid }>{ t('common:action.save') }</Button>
        <Button variant="contained" type="button" style={ { marginLeft: '1rem', marginTop: '1rem' } } onClick={ onCancel }>{ t('common:action.cancel') }</Button>
Maxym Borodenko's avatar
Maxym Borodenko committed
46
47
48
49
50
      </form>
    );
  }
}

Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
51
export default translate()(reduxForm({
Maxym Borodenko's avatar
Maxym Borodenko committed
52
53
  form: EDIT_FOLDER_FORM,
  enableReinitialize: true,
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
54
})(FolderForm));