BrowsePage.tsx 2.19 KB
Newer Older
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
1
2
3
import * as React from 'react';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
4
import { translate } from 'react-i18next';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
5

Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
6
7
8
// Actions
import {createCrop} from 'crop/actions/admin';

Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
9
// Models
Matija Obreza's avatar
Matija Obreza committed
10
import CropDetails from 'model/genesys/CropDetails';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
11
12

// UI
13
import PageLayout, { PageContents } from 'ui/layout/PageLayout';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
14
import ContentHeader from 'ui/common/heading/ContentHeader';
15
import CropCard from 'crop/ui/c/CropCard';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
16
import GridContainer from 'ui/layout/GridContainer';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
17
18
19
import ContentHeaderWithButton from 'ui/common/heading/ContentHeaderWithButton';
import ActionButton from 'ui/common/buttons/ActionButton';
import Authorize from 'ui/common/authorized/Authorize';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
20
import PageTitle from 'ui/common/PageTitle';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
21
22

interface IBrowsePageProps extends React.ClassAttributes<any> {
Matija Obreza's avatar
Matija Obreza committed
23
  crops: CropDetails[];
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
24
  t: any;
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
25
  createCrop: any;
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
26
27
28
29
}

class BrowsePage extends React.Component<IBrowsePageProps> {

Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
30
31
32
33
34
  private addNewCropHandle = () => {
    const {createCrop} = this.props;
    createCrop();
  }

Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
35
  public render() {
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
36
    const {crops, t} = this.props;
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
37
38
39

    return (
      <PageLayout>
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
40
        <PageTitle title={ t('crop.public.p.browse.title') } />
Matija Obreza's avatar
Matija Obreza committed
41
        <ContentHeader title={ t('crop.public.p.browse.title') } subTitle={ t('crop.public.p.browse.subTitle') } />
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
42
        <Authorize role="ROLE_ADMINISTRATOR">
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
43
44
45
46
47
48
          <ContentHeaderWithButton
            isSecondary
            buttons={
              <div>
                <ActionButton title={ t('crop.public.p.browse.createCrop') } action={ this.addNewCropHandle }/>
              </div>
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
49
          }/>
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
50
        </Authorize>
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
51
52
        <PageContents className="pt-1rem">
          <GridContainer>
Matija Obreza's avatar
Matija Obreza committed
53
            { crops && crops.sort((a, b) => a.name.localeCompare(b.name)).map((crop) => <CropCard key={ crop.shortName } crop={ crop } compact />) }
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
54
          </GridContainer>
55
        </PageContents>
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
56
57
58
59
60
61
      </PageLayout>
    );
  }
}

const mapStateToProps = (state, ownProps) => ({
62
  crops: state.crop.public.list || undefined,
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
63
64
65
  filterCode: ownProps.match.params.filterCode,
});

Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
66
67
68
const mapDispatchToProps = (dispatch) => bindActionCreators({
  createCrop,
}, dispatch);
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
69
70


Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
71
export default connect(mapStateToProps, mapDispatchToProps)(translate()(BrowsePage));