Spaces:
Paused
Paused
File size: 5,017 Bytes
a0fda44 |
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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
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 (
<ActivePage
activePageName="selectContacts"
className="relative overflow-y-hidden"
>
{/* Header */}
<div className="px-[1.5rem] flex flex-col gap-[1rem] mb-[1.5rem] py-[.5rem]">
<div className="flex items-center">
<IconWrapper
onClick={() =>
dispatch(
sidebarActions.changeActivePage({ newActivePage: "chatList" })
)
}
>
<svg
xmlns="http://www.w3.org/2000/svg"
width="1em"
height="1em"
preserveAspectRatio="xMidYMid meet"
viewBox="0 0 24 24"
>
<path
fill="currentColor"
d="M19 11H7.14l3.63-4.36a1 1 0 1 0-1.54-1.28l-5 6a1.19 1.19 0 0 0-.09.15c0 .05 0 .08-.07.13A1 1 0 0 0 4 12a1 1 0 0 0 .07.36c0 .05 0 .08.07.13a1.19 1.19 0 0 0 .09.15l5 6A1 1 0 0 0 10 19a1 1 0 0 0 .64-.23a1 1 0 0 0 .13-1.41L7.14 13H19a1 1 0 0 0 0-2Z"
className="stroke-transparent"
/>
</svg>
</IconWrapper>
<h2 className="font-semibold ml-[3rem] text-[2rem]">Add Members</h2>
</div>
{/* All added members */}
{/* Selected contacts */}
<SelectedContacts
contacts={selectedContacts}
removeContact={removeContact}
/>
{/* Search Input */}
{!!contacts.length && (
<input
type="text"
className="focus-within:outline-none placeholder:text-secondary-text bg-transparent w-full ml-[1rem]"
placeholder="Who would you like to add?"
onChange={handleSearchValue}
value={searchValue}
/>
)}
</div>
{/* Contacts */}
{contacts.map((contact) => (
<ContactSelect
contact={contact}
key={contact._id}
selected={selectedContacts.some((con) => con._id === contact._id)}
addContact={addContact}
removeContact={removeContact}
/>
))}
{/* If no contacts exists */}
{!contacts.length && (
<div className="flex flex-col py-[2rem] items-center uppercase">
<button
onClick={() =>
dispatch(
modalActions.openModal({
type: "newContactForm",
positions: {},
})
)
}
className={`bg-cta-icon mt-[5rem] p-[1rem] rounded-xl uppercase text-white font-semibold opacity-80 flex items-center justify-center`}
type="submit"
>
Add Contacts Now
</button>
</div>
)}
{/* ADD button */}
<AnimatePresence>
{selectedContacts.length && (
<motion.div
initial={{ bottom: "-10rem" }}
animate={{ bottom: "2rem" }}
exit={{ bottom: "-10rem" }}
className="w-fit h-fit absolute right-[2rem]"
>
<CTAIconWrapper className="">
<svg
xmlns="http://www.w3.org/2000/svg"
width="1em"
height="1em"
preserveAspectRatio="xMidYMid meet"
viewBox="0 0 24 24"
className="rotate-180"
>
<path
fill="currentColor"
d="M19 11H7.14l3.63-4.36a1 1 0 1 0-1.54-1.28l-5 6a1.19 1.19 0 0 0-.09.15c0 .05 0 .08-.07.13A1 1 0 0 0 4 12a1 1 0 0 0 .07.36c0 .05 0 .08.07.13a1.19 1.19 0 0 0 .09.15l5 6A1 1 0 0 0 10 19a1 1 0 0 0 .64-.23a1 1 0 0 0 .13-1.41L7.14 13H19a1 1 0 0 0 0-2Z"
className="stroke-transparent fill-white"
/>
</svg>
</CTAIconWrapper>
</motion.div>
)}
</AnimatePresence>
</ActivePage>
);
}
export default SelectContacts;
|