added update account functionality
This commit is contained in:
@@ -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 });
|
||||
},
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user