|
@@ -0,0 +1,201 @@
|
|
|
+import React, {useEffect, useState} from 'react';
|
|
|
+import Box from '@mui/material/Box';
|
|
|
+import Modal from '@mui/material/Modal';
|
|
|
+import Button from '@mui/material/Button';
|
|
|
+import IconButton from '@mui/material/IconButton';
|
|
|
+import Typography from '@mui/material/Typography';
|
|
|
+import TextField from '@mui/material/TextField';
|
|
|
+import CloseIcon from '@mui/icons-material/Close';
|
|
|
+import List from '@mui/material/List';
|
|
|
+
|
|
|
+import { ChatAvatar, UserCard } from '.'
|
|
|
+
|
|
|
+import {connect} from 'react-redux'
|
|
|
+
|
|
|
+
|
|
|
+const styleModalParrent = {
|
|
|
+ position: 'absolute',
|
|
|
+ top: '50%',
|
|
|
+ left: '50%',
|
|
|
+ transform: 'translate(-50%, -50%)',
|
|
|
+ width: '70%',
|
|
|
+ maxWidth: '1000px',
|
|
|
+ height: '95%',
|
|
|
+ bgcolor: 'background.paper',
|
|
|
+ border: '1px solid #999',
|
|
|
+ boxShadow: 24,
|
|
|
+ p: 3,
|
|
|
+ display: 'flex',
|
|
|
+ flexDirection: 'column',
|
|
|
+ justifyContent: 'space-between',
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+const ChatInfoModal = ({ chat, render }) => {
|
|
|
+
|
|
|
+ const [open, setOpen] = useState(false)
|
|
|
+ const handleOpen = () => setOpen(true)
|
|
|
+ const handleClose = () => setOpen(false)
|
|
|
+
|
|
|
+
|
|
|
+ const OpenBtn = render
|
|
|
+ return (
|
|
|
+ <>
|
|
|
+ <OpenBtn chat={chat} OPEN={handleOpen} />
|
|
|
+
|
|
|
+ <Modal
|
|
|
+ open={open}
|
|
|
+ onClose={handleClose}
|
|
|
+ >
|
|
|
+
|
|
|
+ <Box sx={styleModalParrent}>
|
|
|
+
|
|
|
+ <Box sx={{ display: 'flex', justifyContent: 'space-between', borderBottom: '1px solid #999', pb: 1, mb: 1 }}>
|
|
|
+
|
|
|
+ <Box sx={{ display: 'flex', justifyContent: 'start' }}>
|
|
|
+ <Typography variant="h6">
|
|
|
+ {((chat?.owner?._id !== myProfile?._id) && !create) ?
|
|
|
+ 'Информация (редактирование запрещено)' : create ? 'Создание чата' : 'Редактирование чата' }
|
|
|
+ </Typography>
|
|
|
+ </Box>
|
|
|
+
|
|
|
+ <Box sx={{ display: 'flex', justifyContent: 'end' }}>
|
|
|
+ <IconButton aria-label="delete" onClick={handleClose}>
|
|
|
+ <CloseIcon />
|
|
|
+ </IconButton>
|
|
|
+ </Box>
|
|
|
+
|
|
|
+ </Box>
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ <Box sx={{ display: 'flex', justifyContent: 'space-between', pl: 3, pr: 6 }} >
|
|
|
+
|
|
|
+ <Box sx={{ display: 'flex', justifyContent: 'start', alignItems: 'start', flexBasis: "35%" }}>
|
|
|
+ <section className="container">
|
|
|
+ <Box {...getRootProps({className: 'dropzone'})}
|
|
|
+ sx={{ cursor: 'pointer', height: '80px', display: 'flex' }}
|
|
|
+ className="avatarInModal" >
|
|
|
+
|
|
|
+ <ChatAvatar
|
|
|
+ chat={{ title: title, avatar: {url: chat?.avatar?.url || ''},
|
|
|
+ localUrl: img && URL.createObjectURL(img)}} bigSize={true} />
|
|
|
+
|
|
|
+ <input {...getInputProps()} type="file" name="media" id='mediaUser' />
|
|
|
+ <Box sx={{ pl: 4 }} >
|
|
|
+ <Typography sx={{ fontWeight: 500, fontSize: 18 }}>
|
|
|
+ Аватар
|
|
|
+ </Typography>
|
|
|
+ </Box>
|
|
|
+ </Box>
|
|
|
+ </section>
|
|
|
+ </Box>
|
|
|
+
|
|
|
+ <Box sx={{ display: 'flex', flexDirection: 'column', justifyContent: 'start', alignItems: 'stretch',
|
|
|
+ flexBasis: "35%" }}>
|
|
|
+
|
|
|
+ <Typography sx={{ fontWeight: 500, fontSize: 18 }}>
|
|
|
+ Название
|
|
|
+ </Typography>
|
|
|
+
|
|
|
+ <TextField
|
|
|
+ onChange={(e) => {
|
|
|
+ setTitle(e.target.value)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ onBlur={() => {
|
|
|
+ setTitleBlur(true)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ onFocus={() => {
|
|
|
+ setTitleBlur(false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ error={titleBlur ? ((title?.length >= minTitle ) ? false : true) : false}
|
|
|
+ helperText={printStrReq(title, minTitle)}
|
|
|
+
|
|
|
+ inputProps={{
|
|
|
+ maxLength: 50
|
|
|
+ }}
|
|
|
+ variant="standard"
|
|
|
+ margin="none"
|
|
|
+ fullWidth
|
|
|
+ id="titleChat"
|
|
|
+ label=""
|
|
|
+ name="title"
|
|
|
+ defaultValue={title}
|
|
|
+ sx={{mt: 1}}
|
|
|
+ />
|
|
|
+ </Box>
|
|
|
+
|
|
|
+ </Box>
|
|
|
+
|
|
|
+
|
|
|
+ <Box sx={{ display: 'flex', flexDirection: 'column', justifyContent: 'center', height: '60%', mt: 2 }}>
|
|
|
+
|
|
|
+ <Box sx={{ display: 'flex', justifyContent: 'center', mb: 1 }}>
|
|
|
+ <Typography sx={{ fontWeight: 500, fontSize: 18 }}>
|
|
|
+ Добавить участников
|
|
|
+ </Typography>
|
|
|
+ </Box>
|
|
|
+
|
|
|
+ <Box sx={{ display: 'flex', justifyContent: 'space-between', height: '100%', }} >
|
|
|
+
|
|
|
+ <Box sx={{ flexBasis: "45%" }}>
|
|
|
+
|
|
|
+ <Box sx={{ height: "40px", display: 'flex', justifyContent: 'center', pt: 1 }}>
|
|
|
+ <Typography sx={{ fontWeight: 400, fontSize: 16 }}>
|
|
|
+ Сейчас в чате
|
|
|
+ </Typography>
|
|
|
+ </Box>
|
|
|
+
|
|
|
+ <Box
|
|
|
+ sx={{ height: "calc(100% - 40px)", overflowY: "auto" }}
|
|
|
+ >
|
|
|
+ <List
|
|
|
+ sx={{ maxWidth: '100%', bgcolor: 'background.paper' }}
|
|
|
+ >
|
|
|
+ { members.map((member, i) => <UserCard key={member._id || i} user={member}
|
|
|
+ render={DelBtn} onAction={() => onDelMember(i)} />)}
|
|
|
+ </List>
|
|
|
+ </Box>
|
|
|
+ </Box>
|
|
|
+
|
|
|
+ <CUserSearch open={open} alreadySearched={members} onAdd={onAddMember} />
|
|
|
+
|
|
|
+ </Box>
|
|
|
+
|
|
|
+ </Box>
|
|
|
+
|
|
|
+
|
|
|
+ <Box sx={{ mt: 2 }} >
|
|
|
+
|
|
|
+ { wrongAlert &&
|
|
|
+ <Typography component="p" variant="body2" my={2} ml={2}
|
|
|
+ sx={{fontWeight: 'medium', fontSize: '0.75rem', color: '#d32f2f'}}>
|
|
|
+ Ошибка создания
|
|
|
+ </Typography>
|
|
|
+ }
|
|
|
+
|
|
|
+ <Box sx={{ display: 'flex', justifyContent: 'center'}}>
|
|
|
+ <Button variant="contained"
|
|
|
+ disabled={ (title?.length < minTitle) ? true :
|
|
|
+ ((chat?.owner?._id !== myProfile?._id) && !create) ? true : false }
|
|
|
+ onClick={() => {
|
|
|
+ onСonfirm( "media", img, title,
|
|
|
+ prepareMembers(members), chat?._id );
|
|
|
+ handleClose()
|
|
|
+ } } >
|
|
|
+ Применить
|
|
|
+ </Button>
|
|
|
+ </Box>
|
|
|
+ </Box>
|
|
|
+
|
|
|
+
|
|
|
+ </Box>
|
|
|
+ </Modal>
|
|
|
+ </>
|
|
|
+ )
|
|
|
+ }
|
|
|
+ export const CChatInfoModal = connect( state => ( { chatError: state.promise.updateChat || {} }))(ChatInfoModal)
|
|
|
+
|