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, Classification } 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
|
|
|
|
37
|
|
|
useEffect((): void => { |
38
|
|
|
if (jobId !== null && job === null) { |
39
|
|
|
nprogress.start(); |
40
|
|
|
} else if (currentPage !== "intro") { |
41
|
|
|
nprogress.done(); |
42
|
|
|
} |
43
|
|
|
}, [currentPage, job, jobId]); |
44
|
|
|
|
45
|
|
|
return ( |
46
|
|
|
<section> |
47
|
|
|
<JobBuilderProgressTracker |
48
|
|
|
job={job} |
49
|
|
|
jobId={jobId} |
50
|
|
|
tasks={keyTasks} |
51
|
|
|
criteria={criteria} |
52
|
|
|
dataIsLoading={dataIsLoading} |
53
|
|
|
currentPage={currentPage} |
54
|
|
|
/> |
55
|
|
|
{jobId !== null && job === null && ( |
56
|
|
|
<div |
57
|
|
|
data-c-container="form" |
58
|
|
|
data-c-padding="top(triple) bottom(triple)" |
59
|
|
|
> |
60
|
|
|
<div |
61
|
|
|
data-c-background="white(100)" |
62
|
|
|
data-c-card |
63
|
|
|
data-c-padding="all(double)" |
64
|
|
|
data-c-radius="rounded" |
65
|
|
|
data-c-align="base(centre)" |
66
|
|
|
> |
67
|
|
|
<p> |
68
|
|
|
<FormattedMessage |
69
|
|
|
id="jobBuilder.loading" |
70
|
|
|
defaultMessage="Your job is loading..." |
71
|
|
|
description="Message indicating that the current job is still being loaded." |
72
|
|
|
/> |
73
|
|
|
</p> |
74
|
|
|
</div> |
75
|
|
|
</div> |
76
|
|
|
)} |
77
|
|
|
{children} |
78
|
|
|
</section> |
79
|
|
|
); |
80
|
|
|
}; |
81
|
|
|
|
82
|
|
|
export const JobBuilderStepContainer: FunctionComponent<{ |
83
|
|
|
jobId: number | null; |
84
|
|
|
currentPage: JobBuilderPage | null; |
85
|
|
|
forceIsLoading?: boolean; |
86
|
|
|
}> = ({ jobId, currentPage, forceIsLoading, children }) => { |
87
|
|
|
const dispatch = useDispatch<DispatchType>(); |
88
|
|
|
|
89
|
|
|
// Trigger fetching of job details |
90
|
|
|
const { job, isLoadingJob } = useLoadJob(jobId, dispatch); |
91
|
|
|
const { tasks, isLoadingTasks } = useLoadTasks(jobId, dispatch); |
92
|
|
|
const { criteria, isLoadingCriteria } = useLoadCriteria(jobId, dispatch); |
93
|
|
|
|
94
|
|
|
// Trigger fetching of other resources needed for Job Builder |
95
|
|
|
const { isLoadingDepartments } = useLoadDepartments(dispatch); |
96
|
|
|
const { isLoadingSkills } = useLoadSkills(dispatch); |
97
|
|
|
|
98
|
|
|
const { isLoadingClassifications } = useLoadClassifications(dispatch); |
99
|
|
|
|
100
|
|
|
const dataIsLoading = |
101
|
|
|
forceIsLoading || |
102
|
|
|
isLoadingJob || |
103
|
|
|
isLoadingTasks || |
104
|
|
|
isLoadingCriteria || |
105
|
|
|
isLoadingDepartments || |
106
|
|
|
isLoadingSkills || |
107
|
|
|
isLoadingClassifications; |
108
|
|
|
|
109
|
|
|
return ( |
110
|
|
|
<JobBuilderStep |
111
|
|
|
jobId={jobId} |
112
|
|
|
currentPage={currentPage} |
113
|
|
|
job={job} |
114
|
|
|
keyTasks={tasks} |
115
|
|
|
criteria={criteria} |
116
|
|
|
dataIsLoading={dataIsLoading} |
117
|
|
|
> |
118
|
|
|
{children} |
119
|
|
|
</JobBuilderStep> |
120
|
|
|
); |
121
|
|
|
}; |
122
|
|
|
|
123
|
|
|
export default JobBuilderStepContainer; |
124
|
|
|
|