forked from folio-org/ui-requests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItemDetail.js
111 lines (100 loc) · 3.21 KB
/
ItemDetail.js
1
2
3
4
5
6
7
8
9
10
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
105
106
107
108
109
110
111
import _ from 'lodash';
import React from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router-dom';
import KeyValue from '@folio/stripes-components/lib/KeyValue';
import { Row, Col } from '@folio/stripes-components/lib/LayoutGrid';
const ItemDetail = ({ item, error, patronGroups, dateFormatter }) => {
let recordLink;
let borrowerLink;
let borrowerName;
let borrowerGroup;
let itemRecord;
let loanRecord;
let borrowerRecord;
if (item) {
({ itemRecord, loanRecord, borrowerRecord } = item);
borrowerName = `${_.get(borrowerRecord, ['personal', 'firstName'], '')} ${_.get(borrowerRecord, ['personal', 'lastName'], '')}`;
borrowerGroup = (borrowerRecord &&
borrowerRecord.patronGroup &&
patronGroups.records &&
patronGroups.records.length > 0) ?
patronGroups.records.find(g => g.id === borrowerRecord.patronGroup).group : '';
if (itemRecord && loanRecord) {
recordLink = <Link to={`/inventory/view/${loanRecord.item.instanceId}/${loanRecord.item.holdingsRecordId}/${loanRecord.itemId}`}>{_.get(itemRecord, ['barcode'], '')}</Link>;
}
if (borrowerRecord) {
borrowerLink = <Link to={`/users/view/${borrowerRecord.id}`}>{borrowerName}</Link>;
}
}
if (error) {
return (
<div style={{ color: 'red' }}>
{error}
</div>
);
}
const location = _.get(itemRecord, ['temporaryLocation', 'name'], null) || _.get(itemRecord, ['permanentLocation', 'name'], '');
return (
<div>
<Row>
<Col xs={12}>
<KeyValue label="Item barcode" value={recordLink} />
</Col>
</Row>
<Row>
<Col xs={12}>
<KeyValue label="Title" value={_.get(itemRecord, ['title'], '')} />
</Col>
</Row>
<Row>
<Col xs={12}>
<KeyValue label="Shelving location" value={location} />
</Col>
</Row>
<h4>Current Loan</h4>
{item && loanRecord &&
<Row>
<Col xs={4}>
<KeyValue label="Loaned to" value={borrowerLink} />
</Col>
<Col xs={2}>
<KeyValue label="Patron group" value={borrowerGroup} />
</Col>
<Col xs={2}>
<KeyValue label="Status" value={_.get(itemRecord, ['status', 'name'], '') || _.get(loanRecord, ['status', 'name'])} />
</Col>
<Col xs={2}>
<KeyValue label="Current due date" value={dateFormatter(_.get(loanRecord, ['dueDate'], ''))} />
</Col>
<Col xs={2}>
<KeyValue label="Requests" value={_.get(item, ['requestCount'], '')} />
</Col>
</Row>
}
{item && !loanRecord &&
<Row>
<Col xs={12}>
<p>Item not checked out</p>
</Col>
</Row>
}
</div>
);
};
ItemDetail.propTypes = {
item: PropTypes.object.isRequired,
error: PropTypes.string,
patronGroups: PropTypes.shape({
hasLoaded: PropTypes.bool.isRequired,
isPending: PropTypes.bool.isPending,
other: PropTypes.shape({
totalRecords: PropTypes.number,
}),
}).isRequired,
dateFormatter: PropTypes.func.isRequired,
};
ItemDetail.defaultProps = {
error: '',
};
export default ItemDetail;