1
|
|
|
/* eslint-disable @typescript-eslint/camelcase */ |
2
|
|
|
/* eslint-disable camelcase */ |
3
|
|
|
import React from "react"; |
4
|
|
|
import { useIntl } from "react-intl"; |
5
|
|
|
import { useDispatch } from "react-redux"; |
6
|
|
|
import ProgressBar, { stepNames } from "../ProgressBar/ProgressBar"; |
7
|
|
|
import makeProgressBarSteps from "../ProgressBar/progressHelpers"; |
8
|
|
|
import Review, { ReviewFormValues } from "./Review"; |
9
|
|
|
import { |
10
|
|
|
applicationIndex, |
11
|
|
|
applicationFit, |
12
|
|
|
applicationSubmission, |
13
|
|
|
} from "../../../helpers/routes"; |
14
|
|
|
import { getLocale } from "../../../helpers/localize"; |
15
|
|
|
import { navigate } from "../../../helpers/router"; |
16
|
|
|
import { DispatchType } from "../../../configureStore"; |
17
|
|
|
import { |
18
|
|
|
useApplication, |
19
|
|
|
useApplicationUser, |
20
|
|
|
useCriteria, |
21
|
|
|
useExperiences, |
22
|
|
|
useExperienceSkills, |
23
|
|
|
useFetchAllApplicationData, |
24
|
|
|
useJob, |
25
|
|
|
useJobApplicationAnswers, |
26
|
|
|
useJobPosterQuestions, |
27
|
|
|
useSkills, |
28
|
|
|
} from "../../../hooks/applicationHooks"; |
29
|
|
|
import { loadingMessages } from "../applicationMessages"; |
30
|
|
|
import { updateApplication as updateApplicationAction } from "../../../store/Application/applicationActions"; |
31
|
|
|
|
32
|
|
|
interface ReviewPageProps { |
33
|
|
|
applicationId: number; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
export const ReviewPage: React.FC<ReviewPageProps> = ({ applicationId }) => { |
37
|
|
|
const intl = useIntl(); |
38
|
|
|
const locale = getLocale(intl.locale); |
39
|
|
|
const dispatch = useDispatch<DispatchType>(); |
40
|
|
|
|
41
|
|
|
// Fetch all un-loaded data that may be required for the Application. |
42
|
|
|
const { |
43
|
|
|
experiencesLoaded, |
44
|
|
|
skillsLoaded, |
45
|
|
|
criteriaLoaded, |
46
|
|
|
experienceSkillsLoaded, |
47
|
|
|
jobQuestionsLoaded, |
48
|
|
|
applicationAnswersLoaded, |
49
|
|
|
} = useFetchAllApplicationData(applicationId, dispatch); |
50
|
|
|
|
51
|
|
|
const application = useApplication(applicationId); |
52
|
|
|
const user = useApplicationUser(applicationId); |
53
|
|
|
const jobId = application?.job_poster_id; |
54
|
|
|
const job = useJob(jobId); |
55
|
|
|
const criteria = useCriteria(jobId); |
56
|
|
|
const experiences = useExperiences(applicationId, application); |
57
|
|
|
const experienceSkills = useExperienceSkills(applicationId, application); |
58
|
|
|
const questions = useJobPosterQuestions(jobId); |
59
|
|
|
const answers = useJobApplicationAnswers(applicationId); |
60
|
|
|
const skills = useSkills(); |
61
|
|
|
|
62
|
|
|
const handleSave = (values: ReviewFormValues): Promise<void> => { |
63
|
|
|
if (application === null) { |
64
|
|
|
// We shouldn't expect this to handler to trigger before application is loaded, but just to be sure. |
65
|
|
|
return Promise.reject(); |
66
|
|
|
} |
67
|
|
|
return dispatch( |
68
|
|
|
updateApplicationAction({ |
69
|
|
|
...application, |
70
|
|
|
share_with_managers: values.shareWithManagers, |
71
|
|
|
}), |
72
|
|
|
) |
73
|
|
|
.then(() => { |
74
|
|
|
navigate(applicationSubmission(locale, applicationId)); |
75
|
|
|
}) |
76
|
|
|
.catch(() => { |
77
|
|
|
// Do nothing on an error. |
78
|
|
|
}); |
79
|
|
|
}; |
80
|
|
|
const handleReturn = (): void => { |
81
|
|
|
navigate(applicationFit(locale, applicationId)); |
82
|
|
|
}; |
83
|
|
|
const handleQuit = (): void => { |
84
|
|
|
// Because the Applications Index is outside of the Application SPA, we navigate to it differently. |
85
|
|
|
window.location.href = applicationIndex(locale); |
86
|
|
|
}; |
87
|
|
|
const handleContinue = (): void => { |
88
|
|
|
navigate(applicationSubmission(locale, applicationId)); |
89
|
|
|
}; |
90
|
|
|
|
91
|
|
|
const closeDate = job?.close_date_time ?? null; |
92
|
|
|
|
93
|
|
|
const allDataLoaded = |
94
|
|
|
application !== null && |
95
|
|
|
job !== null && |
96
|
|
|
user !== null && |
97
|
|
|
criteriaLoaded && |
98
|
|
|
experiencesLoaded && |
99
|
|
|
experienceSkillsLoaded && |
100
|
|
|
jobQuestionsLoaded && |
101
|
|
|
applicationAnswersLoaded && |
102
|
|
|
skillsLoaded; |
103
|
|
|
|
104
|
|
|
return ( |
105
|
|
|
<> |
106
|
|
|
{application !== null && ( |
107
|
|
|
<ProgressBar |
108
|
|
|
closeDateTime={closeDate} |
109
|
|
|
currentTitle={intl.formatMessage(stepNames.step05)} |
110
|
|
|
steps={makeProgressBarSteps( |
111
|
|
|
applicationId, |
112
|
|
|
application, |
113
|
|
|
intl, |
114
|
|
|
"review", |
115
|
|
|
)} |
116
|
|
|
/> |
117
|
|
|
)} |
118
|
|
|
{allDataLoaded && |
119
|
|
|
application !== null && |
120
|
|
|
job !== null && |
121
|
|
|
user !== null ? ( |
122
|
|
|
<Review |
123
|
|
|
application={application} |
124
|
|
|
criteria={criteria} |
125
|
|
|
experiences={experiences} |
126
|
|
|
experienceSkills={experienceSkills} |
127
|
|
|
job={job} |
128
|
|
|
jobQuestions={questions} |
129
|
|
|
jobApplicationAnswers={answers} |
130
|
|
|
skills={skills} |
131
|
|
|
user={user} |
132
|
|
|
handleSave={handleSave} |
133
|
|
|
handleContinue={handleContinue} |
134
|
|
|
handleQuit={handleQuit} |
135
|
|
|
handleReturn={handleReturn} |
136
|
|
|
/> |
137
|
|
|
) : ( |
138
|
|
|
<h2 |
139
|
|
|
data-c-heading="h2" |
140
|
|
|
data-c-align="center" |
141
|
|
|
data-c-padding="top(2) bottom(3)" |
142
|
|
|
> |
143
|
|
|
{intl.formatMessage(loadingMessages.loading)} |
144
|
|
|
</h2> |
145
|
|
|
)} |
146
|
|
|
</> |
147
|
|
|
); |
148
|
|
|
}; |
149
|
|
|
|
150
|
|
|
export default ReviewPage; |
151
|
|
|
|