1
|
|
|
import React, { useEffect } from "react"; |
2
|
|
|
import { useIntl } from "react-intl"; |
3
|
|
|
import ReactDOM from "react-dom"; |
4
|
|
|
import { useDispatch, useSelector } from "react-redux"; |
5
|
|
|
import { RootContainer } from "../RootContainer"; |
6
|
|
|
import { fetchJobIndex } from "../../store/Job/jobActions"; |
7
|
|
|
import { getAllJobsInDept } from "../../store/Job/jobSelector"; |
8
|
|
|
import { RootState } from "../../store/store"; |
9
|
|
|
import { localizeField, getLocale } from "../../helpers/localize"; |
10
|
|
|
import { Job } from "../../models/types"; |
11
|
|
|
|
12
|
|
|
import JobIndexHrPage from "../HRPortal/JobIndexHrPage"; |
13
|
|
|
|
14
|
|
|
const StrJobListing: React.FC<{ jobs: Job[] }> = ({ jobs }) => { |
15
|
|
|
const intl = useIntl(); |
16
|
|
|
const locale = getLocale(intl.locale); |
17
|
|
|
return ( |
18
|
|
|
<> |
19
|
|
|
<h1>{`${jobs.length} jobs loaded.`}</h1> |
20
|
|
|
<ul> |
21
|
|
|
{jobs.map(job => ( |
22
|
|
|
<li key={job.id}> |
23
|
|
|
<p>{localizeField(locale, job, "title")}</p> |
24
|
|
|
</li> |
25
|
|
|
))} |
26
|
|
|
</ul> |
27
|
|
|
</> |
28
|
|
|
); |
29
|
|
|
}; |
30
|
|
|
|
31
|
|
|
const StrJobFetcher: React.FC<{ strDeptId: number }> = ({ strDeptId }) => { |
32
|
|
|
const dispatch = useDispatch(); |
33
|
|
|
|
34
|
|
|
useEffect(() => { |
35
|
|
|
const jobFilter = new Map(); |
36
|
|
|
jobFilter.set("department_id", strDeptId); |
37
|
|
|
dispatch(fetchJobIndex(jobFilter)); |
38
|
|
|
}, [strDeptId, dispatch]); |
39
|
|
|
|
40
|
|
|
const jobs = useSelector((state: RootState) => |
41
|
|
|
getAllJobsInDept(state, { departmentId: strDeptId }), |
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
return <StrJobListing jobs={jobs} />; |
45
|
|
|
}; |
46
|
|
|
|
47
|
|
|
const container = document.getElementById("str-api-test"); |
48
|
|
|
if (container !== null) { |
49
|
|
|
if ("strDeptId" in container.dataset) { |
50
|
|
|
const strDeptId = Number(container.dataset.strDeptId as string); |
51
|
|
|
ReactDOM.render( |
52
|
|
|
<RootContainer> |
53
|
|
|
<StrJobFetcher strDeptId={strDeptId} /> |
54
|
|
|
</RootContainer>, |
55
|
|
|
container, |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
export default JobIndexHrPage; |
61
|
|
|
|