You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

InterviewDialog.js 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. import React, { 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. const InterviewDialog = ({
  25. title,
  26. subtitle,
  27. imgSrc,
  28. onClose,
  29. open,
  30. maxWidth,
  31. fullWidth,
  32. responsive,
  33. }) => {
  34. const [selected, setSelected] = useState("");
  35. const [selectedInterviewer, setSelectedInterviewer] = useState(null);
  36. const [value, setValue] = useState(null);
  37. const theme = useTheme();
  38. const fullScreen = useMediaQuery(theme.breakpoints.down("md"));
  39. const { options } = useSelector((n) => n.options);
  40. const { users } = useSelector((n) => n.users);
  41. const { isSuccess } = useSelector((s) => s.initProcess);
  42. const dispatch = useDispatch();
  43. useEffect(() => {
  44. handleClose();
  45. }, [dispatch, isSuccess]);
  46. const handleChange = (newValue) => {
  47. if (isValid(newValue)) {
  48. // throws an error if invalid value is set
  49. var date = format(newValue, "yyyy-MM-dd'T'HH:mm:ss.SSSxxx");
  50. setValue(date);
  51. }
  52. };
  53. useEffect(() => {
  54. setSelected("");
  55. setSelectedInterviewer(null);
  56. setValue(null);
  57. }, [onClose]);
  58. const handleClose = () => {
  59. onClose();
  60. };
  61. const submitHandler = () => {
  62. dispatch(
  63. fetchInitProcess({
  64. model: {
  65. schedulerId: selectedInterviewer,
  66. appointment: value,
  67. applicantId: selected,
  68. },
  69. })
  70. );
  71. };
  72. return (
  73. <Dialog
  74. maxWidth={maxWidth}
  75. keepMounted={false}
  76. fullWidth={fullWidth}
  77. fullScreen={responsive && fullScreen}
  78. onClose={handleClose}
  79. open={open}
  80. style={{
  81. padding: "36px",
  82. }}
  83. >
  84. <div data-testid="interview-dialog" style={{ padding: "36px" }}>
  85. <DialogTitle style={{ padding: 0 }}>
  86. {fullScreen ? (
  87. <>
  88. <div className="flex-center" style={{ justifyContent: "start" }}>
  89. <img
  90. style={{
  91. position: "relative",
  92. top: -0.25,
  93. paddingRight: "10px",
  94. }}
  95. src={imgSrc}
  96. />
  97. <h5 style={{ textAlign: "start" }}>{title}</h5>
  98. <div style={{ justifySelf: "stretch", flex: "1" }}></div>
  99. <IconButton onClick={onClose}>
  100. <img
  101. style={{
  102. position: "relative",
  103. top: -0.25,
  104. }}
  105. src={x}
  106. />
  107. </IconButton>
  108. </div>
  109. <p
  110. className="dialog-subtitle"
  111. style={{ paddingLeft: "23px", marginTop: "-10px" }}
  112. >
  113. | {subtitle}
  114. </p>
  115. </>
  116. ) : (
  117. <div
  118. className="flex-center"
  119. style={{ justifyContent: "space-between" }}
  120. >
  121. <div className="flex-center" style={{ justifyContent: "start" }}>
  122. <img
  123. style={{
  124. position: "relative",
  125. top: -0.25,
  126. paddingRight: "10px",
  127. }}
  128. src={imgSrc}
  129. />
  130. <h5>{title}</h5>
  131. <div className="vr"></div>
  132. <p className="dialog-subtitle">{subtitle}</p>
  133. </div>
  134. </div>
  135. )}
  136. </DialogTitle>
  137. <DialogContent>
  138. <form className="modal-content interviewDialog">
  139. <FormControl fullWidth>
  140. <InputLabel id="demo-simple-select-label">
  141. Ime kandidata
  142. </InputLabel>
  143. <Select
  144. labelId="demo-simple-select-label"
  145. id="demo-simple-select"
  146. value={selected}
  147. label="Ime kandidata"
  148. onChange={(e) => {
  149. setSelected(e.target.value);
  150. }}
  151. >
  152. {options
  153. ? options.map(
  154. ({ applicantId, firstName, lastName }, index) => (
  155. <MenuItem
  156. key={index}
  157. sx={{ textAlign: "left" }}
  158. value={applicantId}
  159. >
  160. {firstName} {lastName}
  161. </MenuItem>
  162. )
  163. )
  164. : ""}
  165. </Select>
  166. </FormControl>
  167. <FormControl fullWidth>
  168. <InputLabel id="demo-simple-select-label">
  169. Ime intervjuera (opciono)
  170. </InputLabel>
  171. <Select
  172. labelId="demo-simple-select-label"
  173. id="demo-simple-select"
  174. value={selectedInterviewer ? selectedInterviewer : ''}
  175. label="Ime intervjuera (opciono)"
  176. onChange={(e) => {
  177. setSelectedInterviewer(e.target.value);
  178. }}
  179. >
  180. {users
  181. ? users.map(({ id, firstName, lastName }, index) => (
  182. <MenuItem
  183. key={index}
  184. sx={{ textAlign: "left" }}
  185. value={id}
  186. >
  187. {firstName} {lastName}
  188. </MenuItem>
  189. ))
  190. : ""}
  191. </Select>
  192. </FormControl>
  193. <DateTimePicker
  194. label="Termin (opciono)"
  195. value={value}
  196. onChange={handleChange}
  197. renderInput={(params) => <TextField {...params} />}
  198. />
  199. </form>
  200. </DialogContent>
  201. <DialogActions style={{ padding: 0, justifyContent: "space-between" }}>
  202. {!fullScreen ? (
  203. <IconButton
  204. data-testid="editbtn"
  205. className={`c-btn--primary-outlined interview-btn c-btn dialog-btn`}
  206. onClick={onClose}
  207. >
  208. Otkaži
  209. </IconButton>
  210. ) : (
  211. ""
  212. )}
  213. <IconButton
  214. data-testid="editbtn"
  215. className={`c-btn--primary-outlined sm-full interview-btn c-btn dialog-btn`}
  216. onClick={submitHandler}
  217. >
  218. Potvrdi
  219. </IconButton>
  220. </DialogActions>
  221. </div>
  222. </Dialog>
  223. );
  224. };
  225. InterviewDialog.propTypes = {
  226. title: PropTypes.any,
  227. subtitle: PropTypes.any,
  228. imgSrc: PropTypes.any,
  229. open: PropTypes.bool.isRequired,
  230. onClose: PropTypes.func.isRequired,
  231. maxWidth: PropTypes.oneOf(["xs", "sm", "md", "lg", "xl"]),
  232. fullWidth: PropTypes.bool,
  233. responsive: PropTypes.bool,
  234. };
  235. export default InterviewDialog;