diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-11-09 15:40:16 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-11-09 15:40:16 +0700 |
| commit | be0f537dc4fe384eef09436833c6407e6482c16d (patch) | |
| tree | 194b1ad3f34396cb8149075bbbd38b854aedf361 /src/common/stores/useStockOpnameStore.ts | |
| parent | 5d5401ae36e7e0c8eb38ccd943c1aa44a9573d35 (diff) | |
Initial commit
Diffstat (limited to 'src/common/stores/useStockOpnameStore.ts')
| -rw-r--r-- | src/common/stores/useStockOpnameStore.ts | 48 |
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, + })), +})); |
