1
|
|
|
/* eslint camelcase: "off", @typescript-eslint/camelcase: "off" */ |
2
|
|
|
import React, { useEffect } from "react"; |
3
|
|
|
import ReactDOM from "react-dom"; |
4
|
|
|
import { useDispatch, useSelector } from "react-redux"; |
5
|
|
|
import RootContainer from "../../RootContainer"; |
6
|
|
|
import { |
7
|
|
|
ResponseScreeningBuckets as BucketTypes, |
8
|
|
|
ResponseReviewStatusId, |
9
|
|
|
} from "../../../models/lookupConstants"; |
10
|
|
|
import { ResponseScreeningBuckets } from "../../../models/localizedConstants"; |
11
|
|
|
import { getDepartments as getDepartmentsAction } from "../../../store/Department/deptActions"; |
12
|
|
|
import { |
13
|
|
|
Application, |
14
|
|
|
Department, |
15
|
|
|
ApplicationReview, |
16
|
|
|
} from "../../../models/types"; |
17
|
|
|
import ApplicantBucket from "./ApplicantBucket"; |
18
|
|
|
import { Portal } from "../../../models/app"; |
19
|
|
|
import { |
20
|
|
|
fetchApplicationsForJob, |
21
|
|
|
updateApplicationReview as updateApplicationReviewAction, |
22
|
|
|
} from "../../../store/Application/applicationActions"; |
23
|
|
|
import { getApplicationsByJob } from "../../../store/Application/applicationSelector"; |
24
|
|
|
import { RootState } from "../../../store/store"; |
25
|
|
|
import { getDepartments } from "../../../store/Department/deptSelector"; |
26
|
|
|
|
27
|
|
|
interface ResponseScreeningPageProps { |
28
|
|
|
applications: Application[]; |
29
|
|
|
departments: Department[]; |
30
|
|
|
handleUpdateReview: (review: ApplicationReview) => void; |
31
|
|
|
portal: Portal; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
const ResponseScreeningPage: React.FC<ResponseScreeningPageProps> = ({ |
35
|
|
|
applications, |
36
|
|
|
departments, |
37
|
|
|
handleUpdateReview, |
38
|
|
|
portal, |
39
|
|
|
}): React.ReactElement => { |
40
|
|
|
return ( |
41
|
|
|
<> |
42
|
|
|
{Object.keys(ResponseScreeningBuckets).map(bucket => { |
43
|
|
|
const bucketApplications = applications.filter(application => { |
44
|
|
|
if (bucket === BucketTypes.ReadyToAllocate) { |
45
|
|
|
return ( |
46
|
|
|
application.application_review?.review_status_id === |
47
|
|
|
ResponseReviewStatusId.ReadyToAllocate |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
if (bucket === BucketTypes.Allocated) { |
51
|
|
|
return ( |
52
|
|
|
application.application_review?.review_status_id === |
53
|
|
|
ResponseReviewStatusId.Allocated |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
if (bucket === BucketTypes.Unavailable) { |
57
|
|
|
return ( |
58
|
|
|
application.application_review?.review_status_id === |
59
|
|
|
ResponseReviewStatusId.NotAvailable |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
if (bucket === BucketTypes.DoesNotQualify) { |
63
|
|
|
return ( |
64
|
|
|
application.application_review?.review_status_id === |
65
|
|
|
ResponseReviewStatusId.ScreenedOut |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
// Multiple statuses appear in the "Under Consideration" bucket |
69
|
|
|
return ( |
70
|
|
|
application.application_review === null || |
71
|
|
|
application.application_review?.review_status_id === |
72
|
|
|
ResponseReviewStatusId.AssessmentRequired || |
73
|
|
|
application.application_review?.review_status_id === |
74
|
|
|
ResponseReviewStatusId.ReadyForReference |
75
|
|
|
); |
76
|
|
|
}); |
77
|
|
|
|
78
|
|
|
return ( |
79
|
|
|
<ApplicantBucket |
80
|
|
|
applications={bucketApplications} |
81
|
|
|
bucket={bucket} |
82
|
|
|
departments={departments} |
83
|
|
|
handleUpdateReview={handleUpdateReview} |
84
|
|
|
portal={portal} |
85
|
|
|
/> |
86
|
|
|
); |
87
|
|
|
})} |
88
|
|
|
</> |
89
|
|
|
); |
90
|
|
|
}; |
91
|
|
|
|
92
|
|
|
interface ResponseScreeningDataFetcherProps { |
93
|
|
|
jobId: number; |
94
|
|
|
portal: Portal; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
const ResponseScreeningDataFetcher: React.FC<ResponseScreeningDataFetcherProps> = ({ |
98
|
|
|
jobId, |
99
|
|
|
portal, |
100
|
|
|
}) => { |
101
|
|
|
const dispatch = useDispatch(); |
102
|
|
|
|
103
|
|
|
// Load Applications for provided Job |
104
|
|
|
useEffect(() => { |
105
|
|
|
dispatch(fetchApplicationsForJob(jobId)); |
106
|
|
|
}, [dispatch, jobId]); |
107
|
|
|
const applications = useSelector((state: RootState) => |
108
|
|
|
getApplicationsByJob(state, { jobId }), |
109
|
|
|
); |
110
|
|
|
|
111
|
|
|
// Load all departments |
112
|
|
|
useEffect(() => { |
113
|
|
|
dispatch(getDepartmentsAction()); |
114
|
|
|
}, [dispatch]); |
115
|
|
|
const departments = useSelector(getDepartments); |
116
|
|
|
|
117
|
|
|
const updateApplicationReview = (review: ApplicationReview) => { |
118
|
|
|
dispatch(updateApplicationReviewAction(review)); |
119
|
|
|
}; |
120
|
|
|
|
121
|
|
|
return ( |
122
|
|
|
<ResponseScreeningPage |
123
|
|
|
applications={applications} |
124
|
|
|
departments={departments} |
125
|
|
|
handleUpdateReview={updateApplicationReview} |
126
|
|
|
portal={portal} |
127
|
|
|
/> |
128
|
|
|
); |
129
|
|
|
}; |
130
|
|
|
|
131
|
|
|
const container = document.getElementById("job-index-hr"); |
132
|
|
|
if (container !== null) { |
133
|
|
|
if ("jobId" in container.dataset && "portal" in container.dataset) { |
134
|
|
|
const jobId = Number(container.dataset.jobId as string); |
135
|
|
|
const portal = container.dataset.portal as Portal; |
136
|
|
|
ReactDOM.render( |
137
|
|
|
<RootContainer> |
138
|
|
|
<ResponseScreeningDataFetcher jobId={jobId} portal={portal} /> |
139
|
|
|
</RootContainer>, |
140
|
|
|
container, |
141
|
|
|
); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|