-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathContactListTable.jsx
More file actions
97 lines (91 loc) · 3.28 KB
/
ContactListTable.jsx
File metadata and controls
97 lines (91 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// React Imports
import React, { useState } from 'react';
// Material UI Imports
import Box from '@mui/material/Box';
import useMediaQuery from '@mui/material/useMediaQuery';
import { useTheme } from '@mui/material/styles';
// Component Imports
import { NewMessageModal, AddContactModal } from '../Modals';
import ContactListTableDesktop from './ContactListTableDesktop';
import ContactListTableMobile from './ContactListTableMobile';
/**
* @typedef {import("../../typedefs.js").userListObject} userListObject
*/
/**
* ContactListTable - Component that generates the list of contacts
* from data within ContactList
*
* @memberof Contacts
* @name ContactListTable
* @param {object} Props - Props for ContactListTable
* @param {userListObject[]} Props.contacts - This list of contacts to display
* @param {Function} Props.deleteContact - Method to delete contact
* @param {Function} Props.handleDeleteContact - from Contacts page
* @param {Function} Props.addContact - from Contacts page
* @returns {React.JSX.Element} The ContactListTable Component
*/
const ContactListTable = ({ contacts = [], deleteContact, handleDeleteContact, addContact }) => {
const [showMessageModal, setShowMessageModal] = useState(false);
const [messageToField, setMessageToField] = useState('');
const [showAddContactModal, setShowAddContactModal] = useState(false);
const [contactToEdit, setContactToEdit] = useState(null);
const [isEditing, setIsEditing] = useState(false);
const contactWebIds = contacts.map(({ webId }) => webId);
const theme = useTheme();
const isSmallScreen = useMediaQuery(theme.breakpoints.down('sm'));
const isSmallScreenHeight = useMediaQuery('(max-height: 600px)');
const handleSendMessage = (contactId) => {
setShowMessageModal(!showMessageModal);
setMessageToField(isSmallScreen ? contactId.podUrl : contactId.value.podUrl);
};
const handleEditContact = (contact) => {
setShowAddContactModal(!showAddContactModal);
setContactToEdit(contact);
setIsEditing(true);
};
return (
<Box
sx={{
margin: '20px 0',
width: '95vw',
minHeight: '500px'
}}
>
{isSmallScreen || isSmallScreenHeight ? (
<ContactListTableMobile
data-testid="ContactListTableMobile"
contacts={contacts}
deleteContact={deleteContact}
handleSendMessage={handleSendMessage}
editContact={handleEditContact}
/>
) : (
<ContactListTableDesktop
data-testid="ContactListTableDesktop"
contacts={contacts}
deleteContact={deleteContact}
handleSendMessage={handleSendMessage}
editContact={handleEditContact}
/>
)}
<NewMessageModal
showModal={showMessageModal}
setShowModal={setShowMessageModal}
toField={messageToField}
/>
<AddContactModal
showAddContactModal={showAddContactModal}
contactToEdit={contactToEdit}
isEditing={isEditing}
setShowAddContactModal={setShowAddContactModal}
addContact={addContact}
deleteContact={deleteContact}
handleDeleteContact={handleDeleteContact}
contactWebIds={contactWebIds}
contacts={contacts}
setContactToEdit={setContactToEdit}
/>
</Box>
);
};
export default ContactListTable;