diff --git a/components/ModalContent/NewCollectionModal.tsx b/components/ModalContent/NewCollectionModal.tsx index 8c68c83..7c73500 100644 --- a/components/ModalContent/NewCollectionModal.tsx +++ b/components/ModalContent/NewCollectionModal.tsx @@ -5,17 +5,20 @@ import toast from "react-hot-toast"; import { HexColorPicker } from "react-colorful"; import { Collection } from "@prisma/client"; import Modal from "../Modal"; +import { CollectionIncludingMembersAndLinkCount } from "@/types/global"; type Props = { onClose: Function; + parent?: CollectionIncludingMembersAndLinkCount; }; -export default function NewCollectionModal({ onClose }: Props) { +export default function NewCollectionModal({ onClose, parent }: Props) { const initial = { + parentId: parent?.id, name: "", description: "", color: "#0ea5e9", - }; + } as Partial; const [collection, setCollection] = useState>(initial); @@ -47,7 +50,14 @@ export default function NewCollectionModal({ onClose }: Props) { return ( -

Create a New Collection

+ {parent?.id ? ( + <> +

New Sub-Collection

+

For {parent.name}

+ + ) : ( +

Create a New Collection

+ )}
diff --git a/lib/api/controllers/collections/postCollection.ts b/lib/api/controllers/collections/postCollection.ts index a69d016..245f642 100644 --- a/lib/api/controllers/collections/postCollection.ts +++ b/lib/api/controllers/collections/postCollection.ts @@ -48,7 +48,10 @@ export default async function postCollection( const checkIfCollectionExists = findCollection?.collections[0]; if (checkIfCollectionExists) - return { response: "Collection already exists.", status: 400 }; + return { + response: "Oops! There's already a Collection with that name.", + status: 400, + }; const newCollection = await prisma.collection.create({ data: { diff --git a/pages/collections/[id].tsx b/pages/collections/[id].tsx index 6c23d40..fd0f970 100644 --- a/pages/collections/[id].tsx +++ b/pages/collections/[id].tsx @@ -25,6 +25,7 @@ import CardView from "@/components/LinkViews/Layouts/CardView"; import ListView from "@/components/LinkViews/Layouts/ListView"; import { dropdownTriggerer } from "@/lib/client/utils"; import Link from "next/link"; +import NewCollectionModal from "@/components/ModalContent/NewCollectionModal"; export default function Index() { const { settings } = useLocalSettingsStore(); @@ -83,6 +84,7 @@ export default function Index() { }, [activeCollection]); const [editCollectionModal, setEditCollectionModal] = useState(false); + const [newCollectionModal, setNewCollectionModal] = useState(false); const [editCollectionSharingModal, setEditCollectionSharingModal] = useState(false); const [deleteCollectionModal, setDeleteCollectionModal] = useState(false); @@ -112,45 +114,15 @@ export default function Index() { > {activeCollection && (
-
-
- +
+ -

- {activeCollection?.name} -

-
- - {collections.some((e) => e.parentId === activeCollection.id) ? ( -
- - View Sub-Collections - - -
- {collections - .filter((e) => e.parentId === activeCollection?.id) - .map((e, i) => { - return ( - - -

{e.name}

- - ); - })} -
-
- ) : undefined} +

+ {activeCollection?.name} +

@@ -191,6 +163,20 @@ export default function Index() { : "View Team"}
+ {permissions === true ? ( +
  • +
    { + (document?.activeElement as HTMLElement)?.blur(); + setNewCollectionModal(true); + }} + > + Create Sub-Collection +
    +
  • + ) : undefined}
  • ) : undefined} + {newCollectionModal ? ( + setNewCollectionModal(false)} + parent={activeCollection} + /> + ) : undefined} {deleteCollectionModal ? ( setDeleteCollectionModal(false)}