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

// Actions
7
import {loadMaterialRequest, sendValidationEmailAction, recheckPidAction, validateRequestAction} from 'requests/actions/admin';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
8
9

// Models
10
import MaterialRequest from 'model/request/MaterialRequest';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
11
12
13
14
15
16
17
18
19

// UI
import ContentHeaderWithButton from 'ui/common/heading/ContentHeaderWithButton';
import {MainSection, PageContents, PageSection} from 'ui/layout/PageLayout';
import {Properties, PropertiesItem} from 'ui/common/Properties';
import Loading from 'ui/common/Loading';
import PrettyDate from 'ui/common/time/PrettyDate';
import ActionButton from 'ui/common/buttons/ActionButton';
import BackButton from 'ui/common/buttons/BackButton';
Matija Obreza's avatar
Matija Obreza committed
20
import Markdown from 'ui/catalog/markdown';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
21
22
23
24
25
26
27

interface IDisplayPageProps extends React.ClassAttributes<any> {
  t: any;
  requestId: string;
  request: MaterialRequest;
  error: any;
  loadMaterialRequest: any;
Matija Obreza's avatar
Matija Obreza committed
28
  recheckPid: any;
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
29
  validateRequest: any;
Matija Obreza's avatar
Matija Obreza committed
30
  sendValidationEmail: any;
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
}

class DisplayPage extends React.Component<IDisplayPageProps, any> {

  constructor(props: IDisplayPageProps, context: any) {
    super(props, context);
  }

  public componentWillMount() {
    const {requestId, request, loadMaterialRequest} = this.props;
    if (requestId && (!request || requestId !== request.uuid)) {
      loadMaterialRequest(requestId);
    }
  }

  public render() {

Matija Obreza's avatar
Matija Obreza committed
48
    const {request, t, recheckPid, sendValidationEmail, validateRequest} = this.props;
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
49
50
51
52
53


    return request === null ? (<Loading/>) : (
      <div>
        <ContentHeaderWithButton
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
54
          title={ t('requests.admin.p.display.title', {email: request.email}) }
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
55
56
          buttons={
            <div>
Matija Obreza's avatar
Matija Obreza committed
57
58
59
              <ActionButton title={ t('requests.admin.p.display.sendValidationEmail') } action={ () => sendValidationEmail(request.uuid) }/>
              <ActionButton title={ t('requests.admin.p.display.validateRequest') } action={ () => validateRequest(request.uuid) }/>
              <ActionButton title={ t('requests.admin.p.display.recheckPID') } action={ () => recheckPid(request.uuid) }/>
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
60
61
62
63
64
65
              <BackButton defaultTarget="/admin/requests"/>
            </div>
          }
        />
        { request.body &&
          <PageContents>
66
            <MainSection title={ t('requests.admin.p.display.requestInformation') }>
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
67
              <Properties>
68
69
70
71
72
                <PropertiesItem title={ t('user.common.email') }>{ request.email }</PropertiesItem>
                <PropertiesItem title={ t('requests.common.stateLabel') }>{ t(`requests.common.state.${request.state}`) }</PropertiesItem>
                <PropertiesItem title={ t('common:label.created') }><PrettyDate value={ request.createdDate }/></PropertiesItem>
                { request.body.pid && <PropertiesItem title={ t('requests.common.typeLabel') }>{ t(`requests.common.type.${request.body.pid.type}`) }</PropertiesItem> }
                { request.body.requestInfo && <PropertiesItem title={ t('requests.common.purposeTypeLabel') }>{ t(`requests.common.purposeType.${request.body.requestInfo.purposeType}`) }</PropertiesItem> }
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
73
                { request.body.requestInfo && <PropertiesItem title={ t(`requests.common.preacceptSMTA`) }>{ request.body.requestInfo.preacceptSMTA ? 'Yes' : 'No' }</PropertiesItem> }
74
75
                { request.body.requestInfo && <PropertiesItem title={ t('requests.admin.p.display.notes') }>{ request.body.requestInfo.notes }</PropertiesItem> }
                <PropertiesItem title={ t('requests.admin.p.display.requestedAccessionIds') }>{ request.body.accessionIds.reduce((id, acc) => `${acc}, ${id}`) }</PropertiesItem>
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
76
77
78
              </Properties>
            </MainSection>
            { request.body.pid && request.body.pid.type === 'in' &&
79
              <PageSection title={ t('requests.admin.p.display.recipientPIDInformation') }>
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
80
                <Properties>
81
82
83
84
85
86
                  <PropertiesItem title={ t('user.common.name') }>{ request.body.pid.name }</PropertiesItem>
                  <PropertiesItem title={ t('user.common.surname') }>{ request.body.pid.surname }</PropertiesItem>
                  <PropertiesItem title={ t('geo.common.address') }><Markdown source={ request.body.pid.address.replace(/\n/g, '\n\n') } /></PropertiesItem>
                  <PropertiesItem title={ t('geo.common.country') }>{ request.body.pid.country }</PropertiesItem>
                  <PropertiesItem title={ t('user.common.phone') }>{ request.body.pid.telephone }</PropertiesItem>
                  <PropertiesItem title={ t('user.common.email') }>{ request.body.pid.email }</PropertiesItem>
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
87
88
89
90
                </Properties>
              </PageSection>
            }
            { request.body.pid && request.body.pid.type === 'or' &&
91
              <PageSection title={ t('requests.admin.p.display.recipientPIDInformation') }>
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
92
                <Properties>
93
94
95
                  <PropertiesItem title={ t('user.common.name') }>{ request.body.pid.orgName }</PropertiesItem>
                  <PropertiesItem title={ t('geo.common.address') }><Markdown source={ request.body.pid.orgAddress.replace(/\n/g, '\n\n') } /></PropertiesItem>
                  <PropertiesItem title={ t('geo.common.country') }>{ request.body.pid.orgCountry }</PropertiesItem>
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
96
97
98
                </Properties>
              </PageSection>
            }
Matija Obreza's avatar
Matija Obreza committed
99
            { request.body.pid && request.body.pid.shipAddrFlag !== 's' &&
100
              <PageSection title={ t('requests.admin.p.display.shippingAddress') }>
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
101
                <Properties>
102
103
104
                  <PropertiesItem title={ t('geo.common.address') }><Markdown source={ request.body.pid.shipAddress.replace(/\n/g, '\n\n') } /></PropertiesItem>
                  <PropertiesItem title={ t('geo.common.country') }>{ request.body.pid.shipCountry }</PropertiesItem>
                  <PropertiesItem title={ t('user.common.phone') }>{ request.body.pid.shipTelephone }</PropertiesItem>
Matija Obreza's avatar
Matija Obreza committed
105
106
107
108
109
                </Properties>
              </PageSection>
            }

            { request.subrequests && request.subrequests.length > 0 &&
110
              <PageSection title={ t('requests.admin.p.display.dispatchedTo') }>
Matija Obreza's avatar
Matija Obreza committed
111
112
113
114
115
116
117
118
                <Properties>
                { request.subrequests.map((sub) => (
                  <PropertiesItem key={ sub.uuid } title={ sub.instCode }>
                    <PrettyDate value={ sub.lastReminderDate } />
                    &rarr;
                    { sub.instEmail }
                  </PropertiesItem>
                )) }
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
119
120
121
122
123
124
125
126
127
128
129
                </Properties>
              </PageSection>
            }
          </PageContents>
        }
      </div>
    );
  }
}

const mapStateToProps = (state, ownProps) => ({
130
  request: state.requests.admin.request,
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
131
132
133
134
135
  requestId: ownProps.match.params.uuid,
});

const mapDispatchToProps = (dispatch) => bindActionCreators({
  loadMaterialRequest,
Matija Obreza's avatar
Matija Obreza committed
136
137
  recheckPid: recheckPidAction,
  sendValidationEmail: sendValidationEmailAction,
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
138
139
140
141
142
  validateRequest: validateRequestAction,
}, dispatch);


export default connect(mapStateToProps, mapDispatchToProps)((translate()(DisplayPage)));