Files
golunteer/client/src/Zustand.ts
2025-01-24 00:27:53 +00:00

69 lines
1.2 KiB
TypeScript

"use client";
import { create } from "zustand";
import { Task } from "./lib";
import { Availability } from "./app/admin/(availabilities)/AvailabilityEditor";
export interface BaseEvent {
eventID: number;
date: string;
description: string;
}
export type EventData = BaseEvent & {
tasks: TaskAssignment[];
};
export interface TaskAssignment {
taskID: number;
taskName: string;
userName: string | null;
}
export interface User {
userName: string;
admin: boolean;
}
export type UserAddModify = User & {
password: string;
};
interface Zustand {
user: User | null;
tasks?: Task[];
availabilities?: Availability[];
patch: (zustand?: Partial<Zustand>) => void;
reset: (zustand?: Partial<Zustand>) => void;
}
const initialState = {
user: null,
};
const zustand = create<Zustand>()(
// persist(
(set, get) => ({
...initialState,
reset: (newZustand) => {
set({
...initialState,
...newZustand,
});
},
patch: (patch) => set({ ...get(), ...patch }),
}),
// {
// name: "golunteer-storage",
// partialize: (state) =>
// Object.fromEntries(
// Object.entries(state).filter(([key]) =>
// ["user", "tasksList", "tasksMap"].includes(key),
// ),
// ),
// },
// ),
);
export default zustand;