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