index.tsx 2.51 KB
Newer Older
1
import * as React from 'react';
Matija Obreza's avatar
Matija Obreza committed
2 3
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
4
import { WithTranslation, withTranslation } from 'react-i18next';
5

6 7
import { loadAccessionsByUUIDs } from 'list/actions/public';

8 9 10
// ui
import StepperTemplate from 'ui/common/stepper/StepperTemplate';
import Markdown from 'ui/common/markdown';
11
import { Button } from '@material-ui/core';
12

Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
13
interface IAccessionsListStep extends React.ClassAttributes<any>, WithTranslation {
14
  myList: any;
15
  requestInfo: any;
16
  loadAccessionsByUUIDs: () => void;
17 18 19 20 21 22
}

class ConfirmStep extends StepperTemplate<IAccessionsListStep> {


  public componentWillMount() {
23
    const { myList: { accessionUuids, loaded }, requestInfo, loadAccessionsByUUIDs } = this.props;
24
    this.setDisabledActions(!requestInfo || !accessionUuids || accessionUuids.length === 0  || (!requestInfo.internalRequest && requestInfo.preacceptSMTA !== 'true'));
25 26 27 28

    if (accessionUuids.length !== 0 && loaded.length === 0) {
      loadAccessionsByUUIDs();
    }
29 30 31
  }

  public componentWillReceiveProps(nextProps) {
32 33
    const { myList: { accessionUuids }, requestInfo } = nextProps;
    this.setDisabledActions(!requestInfo || !accessionUuids || accessionUuids.length === 0  || (!requestInfo.internalRequest && requestInfo.preacceptSMTA !== 'true'));
34 35
  }

36 37 38 39
  protected renderActions = (props) => {
    const {onPublish, t, classes, disabled} = props;

    return (
40
      <Button disabled={ disabled || this.countAvailable() === 0 } variant="contained" onClick={ onPublish } className={ classes.btnBlue }>
41 42 43 44 45
        { t('requests.public.p.stepper.confirm.submit') }
      </Button>
    );
  }

46 47 48 49 50 51 52 53
  private countAvailable = () => {
    const { myList: { accessionUuids, loaded } } = this.props;
    if (accessionUuids.length === loaded.length) {
      return loaded.filter((accession) => accession.available && accession.institute.allowMaterialRequests).length;
    } else {
      return 0;
    }
  }
54

55
  protected renderContent = () => {
Matija Obreza's avatar
Matija Obreza committed
56 57 58
    const { t } = this.props;
    return (
      <div className="p-20">
Viacheslav Pavlov's avatar
i18n  
Viacheslav Pavlov committed
59
        <Markdown source={ t('requests.public.p.stepper.confirm.instructions') } />
Matija Obreza's avatar
Matija Obreza committed
60 61
      </div>
    );
62 63 64 65 66
  }


}
const mapStateToProps = (state, ownProps) => ({
67
  myList: state.list.public.myList,
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
68
  requestInfo: state.requests.public.requestInfo ? state.requests.public.requestInfo.data : undefined,
69 70 71
});

const mapDispatchToProps = (dispatch) => bindActionCreators({
72
  loadAccessionsByUUIDs,
73 74 75 76
}, dispatch);

export default connect(
  mapStateToProps, mapDispatchToProps,
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
77
)(withTranslation()(ConfirmStep));