ProfilePage.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import React, { useCallback, useState, useEffect } from "react";
  2. import FloatingLabel from "react-bootstrap/FloatingLabel";
  3. import Form from "react-bootstrap/Form";
  4. import Button from "react-bootstrap/esm/Button";
  5. import { useDropzone } from "react-dropzone";
  6. import { Link } from "react-router-dom";
  7. import { CMyAvatar } from "../components/Avatar";
  8. import { actionSetUserInfo } from "../actions";
  9. import { connect } from "react-redux";
  10. const ProfilePage = ({ myProfile, onChanges }) => {
  11. const [login, setLogin] = useState(myProfile.login);
  12. const [nick, setNick] = useState(myProfile.nick);
  13. const [img, setImg] = useState(null);
  14. console.log(img)
  15. const { getRootProps, getInputProps, isDragActive } = useDropzone({
  16. accept: "image/*",
  17. maxFiles: 1,
  18. onDrop: (acceptedFiles) => {
  19. setImg(acceptedFiles[0]);
  20. },
  21. });
  22. return (
  23. <div style={{ paddingTop: "100px" }}>
  24. <h1 className="textProfile">My profile</h1>
  25. <div {...getRootProps({ className: "dropZoneStyle" })}>
  26. <input {...getInputProps()} />
  27. {isDragActive ? (
  28. <p className="dropZoneStyleBr">Drop the files here ...</p>
  29. ) : (
  30. <CMyAvatar text="change avatar" className="profileStyle"/>
  31. )}
  32. </div>
  33. <div className="profileContainer">
  34. <div className="loginNickSetting">
  35. <div className="inputContainer">
  36. <label>Enter a new Login: </label>
  37. <input
  38. className="form-control-editing form-control"
  39. id="loginInput"
  40. type="text"
  41. value={login}
  42. onChange={(e) => {
  43. setLogin(e.target.value);
  44. }}
  45. />
  46. </div>
  47. <div className="inputContainer">
  48. <label>Enter a new Nick: </label>
  49. <input
  50. className="form-control-editing form-control"
  51. id="nickInput"
  52. type="text"
  53. value={nick}
  54. onChange={(e) => {
  55. setNick(e.target.value);
  56. }}
  57. />
  58. </div>
  59. <div className="df">
  60. <Button
  61. variant="primary"
  62. className="buttonSetting"
  63. onClick={() => {
  64. onChanges("media", img, login, nick);
  65. console.log("media", login, nick, img);
  66. }}
  67. >
  68. <Link
  69. to="/changesdone"
  70. style={{
  71. color: "white",
  72. textDecoration: "none",
  73. }}
  74. >
  75. Apply Changes
  76. </Link>
  77. </Button>
  78. <Link to="/changepas" className="changepasLink">
  79. Сhange password
  80. </Link>
  81. </div>
  82. </div>
  83. </div>
  84. </div>
  85. );
  86. };
  87. export const CProfilePage = connect(
  88. (state) => ({
  89. myProfile: state.promise?.myProfile?.payload || {},
  90. }),
  91. { onChanges: actionSetUserInfo }
  92. )(ProfilePage);