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