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) => Promise<ApplicationReview>; |
31
|
|
|
portal: Portal; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
const ResponseScreeningPage: React.FC<ResponseScreeningPageProps> = ({ |
35
|
|
|
applications, |
36
|
|
|
departments, |
37
|
|
|
handleUpdateReview, |
38
|
|
|
portal, |
39
|
|
|
}): React.ReactElement => ( |
40
|
|
|
<> |
41
|
|
|
{Object.keys(ResponseScreeningBuckets).map(bucket => { |
42
|
|
|
const bucketApplications = applications.filter(application => { |
43
|
|
|
if (bucket === BucketTypes.ReadyToAllocate) { |
44
|
|
|
return ( |
45
|
|
|
application.application_review?.review_status_id === |
46
|
|
|
ResponseReviewStatusId.ReadyToAllocate |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
if (bucket === BucketTypes.Allocated) { |
50
|
|
|
return ( |
51
|
|
|
application.application_review?.review_status_id === |
52
|
|
|
ResponseReviewStatusId.Allocated |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
if (bucket === BucketTypes.Unavailable) { |
56
|
|
|
return ( |
57
|
|
|
application.application_review?.review_status_id === |
58
|
|
|
ResponseReviewStatusId.NotAvailable |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
if (bucket === BucketTypes.DoesNotQualify) { |
62
|
|
|
return ( |
63
|
|
|
application.application_review?.review_status_id === |
64
|
|
|
ResponseReviewStatusId.ScreenedOut |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
// Multiple statuses appear in the "Under Consideration" bucket |
68
|
|
|
return ( |
69
|
|
|
application.application_review === undefined || |
70
|
|
|
application.application_review?.review_status_id === |
71
|
|
|
ResponseReviewStatusId.AssessmentRequired || |
72
|
|
|
application.application_review?.review_status_id === |
73
|
|
|
ResponseReviewStatusId.ReadyForReference |
74
|
|
|
); |
75
|
|
|
}); |
76
|
|
|
|
77
|
|
|
return ( |
78
|
|
|
<ApplicantBucket |
79
|
|
|
key={bucket} |
80
|
|
|
applications={bucketApplications} |
81
|
|
|
bucket={bucket} |
82
|
|
|
departments={departments} |
83
|
|
|
handleUpdateReview={handleUpdateReview} |
84
|
|
|
portal={portal} |
85
|
|
|
/> |
86
|
|
|
); |
87
|
|
|
})} |
88
|
|
|
</> |
89
|
|
|
); |
90
|
|
|
|
91
|
|
|
interface ResponseScreeningDataFetcherProps { |
92
|
|
|
jobId: number; |
93
|
|
|
portal: Portal; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
const ResponseScreeningDataFetcher: React.FC<ResponseScreeningDataFetcherProps> = ({ |
97
|
|
|
jobId, |
98
|
|
|
portal, |
99
|
|
|
}) => { |
100
|
|
|
const dispatch = useDispatch(); |
101
|
|
|
|
102
|
|
|
// Load Applications for provided Job |
103
|
|
|
useEffect(() => { |
104
|
|
|
dispatch(fetchApplicationsForJob(jobId)); |
105
|
|
|
}, [dispatch, jobId]); |
106
|
|
|
const applications = useSelector((state: RootState) => |
107
|
|
|
getApplicationsByJob(state, { jobId }), |
108
|
|
|
); |
109
|
|
|
|
110
|
|
|
// Load all departments |
111
|
|
|
useEffect(() => { |
112
|
|
|
dispatch(getDepartmentsAction()); |
113
|
|
|
}, [dispatch]); |
114
|
|
|
const departments = useSelector(getDepartments); |
115
|
|
|
|
116
|
|
|
const updateApplicationReview = async ( |
117
|
|
|
review: ApplicationReview, |
118
|
|
|
): Promise<ApplicationReview> => { |
119
|
|
|
const result = await dispatch(updateApplicationReviewAction(review)); |
120
|
|
|
if (!result.error) { |
121
|
|
|
const resultReview = await result.payload; |
122
|
|
|
return resultReview; |
123
|
|
|
} |
124
|
|
|
return Promise.reject(result.payload); |
125
|
|
|
}; |
126
|
|
|
|
127
|
|
|
return ( |
128
|
|
|
<ResponseScreeningPage |
129
|
|
|
applications={applications} |
130
|
|
|
departments={departments} |
131
|
|
|
handleUpdateReview={updateApplicationReview} |
132
|
|
|
portal={portal} |
133
|
|
|
/> |
134
|
|
|
); |
135
|
|
|
}; |
136
|
|
|
|
137
|
|
|
const container = document.getElementById("response-screening-wrapper"); |
138
|
|
|
if (container !== null) { |
139
|
|
|
if ("jobId" in container.dataset && "portal" in container.dataset) { |
140
|
|
|
const jobId = Number(container.dataset.jobId as string); |
141
|
|
|
const portal = container.dataset.portal as Portal; |
142
|
|
|
ReactDOM.render( |
143
|
|
|
<RootContainer> |
144
|
|
|
<ResponseScreeningDataFetcher jobId={jobId} portal={portal} /> |
145
|
|
|
</RootContainer>, |
146
|
|
|
container, |
147
|
|
|
); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|