feat: add collection functionality

This commit is contained in:
Daniel
2023-04-25 01:00:40 +03:30
parent b02766f6c8
commit 4bfb08a52e
12 changed files with 86 additions and 134 deletions
+6 -3
View File
@@ -5,11 +5,12 @@
import { create } from "zustand";
import { Collection } from "@prisma/client";
import { NewCollection } from "@/types/global";
type CollectionStore = {
collections: Collection[];
setCollections: () => void;
addCollection: (collectionName: string) => void;
addCollection: (body: NewCollection) => Promise<boolean>;
updateCollection: (collection: Collection) => void;
removeCollection: (collectionId: number) => void;
};
@@ -23,9 +24,9 @@ const useCollectionStore = create<CollectionStore>()((set) => ({
if (response.ok) set({ collections: data.response });
},
addCollection: async (collectionName) => {
addCollection: async (body) => {
const response = await fetch("/api/routes/collections", {
body: JSON.stringify({ collectionName }),
body: JSON.stringify(body),
headers: {
"Content-Type": "application/json",
},
@@ -38,6 +39,8 @@ const useCollectionStore = create<CollectionStore>()((set) => ({
set((state) => ({
collections: [...state.collections, data.response],
}));
return response.ok;
},
updateCollection: (collection) =>
set((state) => ({