blob: 4616da6de3b3fce62f36d759a91d31fb916ae4ee [file] [log] [blame]
ervinanohb81c3912022-09-08 04:13:24 -04001import React, { useEffect } from 'react';
idillon531b6f22022-09-16 14:02:00 -04002import ReactDOM from 'react-dom';
3import Modal from 'react-modal';
idillon531b6f22022-09-16 14:02:00 -04004import authManager from '../AuthManager'
ervinanoh8e918042022-09-06 10:30:59 -04005import ConversationAvatar from './ConversationAvatar'
6import Conversation from '../../../model/Conversation'
7import React, { useState } from "react";
8import { useNavigate, useParams } from "react-router-dom"
9import { Person } from "@mui/icons-material";
ervinanohb81c3912022-09-08 04:13:24 -040010import { ListItem, ListItemAvatar, ListItemText, Box, Typography } from '@mui/material'
11import { Button, Stack, Switch, ThemeProvider, Typography, Modal as ModalUM } from "@mui/material"
12import { RemoveContactIcon, VideoCallIcon } from './svgIcons';
13import { AudioCallIcon, BlockContactIcon, ContactDetailsIcon, CrossIcon, MessageIcon } from './svgIcons';
14import { styled } from "@mui/material/styles";
15import {QRCodeSVG, QRCodeCanvas} from 'qrcode.react';
idillon531b6f22022-09-16 14:02:00 -040016
17const customStyles = {
18 content: {
ervinanoh8e918042022-09-06 10:30:59 -040019 // right: "auto",
20 // bottom: "auto",
21 // // marginRight: "-50%",
22 // transform: "translate(-50%, -50%)",
ervinanoh8e918042022-09-06 10:30:59 -040023 // padding: "16px"
24
25 // top: "1364px",
26 left: "94px",
ervinanohb81c3912022-09-08 04:13:24 -040027 width: "180px",
ervinanoh8e918042022-09-06 10:30:59 -040028 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",
ervinanohb81c3912022-09-08 04:13:24 -040035 font: "normal normal normal 12px/26px Ubuntu",
36 letterSpacing: "0px",
37 color: "#000000",
38 },
39};
40
41const 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
58const 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",
ervinanoh8e918042022-09-06 10:30:59 -040070 letterSpacing: "0px",
71 color: "#000000",
idillon531b6f22022-09-16 14:02:00 -040072 },
73};
Adrien Béraud995e8022021-04-08 13:46:51 -040074
ervinanoh8e918042022-09-06 10:30:59 -040075const stackStyles = {
76 flexDirection: "row",
ervinanohb81c3912022-09-08 04:13:24 -040077 marginBottom: "4px",
78 spacing: "40px",
ervinanoh8e918042022-09-06 10:30:59 -040079 flex: 1,
80 alignItems: "center",
ervinanoh8e918042022-09-06 10:30:59 -040081};
82
ervinanohb81c3912022-09-08 04:13:24 -040083const iconTextStyle = {
84 marginRight: "10px",
85};
86
87const iconColor = "#005699";
88
Adrien Béraudaf09a462021-04-15 18:02:29 -040089export default function ConversationListItem(props) {
idillon531b6f22022-09-16 14:02:00 -040090 const { conversationId, contactId } = useParams();
91 const conversation = props.conversation;
92 console.log(
93 "XXX",
94 conversation,
95 conversation.id,
96 conversation.getAccountId()
97 );
Adrien Béraud995e8022021-04-08 13:46:51 -040098
idillon531b6f22022-09-16 14:02:00 -040099 const pathId = conversationId || contactId;
100 const isSelected = conversation.getDisplayUri() === pathId;
101 const navigate = useNavigate();
102
idillon531b6f22022-09-16 14:02:00 -0400103 const [modalIsOpen, setIsOpen] = useState(false);
104 const [modalDetailsIsOpen, setModalDetailsIsOpen] = useState(false);
105 const [modalDeleteIsOpen, setModalDeleteIsOpen] = useState(false);
ervinanohb81c3912022-09-08 04:13:24 -0400106 const [blockOrRemove, setBlockOrRemove] = useState(true);
107 const [userId, setUserId] = useState(
108 conversation.getFirstMember().contact.getUri()
109 );
110 const [isSwarm, setIsSwarm] = useState("true");
idillon531b6f22022-09-16 14:02:00 -0400111
ervinanohb81c3912022-09-08 04:13:24 -0400112 const openModal = (e) => {
113 e.preventDefault();
114 console.log(e);
115 setIsOpen(true);
116 };
idillon531b6f22022-09-16 14:02:00 -0400117 const openModalDetails = () => setModalDetailsIsOpen(true);
118 const openModalDelete = () => setModalDeleteIsOpen(true);
idillon531b6f22022-09-16 14:02:00 -0400119 const closeModal = () => setIsOpen(false);
idillon531b6f22022-09-16 14:02:00 -0400120 const closeModalDetails = () => setModalDetailsIsOpen(false);
121 const closeModalDelete = () => setModalDeleteIsOpen(false);
122
ervinanohb81c3912022-09-08 04:13:24 -0400123 let subtitle;
idillon531b6f22022-09-16 14:02:00 -0400124 function afterOpenModal() {
125 // references are now sync'd and can be accessed.
126 subtitle.style.color = "#f00";
127 }
128
ervinanohb81c3912022-09-08 04:13:24 -0400129 const getContactDetails = () => {
idillon531b6f22022-09-16 14:02:00 -0400130 const controller = new AbortController();
131 authManager
ervinanohb81c3912022-09-08 04:13:24 -0400132 .fetch(
133 `/api/accounts/${conversation.getAccountId()}/contacts/details/${userId}`,
134 {
135 signal: controller.signal,
136 }
137 )
138 .then((res) => res.json())
idillon531b6f22022-09-16 14:02:00 -0400139 .then((result) => {
ervinanohb81c3912022-09-08 04:13:24 -0400140 console.log("CONTACT LIST - DETAILS: ", result);
idillon531b6f22022-09-16 14:02:00 -0400141 })
ervinanohb81c3912022-09-08 04:13:24 -0400142 .catch((e) => console.log("ERROR GET CONTACT DETAILS: ", e));
idillon531b6f22022-09-16 14:02:00 -0400143 };
144
ervinanohb81c3912022-09-08 04:13:24 -0400145 const removeOrBlock = (typeOfRemove) => {
146 console.log(typeOfRemove);
147 setBlockOrRemove(false);
148
149 console.log("EEEH", typeOfRemove, conversation.getAccountId(), userId);
150
151 const controller = new AbortController();
152 authManager
153 .fetch(
154 `/api/accounts/${conversation.getAccountId()}/contacts/${typeOfRemove}/${userId}`,
155 {
156 signal: controller.signal,
157 method: "DELETE",
158 }
159 )
160 .then((res) => res.json())
161 .then((result) => {})
162 .catch((e) => console.log(`ERROR ${typeOfRemove}ing CONTACT : `, e));
163 closeModalDelete();
164 setRefresh(!refresh)
165 };
166 const [refresh, setRefresh] = useState(true)
167
168 useEffect(() => {
169 console.log("refresh");
170 }, [refresh]);
171
idillon531b6f22022-09-16 14:02:00 -0400172
173 const uri = conversation.getId()
174 ? `conversation/${conversation.getId()}`
ervinanohb81c3912022-09-08 04:13:24 -0400175 : `addContact/${userId}`;
idillon531b6f22022-09-16 14:02:00 -0400176 if (conversation instanceof Conversation) {
177 return (
ervinanohb81c3912022-09-08 04:13:24 -0400178 <div onContextMenu={openModal}>
179 <div name="Modal conversation">
180 <Modal
181 isOpen={modalIsOpen}
182 // onAfterOpen={afterOpenModal}
183 onRequestClose={closeModal}
184 style={customStyles}
185 contentLabel="Example Modal"
idillon531b6f22022-09-16 14:02:00 -0400186 >
ervinanohb81c3912022-09-08 04:13:24 -0400187 <Stack
188 onClick={() => {
189 navigate(`/account/${conversation.getAccountId()}/${uri}`);
190 closeModal();
191 }}
192 {...stackStyles}
193 >
194 <div style={{ ...iconTextStyle }}>
195 <MessageIcon style={{ color: iconColor }} />
196 </div>
197 Message
198 </Stack>
199 <Stack {...stackStyles}>
200 <div style={{ ...iconTextStyle }}>
201 <AudioCallIcon style={{ color: iconColor }} />
202 </div>
203 Démarrer appel audio
204 </Stack>
205
206 <Stack {...stackStyles}>
207 <div style={{ ...iconTextStyle }}>
208 <VideoCallIcon style={{ color: iconColor }} />
209 </div>
210 Démarrer appel vidéo
211 </Stack>
212
213 <Stack
214 {...stackStyles}
215 onClick={() => {
216 navigate(`/account/${conversation.getAccountId()}/`);
217 closeModal();
ervinanoh8e918042022-09-06 10:30:59 -0400218 }}
219 >
ervinanohb81c3912022-09-08 04:13:24 -0400220 <div style={{ ...iconTextStyle }}>
221 <CrossIcon style={{ color: iconColor }} />
222 </div>
223 Fermer la conversation
224 </Stack>
225
226 <Stack
227 onClick={() => {
228 console.log("open details contact for: ");
229 closeModal();
230 openModalDetails();
231 getContactDetails();
232 }}
233 {...stackStyles}
234 >
235 <div style={{ ...iconTextStyle }}>
236 <ContactDetailsIcon style={{ color: iconColor }} />
237 </div>
238 Détails de la conversation
239 </Stack>
240
241 <Stack
242 onClick={() => {
243 setBlockOrRemove(true);
244 closeModal();
245 openModalDelete();
246 }}
247 {...stackStyles}
248 >
249 <div style={{ ...iconTextStyle }}>
250 <BlockContactIcon style={{ color: iconColor }} />
251 </div>
252 Bloquer le contact
253 </Stack>
254
255 <Stack
256 onClick={() => {
257 setBlockOrRemove(false);
258 closeModal();
259 openModalDelete();
260 }}
261 {...stackStyles}
262 >
263 <div style={{ ...iconTextStyle }}>
264 <RemoveContactIcon style={{ color: iconColor }} />
265 </div>
266 Supprimer contact
267 </Stack>
268 </Modal>
269 </div>
270
271 <div name="Contact details">
272 <Modal
273 isOpen={modalDetailsIsOpen}
274 onRequestClose={closeModalDetails}
275 style={contactDetailsStyles}
276 contentLabel="Détails contact"
277 >
278 <Stack direction={"row"} alignContent="flex-end">
279 <Stack direction={"column"}>
280 <div style={{ height: "100px" }}>
281 <ConversationAvatar
282 displayName={conversation.getDisplayNameNoFallback()}
283 />
284 </div>
285
286 <div
287 style={{
288 fontSize: "20px",
289 marginBottom: "20px",
290 height: "20px",
291 }}
292 >
293 Informations
294 </div>
295
296 <Typography variant="caption">Nom d'utilisateur</Typography>
297 <div style={{ height: "20px" }} />
298 <Typography variant="caption">Identifiant </Typography>
299 <div style={{ height: "20px" }} />
300
301 <div
302 style={{
303 flex: 1,
304 height: "150px",
305 direction: "column",
306 flexDirection: "column",
307 // alignSelf: "flex-end",
308 }}
309 >
310 <Typography variant="caption">Code QR</Typography>
311 </div>
312
313 <Typography variant="caption">est un swarm </Typography>
314 </Stack>
315
316 <Stack direction={"column"}>
317 <div
318 style={{
319 fontWeight: "bold",
320 fontSize: "20px",
321 height: "100px",
322 }}
323 >
324 {conversation.getDisplayNameNoFallback() + "(resolved name)"}
325 </div>
326
327 <div
328 style={{
329 height: "40px",
330 }}
331 />
332 <Typography variant="caption">
333 <div style={{ fontWeight: "bold" }}>
334 {conversation.getDisplayNameNoFallback()}
335 </div>
336 </Typography>
337
338 <div style={{ height: "20px" }} />
339
340 <Typography variant="caption">
341 <div style={{ fontWeight: "bold" }}> {userId}</div>
342 </Typography>
343
344 <div style={{ height: "20px" }} />
345
346 <div height={"40px"}>
347 <QRCodeCanvas value={`${userId}`} />
348 </div>
349
350 <Typography variant="caption">
351 <div style={{ fontWeight: "bold" }}> {isSwarm}</div>
352 </Typography>
353 </Stack>
354 </Stack>
355 <div
356 onClick={closeModalDetails}
357 style={{
358 width: "100px",
359 borderStyle: "solid",
360 textAlign: "center",
361 borderRadius: "5px",
362 marginLeft: "150px",
363 marginTop: "10px",
364 }}
365 >
366 <Typography variant="caption">Fermer</Typography>
ervinanoh8e918042022-09-06 10:30:59 -0400367 </div>
ervinanohb81c3912022-09-08 04:13:24 -0400368 </Modal>
369 </div>
idillon531b6f22022-09-16 14:02:00 -0400370
ervinanohb81c3912022-09-08 04:13:24 -0400371 <div name="Remove or block details">
372 <Modal
373 isOpen={modalDeleteIsOpen}
374 onRequestClose={closeModalDelete}
375 style={cancelStyles}
376 contentLabel="Merci de confirmer"
idillon531b6f22022-09-16 14:02:00 -0400377 >
ervinanohb81c3912022-09-08 04:13:24 -0400378 <Typography variant="h4">Merci de confirmer</Typography>
379 <Stack
380 direction={"column"}
381 justifyContent="space-around"
382 spacing={"75px"}
383 >
384 <div style={{ textAlign: "center", marginTop: "10%" }}>
385 <Typography variant="body2">
386 Voulez vous vraiment {blockOrRemove ? "bloquer" : "supprimer"}{" "}
387 ce contact?
388 </Typography>
389 </div>
ervinanoh8e918042022-09-06 10:30:59 -0400390
ervinanohb81c3912022-09-08 04:13:24 -0400391 <Stack
392 direction={"row"}
393 top={"25px"}
394 alignSelf="center"
395 spacing={1}
396 >
397 <Box
398 onClick={() => {
399 if (blockOrRemove) removeOrBlock("block");
400 else removeOrBlock("remove");
401 }}
402 style={{
403 width: "100px",
404 textAlign: "center",
405 borderStyle: "solid",
406 borderColor: "red",
407 borderRadius: "10px",
408 color: "red",
409 }}
410 >
411 {blockOrRemove ? "Bloquer" : "Supprimer"}
412 </Box>
413 <Box
414 onClick={closeModalDelete}
415 style={{
416 width: "100px",
417 textAlign: "center",
418 paddingLeft: "12px",
419 paddingRight: "12px",
420 borderStyle: "solid",
421 borderRadius: "10px",
422 }}
423 >
424 Annuler
425 </Box>
426 </Stack>
427 </Stack>
428 </Modal>
429 </div>
idillon531b6f22022-09-16 14:02:00 -0400430
431 <ListItem
432 button
433 alignItems="flex-start"
434 selected={isSelected}
ervinanohb81c3912022-09-08 04:13:24 -0400435 onClick={() =>
436 navigate(`/account/${conversation.getAccountId()}/${uri}`)
437 }
idillon531b6f22022-09-16 14:02:00 -0400438 >
439 <ListItemAvatar>
440 <ConversationAvatar
441 displayName={conversation.getDisplayNameNoFallback()}
442 />
443 </ListItemAvatar>
444 <ListItemText
445 primary={conversation.getDisplayName()}
446 secondary={conversation.getDisplayUri()}
447 />
448 </ListItem>
449 </div>
450 );
451 } else return null;
Adrien Béraud995e8022021-04-08 13:46:51 -0400452}