1
|
|
|
import React, { useState } from "react"; |
2
|
|
|
import { FormattedMessage } from "react-intl"; |
3
|
|
|
import { Application, ApplicationReview } from "../../models/types"; |
4
|
|
|
import ApplicationRow from "./ApplicationRow"; |
5
|
|
|
import { |
6
|
|
|
applicationCompare, |
7
|
|
|
applicationComparePrioritizeVeterans, |
8
|
|
|
} from "./helpers"; |
9
|
|
|
import { Portal } from "../../models/app"; |
10
|
|
|
|
11
|
|
|
interface ApplicantBucketProps { |
12
|
|
|
title: string; |
13
|
|
|
description: string; |
14
|
|
|
applications: Application[]; |
15
|
|
|
handleUpdateReview: (review: ApplicationReview) => Promise<void>; |
16
|
|
|
prioritizeVeterans: boolean; |
17
|
|
|
portal: Portal; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
const ApplicantBucket: React.FC<ApplicantBucketProps> = ({ |
21
|
|
|
title, |
22
|
|
|
description, |
23
|
|
|
applications, |
24
|
|
|
handleUpdateReview, |
25
|
|
|
prioritizeVeterans, |
26
|
|
|
portal, |
27
|
|
|
}: ApplicantBucketProps): React.ReactElement | null => { |
28
|
|
|
const [isExpanded, setIsExpanded] = useState(false); |
29
|
|
|
|
30
|
|
|
if (applications.length === 0) { |
31
|
|
|
return null; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
const compareFunction = prioritizeVeterans |
35
|
|
|
? applicationComparePrioritizeVeterans |
36
|
|
|
: applicationCompare; |
37
|
|
|
const sortedApplications = applications.slice().sort(compareFunction); |
38
|
|
|
return ( |
39
|
|
|
<div className={`accordion applicant-bucket${isExpanded ? " active" : ""}`}> |
40
|
|
|
<button |
41
|
|
|
aria-expanded={isExpanded} |
42
|
|
|
className="accordion-trigger" |
43
|
|
|
tabIndex={0} |
44
|
|
|
type="button" |
45
|
|
|
onClick={(): void => { |
46
|
|
|
setIsExpanded(!isExpanded); |
47
|
|
|
}} |
48
|
|
|
> |
49
|
|
|
<span className="bucket-title"> |
50
|
|
|
{title} ({applications.length}) |
51
|
|
|
</span> |
52
|
|
|
|
53
|
|
|
<span className="invisible"> |
54
|
|
|
<FormattedMessage |
55
|
|
|
id="button.toggleAccordion" |
56
|
|
|
defaultMessage="Toggle this step to view relevant applicants." |
57
|
|
|
description="Instructions to reveal hidden list data." |
58
|
|
|
/> |
59
|
|
|
</span> |
60
|
|
|
|
61
|
|
|
<i className="fas fa-chevron-up" /> |
62
|
|
|
</button> |
63
|
|
|
|
64
|
|
|
{/* Accordion Content */} |
65
|
|
|
<div aria-hidden={!isExpanded} className="accordion-content"> |
66
|
|
|
<p>{description}</p> |
67
|
|
|
|
68
|
|
|
{sortedApplications.map( |
69
|
|
|
(application: Application): React.ReactElement => ( |
70
|
|
|
<ApplicationRow |
71
|
|
|
key={application.id} |
72
|
|
|
application={application} |
73
|
|
|
handleUpdateReview={handleUpdateReview} |
74
|
|
|
portal={portal} |
75
|
|
|
/> |
76
|
|
|
), |
77
|
|
|
)} |
78
|
|
|
</div> |
79
|
|
|
</div> |
80
|
|
|
); |
81
|
|
|
}; |
82
|
|
|
|
83
|
|
|
export default ApplicantBucket; |
84
|
|
|
|