summaryrefslogtreecommitdiff
path: root/src/common/stores/useResultStore.ts
blob: 680db56bbdd664e8ff096fc3285d4a737834ceb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { create } from "zustand";
import { SelectOption } from "../types/select";

type State = {
  filter: {
    search: string;
    company: string;
    show: string;
    page: number;
  };
  companies: SelectOption[];
};

type Action = {
  updateFilter: (name: string, value: string | number) => void;
  setCompanies: (data: SelectOption[]) => void;
};

export const useResultStore = create<State & Action>((set) => ({
  filter: {
    search: "",
    company: "",
    show: "1",
    page: 1,
  },
  updateFilter: (name, value) =>
    set((state) => ({
      filter: {
        ...state.filter,
        [name]: value,
      },
    })),
  companies: [],
  setCompanies: (data) =>
    set(() => ({
      companies: data,
    })),
}));