Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

StatusDialog.js 9.1KB

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