|
@@ -0,0 +1,139 @@
|
|
|
+import { makeStyles, TextField, Typography } from '@material-ui/core'
|
|
|
+import ListItemAvatar from '@mui/material/ListItemAvatar';
|
|
|
+import Avatar from '@mui/material/Avatar';
|
|
|
+import Checkbox from '@mui/material/Checkbox';
|
|
|
+import ListItemText from '@mui/material/ListItemText';
|
|
|
+import DoneIcon from '@mui/icons-material/Done';
|
|
|
+import { useState,useEffect } from 'react';
|
|
|
+import { format,firstLetter,slicedWord } from '../../../../../../../helpers'
|
|
|
+import { muteChat, updateContact } from '../../../../../../../api-data';
|
|
|
+import { TChat } from '../../../../../../../typescript/redux/chat/types'
|
|
|
+import { TContact } from '../../../../../../../typescript/redux/contacts/types'
|
|
|
+
|
|
|
+const useStyles = makeStyles({
|
|
|
+ container: {
|
|
|
+ display: 'flex',
|
|
|
+ alignItems: 'center',
|
|
|
+ alignContent:'center',
|
|
|
+ flexDirection: 'column',
|
|
|
+ width: '100%',
|
|
|
+ margin: '0 auto',
|
|
|
+ padding: 20,
|
|
|
+ marginBottom:15,
|
|
|
+ position: 'relative',
|
|
|
+ backgroundColor:'#ffffff'
|
|
|
+ },
|
|
|
+ textField: {
|
|
|
+ marginBottom:20
|
|
|
+ },
|
|
|
+ notifications: {
|
|
|
+ width: '100%',
|
|
|
+ display: 'flex',
|
|
|
+ justifyContent: 'flex-start',
|
|
|
+ alignContent: 'start',
|
|
|
+ alignItems: 'start',
|
|
|
+ marginBottom:'auto'
|
|
|
+ },
|
|
|
+ avatarArrow: {
|
|
|
+ cursor: 'pointer',
|
|
|
+ alignSelf: 'flex-end',
|
|
|
+ '&:hover': {
|
|
|
+ backgroundColor: 'rgb(62, 149, 231)'
|
|
|
+ }
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
+const label = { inputProps: { 'aria-label': 'Checkbox demo' } };
|
|
|
+
|
|
|
+const EditList = ({chat,isContact}:{chat:TChat,isContact:TContact}) => {
|
|
|
+ const classes = useStyles()
|
|
|
+ const [name, setName] = useState<string>('')
|
|
|
+ const [lastName, setLastName] = useState<string>('')
|
|
|
+ const [mute, setMute] = useState<boolean>(true)
|
|
|
+ const [openBtn, setOpenBtn] = useState<boolean>(false)
|
|
|
+ const { avatarUrl,color,mute:Mute,name:Name,lastName:LastName,companionId,_id } = chat
|
|
|
+ const handleNotifications = () => {
|
|
|
+ setMute(!mute)
|
|
|
+ !openBtn&&setOpenBtn(true)
|
|
|
+ }
|
|
|
+ const handleTextField = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
+ !openBtn&&setOpenBtn(true)
|
|
|
+ const value = format(e.target.value)
|
|
|
+ const name = e.target.name
|
|
|
+ switch (name) {
|
|
|
+ case 'name':
|
|
|
+ setName(value)
|
|
|
+ break;
|
|
|
+ case 'lastName':
|
|
|
+ setLastName(value)
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const handleSubmit = () => {
|
|
|
+ if (mute !== !Mute) {
|
|
|
+ muteChat(companionId)
|
|
|
+ }
|
|
|
+ if (name !== Name || lastName !== LastName) {
|
|
|
+ updateContact(isContact._id,_id,name,lastName)
|
|
|
+ }
|
|
|
+ openBtn&&setOpenBtn(false)
|
|
|
+ }
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ Name&&setName(Name)
|
|
|
+ LastName && setLastName(LastName)
|
|
|
+ setMute(!Mute)
|
|
|
+ }, [Name, LastName, Mute])
|
|
|
+
|
|
|
+ return (
|
|
|
+ <div className={classes.container} >
|
|
|
+ <ListItemAvatar style={{marginBottom:10}}>
|
|
|
+ <Avatar alt={name} src={avatarUrl?`http://localhost:3000/${avatarUrl}`:undefined}
|
|
|
+ sx={{ background: color, width: 120, height: 120,marginRight:2}}>
|
|
|
+ {`${firstLetter(name)}${firstLetter(lastName)}`}
|
|
|
+ </Avatar>
|
|
|
+ </ListItemAvatar>
|
|
|
+ <Typography style={{color: '#080808',fontSize:22,fontWeight:500}}>
|
|
|
+ {`${firstLetter(Name)}${slicedWord(Name, 15, 1)}
|
|
|
+ ${firstLetter(LastName)}${slicedWord(LastName, 15, 1)}`}
|
|
|
+ </Typography>
|
|
|
+ <Typography style={{fontSize:17,marginBottom:20}}>original name</Typography>
|
|
|
+ <TextField
|
|
|
+ id="name"
|
|
|
+ name='name'
|
|
|
+ label="Name"
|
|
|
+ value={name}
|
|
|
+ fullWidth
|
|
|
+ variant='outlined'
|
|
|
+ onChange={handleTextField}
|
|
|
+ className={classes.textField}
|
|
|
+ required
|
|
|
+ />
|
|
|
+ <TextField
|
|
|
+ id="lastName"
|
|
|
+ name='lastName'
|
|
|
+ label="LastName"
|
|
|
+ value={lastName}
|
|
|
+ fullWidth
|
|
|
+ variant='outlined'
|
|
|
+ onChange={handleTextField}
|
|
|
+ className={classes.textField}
|
|
|
+ required
|
|
|
+ />
|
|
|
+ <div className={classes.notifications}>
|
|
|
+ <Checkbox onChange={handleNotifications} {...label} checked={mute} style={{marginRight:20}} />
|
|
|
+ <ListItemText primary="Notifications" primaryTypographyProps={{ color: "#0e0d0d" }}
|
|
|
+ secondary={!mute ? 'Disabled':'Enabled'} />
|
|
|
+ </div>
|
|
|
+ {openBtn&&<Avatar onClick={handleSubmit} className={classes.avatarArrow}
|
|
|
+ sx={{width: 56, height: 56,backgroundColor: 'rgb(41, 139, 231)',color: '#ffffff'}}>
|
|
|
+ <DoneIcon fontSize="medium" />
|
|
|
+ </Avatar>}
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+};
|
|
|
+
|
|
|
+export default EditList;
|