forked from folio-org/ui-requests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserDetail.js
58 lines (51 loc) · 1.52 KB
/
UserDetail.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
import React from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router-dom';
import { Row, Col } from '@folio/stripes-components/lib/LayoutGrid';
import KeyValue from '@folio/stripes-components/lib/KeyValue';
import { getFullName } from './utils';
const UserDetail = (props) => {
if (props.error) {
return <div style={{ color: 'red' }}>{props.error}</div>;
}
const patronGroups = (props.patronGroups || {}).records || [];
const user = props.user || {};
const patronGroupId = user.patronGroup || {};
const requesterGroup = (patronGroups.find(g => g.id === patronGroupId) || {}).group || '';
const path = `/users/view/${user.id}`;
return (
<div>
<br />
<Row>
<Col xs={12}>
<KeyValue label="Requester name" value={<Link to={path}>{getFullName(user)}</Link>} />
</Col>
</Row>
<Row>
<Col xs={12}>
<KeyValue label="Barcode" value={user.barcode ? <Link to={path}>{user.barcode}</Link> : ''} />
</Col>
</Row>
<Row>
<Col xs={12}>
<KeyValue label="Patron group" value={requesterGroup} />
</Col>
</Row>
</div>
);
};
UserDetail.propTypes = {
error: PropTypes.string,
patronGroups: PropTypes.shape({
hasLoaded: PropTypes.bool.isRequired,
isPending: PropTypes.bool.isPending,
other: PropTypes.shape({
totalRecords: PropTypes.number,
}),
}).isRequired,
user: PropTypes.object.isRequired,
};
UserDetail.defaultProps = {
error: '',
};
export default UserDetail;