Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

StatusDialog.js 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. import React, { useContext, useState } from "react";
  2. import PropTypes from "prop-types";
  3. import x from "../../assets/images/x.png";
  4. import {
  5. Dialog,
  6. DialogTitle,
  7. DialogActions,
  8. useMediaQuery,
  9. useTheme,
  10. DialogContent,
  11. FormControl,
  12. InputLabel,
  13. Select,
  14. MenuItem,
  15. TextField,
  16. // TextField,
  17. } from "@mui/material";
  18. import IconButton from "../IconButton/IconButton";
  19. import { DateTimePicker } from "@mui/x-date-pickers/DateTimePicker";
  20. import { useDispatch, useSelector } from "react-redux";
  21. import { format, isValid } from "date-fns";
  22. // import { fetchInitProcess } from "../../store/actions/candidates/candidatesActions";
  23. import { useEffect } from "react";
  24. import { SelectionContext } from "../../context/SelectionContext";
  25. import { setUpdateStatusReq } from "../../store/actions/processes/processAction";
  26. import { createScreeningTest } from "../../store/actions/screeningTests/screeningTestActions";
  27. const StatusDialog = ({
  28. title,
  29. subtitle,
  30. imgSrc,
  31. onClose,
  32. open,
  33. maxWidth,
  34. fullWidth,
  35. responsive,
  36. }) => {
  37. const [selected, setSelected] = useState('');
  38. const [value, setValue] = useState(null);
  39. const [selectedScreeningTest, setSelectedScreeningTest] = useState("");
  40. const { activeProcess, setActiveProcess } = useContext(SelectionContext);
  41. const theme = useTheme();
  42. const fullScreen = useMediaQuery(theme.breakpoints.down("md"));
  43. const { users } = useSelector((s) => s.users);
  44. const { isSuccess } = useSelector((s) => s.initProcess);
  45. const { screeningTests } = useSelector((s) => s.screeningTests);
  46. const dispatch = useDispatch();
  47. useEffect(() => {
  48. handleClose();
  49. }, [dispatch, isSuccess]);
  50. const handleChange = (newValue) => {
  51. if (isValid(newValue)) {
  52. // throws an error if invalid value is set
  53. var date = format(newValue, "yyyy-MM-dd'T'HH:mm:ss.SSSxxx");
  54. setValue(date);
  55. }
  56. };
  57. useEffect(() => {
  58. setSelected('');
  59. setValue(null);
  60. setSelectedScreeningTest("")
  61. }, [onClose]);
  62. const handleClose = () => {
  63. onClose();
  64. };
  65. const submitHandler = () => {
  66. console.log(selected)
  67. if (activeProcess.process.selectionLevelId !== 2) {
  68. dispatch(
  69. setUpdateStatusReq({
  70. data: {
  71. schedulerId: selected,
  72. appointment: value,
  73. newStatus: activeProcess.status,
  74. processId: activeProcess.process.id,
  75. },
  76. responseHandler: apiSuccess,
  77. })
  78. );
  79. } else {
  80. dispatch(
  81. setUpdateStatusReq({
  82. data: {
  83. schedulerId: selected,
  84. appointment: value,
  85. newStatus: activeProcess.status,
  86. processId: activeProcess.process.id,
  87. },
  88. responseHandler: apiSuccessScreeningTests,
  89. })
  90. );
  91. }
  92. };
  93. const apiSuccessScreeningTests = () => {
  94. const user = users.find(k => k.id === selected)
  95. dispatch(
  96. createScreeningTest({
  97. adminEmail: user.email,
  98. email: activeProcess.process.applicant.email,
  99. duration: 60,
  100. testId: parseInt(selectedScreeningTest),
  101. url: "https:dzenis-meris.com",
  102. })
  103. );
  104. setActiveProcess(null);
  105. };
  106. const apiSuccess = () => {
  107. setActiveProcess(null);
  108. };
  109. return (
  110. <Dialog
  111. maxWidth={maxWidth}
  112. keepMounted={false}
  113. fullWidth={fullWidth}
  114. fullScreen={responsive && fullScreen}
  115. onClose={handleClose}
  116. open={open}
  117. style={{
  118. padding: "36px",
  119. }}
  120. >
  121. <div style={{ padding: "36px" }}>
  122. <DialogTitle style={{ padding: 0 }}>
  123. {fullScreen ? (
  124. <>
  125. <div className="flex-center" style={{ justifyContent: "start" }}>
  126. <img
  127. style={{
  128. position: "relative",
  129. top: -0.25,
  130. paddingRight: "10px",
  131. }}
  132. src={imgSrc}
  133. />
  134. <h5 style={{ textAlign: "start" }}>{title}</h5>
  135. <div style={{ justifySelf: "stretch", flex: "1" }}></div>
  136. <IconButton onClick={onClose}>
  137. <img
  138. style={{
  139. position: "relative",
  140. top: -0.25,
  141. }}
  142. src={x}
  143. />
  144. </IconButton>
  145. </div>
  146. <p
  147. className="dialog-subtitle"
  148. style={{ paddingLeft: "23px", marginTop: "-10px" }}
  149. >
  150. | {subtitle}
  151. </p>
  152. </>
  153. ) : (
  154. <div
  155. className="flex-center"
  156. style={{ justifyContent: "space-between" }}
  157. >
  158. <div className="flex-center" style={{ justifyContent: "start" }}>
  159. <img
  160. style={{
  161. position: "relative",
  162. top: -0.25,
  163. paddingRight: "10px",
  164. }}
  165. src={imgSrc}
  166. />
  167. <h5>{title}</h5>
  168. <div className="vr"></div>
  169. <p className="dialog-subtitle">{subtitle}</p>
  170. </div>
  171. </div>
  172. )}
  173. </DialogTitle>
  174. <DialogContent>
  175. <form className="modal-content interviewDialog">
  176. <FormControl fullWidth>
  177. <InputLabel id="demo-simple-select-label">
  178. Ime intervjuera
  179. </InputLabel>
  180. <Select
  181. labelId="demo-simple-select-label"
  182. id="demo-simple-select"
  183. value={selected}
  184. label="Ime intervjuera"
  185. onChange={(e) => {
  186. setSelected(e.target.value);
  187. }}
  188. >
  189. {users
  190. ? users.map(({ id, firstName, lastName }, index) => (
  191. <MenuItem
  192. key={index}
  193. sx={{ textAlign: "left" }}
  194. value={id}
  195. >
  196. {firstName} {lastName}
  197. </MenuItem>
  198. ))
  199. : ""}
  200. </Select>
  201. </FormControl>
  202. {activeProcess !== null &&
  203. activeProcess.process.selectionLevelId === 2 && (
  204. <FormControl fullWidth>
  205. <InputLabel id="demo-simple-select-label">
  206. Screening test
  207. </InputLabel>
  208. <Select
  209. labelId="demo-simple-select-label"
  210. id="demo-simple-select"
  211. value={selectedScreeningTest}
  212. label="Screening test"
  213. onChange={(e) => {
  214. setSelectedScreeningTest(e.target.value);
  215. }}
  216. >
  217. {screeningTests
  218. ? screeningTests.map((screeningTest, index) => (
  219. <MenuItem
  220. key={index}
  221. sx={{ textAlign: "left" }}
  222. value={screeningTest.id}
  223. >
  224. {screeningTest.name}
  225. </MenuItem>
  226. ))
  227. : ""}
  228. </Select>
  229. </FormControl>
  230. )}
  231. {/* {activeProcess.process && activeProcess.process.date ? <p>Proces ima zakazan termin</p> : ''} */}
  232. <DateTimePicker
  233. label="Termin"
  234. value={value}
  235. onChange={handleChange}
  236. renderInput={(params) => <TextField {...params} />}
  237. />
  238. </form>
  239. </DialogContent>
  240. <DialogActions style={{ padding: 0, justifyContent: "space-between" }}>
  241. {!fullScreen ? (
  242. <IconButton
  243. data-testid="editbtn"
  244. className={`c-btn--primary-outlined interview-btn c-btn dialog-btn`}
  245. onClick={onClose}
  246. >
  247. Cancel
  248. </IconButton>
  249. ) : (
  250. ""
  251. )}
  252. <IconButton
  253. data-testid="editbtn"
  254. className={`c-btn--primary-outlined sm-full interview-btn c-btn dialog-btn`}
  255. onClick={submitHandler}
  256. >
  257. Confirm
  258. </IconButton>
  259. </DialogActions>
  260. </div>
  261. </Dialog>
  262. );
  263. };
  264. StatusDialog.propTypes = {
  265. title: PropTypes.any,
  266. subtitle: PropTypes.any,
  267. imgSrc: PropTypes.any,
  268. open: PropTypes.bool.isRequired,
  269. onClose: PropTypes.func.isRequired,
  270. maxWidth: PropTypes.oneOf(["xs", "sm", "md", "lg", "xl"]),
  271. fullWidth: PropTypes.bool,
  272. responsive: PropTypes.bool,
  273. };
  274. export default StatusDialog;