import { Dispatch, SetStateAction, useState } from "react"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faClose, faPenToSquare, faPlus, faUserPlus, } from "@fortawesome/free-solid-svg-icons"; import useCollectionStore from "@/store/collections"; import { CollectionIncludingMembersAndLinkCount, Member } from "@/types/global"; import { useSession } from "next-auth/react"; import addMemberToCollection from "@/lib/client/addMemberToCollection"; import Checkbox from "../../Checkbox"; import SubmitButton from "@/components/SubmitButton"; import ProfilePhoto from "@/components/ProfilePhoto"; type Props = { toggleCollectionModal: Function; setCollection: Dispatch< SetStateAction >; collection: CollectionIncludingMembersAndLinkCount; method: "CREATE" | "UPDATE"; }; export default function TeamManagement({ toggleCollectionModal, setCollection, collection, method, }: Props) { const currentURL = new URL(document.URL); const publicCollectionURL = `${currentURL.origin}/public/collections/${collection.id}`; const [member, setMember] = useState({ canCreate: false, canUpdate: false, canDelete: false, user: { name: "", email: "", }, }); const { addCollection, updateCollection } = useCollectionStore(); const session = useSession(); const setMemberState = (newMember: Member) => { if (!collection) return null; setCollection({ ...collection, members: [...collection.members, newMember], }); setMember({ canCreate: false, canUpdate: false, canDelete: false, user: { name: "", email: "", }, }); }; const submit = async () => { if (!collection) return null; let response = null; if (method === "CREATE") response = await addCollection(collection); else if (method === "UPDATE") response = await updateCollection(collection); else console.log("Unknown method."); if (response) toggleCollectionModal(); }; return (

Make Public

setCollection({ ...collection, isPublic: !collection.isPublic }) } />

This will let Anyone to view this collection.

{collection.isPublic ? (

Public Link (Click to copy)

{ try { navigator.clipboard .writeText(publicCollectionURL) .then(() => console.log("Copied!")); } catch (err) { console.log(err); } }} className="w-full hide-scrollbar overflow-x-auto whitespace-nowrap rounded-md p-3 border-sky-100 border-solid border outline-none hover:border-sky-500 duration-100 cursor-text" > {publicCollectionURL}
) : null}

Member Management

{ setMember({ ...member, user: { ...member.user, email: e.target.value }, }); }} onKeyDown={(e) => e.key === "Enter" && addMemberToCollection( session.data?.user.email as string, member.user.email, collection, setMemberState ) } type="text" placeholder="Email" className="w-full rounded-md p-3 border-sky-100 border-solid border outline-none focus:border-sky-500 duration-100" />
addMemberToCollection( session.data?.user.email as string, member.user.email, collection, setMemberState ) } className="flex items-center justify-center bg-sky-500 hover:bg-sky-400 duration-100 text-white w-12 h-12 p-3 rounded-md cursor-pointer" >
{collection?.members[0]?.user && ( <>

(All Members have Read access to this collection.)

{collection.members .sort((a, b) => (a.userId as number) - (b.userId as number)) .map((e, i) => { return (
{ const updatedMembers = collection.members.filter( (member) => { return member.user.email !== e.user.email; } ); setCollection({ ...collection, members: updatedMembers, }); }} />

{e.user.name}

{e.user.email}

Permissions

(Click to toggle.)

); })}
)}
); }