FormUpload.jsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import {useState} from "react";
  2. import {Button, Grid, TextField} from "@mui/material";
  3. import SendAndArchiveIcon from "@mui/icons-material/SendAndArchive";
  4. import CancelIcon from "@mui/icons-material/Cancel";
  5. import {connect} from "react-redux";
  6. import {
  7. actionSetAvatar,
  8. actionSetUserUpsert
  9. } from "../../actions/ActionUploadFile";
  10. import {actionFullUserFindOne} from "../../actions/ActionUserFind";
  11. import {MyDropzone} from "./MyDropzone";
  12. const FormUpload = ({user, setStatus, setUserUpsert, setImage}) => {
  13. const [loginValue, setLoginValue] = useState(user?.login || '')
  14. const [nickValue, setNickValue] = useState(user?.nick || '')
  15. const [passwordValue, setPasswordValue] = useState('')
  16. const [fileValue, setFileValue] = useState('')
  17. return (
  18. <Grid
  19. container
  20. spacing={2}
  21. justifyContent='center'
  22. textAlign='center'
  23. flexDirection='column'
  24. >
  25. <Grid
  26. item xs={12}
  27. display='flex'
  28. justifyContent='space-between'
  29. alignItems='center'
  30. marginBottom='30px'
  31. >
  32. <TextField
  33. sx={{color: '#000'}}
  34. label={'Login'}
  35. variant="outlined"
  36. placeholder={user?.login || ''}
  37. onChange={e => setLoginValue(e.target.value)}
  38. />
  39. <TextField
  40. sx={{color: '#000'}}
  41. label={'Nick'}
  42. variant="outlined"
  43. placeholder={user?.nick || ''}
  44. onChange={e => setNickValue(e.target.value)}
  45. />
  46. <TextField
  47. sx={{color: '#000'}}
  48. label={'Password'}
  49. type='password'
  50. variant="outlined"
  51. onChange={e => setPasswordValue(e.target.value)}
  52. />
  53. </Grid>
  54. <Grid
  55. item xs={12}
  56. display='flex'
  57. justifyContent='space-between'
  58. alignItems='center'
  59. marginBottom='30px'
  60. >
  61. <MyDropzone onLoad={value => setFileValue(value)}/>
  62. </Grid>
  63. <Grid
  64. item xs={12}
  65. display='flex'
  66. justifyContent='center'
  67. alignItems='center'
  68. >
  69. <Button
  70. style={{ color: '#1976d2'}}
  71. fullWidth
  72. type='submit'
  73. onClick={() => {
  74. let obj = {}
  75. if (loginValue !== user?.login) {
  76. obj.login = loginValue
  77. }
  78. if (nickValue !== user?.nick) {
  79. obj.nick = nickValue
  80. }
  81. if (passwordValue){
  82. obj.password = passwordValue
  83. }
  84. if (Array.isArray(fileValue) && fileValue[0]) {
  85. setImage(fileValue[0]);
  86. setStatus(false)
  87. }
  88. if (Object.values(obj).length > 0){
  89. setUserUpsert(obj)
  90. setStatus(false)
  91. }
  92. }}
  93. >
  94. <SendAndArchiveIcon style={{marginRight: '5px'}}/>
  95. Save
  96. </Button>
  97. <Button
  98. style={{ color: '#1976d2'}}
  99. fullWidth
  100. onClick={() => setStatus(false)}
  101. >
  102. <CancelIcon style={{marginRight: '5px'}}/>
  103. Cancel
  104. </Button>
  105. </Grid>
  106. </Grid>
  107. )
  108. }
  109. export const CFormUpload = connect(null,
  110. {setUserUpsert: actionSetUserUpsert,
  111. setImage: actionSetAvatar, userUpdate: actionFullUserFindOne})(FormUpload)