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.

UserDetails.js 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. import React from "react";
  2. import PropTypes from "prop-types";
  3. import avatar from "../../assets/images/Avatar.png";
  4. import filters from "../../assets/images/filters.png";
  5. import lock from "../../assets/images/lock.png";
  6. import forbiden from "../../assets/images/forbiden.png";
  7. import IconButton from "../../components/IconButton/IconButton";
  8. import { Link, useParams } from "react-router-dom";
  9. import { deleteUserReq, setEnableUsersReq, userDetailsReq } from "../../store/actions/users/usersActions";
  10. import { useDispatch, useSelector } from "react-redux";
  11. import { USERS_PAGE } from "../../constants/pages";
  12. import { forgetPassword } from "../../store/actions/login/loginActions";
  13. import { useEffect } from "react";
  14. import { useTheme } from "@emotion/react";
  15. import { useMediaQuery } from "@mui/material";
  16. const UserDetails = ({ history }) => {
  17. const theme = useTheme();
  18. const matches = useMediaQuery(theme.breakpoints.down("sm"));
  19. const { id } = useParams();
  20. const dispatch = useDispatch();
  21. const { user } = useSelector((s) => s.userDetails);
  22. const handleReset = (email) => {
  23. dispatch(
  24. forgetPassword({
  25. email,
  26. handleApiResponseSuccessReset,
  27. })
  28. );
  29. };
  30. const enableHandler = () =>{
  31. dispatch(setEnableUsersReq({ id: user.id }));
  32. }
  33. const handleApiResponseSuccessReset = () => {
  34. console.log('DONE!')
  35. };
  36. const handleApiResponseSuccess = () => {
  37. history.push({
  38. pathname: USERS_PAGE,
  39. state: {
  40. from: history.location.pathname,
  41. },
  42. });
  43. };
  44. const deleteHandler = () => {
  45. dispatch(deleteUserReq({ id, handleApiResponseSuccess }));
  46. };
  47. useEffect(()=>{
  48. dispatch(userDetailsReq({id}))
  49. },[dispatch])
  50. return (
  51. <div>
  52. <div className="l-t-rectangle"></div>
  53. <div className="r-b-rectangle"></div>
  54. <div className="pl-144 pt-36px">
  55. <div className="divider">
  56. <div className="flex-center">
  57. <h1 style={{ letterSpacing: "1px" }}>Korisnik</h1>
  58. <div
  59. className="vr"
  60. style={{
  61. margin: "0px 10px 0px 15px",
  62. top: "6px",
  63. backgroundColor: "#252525",
  64. }}
  65. ></div>
  66. <h3
  67. style={{
  68. letterSpacing: "0.75px",
  69. position: "relative",
  70. top: "4px",
  71. }}
  72. className="text-blue"
  73. >
  74. {user && user.firstName} {user && user.lastName}
  75. </h3>
  76. </div>
  77. <div className="flex-center">
  78. <IconButton
  79. className={
  80. "c-btn--primary-outlined c-btn userPageBtn ml-20px no-padding"
  81. }
  82. onClick={() => handleReset(user.email)}
  83. >
  84. {!matches && 'Resetuj password'}
  85. <img
  86. style={{
  87. position: "relative",
  88. top: -0.25,
  89. paddingLeft: !matches && "10px",
  90. }}
  91. src={lock}
  92. />
  93. </IconButton>
  94. {!matches && <IconButton
  95. className={
  96. `c-btn--primary-outlined c-btn userPageBtn ml-20px no-padding ${user?.isEnabled ? 'activeEnable' : 'deactiveEnable'}`
  97. }
  98. onClick={enableHandler}
  99. >
  100. {user?.isEnabled ? 'Blokiraj' : 'Odblokiraj'}
  101. <img
  102. style={{
  103. position: "relative",
  104. top: -0.25,
  105. paddingLeft: "10px",
  106. }}
  107. src={forbiden}
  108. />
  109. </IconButton>}
  110. {!matches && <IconButton
  111. className={
  112. "c-btn--primary-outlined c-btn userPageBtn ml-20px no-padding"
  113. }
  114. onClick={deleteHandler}
  115. >
  116. Obrisi
  117. <img
  118. style={{
  119. position: "relative",
  120. top: -0.25,
  121. paddingLeft: "10px",
  122. }}
  123. src={filters}
  124. />
  125. </IconButton>}
  126. <IconButton
  127. className={
  128. "c-btn--primary-outlined c-btn userPageBtn ml-20px no-padding"
  129. }
  130. >
  131. {!matches && "Uredi profil"}
  132. <img
  133. style={{
  134. position: "relative",
  135. top: -0.25,
  136. paddingLeft: !matches && "10px",
  137. }}
  138. src={filters}
  139. />
  140. </IconButton>
  141. </div>
  142. </div>
  143. <div className="flex-center" style={{ justifyContent: "flex-start" }}>
  144. <img
  145. src={avatar}
  146. height="108px"
  147. width="108px"
  148. style={{ margin: "18px 15px 36px 0px" }}
  149. />
  150. <p>{user?.position ? user.position : "Position has not been declared yet."}</p>
  151. </div>
  152. <div style={{ display: "flex", flexDirection: "column", gap: "18px" }}>
  153. <p style={{ fontWeight: "600" }}>Kontakt</p>
  154. <div className="flex-center" style={{ justifyContent: "flex-start" }}>
  155. <p style={{ width: "85px" }}>Email:</p>
  156. <p className="text-blue">{user && user.email}</p>
  157. </div>
  158. <div className="flex-center" style={{ justifyContent: "flex-start" }}>
  159. <p style={{ width: "85px" }}>Telefon:</p>
  160. <p className="text-blue">{user?.phoneNumber ? user.phoneNumber : "User has no phone number saved."}</p>
  161. </div>
  162. </div>
  163. <div
  164. style={{
  165. display: "flex",
  166. flexDirection: "column",
  167. gap: "18px",
  168. paddingTop: "36px",
  169. }}
  170. >
  171. <p style={{ fontWeight: "600" }}>Drustvene mreze</p>
  172. <div className="flex-center" style={{ justifyContent: "flex-start" }}>
  173. <p style={{ width: "85px" }}>LinkedIn:</p>
  174. <p className="text-blue">{user?.socialMedias ? user.socialMedias : "User takes not part in any social media."}</p>
  175. </div>
  176. </div>
  177. <div
  178. style={{
  179. display: "flex",
  180. justifyContent: "flex-end",
  181. marginTop: "150px",
  182. }}
  183. >
  184. <Link to={"/users"} className="text-blue">
  185. Nazad na listu korisnika
  186. </Link>
  187. </div>
  188. </div>
  189. </div>
  190. );
  191. };
  192. export default UserDetails;
  193. UserDetails.propTypes = {
  194. history: PropTypes.shape({
  195. replace: PropTypes.func,
  196. push: PropTypes.func,
  197. location: PropTypes.shape({
  198. pathname: PropTypes.string,
  199. }),
  200. }),
  201. };