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