index.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import { makeStyles, TextField, Typography } from '@material-ui/core'
  2. import ListItemAvatar from '@mui/material/ListItemAvatar';
  3. import Avatar from '@mui/material/Avatar';
  4. import Checkbox from '@mui/material/Checkbox';
  5. import ListItemText from '@mui/material/ListItemText';
  6. import { format,firstLetter,slicedWord,prodBaseURL } from '../../../../../../helpers'
  7. import { TChat } from '../../../../../../typescript/redux/chat/types'
  8. const useStyles = makeStyles({
  9. container: {
  10. display: 'flex',
  11. alignItems: 'center',
  12. alignContent:'center',
  13. flexDirection: 'column',
  14. width: '100%',
  15. margin: '0 auto',
  16. padding: 20,
  17. marginBottom:15,
  18. position: 'relative',
  19. backgroundColor: '#ffffff',
  20. },
  21. textField: {
  22. marginBottom:20
  23. },
  24. notifications: {
  25. width: '100%',
  26. display: 'flex',
  27. justifyContent: 'flex-start',
  28. alignContent: 'start',
  29. alignItems: 'start',
  30. marginBottom:'auto'
  31. },
  32. avatarArrow: {
  33. cursor: 'pointer',
  34. alignSelf: 'flex-end',
  35. '&:hover': {
  36. backgroundColor: 'rgb(62, 149, 231)'
  37. }
  38. }
  39. })
  40. const label = { inputProps: { 'aria-label': 'Checkbox demo' } };
  41. interface IEditList {
  42. chat: TChat,
  43. name: string,
  44. setName: any,
  45. lastName: string,
  46. setLastName: any,
  47. mute: boolean,
  48. setMute: any,
  49. openBtn: boolean,
  50. setOpenBtn: any,
  51. }
  52. const EditList = (props: IEditList) => {
  53. const classes = useStyles()
  54. const {chat,name,setName,lastName,setLastName,mute,setMute,openBtn,setOpenBtn} = props
  55. const { avatarUrl,color,originalName,originalLastName } = chat
  56. const handleNotifications = () => {
  57. setMute(!mute)
  58. !openBtn&&setOpenBtn(true)
  59. }
  60. const handleTextField = (e: React.ChangeEvent<HTMLInputElement>) => {
  61. !openBtn&&setOpenBtn(true)
  62. const value = format(e.target.value)
  63. const name = e.target.name
  64. switch (name) {
  65. case 'name':
  66. setName(value)
  67. break;
  68. case 'lastName':
  69. setLastName(value)
  70. break;
  71. default:
  72. break;
  73. }
  74. }
  75. return (
  76. <div className={classes.container} >
  77. <ListItemAvatar style={{marginBottom:10}}>
  78. <Avatar alt={name} src={avatarUrl?`${prodBaseURL}/${avatarUrl}`:undefined}
  79. sx={{ background: color, width: 120, height: 120,marginRight:2}}>
  80. {`${firstLetter(name)}${firstLetter(lastName)}`}
  81. </Avatar>
  82. </ListItemAvatar>
  83. <Typography style={{color: '#080808',fontSize:22,fontWeight:500}}>
  84. {`${firstLetter(originalName)}${slicedWord(originalName, 15, 1)}
  85. ${firstLetter(originalLastName)}${slicedWord(originalLastName, 15, 1)}`}
  86. </Typography>
  87. <Typography style={{fontSize:17,marginBottom:20}}>original name</Typography>
  88. <TextField
  89. id="name"
  90. name='name'
  91. label="Name"
  92. value={name}
  93. fullWidth
  94. variant='outlined'
  95. onChange={handleTextField}
  96. className={classes.textField}
  97. />
  98. <TextField
  99. id="lastName"
  100. name='lastName'
  101. label="LastName"
  102. value={lastName}
  103. fullWidth
  104. variant='outlined'
  105. onChange={handleTextField}
  106. className={classes.textField}
  107. />
  108. <div className={classes.notifications}>
  109. <Checkbox onChange={handleNotifications} {...label} checked={mute} style={{marginRight:20}} />
  110. <ListItemText primary="Notifications" primaryTypographyProps={{ color: "#0e0d0d" }}
  111. secondary={!mute ? 'Disabled':'Enabled'} />
  112. </div>
  113. </div>
  114. )
  115. };
  116. export default EditList;