1
|
|
|
import React, { FunctionComponent, useEffect } from "react"; |
2
|
|
|
import { FormattedMessage } from "react-intl"; |
3
|
|
|
import { useDispatch } from "react-redux"; |
4
|
|
|
import nprogress from "nprogress"; |
5
|
|
|
import { Job, JobPosterKeyTask, Criteria } from "../../models/types"; |
6
|
|
|
import { JobBuilderPage } from "./jobBuilderHelpers"; |
7
|
|
|
import { DispatchType } from "../../configureStore"; |
8
|
|
|
import JobBuilderProgressTracker from "./JobBuilderProgressTracker"; |
9
|
|
|
import { |
10
|
|
|
useLoadCriteria, |
11
|
|
|
useLoadDepartments, |
12
|
|
|
useLoadClassifications, |
13
|
|
|
useLoadJob, |
14
|
|
|
useLoadSkills, |
15
|
|
|
useLoadTasks, |
16
|
|
|
} from "../../hooks/jobBuilderHooks"; |
17
|
|
|
|
18
|
|
|
interface JobBuilderStepProps { |
19
|
|
|
jobId: number | null; |
20
|
|
|
job: Job | null; |
21
|
|
|
keyTasks: JobPosterKeyTask[]; |
22
|
|
|
criteria: Criteria[]; |
23
|
|
|
currentPage: JobBuilderPage | null; |
24
|
|
|
dataIsLoading: boolean; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
const JobBuilderStep: React.FunctionComponent<JobBuilderStepProps> = ({ |
28
|
|
|
jobId, |
29
|
|
|
job, |
30
|
|
|
keyTasks, |
31
|
|
|
criteria, |
32
|
|
|
currentPage, |
33
|
|
|
dataIsLoading, |
34
|
|
|
children, |
35
|
|
|
}): React.ReactElement => { |
36
|
|
|
useEffect((): void => { |
37
|
|
|
if (jobId !== null && job === null) { |
38
|
|
|
nprogress.start(); |
39
|
|
|
} else if (currentPage !== "intro") { |
40
|
|
|
nprogress.done(); |
41
|
|
|
} |
42
|
|
|
}, [currentPage, job, jobId]); |
43
|
|
|
|
44
|
|
|
return ( |
45
|
|
|
<section> |
46
|
|
|
<JobBuilderProgressTracker |
47
|
|
|
job={job} |
48
|
|
|
jobId={jobId} |
49
|
|
|
tasks={keyTasks} |
50
|
|
|
criteria={criteria} |
51
|
|
|
dataIsLoading={dataIsLoading} |
52
|
|
|
currentPage={currentPage} |
53
|
|
|
/> |
54
|
|
|
{jobId !== null && job === null && ( |
55
|
|
|
<div |
56
|
|
|
data-c-container="form" |
57
|
|
|
data-c-padding="top(triple) bottom(triple)" |
58
|
|
|
> |
59
|
|
|
<div |
60
|
|
|
data-c-background="white(100)" |
61
|
|
|
data-c-card |
62
|
|
|
data-c-padding="all(double)" |
63
|
|
|
data-c-radius="rounded" |
64
|
|
|
data-c-align="base(centre)" |
65
|
|
|
> |
66
|
|
|
<p> |
67
|
|
|
<FormattedMessage |
68
|
|
|
id="jobBuilder.loading" |
69
|
|
|
defaultMessage="Your job is loading..." |
70
|
|
|
description="Message indicating that the current job is still being loaded." |
71
|
|
|
/> |
72
|
|
|
</p> |
73
|
|
|
</div> |
74
|
|
|
</div> |
75
|
|
|
)} |
76
|
|
|
{children} |
77
|
|
|
</section> |
78
|
|
|
); |
79
|
|
|
}; |
80
|
|
|
|
81
|
|
|
export const JobBuilderStepContainer: FunctionComponent<{ |
82
|
|
|
jobId: number | null; |
83
|
|
|
currentPage: JobBuilderPage | null; |
84
|
|
|
forceIsLoading?: boolean; |
85
|
|
|
}> = ({ jobId, currentPage, forceIsLoading, children }) => { |
86
|
|
|
const dispatch = useDispatch<DispatchType>(); |
87
|
|
|
|
88
|
|
|
// Trigger fetching of job details |
89
|
|
|
const { job, isLoadingJob } = useLoadJob(jobId, dispatch); |
90
|
|
|
const { tasks, isLoadingTasks } = useLoadTasks(jobId, dispatch); |
91
|
|
|
const { criteria, isLoadingCriteria } = useLoadCriteria(jobId, dispatch); |
92
|
|
|
|
93
|
|
|
// Trigger fetching of other resources needed for Job Builder |
94
|
|
|
const { isLoadingDepartments } = useLoadDepartments(dispatch); |
95
|
|
|
const { isLoadingSkills } = useLoadSkills(dispatch); |
96
|
|
|
|
97
|
|
|
const { isLoadingClassifications } = useLoadClassifications(dispatch); |
98
|
|
|
|
99
|
|
|
const dataIsLoading = |
100
|
|
|
forceIsLoading || |
101
|
|
|
isLoadingJob || |
102
|
|
|
isLoadingTasks || |
103
|
|
|
isLoadingCriteria || |
104
|
|
|
isLoadingDepartments || |
105
|
|
|
isLoadingSkills || |
106
|
|
|
isLoadingClassifications; |
107
|
|
|
|
108
|
|
|
return ( |
109
|
|
|
<JobBuilderStep |
110
|
|
|
jobId={jobId} |
111
|
|
|
currentPage={currentPage} |
112
|
|
|
job={job} |
113
|
|
|
keyTasks={tasks} |
114
|
|
|
criteria={criteria} |
115
|
|
|
dataIsLoading={dataIsLoading} |
116
|
|
|
> |
117
|
|
|
{children} |
118
|
|
|
</JobBuilderStep> |
119
|
|
|
); |
120
|
|
|
}; |
121
|
|
|
|
122
|
|
|
export default JobBuilderStepContainer; |
123
|
|
|
|