import React, { useState } from "react"; import { useDispatch } from "react-redux"; import useContactList from "../hooks/useContactList"; import { sidebarActions } from "../store/sidebarSlice"; import IconWrapper from "../components/globals/IconWrapper"; import ActivePage from "../components/pages/Sidebar/ActivePage"; import ContactSelect from "../components/pages/SelectContacts/ContactSelect"; import SelectedContacts from "../components/pages/SelectContacts/SelectedContacts"; import CTAIconWrapper from "../components/globals/CTAIconWrapper"; import { AnimatePresence, motion } from "framer-motion"; import { modalActions } from "../store/modalSlice"; function SelectContacts() { const { contacts, handleSearchValue, searchValue } = useContactList(); const [selectedContacts, setSelectedContacts] = useState([]); const dispatch = useDispatch(); const removeContact = (contactId) => { setSelectedContacts((prevState) => prevState.filter((contact) => contact._id !== contactId) ); }; const addContact = (contact) => { setSelectedContacts((prevState) => prevState.concat(contact)); }; return ( {/* Header */}
dispatch( sidebarActions.changeActivePage({ newActivePage: "chatList" }) ) } >

Add Members

{/* All added members */} {/* Selected contacts */} {/* Search Input */} {!!contacts.length && ( )}
{/* Contacts */} {contacts.map((contact) => ( con._id === contact._id)} addContact={addContact} removeContact={removeContact} /> ))} {/* If no contacts exists */} {!contacts.length && (
)} {/* ADD button */} {selectedContacts.length && ( )}
); } export default SelectContacts;