diff --git a/components/CollectionCard.tsx b/components/CollectionCard.tsx index 7a12785..38a554e 100644 --- a/components/CollectionCard.tsx +++ b/components/CollectionCard.tsx @@ -41,7 +41,7 @@ export default function ({ collection }: { collection: ExtendedCollection }) { }; return ( -
+
setExpandDropdown(!expandDropdown)} id="edit-dropdown" @@ -54,7 +54,7 @@ export default function ({ collection }: { collection: ExtendedCollection }) { />
-
+

{collection.name}

diff --git a/components/Dropdown.tsx b/components/Dropdown.tsx index 2542cd1..1eff26f 100644 --- a/components/Dropdown.tsx +++ b/components/Dropdown.tsx @@ -24,7 +24,7 @@ export default function ({ onClickOutside, className, items }: Props) { return ( {items.map((e, i) => { const inner = ( diff --git a/components/Modal/AddCollection.tsx b/components/Modal/AddCollection.tsx index b287d51..e949c28 100644 --- a/components/Modal/AddCollection.tsx +++ b/components/Modal/AddCollection.tsx @@ -5,7 +5,12 @@ import React, { useState } from "react"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import { faClose, faPlus, faUser } from "@fortawesome/free-solid-svg-icons"; +import { + faClose, + faPlus, + faUser, + faUserPlus, +} from "@fortawesome/free-solid-svg-icons"; import useCollectionStore from "@/store/collections"; import { ExtendedCollection, NewCollection } from "@/types/global"; import { useSession } from "next-auth/react"; @@ -111,7 +116,7 @@ export default function AddCollection({ toggleCollectionModal }: Props) { } 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" > - +
diff --git a/components/Modal/EditCollection.tsx b/components/Modal/EditCollection.tsx index a30c8cb..46359ac 100644 --- a/components/Modal/EditCollection.tsx +++ b/components/Modal/EditCollection.tsx @@ -11,6 +11,7 @@ import { faPlus, faTrashCan, faUser, + faUserPlus, } from "@fortawesome/free-solid-svg-icons"; import useCollectionStore from "@/store/collections"; import { ExtendedCollection } from "@/types/global"; @@ -20,6 +21,7 @@ import DeleteCollection from "@/components/Modal/DeleteCollection"; import RequiredBadge from "../RequiredBadge"; import addMemberToCollection from "@/lib/client/addMemberToCollection"; import ImageWithFallback from "../ImageWithFallback"; +import Checkbox from "../Checkbox"; type Props = { toggleCollectionModal: Function; @@ -102,9 +104,27 @@ export default function EditCollection({
-
+
+ + {/*

Sharing & Collaboration Settings

+ +

Collaboration

+ +
+
+ Manage Team +
+
+ + console.log("Clicked!")} + /> +

+ This will let anyone to access this collection. +

*/} -

Members

- +
{activeCollection.members[0] ? ( diff --git a/components/Modal/Team.tsx b/components/Modal/Team.tsx new file mode 100644 index 0000000..b287d51 --- /dev/null +++ b/components/Modal/Team.tsx @@ -0,0 +1,265 @@ +// 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, faPlus, faUser } from "@fortawesome/free-solid-svg-icons"; +import useCollectionStore from "@/store/collections"; +import { ExtendedCollection, NewCollection } from "@/types/global"; +import { useSession } from "next-auth/react"; +import RequiredBadge from "../RequiredBadge"; +import addMemberToCollection from "@/lib/client/addMemberToCollection"; +import ImageWithFallback from "../ImageWithFallback"; + +type Props = { + toggleCollectionModal: Function; +}; + +export default function AddCollection({ toggleCollectionModal }: Props) { + const [newCollection, setNewCollection] = useState({ + name: "", + description: "", + members: [], + }); + + const [memberEmail, setMemberEmail] = useState(""); + + const { addCollection } = useCollectionStore(); + + const session = useSession(); + + const submit = async () => { + console.log(newCollection); + + const response = await addCollection(newCollection as NewCollection); + + if (response) toggleCollectionModal(); + }; + + const setMemberState = (newMember: any) => { + setNewCollection({ + ...newCollection, + members: [...newCollection.members, newMember], + }); + + setMemberEmail(""); + }; + + return ( +
+

New Collection

+ +
+
+

+ Name + +

+ + setNewCollection({ ...newCollection, 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

+ + setNewCollection({ + ...newCollection, + 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, + newCollection as unknown as ExtendedCollection, + setMemberState, + "ADD" + ) + } + 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" + > + +
+
+ + {newCollection.members[0] ? ( +

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

+ ) : null} + +
+ {newCollection.members.map((e, i) => { + return ( +
+ { + const updatedMembers = newCollection.members.filter( + (member) => { + return member.email !== e.email; + } + ); + setNewCollection({ + ...newCollection, + members: updatedMembers, + }); + }} + /> +
+ +
+ +
+
+
+

{e.name}

+

{e.email}

+
+
+
+
+

Permissions

+

+ (Click to toggle.) +

+
+ +
+ + + + + +
+
+
+ ); + })} +
+ +
+ + Add Collection +
+
+ ); +} diff --git a/components/Modal/UserSettings.tsx b/components/Modal/UserSettings.tsx index aef239e..3c1b308 100644 --- a/components/Modal/UserSettings.tsx +++ b/components/Modal/UserSettings.tsx @@ -41,16 +41,6 @@ export default function UserSettings({ toggleSettingsModal }: Props) { setUser({ ...user, oldPassword, newPassword }); }; - // useEffect(() => { - // const determineProfilePicSource = async () => { - // const path = `/api/avatar/${account.id}`; - // const imageExists = await avatarExists(path).catch((e) => console.log(e)); - // if (imageExists) setUser({ ...user, profilePic: path }); - // }; - - // determineProfilePicSource(); - // }, []); - useEffect(() => { setUser({ ...user, diff --git a/components/Sidebar/SidebarItem.tsx b/components/Sidebar/SidebarItem.tsx index 45bf85a..c104d35 100644 --- a/components/Sidebar/SidebarItem.tsx +++ b/components/Sidebar/SidebarItem.tsx @@ -28,12 +28,14 @@ export default function ({ text, icon, path, className }: SidebarItemProps) {
{React.cloneElement(icon, { className: `w-4 ${active ? "text-white" : "text-sky-300"}`, })} -

{text}

+

+ {text} +

); diff --git a/lib/api/controllers/users/updateUser.ts b/lib/api/controllers/users/updateUser.ts index 2630867..5ca5b06 100644 --- a/lib/api/controllers/users/updateUser.ts +++ b/lib/api/controllers/users/updateUser.ts @@ -12,7 +12,7 @@ import bcrypt from "bcrypt"; export default async function (user: AccountSettings, userId: number) { const profilePic = user.profilePic; - if (profilePic && profilePic !== "DELETE") { + if (profilePic?.startsWith("data:image/jpeg;base64")) { if ((user?.profilePic?.length as number) < 1572864) { try { const filePath = path.join( diff --git a/pages/collections/[id].tsx b/pages/collections/[id].tsx index 46d8c7d..48d7856 100644 --- a/pages/collections/[id].tsx +++ b/pages/collections/[id].tsx @@ -28,6 +28,7 @@ import MainLayout from "@/layouts/MainLayout"; import RadioButton from "@/components/RadioButton"; import ClickAwayHandler from "@/components/ClickAwayHandler"; import ImageWithFallback from "@/components/ImageWithFallback"; +import { useSession } from "next-auth/react"; export default function () { const router = useRouter(); @@ -35,6 +36,8 @@ export default function () { const { links } = useLinkStore(); const { collections } = useCollectionStore(); + const { data } = useSession(); + const [expandDropdown, setExpandDropdown] = useState(false); const [linkModal, setLinkModal] = useState(false); const [editCollectionModal, setEditCollectionModal] = useState(false); @@ -102,7 +105,7 @@ export default function () {
-
+
-
-
- View Team +
+
+ {activeCollection.ownerId === data?.user.id + ? "Manage" + : "View"}{" "} + Team
{activeCollection?.members .sort((a, b) => a.userId - b.userId) @@ -143,7 +149,7 @@ export default function () { {activeCollection?.members.length && activeCollection.members.length - 4 > 0 ? (
- +{activeCollection?.members?.length - 3} + +{activeCollection?.members?.length - 4}
) : null}