BasicInfoForm.tsx 3.69 KB
Newer Older
1 2 3 4 5 6 7 8 9
import * as React from 'react';
import { Field, reduxForm, FieldArray } from 'redux-form';
import { translate } from 'react-i18next';

import { saveDataset } from 'datasets/actions/editor';

import { DATASET_BASIC_INFO_FORM } from 'datasets/constants';

import { TextField } from 'ui/common/text-field';
Matija Obreza's avatar
Matija Obreza committed
10
import { MarkdownField } from 'ui/common/markdown';
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
import SelectPartner from 'partners/ui/c/SelectPartner';
import CropSelector from 'crop/ui/c/CropSelector';

import Validators from 'utilities/Validators';

import LicenseSelector from 'ui/genesys/LicenseSelector';
import VocabularyTermPicker from 'vocabulary/ui/c/VocabularyTermPicker';

interface ILoginContainerProps extends React.ClassAttributes<any> {
  handleSubmit: () => void;
  initialValues: any;
  classes: any;
  uuid: string;
  t: any;
}

class BasicInfoStep extends React.Component<ILoginContainerProps, any> {

  public render() {

    const { initialValues, handleSubmit, t } = this.props;

    return (
      <form onSubmit={ handleSubmit } className="p-20 m-20 even-row">
        <Field required
               name="owner"
               component={ SelectPartner }
               onlyMine
               label="datasets.dashboard.p.stepper.basicInfo.partner.label"
               placeholder={ t('datasets.dashboard.p.stepper.basicInfo.partner.placeholder') }
               editable={ !(initialValues.uuid && initialValues.version) }
               validate={ [Validators.required] }
        />
        <Field required
               name="title"
               basicMarkdown
               component={ MarkdownField }
               label={ t('datasets.dashboard.p.stepper.basicInfo.titleField.label') }
               placeholder={ t('datasets.dashboard.p.stepper.basicInfo.titleField.placeholder') }
               validate={ [Validators.required] }
        />
        <Field required
               name="versionTag"
               component={ TextField }
               label={ t('datasets.dashboard.p.stepper.basicInfo.version.label') }
               placeholder="2018.1"
               validate={ [Validators.required] }
        />
        <Field
          name="description"
          component={ MarkdownField }
          label={ t('datasets.dashboard.p.stepper.basicInfo.description.label') }
          placeholder={ t('datasets.dashboard.p.stepper.basicInfo.description.placeholder') }
        />
        <Field
          name="created"
          component={ TextField }
          label={ t('datasets.dashboard.p.stepper.basicInfo.created.label') }
          placeholder={ t('datasets.dashboard.p.stepper.basicInfo.created.placeholder') }
          validate={ [Validators.mcpdDate] }
        />
        <Field
          name="rights"
          component={ LicenseSelector }
        />
        <Field
          name="language"
          component={ VocabularyTermPicker }
          label={ t('datasets.dashboard.p.stepper.basicInfo.language.label') }
          placeholder={ t('datasets.dashboard.p.stepper.basicInfo.language.placeholder') }
          suggestionLabel="title"
          vocabularyUuid="21b10067-ba15-44dd-867f-6a18a117fee8"
        />
        <Field
          name="source"
          component={ MarkdownField }
          label={ t('datasets.dashboard.p.stepper.basicInfo.source.label') }
          placeholder={ t('datasets.dashboard.p.stepper.basicInfo.source.placeholder') }
        />
        <FieldArray
          name="crops"
          component={ CropSelector }
          label={ t('datasets.dashboard.p.stepper.basicInfo.crops.label') }
        />
      </form>
    );
  }
}

export default translate()(reduxForm({
  form: DATASET_BASIC_INFO_FORM,
  onSubmit: (values, dispatch) => dispatch(saveDataset(values)),
  enableReinitialize: true,
})((BasicInfoStep)));