Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. import React, { useState } from "react";
  2. import IconButton from "../../components/IconButton/IconButton";
  3. import planeVector from "../../assets/images/planeVector.png";
  4. import lock from "../../assets/images/lock.png";
  5. // import filters from "../../assets/images/filters.png";
  6. import forbiden from "../../assets/images/forbiden.png";
  7. import x from "../../assets/images/x.png";
  8. import edit from "../../assets/images/edit.png";
  9. import { useEffect } from "react";
  10. import addUser from "../../assets/images/addUser.png";
  11. // import { getAllUsers } from "../../request/usersRequest";
  12. // import { getUsers } from "../../store/saga/usersSaga";
  13. import { useDispatch, useSelector } from "react-redux";
  14. import {
  15. // deleteUserReq,
  16. setEnableUsersReq,
  17. setUsersReq,
  18. } from "../../store/actions/users/usersActions";
  19. import { useTheme } from "@mui/system";
  20. import { TextField, useMediaQuery } from "@mui/material";
  21. // import DialogComponent from "../../components/MUI/DialogComponent";
  22. import InviteDialog from "../../components/MUI/InviteDialog";
  23. import { Link } from "react-router-dom";
  24. import { forgetPassword } from "../../store/actions/login/loginActions";
  25. import { useTranslation } from "react-i18next";
  26. import ConfirmDialog from "../../components/MUI/ConfirmDialog";
  27. import EditButton from "../../components/Button/EditButton";
  28. const UsersPage = () => {
  29. const theme = useTheme();
  30. const matches = useMediaQuery(theme.breakpoints.down("sm"));
  31. const dispatch = useDispatch();
  32. const { users } = useSelector((s) => s.users);
  33. const [showInvite, setShowInvite] = useState(false);
  34. const [editEnable, setEdit] = useState(false);
  35. const [search, setSearch] = useState("");
  36. const [chosen, setChosen] = useState(null);
  37. const [showConfirm, setConfirm] = useState(false);
  38. const [showReset, setReset] = useState(false);
  39. const { t } = useTranslation();
  40. useEffect(() => {
  41. dispatch(setUsersReq());
  42. }, [dispatch]);
  43. const disableHandler = (id) => {
  44. dispatch(
  45. setEnableUsersReq({
  46. id,
  47. handleApiResponseSuccess: handleApiResponseSuccessEnable,
  48. })
  49. );
  50. };
  51. const handleReset = (email) => {
  52. dispatch(
  53. forgetPassword({
  54. email,
  55. handleApiResponseSuccess: handleApiResponseSuccessReset,
  56. })
  57. );
  58. };
  59. const handleApiResponseSuccessReset = () => {
  60. setReset(false);
  61. };
  62. const handleApiResponseSuccessEnable = () => {
  63. setConfirm(false);
  64. };
  65. const formatLabel = (string, value) => {
  66. if (!value) {
  67. return string;
  68. }
  69. return (
  70. <span>
  71. {string.split(value).reduce((prev, current, i) => {
  72. if (!i) {
  73. return [current];
  74. }
  75. return prev.concat(
  76. <b className="highlighted" key={value + current}>
  77. {value}
  78. </b>,
  79. current
  80. );
  81. }, [])}
  82. </span>
  83. );
  84. };
  85. return (
  86. <div>
  87. <div className="l-t-rectangle"></div>
  88. <div className="r-b-rectangle"></div>
  89. <ConfirmDialog
  90. open={showConfirm}
  91. title={"Disable user"}
  92. subtitle={chosen?.firstName + " " + chosen?.lastName}
  93. imgSrc={forbiden}
  94. content="Are you sure you want to disable user?"
  95. onClose={() => {
  96. setConfirm(false);
  97. }}
  98. onConfirm={() => {
  99. disableHandler(chosen.id);
  100. // setConfirm(false)
  101. }}
  102. />
  103. <ConfirmDialog
  104. open={showReset}
  105. title={"Reset password"}
  106. subtitle={chosen?.firstName + " " + chosen?.lastName}
  107. imgSrc={lock}
  108. content="Are you sure you want to send password reset link?"
  109. onClose={() => {
  110. setReset(false);
  111. }}
  112. onConfirm={() => {
  113. handleReset(chosen.email);
  114. // setConfirm(false)
  115. }}
  116. />
  117. <InviteDialog
  118. open={showInvite}
  119. onClose={() => {
  120. setShowInvite(false);
  121. }}
  122. title={
  123. <div
  124. className="flex-center"
  125. style={{ justifyContent: "space-between" }}
  126. >
  127. <div className="flex-center" style={{ justifyContent: "start" }}>
  128. <img
  129. style={{
  130. position: "relative",
  131. top: -0.25,
  132. paddingRight: "10px",
  133. }}
  134. src={addUser}
  135. />
  136. <h5>{t("users.inviteUser")}</h5>
  137. {!matches && <div className="vr"></div>}
  138. {!matches && <p className="dialog-subtitle">{t("users.regLink")}</p>}
  139. </div>
  140. <IconButton onClick={() => setShowInvite(false)}>
  141. <img
  142. style={{
  143. position: "relative",
  144. top: -0.25,
  145. }}
  146. src={x}
  147. />
  148. </IconButton>
  149. </div>
  150. }
  151. />
  152. <div>
  153. <div
  154. className="pl-144 flex-center"
  155. style={{ paddingTop: "36px", justifyContent: "space-between" }}
  156. >
  157. <h1 className="page-heading">{t("users.management")}</h1>
  158. <div className="flex-center">
  159. {/* <button></button> */}
  160. <EditButton
  161. onEnableEdit={() => {
  162. setEdit((s) => !s);
  163. }}
  164. />
  165. <IconButton
  166. className={"c-btn--primary c-btn inviteBtn"}
  167. onClick={() => {
  168. setShowInvite(true);
  169. }}
  170. >
  171. {t("users.invite")}
  172. <img
  173. style={{
  174. position: "relative",
  175. top: 1.25,
  176. paddingLeft: "15px",
  177. }}
  178. src={planeVector}
  179. />{" "}
  180. </IconButton>
  181. </div>
  182. </div>
  183. <div
  184. className="pl-144"
  185. style={{
  186. display: "flex",
  187. marginTop: "39px",
  188. flexDirection: "column",
  189. justifyContent: "space-between",
  190. minHeight: "500px",
  191. }}
  192. >
  193. <div className="table-cont">
  194. <TextField
  195. name="username"
  196. label={t("common.labelUsername")}
  197. margin="normal"
  198. value={search}
  199. onChange={(e) => setSearch(e.target.value)}
  200. style={{
  201. width: editEnable ? "960px" : '720px',
  202. }}
  203. />
  204. <table className={editEnable ? 'usersTable-users normal' : 'usersTable-users mini'}
  205. // style={{ width: "893.56px" }}
  206. >
  207. <thead>
  208. <tr className="headingRow">
  209. <th>{t("users.fullName")}</th>
  210. <th>E-mail</th>
  211. <th>{t("users.position")}</th>
  212. {editEnable && <th></th>}
  213. </tr>
  214. </thead>
  215. <tbody>
  216. {
  217. users
  218. .filter((n) =>
  219. (n.firstName + " " + n.lastName)
  220. .toLowerCase()
  221. .includes(search.toLowerCase())
  222. )
  223. .map((n) => (
  224. <tr key={n.id} className="secondaryRow">
  225. <td>
  226. {(n.firstName + " " + n.lastName).includes(search) ? (
  227. formatLabel(n.firstName + " " + n.lastName, search)
  228. ) : (
  229. <span>{n.firstName + " " + n.lastName}</span>
  230. )}
  231. </td>
  232. <td>{n.email}</td>
  233. <td className='profession'>HR Specialist</td>
  234. {editEnable && (
  235. <td>
  236. <>
  237. <IconButton
  238. className={`c-btn--primary-outlined c-btn td-btn`}
  239. onClick={() => {
  240. setChosen(n);
  241. setReset(true);
  242. }}
  243. >
  244. <img
  245. style={{
  246. position: "relative",
  247. }}
  248. src={lock}
  249. />
  250. </IconButton>
  251. <IconButton
  252. className={`c-btn--primary-outlined c-btn td-btn ${
  253. n.isEnabled ? "active" : "inactive"
  254. }`}
  255. onClick={() => {
  256. setChosen(n);
  257. setConfirm(true);
  258. }}
  259. >
  260. <img
  261. style={{
  262. position: "relative",
  263. }}
  264. src={forbiden}
  265. />
  266. </IconButton>
  267. <Link to={`/users/${n.id}`}>
  268. <IconButton
  269. className={
  270. "c-btn--primary-outlined c-btn td-btn"
  271. }
  272. >
  273. <img
  274. style={{
  275. position: "relative",
  276. }}
  277. src={edit}
  278. />
  279. </IconButton>
  280. </Link>
  281. </>
  282. </td>
  283. )}
  284. </tr>
  285. ))
  286. }
  287. </tbody>
  288. </table>
  289. </div>
  290. <div
  291. style={{
  292. display: "flex",
  293. justifyContent: "flex-end",
  294. marginBottom: "35px",
  295. }}
  296. ></div>
  297. </div>
  298. </div>
  299. </div>
  300. );
  301. };
  302. export default UsersPage;