added update account functionality

This commit is contained in:
Daniel
2023-05-20 22:55:00 +03:30
parent e3862188de
commit 0ce97f0b64
13 changed files with 345 additions and 61 deletions
+18
View File
@@ -5,10 +5,13 @@
import { create } from "zustand";
import { User } from "@prisma/client";
import { AccountSettings } from "@/types/global";
import { useSession } from "next-auth/react";
type AccountStore = {
account: User;
setAccount: (email: string) => void;
updateAccount: (user: AccountSettings) => void;
};
const useAccountStore = create<AccountStore>()((set) => ({
@@ -20,6 +23,21 @@ const useAccountStore = create<AccountStore>()((set) => ({
console.log(data);
if (response.ok) set({ account: data.response });
},
updateAccount: async (user) => {
const response = await fetch("/api/routes/users", {
method: "PUT",
body: JSON.stringify(user),
headers: {
"Content-Type": "application/json",
},
});
const data = await response.json();
console.log(data);
if (response.ok) set({ account: data.response });
},
}));