Passed
Push — task/add-application-constants... ( 48da6a...485838 )
by Yonathan
04:42
created

resources/assets/js/components/StrategicTalentResponse/StrApiTestPage.tsx   A

Complexity

Total Complexity 2
Complexity/F 0

Size

Lines of Code 61
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 52
mnd 2
bc 2
fnc 0
dl 0
loc 61
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
rs 10
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