-
Notifications
You must be signed in to change notification settings - Fork 126
/
DocumentsFiled.jsx
204 lines (185 loc) · 6.63 KB
/
DocumentsFiled.jsx
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import PropTypes from 'prop-types';
import React, { useCallback, useState } from 'react';
import { VaPagination } from '@department-of-veterans-affairs/component-library/dist/react-bindings';
import moment from 'moment';
import { ITEMS_PER_PAGE } from '../../constants';
import { buildDateFormatter } from '../../utils/helpers';
const NEED_ITEMS_STATUS = 'NEEDED_FROM_';
const formatDate = buildDateFormatter();
const getTrackedItemText = item => {
if (item.status === 'INITIAL_REVIEW_COMPLETE' || item.status === 'ACCEPTED') {
return `Reviewed by VA on ${formatDate(item.receivedDate)}`;
}
if (item.status === 'NO_LONGER_REQUIRED' && item.closedDate !== null) {
return 'No longer needed';
}
if (item.status === 'SUBMITTED_AWAITING_REVIEW') {
return 'Pending review';
}
return null;
};
const generateDocsFiled = docsFiled => {
return docsFiled.map(document => {
if (document.id && document.status) {
return {
requestTypeText: `Request type: ${document.displayName}`,
documents: document.documents,
text: getTrackedItemText(document),
date:
document.documents.length !== 0
? document.documents[0].uploadDate || document.date
: document.date,
type: 'tracked_item',
};
}
return {
requestTypeText: 'Additional evidence',
documents: [
{
originalFileName: document.originalFileName,
documentTypeLabel: document.documentTypeLabel,
uploadDate: document.date,
},
],
text: null,
date: document.date,
type: 'additional_evidence_item',
};
});
};
const getSortedItems = itemsFiled => {
// Get items from trackedItems and additionalEvidence
const items = generateDocsFiled(itemsFiled);
return items.sort((item1, item2) => {
return moment(item2.date) - moment(item1.date);
});
};
const reviewed = text => {
return text?.includes('Reviewed');
};
const receivedDateExists = (uploadDate, itemDate) => {
return uploadDate !== null || (uploadDate === null && itemDate !== null);
};
const docsFiledDocType = (uploadDate, itemDate) =>
[
'vads-u-margin-top--0p5',
receivedDateExists(uploadDate, itemDate)
? 'vads-u-margin-bottom--0'
: 'vads-u-margin-bottom--1',
].join(' ');
function DocumentsFiled({ claim }) {
const { supportingDocuments, trackedItems } = claim.attributes;
const [currentPage, setCurrentPage] = useState(1);
// Get itemsFiled from trackedItems and supportingDocuments
const itemsFiled = trackedItems.filter(
item => !item.status.startsWith(NEED_ITEMS_STATUS),
);
itemsFiled.push(...supportingDocuments);
const items = getSortedItems(itemsFiled);
const pageLength = items.length;
const numPages = Math.ceil(pageLength / ITEMS_PER_PAGE);
const shouldPaginate = numPages > 1;
let currentPageItems = items;
if (shouldPaginate) {
const start = (currentPage - 1) * ITEMS_PER_PAGE;
const end = Math.min(currentPage * ITEMS_PER_PAGE, pageLength);
currentPageItems = items.slice(start, end);
}
const onPageSelect = useCallback(
selectedPage => {
setCurrentPage(selectedPage);
},
[setCurrentPage],
);
return (
<div className="documents-filed-container">
<h3 className="vads-u-margin-top--0 vads-u-margin-bottom--3">
Documents filed
</h3>
{currentPageItems.length === 0 ? (
<div>
<p>You haven’t turned in any documents to the VA.</p>
</div>
) : (
<>
{pageLength > 0 && (
<ol className="va-list-horizontal">
{currentPageItems.map((item, itemIndex) => (
<li
key={itemIndex}
className="vads-u-margin-bottom--2 vads-u-padding-bottom--1"
>
{item.documents.length === 0 ? (
<>
<h4 className="vads-u-margin-y--0">File name unknown</h4>
<p className="vads-u-margin-top--0p5 vads-u-margin-bottom--0">
{item.requestTypeText}
</p>
{item.date !== null && (
<p className="vads-u-margin-top--0p5 vads-u-margin-bottom--1">
{`Received on ${formatDate(item.date)}`}
</p>
)}
</>
) : (
item.documents.map((doc, index) => (
<div key={index}>
<h4 className="vads-u-margin-y--0">
{doc.originalFileName
? doc.originalFileName
: 'File name unknown'}
</h4>
<p className="vads-u-margin-top--0p5 vads-u-margin-bottom--0">
{item.requestTypeText}
</p>
<p
className={docsFiledDocType(
doc.uploadDate,
item.date,
)}
>
{`Document type: ${doc.documentTypeLabel}`}
</p>
{doc.uploadDate !== null && (
<p className="vads-u-margin-top--0p5 vads-u-margin-bottom--1">
{`Received on ${formatDate(doc.uploadDate)}`}
</p>
)}
{doc.uploadDate === null &&
item.date !== null && (
<p className="vads-u-margin-top--0p5 vads-u-margin-bottom--1">
{`Received on ${formatDate(item.date)}`}
</p>
)}
</div>
))
)}
{item.text && (
<div className="vads-u-margin-top--0 vads-u-margin-bottom--1">
{reviewed(item.text) && (
<i className="fa fa-check-circle docs-filed-icon" />
)}
<span className="docs-filed-text">{item.text}</span>
</div>
)}
</li>
))}
</ol>
)}
{shouldPaginate && (
<VaPagination
className="vads-u-border--0"
page={currentPage}
pages={numPages}
onPageSelect={e => onPageSelect(e.detail.page)}
/>
)}
</>
)}
</div>
);
}
DocumentsFiled.propTypes = {
claim: PropTypes.object,
};
export default DocumentsFiled;