// Copyright (C) 2022-present Daniel31x13 // This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3. // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // You should have received a copy of the GNU General Public License along with this program. If not, see . import React, { useState } from "react"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faClose, faPenToSquare, faPlus, faTrashCan, } from "@fortawesome/free-solid-svg-icons"; import useCollectionStore from "@/store/collections"; import { ExtendedCollection } from "@/types/global"; import { useSession } from "next-auth/react"; import Modal from "@/components/Modal"; import DeleteCollection from "@/components/Modal/DeleteCollection"; import RequiredBadge from "../RequiredBadge"; import addMemberToCollection from "@/lib/client/addMemberToCollection"; type Props = { toggleCollectionModal: Function; collection: ExtendedCollection; }; export default function EditCollection({ toggleCollectionModal, collection, }: Props) { const [activeCollection, setActiveCollection] = useState(collection); const [memberEmail, setMemberEmail] = useState(""); const { updateCollection } = useCollectionStore(); const [deleteCollectionModal, setDeleteCollectionModal] = useState(false); const toggleDeleteCollectionModal = () => { setDeleteCollectionModal(!deleteCollectionModal); }; const session = useSession(); const setMemberState = (newMember: any) => { setActiveCollection({ ...activeCollection, members: [...activeCollection.members, newMember], }); setMemberEmail(""); }; const submit = async () => { console.log(activeCollection); const response = await updateCollection( activeCollection as ExtendedCollection ); if (response) toggleCollectionModal(); }; return (

Edit Collection

Name

setActiveCollection({ ...activeCollection, name: e.target.value }) } type="text" placeholder="e.g. Example Collection" className="w-full rounded-md p-3 border-sky-100 border-solid border outline-none focus:border-sky-500 duration-100" />

Description

setActiveCollection({ ...activeCollection, description: e.target.value, }) } type="text" placeholder="Collection description" className="w-full rounded-md p-3 border-sky-100 border-solid border outline-none focus:border-sky-500 duration-100" />

Members

{ setMemberEmail(e.target.value); }} type="text" placeholder="Email" className="w-full rounded-md p-3 pr-12 border-sky-100 border-solid border outline-none focus:border-sky-500 duration-100" />
addMemberToCollection( session.data?.user.email as string, memberEmail, activeCollection, setMemberState, "UPDATE" ) } className="absolute flex items-center justify-center right-2 top-2 bottom-2 bg-sky-500 hover:bg-sky-400 duration-100 text-white w-9 rounded-md cursor-pointer" >
{activeCollection.members[0] ? (

(All Members will have Read access to this collection.)

) : null} {activeCollection.members.map((e, i) => { return (
{ const updatedMembers = activeCollection.members.filter( (member) => { return member.user.email !== e.user.email; } ); setActiveCollection({ ...activeCollection, members: updatedMembers, }); }} />

{e.user.name}

{e.user.email}

Permissions

(Click to toggle.)

); })}
Edit Collection

OR


{ toggleDeleteCollectionModal(); }} className="w-fit inline-flex rounded-md cursor-pointer bg-red-500 hover:bg-red-400 duration-100 p-2" >
{deleteCollectionModal ? ( ) : null}
); }