index.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. import React, { useState, useEffect } from 'react'
  2. import { CEditAvatar } from '../../components/EditAvatar'
  3. import { CustomInput } from '../../components/Input'
  4. import { message, Image, Button } from 'antd'
  5. import { connect } from 'react-redux'
  6. import {
  7. actionChangePassword,
  8. } from '../../actions/query/aboutMeQuery'
  9. import {actionClearPromiseForName} from '../../actions/types/promiseTypes'
  10. import { Basic, ConstructorModal } from '../../helpers'
  11. import { SpoilerButton } from '../../components/comment/SpoilerButton'
  12. import { actionUserUpdateTypeSaga } from '../../actions/typeSaga/myDataTypesSaga'
  13. import { EyeOutlined, EyeInvisibleOutlined } from '@ant-design/icons'
  14. export const EditAccount = ({ showModalEdit }) => {
  15. return (
  16. <Button
  17. type="primary"
  18. style={{
  19. fontWeight: '600',
  20. fontSize: '15px',
  21. transition: '.3s',
  22. boxShadow: '0 5px 15px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22)',
  23. }}
  24. onClick={showModalEdit}
  25. >
  26. Edit Setting
  27. </Button>
  28. )
  29. }
  30. const EditSetting = ({
  31. info,
  32. myId,
  33. onSaveUserUpsert,
  34. onClearPromise,
  35. onSaveNewPassword,
  36. changePassword,
  37. }) => {
  38. const [state, setState] = useState(info)
  39. const [changePass, setChangePass] = useState(changePassword)
  40. const [isModalVisibleEdit, setIsModalVisibleEdit] = useState(false)
  41. const [checked1, setChecked1] = useState(true)
  42. const [checked2, setChecked2] = useState(true)
  43. console.log('checked ', checked2)
  44. const showModalEdit = () => {
  45. setIsModalVisibleEdit(true)
  46. }
  47. const handleCancelEdit = () => {
  48. setIsModalVisibleEdit(false)
  49. }
  50. const onChangeLogin = (event) =>
  51. setState({
  52. ...state,
  53. login: event.target.value,
  54. })
  55. const onChangeNick = (event) =>
  56. setState({
  57. ...state,
  58. nick: event.target.value,
  59. })
  60. const onChangePassLogin = (event) =>
  61. setChangePass({
  62. ...changePass,
  63. login: event.target.value,
  64. })
  65. const onChangePassPassword = (event) =>
  66. setChangePass({
  67. ...changePass,
  68. password: event.target.value,
  69. })
  70. const onChangePassNew = (event) =>
  71. setChangePass({
  72. ...changePass,
  73. newPassword: event.target.value,
  74. })
  75. const saveChange = () => {
  76. onSaveUserUpsert(state, myId) &&
  77. message.success(`Successfully saved changed new login!`) &&
  78. setIsModalVisibleEdit(false)
  79. // &&onClearPromise('userUpsert')
  80. }
  81. const saveNewPassword = () => {
  82. onSaveNewPassword(
  83. changePass.login,
  84. changePass.password,
  85. changePass.newPassword,
  86. )
  87. if (changePassword?.payload == null && changePass.login != info?.login) {
  88. message.error(`You entered wrong login/password! Try again!`)
  89. // onClearPromise('newPassword')
  90. } else {
  91. message.success(`Successfully saved changed new password!`) &&
  92. setIsModalVisibleEdit(false)
  93. // && onClearPromise('newPassword')
  94. }
  95. }
  96. console.log('save pass', changePass?.login != info?.login)
  97. return (
  98. <div>
  99. <EditAccount showModalEdit={showModalEdit} />
  100. <ConstructorModal
  101. title={'Edit setting'}
  102. isModalVisible={isModalVisibleEdit}
  103. setIsModalVisible={setIsModalVisibleEdit}
  104. handleCancel={handleCancelEdit}
  105. >
  106. <h2> Edit avatar </h2>
  107. <SpoilerButton text={'Change avatar'} style={{ width: '100%' }}>
  108. <CEditAvatar setIsModalVisibleEdit={setIsModalVisibleEdit} />
  109. </SpoilerButton>
  110. <h2> Edit login </h2>
  111. <SpoilerButton text={'Change login'} style={{ width: '100%' }}>
  112. <div
  113. style={{
  114. display: 'flex',
  115. alignItems: 'center',
  116. flexDirection: 'row',
  117. }}
  118. >
  119. <CustomInput
  120. state={state?.login || ''}
  121. onChangeText={onChangeLogin}
  122. />
  123. <Button
  124. size="large"
  125. style={{ margin: '10px' }}
  126. onClick={saveChange}
  127. disabled={state?.login ? false : true}
  128. type="primary"
  129. >
  130. {' '}
  131. Save login{' '}
  132. </Button>
  133. </div>
  134. </SpoilerButton>
  135. <h2> Edit nick </h2>
  136. <SpoilerButton text={'Change nick'} style={{ width: '100%' }}>
  137. <div
  138. style={{
  139. display: 'flex',
  140. alignItems: 'center',
  141. flexDirection: 'row',
  142. }}
  143. >
  144. <CustomInput
  145. state={state?.nick || ''}
  146. onChangeText={onChangeNick}
  147. />
  148. <Button
  149. style={{ margin: '10px' }}
  150. disabled={state?.nick ? false : true}
  151. onClick={saveChange}
  152. size="large"
  153. type="primary"
  154. >
  155. Save nick
  156. </Button>
  157. </div>
  158. </SpoilerButton>
  159. <h2> Edit password </h2>
  160. <SpoilerButton text={'Change password'} style={{ width: '100%' }}>
  161. <h3> Login</h3>
  162. <div
  163. style={{
  164. display: 'flex',
  165. alignItems: 'center',
  166. flexDirection: 'row',
  167. }}
  168. >
  169. <CustomInput
  170. state={changePass?.login}
  171. onChangeText={onChangePassLogin}
  172. type={true}
  173. />
  174. </div>
  175. <h3> Old password</h3>
  176. <div
  177. style={{
  178. display: 'flex',
  179. alignItems: 'center',
  180. flexDirection: 'row',
  181. }}
  182. >
  183. <CustomInput
  184. state={changePass?.password}
  185. onChangeText={onChangePassPassword}
  186. checked={checked1}
  187. />
  188. {checked1 ? (
  189. <EyeInvisibleOutlined
  190. onClick={() => setChecked1(!checked1)}
  191. style={{ marginLeft: '5px', fontSize: 'xx-large' }}
  192. />
  193. ) : (
  194. <EyeOutlined
  195. onClick={() => setChecked1(!checked1)}
  196. style={{ marginLeft: '5px', fontSize: 'xx-large' }}
  197. />
  198. )}
  199. </div>
  200. {console.log('ckeck тутааа', checked1)}
  201. <h3> New password</h3>
  202. <div
  203. style={{
  204. display: 'flex',
  205. alignItems: 'center',
  206. flexDirection: 'row',
  207. }}
  208. >
  209. <CustomInput
  210. state={changePass?.newPassword || ''}
  211. // type={checkEye1 ? 'password' : 'text'}
  212. checked={checked2}
  213. onChangeText={onChangePassNew}
  214. />
  215. {checked2 ? (
  216. <EyeInvisibleOutlined
  217. onClick={() => setChecked2(!checked2)}
  218. style={{ marginLeft: '5px', fontSize: 'xx-large' }}
  219. />
  220. ) : (
  221. <EyeOutlined
  222. onClick={() => setChecked2(!checked2)}
  223. style={{ marginLeft: '5px', fontSize: 'xx-large' }}
  224. />
  225. )}
  226. </div>
  227. <div
  228. style={{
  229. display: 'flex',
  230. alignItems: 'center',
  231. flexDirection: 'column',
  232. }}
  233. >
  234. <Button
  235. style={{ margin: '10px' }}
  236. disabled={
  237. changePass?.login &&
  238. changePass?.password &&
  239. changePass?.newPassword
  240. ? false
  241. : true
  242. }
  243. onClick={saveNewPassword}
  244. size="x-large"
  245. type="primary"
  246. >
  247. Save new password
  248. </Button>
  249. </div>
  250. </SpoilerButton>
  251. </ConstructorModal>
  252. </div>
  253. )
  254. }
  255. export const CEditSetting = connect(
  256. (state) => ({
  257. myId: state?.auth.payload.sub?.id,
  258. info: state?.myData?.aboutMe,
  259. changePassword: state.promise?.newPassword,
  260. }),
  261. {
  262. onSaveUserUpsert: actionUserUpdateTypeSaga,
  263. onSaveNewPassword: actionChangePassword,
  264. onClearPromise: actionClearPromiseForName,
  265. },
  266. )(EditSetting)