Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Selection.js 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import React, { useState } from "react";
  2. import PropTypes from "prop-types";
  3. import { selectDoneProcessError } from "../../store/selectors/processSelectors";
  4. import { selectAuthUser } from "../../store/selectors/userSelectors";
  5. import { setDoneProcessReq } from "../../store/actions/processes/processAction";
  6. import { useDispatch, useSelector } from "react-redux";
  7. // import { formatDateSrb, formatTimeSrb } from "../../util/helpers/dateHelpers";
  8. import { SELECTION_PROCESS_OF_APPLICANT_PAGE } from "../../constants/pages";
  9. import { PUT_PROCESS_LOADING } from "../../store/actions/processes/processesActionConstants";
  10. import { selectIsLoadingByActionType } from "../../store/selectors/loadingSelectors";
  11. import Backdrop from "../../components/MUI/BackdropComponent";
  12. import { IconButton } from "@mui/material";
  13. import plus from "../../assets/images/plus.png";
  14. import SelectionCard from "./SelectionCard";
  15. import { useTranslation } from "react-i18next";
  16. const Selection = (props) => {
  17. const [over, setOver] = useState(false);
  18. const allApplicants = props.selection.selectionProcesses;
  19. const errorMessage = useSelector(selectDoneProcessError);
  20. const dispatch = useDispatch();
  21. const user = useSelector(selectAuthUser);
  22. const { t } = useTranslation();
  23. const dropItem = (e, selId) => {
  24. setOver(false);
  25. var data = e.dataTransfer.getData("text/plain");
  26. const selectionProcess = JSON.parse(data);
  27. if (
  28. selectionProcess.selectionLevelId < selId &&
  29. selectionProcess.status !== "Neuspešno"
  30. ) {
  31. dispatch(
  32. setDoneProcessReq({
  33. id: selectionProcess.id,
  34. name: "Some random name",
  35. applicantId: selectionProcess.applicant.applicantId,
  36. schedulerId: user.id,
  37. })
  38. );
  39. }
  40. if (errorMessage) {
  41. console.log(errorMessage);
  42. }
  43. };
  44. const dragStart = (e, applicant) => {
  45. e.dataTransfer.setData("text/plain", JSON.stringify(applicant));
  46. };
  47. const dragOver = (e) => {
  48. e.preventDefault();
  49. setOver(true);
  50. };
  51. const isLoading = useSelector(
  52. selectIsLoadingByActionType(PUT_PROCESS_LOADING)
  53. );
  54. const handleOpenDetails = (id) => {
  55. props.history.push(SELECTION_PROCESS_OF_APPLICANT_PAGE.replace(":id", id));
  56. };
  57. const applicants = allApplicants?.filter(
  58. (a) => a.status !== "Odrađen" || a.selectionLevelId === 4
  59. );
  60. const renderList = applicants?.map((item, index) => {
  61. return (
  62. <SelectionCard
  63. key={index}
  64. item={item}
  65. dragStart={(e) => dragStart(e, item)}
  66. click={() => handleOpenDetails(item.applicant.applicantId)}
  67. />
  68. );
  69. });
  70. return (
  71. <div
  72. data-testid="selection-level"
  73. dropppable="true"
  74. id={props.selection.id}
  75. className={`selection-card ${over ? "over" : ""}`}
  76. onDragOver={(e) => dragOver(e)}
  77. onDragLeave={() => setOver(false)}
  78. onDrop={(e) => dropItem(e, props.selection.id)}
  79. >
  80. <div className="selection-card-title">
  81. <h3 style={{ marginRight: "50px" }}>
  82. {props.selection.name === "HR intervju" && t("processes.hr")}
  83. {props.selection.name === "Screening test" && t("processes.st")}
  84. {props.selection.name === "Tehnicki intervju" && t("processes.ti")}
  85. {props.selection.name === "Konacna odluka" && t("processes.fd")}
  86. </h3>
  87. {props.order === 0 ? (
  88. <IconButton
  89. sx={{ marginRight: "35px" }}
  90. className={`c-btn--primary-outlined c-btn td-btn`}
  91. onClick={props.modalEvent}
  92. >
  93. <img
  94. style={{
  95. position: "relative",
  96. }}
  97. src={plus}
  98. data-testid="interview-image"
  99. />
  100. </IconButton>
  101. ) : (
  102. ""
  103. )}
  104. </div>
  105. <Backdrop position="absolute" isLoading={isLoading} />
  106. {applicants &&
  107. applicants !== null &&
  108. applicants?.length > 0 &&
  109. renderList}
  110. {applicants && applicants !== null && applicants?.length === 0 && (
  111. <div className="sel-item-no-data">
  112. <div className="date">
  113. <p data-testid="empty-selection" style={{ width: "240px" }}>
  114. {t("selection.noCandidates")}
  115. </p>
  116. </div>
  117. </div>
  118. )}
  119. </div>
  120. );
  121. };
  122. Selection.propTypes = {
  123. history: PropTypes.shape({
  124. replace: PropTypes.func,
  125. push: PropTypes.func,
  126. location: PropTypes.shape({
  127. pathname: PropTypes.string,
  128. }),
  129. }),
  130. order: PropTypes.number,
  131. modalEvent: PropTypes.func,
  132. selection: PropTypes.shape({
  133. id: PropTypes.number,
  134. name: PropTypes.string,
  135. selectionProcesses: PropTypes.arrayOf(
  136. PropTypes.shape({
  137. id: PropTypes.number,
  138. name: PropTypes.string,
  139. date: PropTypes.string,
  140. status: PropTypes.string,
  141. currentSelection: PropTypes.number,
  142. map: PropTypes.func,
  143. applicant: PropTypes.shape({
  144. firstName: PropTypes.string,
  145. lastName: PropTypes.string,
  146. }),
  147. })
  148. ),
  149. }),
  150. };
  151. export default Selection;