forked from folio-org/ui-users
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoansHistory.js
111 lines (103 loc) · 3.59 KB
/
LoansHistory.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 { Row, Col } from '@folio/stripes-components/lib/LayoutGrid';
import Paneset from '@folio/stripes-components/lib/Paneset';
import Pane from '@folio/stripes-components/lib/Pane';
import PaneMenu from '@folio/stripes-components/lib/PaneMenu';
import TabButton from '@folio/stripes-components/lib/TabButton';
import IconButton from '@folio/stripes-components/lib/IconButton';
import { getFullName } from './util';
import OpenLoans from './lib/OpenLoans';
import ClosedLoans from './lib/ClosedLoans';
/**
* List a user's open or closed loans.
*
* Table-view of a user's loans, including links to the loan details and
* the loan's item-record.
*/
class LoansHistory extends React.Component {
static propTypes = {
stripes: PropTypes.shape({
locale: PropTypes.string.isRequired,
connect: PropTypes.func.isRequired,
}).isRequired,
resources: PropTypes.shape({
loansHistory: PropTypes.shape({
records: PropTypes.arrayOf(PropTypes.object),
}),
}),
onCancel: PropTypes.func.isRequired,
openLoans: PropTypes.bool,
onClickViewOpenLoans: PropTypes.func.isRequired,
onClickViewClosedLoans: PropTypes.func.isRequired,
user: PropTypes.object.isRequired,
patronGroup: PropTypes.object.isRequired,
};
static manifest = Object.freeze({
loansHistory: {
type: 'okapi',
records: 'loans',
path: 'circulation/loans?query=(userId=!{user.id}) sortby id&limit=100',
},
});
constructor(props) {
super(props);
this.connectedOpenLoans = props.stripes.connect(OpenLoans);
this.connectedClosedLoans = props.stripes.connect(ClosedLoans);
}
render() {
const { user, patronGroup, resources, openLoans } = this.props;
const loansHistory = _.get(resources, ['loansHistory', 'records']);
const loanStatus = openLoans ? 'Open' : 'Closed';
const loans = _.filter(loansHistory, loan => loanStatus === _.get(loan, ['status', 'name']));
if (!loans) return <div />;
const paneHeader = (
<Row style={{ width: '100%' }}>
<Col xs={1}>
<PaneMenu>
<IconButton
icon="closeX"
onClick={this.props.onCancel}
title="Close pane"
ariaLabel="Close Loans"
/>
</PaneMenu>
</Col>
<Col xs={1}>
<PaneMenu>
<TabButton title="Loans" aria-label="Loans">Loans</TabButton>
</PaneMenu>
</Col>
<Col xs={3}>
<TabButton title="Loans" aria-label="User Name and Patron Group">
{`Borrower: ${getFullName(user)} (${_.upperFirst(patronGroup.group)})`}
</TabButton>
</Col>
<Col xs={7}>
<PaneMenu>
<TabButton title="Open Loans" aria-label="Open Loans" onClick={this.props.onClickViewOpenLoans} selected={openLoans}>Open Loans</TabButton>
<TabButton title="Closed Loans" aria-label="Closed Loans" onClick={this.props.onClickViewClosedLoans} selected={!openLoans}>Closed Loans</TabButton>
</PaneMenu>
</Col>
</Row>
);
return (
<Paneset isRoot>
<Pane
padContent={false}
id="pane-loanshistory"
defaultWidth="100%"
dismissible
onClose={this.props.onCancel}
header={paneHeader}
>
{openLoans
? (<this.connectedOpenLoans loans={loans} {...this.props} />)
: (<this.connectedClosedLoans loans={loans} {...this.props} />)
}
</Pane>
</Paneset>);
}
}
export default LoansHistory;