1
|
|
|
import React from "react"; |
2
|
|
|
import { useIntl } from "react-intl"; |
3
|
|
|
import { connect, useDispatch } from "react-redux"; |
4
|
|
|
import ReactDOM from "react-dom"; |
5
|
|
|
import RootContainer from "../../RootContainer"; |
6
|
|
|
import { |
7
|
|
|
Job, |
8
|
|
|
JobPosterKeyTask, |
9
|
|
|
Criteria, |
10
|
|
|
Skill, |
11
|
|
|
Classification, |
12
|
|
|
} from "../../../models/types"; |
13
|
|
|
import JobSkills from "./JobSkills"; |
14
|
|
|
import { jobBuilderTasks, jobBuilderReview } from "../../../helpers/routes"; |
15
|
|
|
import { RootState } from "../../../store/store"; |
16
|
|
|
import { |
17
|
|
|
getJob, |
18
|
|
|
getTasksByJob, |
19
|
|
|
getCriteriaByJob, |
20
|
|
|
} from "../../../store/Job/jobSelector"; |
21
|
|
|
import { getSkills } from "../../../store/Skill/skillSelector"; |
22
|
|
|
import { DispatchType } from "../../../configureStore"; |
23
|
|
|
import { batchUpdateCriteria } from "../../../store/Job/jobActions"; |
24
|
|
|
import JobBuilderStepContainer from "../JobBuilderStep"; |
25
|
|
|
import { navigate } from "../../../helpers/router"; |
26
|
|
|
import { getLocale } from "../../../helpers/localize"; |
27
|
|
|
import { useLoadClassifications } from "../../../hooks/classificationHooks"; |
28
|
|
|
|
29
|
|
|
interface JobSkillsPageProps { |
30
|
|
|
jobId: number; |
31
|
|
|
job: Job | null; |
32
|
|
|
skills: Skill[]; |
33
|
|
|
keyTasks: JobPosterKeyTask[]; |
34
|
|
|
criteria: Criteria[]; |
35
|
|
|
handleSubmitCriteria: ( |
36
|
|
|
jobId: number, |
37
|
|
|
criteria: Criteria[], |
38
|
|
|
) => Promise<Criteria[]>; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
const JobSkillsPage: React.FunctionComponent<JobSkillsPageProps> = ({ |
42
|
|
|
jobId, |
43
|
|
|
job, |
44
|
|
|
skills, |
45
|
|
|
keyTasks, |
46
|
|
|
criteria, |
47
|
|
|
handleSubmitCriteria, |
48
|
|
|
}): React.ReactElement => { |
49
|
|
|
const intl = useIntl(); |
50
|
|
|
const locale = getLocale(intl.locale); |
51
|
|
|
const dispatch = useDispatch<DispatchType>(); |
52
|
|
|
const { classifications } = useLoadClassifications(dispatch); |
53
|
|
|
const classificationKey: string = |
54
|
|
|
classifications.find( |
55
|
|
|
(item: Classification) => item.id === job?.classification_id, |
56
|
|
|
)?.key || ""; |
57
|
|
|
|
58
|
|
|
const handleReturn = (): void => { |
59
|
|
|
// Continue to next page |
60
|
|
|
navigate(jobBuilderTasks(locale, jobId)); |
61
|
|
|
}; |
62
|
|
|
const handleContinue = (): void => { |
63
|
|
|
// Continue to next page |
64
|
|
|
navigate(jobBuilderReview(locale, jobId)); |
65
|
|
|
}; |
66
|
|
|
|
67
|
|
|
const handleSubmit = (tasks: Criteria[]): Promise<Criteria[]> => |
68
|
|
|
handleSubmitCriteria(jobId, tasks); |
69
|
|
|
const handleSkipToReview = async (): Promise<void> => { |
70
|
|
|
navigate(jobBuilderReview(locale, jobId)); |
71
|
|
|
}; |
72
|
|
|
// As long as Skills is the last step, we never need to show the Skip to Review button |
73
|
|
|
const jobIsComplete = false; |
74
|
|
|
return ( |
75
|
|
|
<JobBuilderStepContainer jobId={jobId} currentPage="skills"> |
76
|
|
|
{job !== null && ( |
77
|
|
|
<JobSkills |
78
|
|
|
job={job} |
79
|
|
|
classificationKey={classificationKey} |
80
|
|
|
keyTasks={keyTasks} |
81
|
|
|
initialCriteria={criteria} |
82
|
|
|
skills={skills} |
83
|
|
|
handleSubmit={handleSubmit} |
84
|
|
|
handleReturn={handleReturn} |
85
|
|
|
handleContinue={handleContinue} |
86
|
|
|
jobIsComplete={jobIsComplete} |
87
|
|
|
handleSkipToReview={handleSkipToReview} |
88
|
|
|
/> |
89
|
|
|
)} |
90
|
|
|
</JobBuilderStepContainer> |
91
|
|
|
); |
92
|
|
|
}; |
93
|
|
|
|
94
|
|
|
const mapStateToProps = ( |
95
|
|
|
state: RootState, |
96
|
|
|
ownProps: { jobId: number }, |
97
|
|
|
): { |
98
|
|
|
job: Job | null; |
99
|
|
|
skills: Skill[]; |
100
|
|
|
keyTasks: JobPosterKeyTask[]; |
101
|
|
|
criteria: Criteria[]; |
102
|
|
|
} => ({ |
103
|
|
|
job: getJob(state, ownProps), |
104
|
|
|
skills: getSkills(state), |
105
|
|
|
keyTasks: getTasksByJob(state, ownProps), |
106
|
|
|
criteria: getCriteriaByJob(state, ownProps), |
107
|
|
|
}); |
108
|
|
|
|
109
|
|
|
const mapDispatchToProps = ( |
110
|
|
|
dispatch: DispatchType, |
111
|
|
|
): { |
112
|
|
|
handleSubmitCriteria: ( |
113
|
|
|
jobId: number, |
114
|
|
|
criteria: Criteria[], |
115
|
|
|
) => Promise<Criteria[]>; |
116
|
|
|
} => ({ |
117
|
|
|
handleSubmitCriteria: async ( |
118
|
|
|
jobId: number, |
119
|
|
|
criteria: Criteria[], |
120
|
|
|
): Promise<Criteria[]> => { |
121
|
|
|
const result = await dispatch(batchUpdateCriteria(jobId, criteria)); |
122
|
|
|
if (result.error) { |
123
|
|
|
return Promise.reject(result.payload); |
124
|
|
|
} |
125
|
|
|
const resultCriteria = await result.payload; |
126
|
|
|
return resultCriteria; |
127
|
|
|
}, |
128
|
|
|
}); |
129
|
|
|
|
130
|
|
|
const JobSkillsPageContainer = connect( |
131
|
|
|
mapStateToProps, |
132
|
|
|
mapDispatchToProps, |
133
|
|
|
)(JobSkillsPage); |
134
|
|
|
|
135
|
|
|
export default JobSkillsPageContainer; |
136
|
|
|
|
137
|
|
|
if (document.getElementById("job-builder-skills")) { |
138
|
|
|
const container = document.getElementById( |
139
|
|
|
"job-builder-skills", |
140
|
|
|
) as HTMLElement; |
141
|
|
|
const jobIdAttr = container.getAttribute("data-job-id"); |
142
|
|
|
const jobId = jobIdAttr ? Number(jobIdAttr) : null; |
143
|
|
|
if (jobId) { |
144
|
|
|
ReactDOM.render( |
145
|
|
|
<RootContainer> |
146
|
|
|
<JobSkillsPageContainer jobId={jobId} /> |
147
|
|
|
</RootContainer>, |
148
|
|
|
container, |
149
|
|
|
); |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|