summaryrefslogtreecommitdiff
path: root/src/common/stores/useStockOpnameStore.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/stores/useStockOpnameStore.ts')
-rw-r--r--src/common/stores/useStockOpnameStore.ts48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/common/stores/useStockOpnameStore.ts b/src/common/stores/useStockOpnameStore.ts
new file mode 100644
index 0000000..8aeff77
--- /dev/null
+++ b/src/common/stores/useStockOpnameStore.ts
@@ -0,0 +1,48 @@
+import { create } from "zustand";
+import { SelectOption } from "../types/select";
+import { SingleValue } from "react-select";
+import { User } from "@prisma/client";
+
+type State = {
+ form: {
+ location: SingleValue<SelectOption> | null;
+ product: SingleValue<SelectOption> | null;
+ quantity: string;
+ };
+ oldOpname: {
+ id: number;
+ quantity: number;
+ user: User;
+ } | null;
+};
+
+type Action = {
+ updateForm: (
+ name: keyof State["form"],
+ value: SingleValue<SelectOption> | string
+ ) => void;
+ setOldOpname: (value: State["oldOpname"]) => void;
+ resetForm: () => void;
+};
+
+export const useStockOpnameStore = create<State & Action>((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,
+ })),
+}));