functionally completed user editing
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
import { create } from "zustand";
|
||||
import { persist } from "zustand/middleware";
|
||||
import { apiCall } from "./lib";
|
||||
|
||||
export interface EventData {
|
||||
id: number;
|
||||
@@ -17,48 +16,29 @@ export interface User {
|
||||
}
|
||||
|
||||
interface Zustand {
|
||||
events: EventData[];
|
||||
pendingEvents: number;
|
||||
user: User | null;
|
||||
setEvents: (events: EventData[]) => void;
|
||||
reset: (zustand?: Partial<Zustand>) => void;
|
||||
getPendingEvents: () => Promise<void>;
|
||||
}
|
||||
|
||||
const initialState = {
|
||||
events: [],
|
||||
user: null,
|
||||
pendingEvents: 0,
|
||||
};
|
||||
|
||||
const zustand = create<Zustand>()(
|
||||
persist(
|
||||
(set) => ({
|
||||
...initialState,
|
||||
setEvents: (events) => set({ events }),
|
||||
reset: (newZustand) =>
|
||||
set({
|
||||
...initialState,
|
||||
...newZustand,
|
||||
}),
|
||||
getPendingEvents: async () => {
|
||||
const result = await apiCall<{ pendingEvents: number }>(
|
||||
"GET",
|
||||
"events/user/pending",
|
||||
);
|
||||
|
||||
if (result.ok) {
|
||||
const resultData = await result.json();
|
||||
|
||||
set(() => ({ pendingEvents: resultData }));
|
||||
}
|
||||
},
|
||||
}),
|
||||
{
|
||||
name: "golunteer-storage",
|
||||
partialize: (state) =>
|
||||
Object.fromEntries(
|
||||
Object.entries(state).filter(([key]) => !["events"].includes(key)),
|
||||
Object.entries(state).filter(([key]) => ["user"].includes(key)),
|
||||
),
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user