FormUpload.jsx 4.1 KB

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