ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 1 | import React, { useEffect } from 'react'; |
idillon | 531b6f2 | 2022-09-16 14:02:00 -0400 | [diff] [blame] | 2 | import Modal from 'react-modal'; |
idillon | 531b6f2 | 2022-09-16 14:02:00 -0400 | [diff] [blame] | 3 | import authManager from '../AuthManager' |
ervinanoh | 8e91804 | 2022-09-06 10:30:59 -0400 | [diff] [blame] | 4 | import ConversationAvatar from './ConversationAvatar' |
| 5 | import Conversation from '../../../model/Conversation' |
| 6 | import React, { useState } from "react"; |
| 7 | import { useNavigate, useParams } from "react-router-dom" |
ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 8 | import { ListItem, ListItemAvatar, ListItemText, Box, Typography } from '@mui/material' |
ervinanoh | 34eb947 | 2022-09-13 04:20:28 -0400 | [diff] [blame] | 9 | import { Button, Stack, Typography, Modal as ModalUM } from "@mui/material" |
ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 10 | import { RemoveContactIcon, VideoCallIcon } from './svgIcons'; |
| 11 | import { AudioCallIcon, BlockContactIcon, ContactDetailsIcon, CrossIcon, MessageIcon } from './svgIcons'; |
ervinanoh | 34eb947 | 2022-09-13 04:20:28 -0400 | [diff] [blame] | 12 | import { QRCodeCanvas} from 'qrcode.react'; |
| 13 | import { setRefreshFromSlice } from '../../redux/appSlice'; |
| 14 | import { useAppDispatch } from '../../redux/hooks'; |
| 15 | |
idillon | 531b6f2 | 2022-09-16 14:02:00 -0400 | [diff] [blame] | 16 | |
| 17 | const customStyles = { |
| 18 | content: { |
ervinanoh | 8e91804 | 2022-09-06 10:30:59 -0400 | [diff] [blame] | 19 | // right: "auto", |
| 20 | // bottom: "auto", |
| 21 | // // marginRight: "-50%", |
| 22 | // transform: "translate(-50%, -50%)", |
ervinanoh | 8e91804 | 2022-09-06 10:30:59 -0400 | [diff] [blame] | 23 | // padding: "16px" |
| 24 | |
| 25 | // top: "1364px", |
| 26 | left: "94px", |
ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 27 | width: "180px", |
ervinanoh | 8e91804 | 2022-09-06 10:30:59 -0400 | [diff] [blame] | 28 | height: "262px", |
| 29 | background: "#FFFFFF 0% 0% no-repeat padding-box", |
| 30 | boxShadow: "3px 3px 7px #00000029", |
| 31 | borderRadius: "5px 20px 20px 20px", |
| 32 | opacity: "1", |
| 33 | |
| 34 | textAlign: "left", |
ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 35 | font: "normal normal normal 12px/26px Ubuntu", |
| 36 | letterSpacing: "0px", |
| 37 | color: "#000000", |
| 38 | }, |
| 39 | }; |
| 40 | |
| 41 | const cancelStyles = { |
| 42 | content: { |
| 43 | left: "94px", |
| 44 | width: "300px", |
| 45 | height: "220px", |
| 46 | background: "#FFFFFF 0% 0% no-repeat padding-box", |
| 47 | boxShadow: "3px 3px 7px #00000029", |
| 48 | borderRadius: "20px", |
| 49 | opacity: "1", |
| 50 | |
| 51 | textAlign: "left", |
| 52 | font: "normal normal normal 12px/26px Ubuntu", |
| 53 | letterSpacing: "0px", |
| 54 | color: "#000000", |
| 55 | }, |
| 56 | }; |
| 57 | |
| 58 | const contactDetailsStyles = { |
| 59 | content: { |
| 60 | left: "94px", |
| 61 | width: "450px", |
| 62 | height: "450px", |
| 63 | background: "#FFFFFF 0% 0% no-repeat padding-box", |
| 64 | boxShadow: "3px 3px 7px #00000029", |
| 65 | borderRadius: "20px", |
| 66 | opacity: "1", |
| 67 | |
| 68 | textAlign: "left", |
| 69 | font: "normal normal normal 12px/26px Ubuntu", |
ervinanoh | 8e91804 | 2022-09-06 10:30:59 -0400 | [diff] [blame] | 70 | letterSpacing: "0px", |
| 71 | color: "#000000", |
idillon | 531b6f2 | 2022-09-16 14:02:00 -0400 | [diff] [blame] | 72 | }, |
| 73 | }; |
Adrien Béraud | 995e802 | 2021-04-08 13:46:51 -0400 | [diff] [blame] | 74 | |
ervinanoh | 8e91804 | 2022-09-06 10:30:59 -0400 | [diff] [blame] | 75 | const stackStyles = { |
| 76 | flexDirection: "row", |
ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 77 | marginBottom: "4px", |
| 78 | spacing: "40px", |
ervinanoh | 8e91804 | 2022-09-06 10:30:59 -0400 | [diff] [blame] | 79 | flex: 1, |
| 80 | alignItems: "center", |
ervinanoh | 8e91804 | 2022-09-06 10:30:59 -0400 | [diff] [blame] | 81 | }; |
| 82 | |
ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 83 | const iconTextStyle = { |
| 84 | marginRight: "10px", |
| 85 | }; |
| 86 | |
| 87 | const iconColor = "#005699"; |
| 88 | |
Adrien Béraud | af09a46 | 2021-04-15 18:02:29 -0400 | [diff] [blame] | 89 | export default function ConversationListItem(props) { |
idillon | 531b6f2 | 2022-09-16 14:02:00 -0400 | [diff] [blame] | 90 | const { conversationId, contactId } = useParams(); |
ervinanoh | 34eb947 | 2022-09-13 04:20:28 -0400 | [diff] [blame] | 91 | const dispatch = useAppDispatch(); |
| 92 | |
idillon | 531b6f2 | 2022-09-16 14:02:00 -0400 | [diff] [blame] | 93 | const conversation = props.conversation; |
Adrien Béraud | 995e802 | 2021-04-08 13:46:51 -0400 | [diff] [blame] | 94 | |
idillon | 531b6f2 | 2022-09-16 14:02:00 -0400 | [diff] [blame] | 95 | const pathId = conversationId || contactId; |
| 96 | const isSelected = conversation.getDisplayUri() === pathId; |
| 97 | const navigate = useNavigate(); |
| 98 | |
idillon | 531b6f2 | 2022-09-16 14:02:00 -0400 | [diff] [blame] | 99 | const [modalIsOpen, setIsOpen] = useState(false); |
| 100 | const [modalDetailsIsOpen, setModalDetailsIsOpen] = useState(false); |
| 101 | const [modalDeleteIsOpen, setModalDeleteIsOpen] = useState(false); |
ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 102 | const [blockOrRemove, setBlockOrRemove] = useState(true); |
| 103 | const [userId, setUserId] = useState( |
ervinanoh | 34eb947 | 2022-09-13 04:20:28 -0400 | [diff] [blame] | 104 | conversation?.getFirstMember()?.contact.getUri() |
ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 105 | ); |
| 106 | const [isSwarm, setIsSwarm] = useState("true"); |
idillon | 531b6f2 | 2022-09-16 14:02:00 -0400 | [diff] [blame] | 107 | |
ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 108 | const openModal = (e) => { |
| 109 | e.preventDefault(); |
| 110 | console.log(e); |
| 111 | setIsOpen(true); |
| 112 | }; |
idillon | 531b6f2 | 2022-09-16 14:02:00 -0400 | [diff] [blame] | 113 | const openModalDetails = () => setModalDetailsIsOpen(true); |
| 114 | const openModalDelete = () => setModalDeleteIsOpen(true); |
idillon | 531b6f2 | 2022-09-16 14:02:00 -0400 | [diff] [blame] | 115 | const closeModal = () => setIsOpen(false); |
idillon | 531b6f2 | 2022-09-16 14:02:00 -0400 | [diff] [blame] | 116 | const closeModalDetails = () => setModalDetailsIsOpen(false); |
| 117 | const closeModalDelete = () => setModalDeleteIsOpen(false); |
| 118 | |
ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 119 | let subtitle; |
idillon | 531b6f2 | 2022-09-16 14:02:00 -0400 | [diff] [blame] | 120 | function afterOpenModal() { |
| 121 | // references are now sync'd and can be accessed. |
| 122 | subtitle.style.color = "#f00"; |
| 123 | } |
| 124 | |
ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 125 | const getContactDetails = () => { |
idillon | 531b6f2 | 2022-09-16 14:02:00 -0400 | [diff] [blame] | 126 | const controller = new AbortController(); |
| 127 | authManager |
ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 128 | .fetch( |
| 129 | `/api/accounts/${conversation.getAccountId()}/contacts/details/${userId}`, |
| 130 | { |
| 131 | signal: controller.signal, |
| 132 | } |
| 133 | ) |
| 134 | .then((res) => res.json()) |
idillon | 531b6f2 | 2022-09-16 14:02:00 -0400 | [diff] [blame] | 135 | .then((result) => { |
ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 136 | console.log("CONTACT LIST - DETAILS: ", result); |
idillon | 531b6f2 | 2022-09-16 14:02:00 -0400 | [diff] [blame] | 137 | }) |
ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 138 | .catch((e) => console.log("ERROR GET CONTACT DETAILS: ", e)); |
idillon | 531b6f2 | 2022-09-16 14:02:00 -0400 | [diff] [blame] | 139 | }; |
| 140 | |
ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 141 | const removeOrBlock = (typeOfRemove) => { |
| 142 | console.log(typeOfRemove); |
| 143 | setBlockOrRemove(false); |
| 144 | |
| 145 | console.log("EEEH", typeOfRemove, conversation.getAccountId(), userId); |
| 146 | |
| 147 | const controller = new AbortController(); |
| 148 | authManager |
| 149 | .fetch( |
| 150 | `/api/accounts/${conversation.getAccountId()}/contacts/${typeOfRemove}/${userId}`, |
| 151 | { |
| 152 | signal: controller.signal, |
| 153 | method: "DELETE", |
| 154 | } |
| 155 | ) |
| 156 | .then((res) => res.json()) |
ervinanoh | 34eb947 | 2022-09-13 04:20:28 -0400 | [diff] [blame] | 157 | .then((result) => { |
| 158 | console.log("propre"); |
| 159 | dispatch(setRefreshFromSlice()); |
| 160 | }) |
| 161 | .catch((e) => { |
| 162 | console.log(`ERROR ${typeOfRemove}ing CONTACT : `, e); |
| 163 | dispatch(setRefreshFromSlice()); |
| 164 | }); |
ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 165 | closeModalDelete(); |
ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 166 | }; |
ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 167 | |
idillon | 531b6f2 | 2022-09-16 14:02:00 -0400 | [diff] [blame] | 168 | |
| 169 | const uri = conversation.getId() |
| 170 | ? `conversation/${conversation.getId()}` |
ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 171 | : `addContact/${userId}`; |
idillon | 531b6f2 | 2022-09-16 14:02:00 -0400 | [diff] [blame] | 172 | if (conversation instanceof Conversation) { |
| 173 | return ( |
ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 174 | <div onContextMenu={openModal}> |
| 175 | <div name="Modal conversation"> |
| 176 | <Modal |
| 177 | isOpen={modalIsOpen} |
| 178 | // onAfterOpen={afterOpenModal} |
| 179 | onRequestClose={closeModal} |
| 180 | style={customStyles} |
| 181 | contentLabel="Example Modal" |
idillon | 531b6f2 | 2022-09-16 14:02:00 -0400 | [diff] [blame] | 182 | > |
ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 183 | <Stack |
| 184 | onClick={() => { |
| 185 | navigate(`/account/${conversation.getAccountId()}/${uri}`); |
| 186 | closeModal(); |
| 187 | }} |
| 188 | {...stackStyles} |
| 189 | > |
| 190 | <div style={{ ...iconTextStyle }}> |
| 191 | <MessageIcon style={{ color: iconColor }} /> |
| 192 | </div> |
| 193 | Message |
| 194 | </Stack> |
| 195 | <Stack {...stackStyles}> |
| 196 | <div style={{ ...iconTextStyle }}> |
| 197 | <AudioCallIcon style={{ color: iconColor }} /> |
| 198 | </div> |
| 199 | Démarrer appel audio |
| 200 | </Stack> |
| 201 | |
| 202 | <Stack {...stackStyles}> |
| 203 | <div style={{ ...iconTextStyle }}> |
| 204 | <VideoCallIcon style={{ color: iconColor }} /> |
| 205 | </div> |
| 206 | Démarrer appel vidéo |
| 207 | </Stack> |
| 208 | |
| 209 | <Stack |
| 210 | {...stackStyles} |
| 211 | onClick={() => { |
| 212 | navigate(`/account/${conversation.getAccountId()}/`); |
| 213 | closeModal(); |
ervinanoh | 8e91804 | 2022-09-06 10:30:59 -0400 | [diff] [blame] | 214 | }} |
| 215 | > |
ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 216 | <div style={{ ...iconTextStyle }}> |
| 217 | <CrossIcon style={{ color: iconColor }} /> |
| 218 | </div> |
| 219 | Fermer la conversation |
| 220 | </Stack> |
| 221 | |
| 222 | <Stack |
| 223 | onClick={() => { |
| 224 | console.log("open details contact for: "); |
| 225 | closeModal(); |
| 226 | openModalDetails(); |
| 227 | getContactDetails(); |
| 228 | }} |
| 229 | {...stackStyles} |
| 230 | > |
| 231 | <div style={{ ...iconTextStyle }}> |
| 232 | <ContactDetailsIcon style={{ color: iconColor }} /> |
| 233 | </div> |
| 234 | Détails de la conversation |
| 235 | </Stack> |
| 236 | |
| 237 | <Stack |
| 238 | onClick={() => { |
| 239 | setBlockOrRemove(true); |
| 240 | closeModal(); |
| 241 | openModalDelete(); |
| 242 | }} |
| 243 | {...stackStyles} |
| 244 | > |
| 245 | <div style={{ ...iconTextStyle }}> |
| 246 | <BlockContactIcon style={{ color: iconColor }} /> |
| 247 | </div> |
| 248 | Bloquer le contact |
| 249 | </Stack> |
| 250 | |
| 251 | <Stack |
| 252 | onClick={() => { |
| 253 | setBlockOrRemove(false); |
| 254 | closeModal(); |
| 255 | openModalDelete(); |
| 256 | }} |
| 257 | {...stackStyles} |
| 258 | > |
| 259 | <div style={{ ...iconTextStyle }}> |
| 260 | <RemoveContactIcon style={{ color: iconColor }} /> |
| 261 | </div> |
| 262 | Supprimer contact |
| 263 | </Stack> |
| 264 | </Modal> |
| 265 | </div> |
| 266 | |
| 267 | <div name="Contact details"> |
| 268 | <Modal |
| 269 | isOpen={modalDetailsIsOpen} |
| 270 | onRequestClose={closeModalDetails} |
| 271 | style={contactDetailsStyles} |
| 272 | contentLabel="Détails contact" |
| 273 | > |
| 274 | <Stack direction={"row"} alignContent="flex-end"> |
| 275 | <Stack direction={"column"}> |
| 276 | <div style={{ height: "100px" }}> |
| 277 | <ConversationAvatar |
| 278 | displayName={conversation.getDisplayNameNoFallback()} |
| 279 | /> |
| 280 | </div> |
| 281 | |
| 282 | <div |
| 283 | style={{ |
| 284 | fontSize: "20px", |
| 285 | marginBottom: "20px", |
| 286 | height: "20px", |
| 287 | }} |
| 288 | > |
| 289 | Informations |
| 290 | </div> |
| 291 | |
| 292 | <Typography variant="caption">Nom d'utilisateur</Typography> |
| 293 | <div style={{ height: "20px" }} /> |
| 294 | <Typography variant="caption">Identifiant </Typography> |
| 295 | <div style={{ height: "20px" }} /> |
| 296 | |
| 297 | <div |
| 298 | style={{ |
| 299 | flex: 1, |
| 300 | height: "150px", |
| 301 | direction: "column", |
| 302 | flexDirection: "column", |
| 303 | // alignSelf: "flex-end", |
| 304 | }} |
| 305 | > |
| 306 | <Typography variant="caption">Code QR</Typography> |
| 307 | </div> |
| 308 | |
| 309 | <Typography variant="caption">est un swarm </Typography> |
| 310 | </Stack> |
| 311 | |
| 312 | <Stack direction={"column"}> |
| 313 | <div |
| 314 | style={{ |
| 315 | fontWeight: "bold", |
| 316 | fontSize: "20px", |
| 317 | height: "100px", |
| 318 | }} |
| 319 | > |
| 320 | {conversation.getDisplayNameNoFallback() + "(resolved name)"} |
| 321 | </div> |
| 322 | |
| 323 | <div |
| 324 | style={{ |
| 325 | height: "40px", |
| 326 | }} |
| 327 | /> |
| 328 | <Typography variant="caption"> |
| 329 | <div style={{ fontWeight: "bold" }}> |
| 330 | {conversation.getDisplayNameNoFallback()} |
| 331 | </div> |
| 332 | </Typography> |
| 333 | |
| 334 | <div style={{ height: "20px" }} /> |
| 335 | |
| 336 | <Typography variant="caption"> |
| 337 | <div style={{ fontWeight: "bold" }}> {userId}</div> |
| 338 | </Typography> |
| 339 | |
| 340 | <div style={{ height: "20px" }} /> |
| 341 | |
| 342 | <div height={"40px"}> |
| 343 | <QRCodeCanvas value={`${userId}`} /> |
| 344 | </div> |
| 345 | |
| 346 | <Typography variant="caption"> |
| 347 | <div style={{ fontWeight: "bold" }}> {isSwarm}</div> |
| 348 | </Typography> |
| 349 | </Stack> |
| 350 | </Stack> |
| 351 | <div |
| 352 | onClick={closeModalDetails} |
| 353 | style={{ |
| 354 | width: "100px", |
| 355 | borderStyle: "solid", |
| 356 | textAlign: "center", |
| 357 | borderRadius: "5px", |
| 358 | marginLeft: "150px", |
| 359 | marginTop: "10px", |
| 360 | }} |
| 361 | > |
| 362 | <Typography variant="caption">Fermer</Typography> |
ervinanoh | 8e91804 | 2022-09-06 10:30:59 -0400 | [diff] [blame] | 363 | </div> |
ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 364 | </Modal> |
| 365 | </div> |
idillon | 531b6f2 | 2022-09-16 14:02:00 -0400 | [diff] [blame] | 366 | |
ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 367 | <div name="Remove or block details"> |
| 368 | <Modal |
| 369 | isOpen={modalDeleteIsOpen} |
| 370 | onRequestClose={closeModalDelete} |
| 371 | style={cancelStyles} |
| 372 | contentLabel="Merci de confirmer" |
idillon | 531b6f2 | 2022-09-16 14:02:00 -0400 | [diff] [blame] | 373 | > |
ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 374 | <Typography variant="h4">Merci de confirmer</Typography> |
| 375 | <Stack |
| 376 | direction={"column"} |
| 377 | justifyContent="space-around" |
| 378 | spacing={"75px"} |
| 379 | > |
| 380 | <div style={{ textAlign: "center", marginTop: "10%" }}> |
| 381 | <Typography variant="body2"> |
| 382 | Voulez vous vraiment {blockOrRemove ? "bloquer" : "supprimer"}{" "} |
| 383 | ce contact? |
| 384 | </Typography> |
| 385 | </div> |
ervinanoh | 8e91804 | 2022-09-06 10:30:59 -0400 | [diff] [blame] | 386 | |
ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 387 | <Stack |
| 388 | direction={"row"} |
| 389 | top={"25px"} |
| 390 | alignSelf="center" |
| 391 | spacing={1} |
| 392 | > |
| 393 | <Box |
| 394 | onClick={() => { |
| 395 | if (blockOrRemove) removeOrBlock("block"); |
| 396 | else removeOrBlock("remove"); |
| 397 | }} |
| 398 | style={{ |
| 399 | width: "100px", |
| 400 | textAlign: "center", |
| 401 | borderStyle: "solid", |
| 402 | borderColor: "red", |
| 403 | borderRadius: "10px", |
| 404 | color: "red", |
| 405 | }} |
| 406 | > |
| 407 | {blockOrRemove ? "Bloquer" : "Supprimer"} |
| 408 | </Box> |
| 409 | <Box |
| 410 | onClick={closeModalDelete} |
| 411 | style={{ |
| 412 | width: "100px", |
| 413 | textAlign: "center", |
| 414 | paddingLeft: "12px", |
| 415 | paddingRight: "12px", |
| 416 | borderStyle: "solid", |
| 417 | borderRadius: "10px", |
| 418 | }} |
| 419 | > |
| 420 | Annuler |
| 421 | </Box> |
| 422 | </Stack> |
| 423 | </Stack> |
| 424 | </Modal> |
| 425 | </div> |
idillon | 531b6f2 | 2022-09-16 14:02:00 -0400 | [diff] [blame] | 426 | |
| 427 | <ListItem |
| 428 | button |
| 429 | alignItems="flex-start" |
| 430 | selected={isSelected} |
ervinanoh | b81c391 | 2022-09-08 04:13:24 -0400 | [diff] [blame] | 431 | onClick={() => |
| 432 | navigate(`/account/${conversation.getAccountId()}/${uri}`) |
| 433 | } |
idillon | 531b6f2 | 2022-09-16 14:02:00 -0400 | [diff] [blame] | 434 | > |
| 435 | <ListItemAvatar> |
| 436 | <ConversationAvatar |
| 437 | displayName={conversation.getDisplayNameNoFallback()} |
| 438 | /> |
| 439 | </ListItemAvatar> |
| 440 | <ListItemText |
| 441 | primary={conversation.getDisplayName()} |
| 442 | secondary={conversation.getDisplayUri()} |
| 443 | /> |
| 444 | </ListItem> |
| 445 | </div> |
| 446 | ); |
| 447 | } else return null; |
Adrien Béraud | 995e802 | 2021-04-08 13:46:51 -0400 | [diff] [blame] | 448 | } |