summaryrefslogtreecommitdiff
path: root/src/common/stores
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-11-09 15:40:16 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-11-09 15:40:16 +0700
commitbe0f537dc4fe384eef09436833c6407e6482c16d (patch)
tree194b1ad3f34396cb8149075bbbd38b854aedf361 /src/common/stores
parent5d5401ae36e7e0c8eb38ccd943c1aa44a9573d35 (diff)
Initial commit
Diffstat (limited to 'src/common/stores')
-rw-r--r--src/common/stores/useAuthStore.ts15
-rw-r--r--src/common/stores/useLoginStore.ts26
-rw-r--r--src/common/stores/useResultStore.ts26
-rw-r--r--src/common/stores/useStockOpnameStore.ts48
4 files changed, 115 insertions, 0 deletions
diff --git a/src/common/stores/useAuthStore.ts b/src/common/stores/useAuthStore.ts
new file mode 100644
index 0000000..b88cf0b
--- /dev/null
+++ b/src/common/stores/useAuthStore.ts
@@ -0,0 +1,15 @@
+import { create } from "zustand";
+import { Credential } from "../types/auth";
+
+type State = {
+ credentials: Credential | null | undefined;
+};
+
+type Action = {
+ setCredentials: (credentials: Credential | null) => void;
+};
+
+export const useAuthStore = create<State & Action>((set) => ({
+ credentials: null,
+ setCredentials: (credentials) => set({ credentials }),
+}));
diff --git a/src/common/stores/useLoginStore.ts b/src/common/stores/useLoginStore.ts
new file mode 100644
index 0000000..7b4551c
--- /dev/null
+++ b/src/common/stores/useLoginStore.ts
@@ -0,0 +1,26 @@
+import { create } from "zustand";
+
+type State = {
+ form: {
+ username: string;
+ password: string;
+ };
+};
+
+type Action = {
+ updateForm: (name: string, value: string) => void;
+};
+
+export const useLoginStore = create<State & Action>((set) => ({
+ form: {
+ username: "",
+ password: "",
+ },
+ updateForm: (name, value) =>
+ set((state) => ({
+ form: {
+ ...state.form,
+ [name]: value,
+ },
+ })),
+}));
diff --git a/src/common/stores/useResultStore.ts b/src/common/stores/useResultStore.ts
new file mode 100644
index 0000000..d8da56c
--- /dev/null
+++ b/src/common/stores/useResultStore.ts
@@ -0,0 +1,26 @@
+import { create } from "zustand";
+
+type State = {
+ filter: {
+ search: string;
+ company: string;
+ };
+};
+
+type Action = {
+ updateFilter: (name: string, value: string) => void;
+};
+
+export const useResultStore = create<State & Action>((set) => ({
+ filter: {
+ search: "",
+ company: "",
+ },
+ updateFilter: (name, value) =>
+ set((state) => ({
+ filter: {
+ ...state.filter,
+ [name]: value,
+ },
+ })),
+}));
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,
+ })),
+}));