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 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. const StatusDialog = ({
  27. title,
  28. subtitle,
  29. imgSrc,
  30. onClose,
  31. open,
  32. maxWidth,
  33. fullWidth,
  34. responsive,
  35. }) => {
  36. const [selected, setSelected] = useState("");
  37. const [value, setValue] = useState(null);
  38. const { activeProcess, setActiveProcess } = useContext(SelectionContext)
  39. const theme = useTheme();
  40. const fullScreen = useMediaQuery(theme.breakpoints.down("md"));
  41. const { users } = useSelector((s) => s.users);
  42. const { isSuccess } = useSelector((s) => s.initProcess);
  43. const dispatch = useDispatch();
  44. useEffect(() => {
  45. handleClose();
  46. }, [dispatch, isSuccess]);
  47. const handleChange = (newValue) => {
  48. if (isValid(newValue)) { // 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. setValue(null)
  56. }, [onClose])
  57. const handleClose = () => {
  58. onClose();
  59. };
  60. const submitHandler = () => {
  61. dispatch(
  62. setUpdateStatusReq({
  63. data: {
  64. schedulerId: selected,
  65. appointment: value,
  66. newStatus: activeProcess.status,
  67. processId: activeProcess.process.id,
  68. },
  69. responseHandler: apiSuccess
  70. })
  71. );
  72. };
  73. const apiSuccess = () =>{
  74. setActiveProcess(null)
  75. }
  76. return (
  77. <Dialog
  78. maxWidth={maxWidth}
  79. keepMounted={false}
  80. fullWidth={fullWidth}
  81. fullScreen={responsive && fullScreen}
  82. onClose={handleClose}
  83. open={open}
  84. style={{
  85. padding: "36px",
  86. }}
  87. >
  88. <div style={{ padding: "36px" }}>
  89. <DialogTitle style={{ padding: 0 }}>
  90. {fullScreen ? (
  91. <>
  92. <div className="flex-center" style={{ justifyContent: "start" }}>
  93. <img
  94. style={{
  95. position: "relative",
  96. top: -0.25,
  97. paddingRight: "10px",
  98. }}
  99. src={imgSrc}
  100. />
  101. <h5 style={{ textAlign: "start" }}>{title}</h5>
  102. <div style={{ justifySelf: "stretch", flex: "1" }}></div>
  103. <IconButton onClick={onClose}>
  104. <img
  105. style={{
  106. position: "relative",
  107. top: -0.25,
  108. }}
  109. src={x}
  110. />
  111. </IconButton>
  112. </div>
  113. <p
  114. className="dialog-subtitle"
  115. style={{ paddingLeft: "23px", marginTop: "-10px" }}
  116. >
  117. | {subtitle}
  118. </p>
  119. </>
  120. ) : (
  121. <div
  122. className="flex-center"
  123. style={{ justifyContent: "space-between" }}
  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>{title}</h5>
  135. <div className="vr"></div>
  136. <p className="dialog-subtitle">{subtitle}</p>
  137. </div>
  138. </div>
  139. )}
  140. </DialogTitle>
  141. <DialogContent>
  142. <form className="modal-content interviewDialog">
  143. <FormControl fullWidth>
  144. <InputLabel id="demo-simple-select-label">
  145. Ime intervjuera
  146. </InputLabel>
  147. <Select
  148. labelId="demo-simple-select-label"
  149. id="demo-simple-select"
  150. value={selected}
  151. label="Ime intervjuera"
  152. onChange={(e) => {
  153. setSelected(e.target.value);
  154. }}
  155. >
  156. {users
  157. ? users.map(
  158. ({ id, firstName, lastName }, index) => (
  159. <MenuItem
  160. key={index}
  161. sx={{ textAlign: "left" }}
  162. value={id}
  163. >
  164. {firstName} {lastName}
  165. </MenuItem>
  166. )
  167. )
  168. : ""}
  169. </Select>
  170. </FormControl>
  171. {/* {activeProcess.process && activeProcess.process.date ? <p>Proces ima zakazan termin</p> : ''} */}
  172. <DateTimePicker
  173. label="Termin"
  174. value={value}
  175. onChange={handleChange}
  176. renderInput={(params) => <TextField {...params} />}
  177. />
  178. </form>
  179. </DialogContent>
  180. <DialogActions style={{ padding: 0, justifyContent: "space-between" }}>
  181. {!fullScreen ? (
  182. <IconButton
  183. data-testid="editbtn"
  184. className={`c-btn--primary-outlined interview-btn c-btn dialog-btn`}
  185. onClick={onClose}
  186. >
  187. Cancel
  188. </IconButton>
  189. ) : (
  190. ""
  191. )}
  192. <IconButton
  193. data-testid="editbtn"
  194. className={`c-btn--primary-outlined sm-full interview-btn c-btn dialog-btn`}
  195. onClick={submitHandler}
  196. >
  197. Confirm
  198. </IconButton>
  199. </DialogActions>
  200. </div>
  201. </Dialog>
  202. );
  203. };
  204. StatusDialog.propTypes = {
  205. title: PropTypes.any,
  206. subtitle: PropTypes.any,
  207. imgSrc: PropTypes.any,
  208. open: PropTypes.bool.isRequired,
  209. onClose: PropTypes.func.isRequired,
  210. maxWidth: PropTypes.oneOf(["xs", "sm", "md", "lg", "xl"]),
  211. fullWidth: PropTypes.bool,
  212. responsive: PropTypes.bool,
  213. };
  214. export default StatusDialog;