import { create } from "zustand"; import { SelectOption } from "../types/select"; import { SingleValue } from "react-select"; import { User } from "@prisma/client"; type State = { form: { location: SingleValue | null; product: SingleValue | null; quantity: string; }; oldOpname: { id: number; quantity: number; user: User; } | null; }; type Action = { updateForm: ( name: keyof State["form"], value: SingleValue | string ) => void; setOldOpname: (value: State["oldOpname"]) => void; resetForm: () => void; }; export const useStockOpnameStore = create((set) => ({ form: { location: null, product: null, quantity: "", }, oldOpname: null, updateForm: (name, value) => set((state) => ({ form: { ...state.form, [name]: value, }, })), setOldOpname: (value) => set(() => ({ oldOpname: value })), resetForm: () => set((state) => ({ form: { ...state.form, product: null, quantity: "" }, oldOpname: null, })), }));