From 490b84b0e6169cc2eb6f2d99a5759dbb5355ad52 Mon Sep 17 00:00:00 2001 From: nflnkr <105123049+nflnkr@users.noreply.github.com> Date: Sat, 18 Feb 2023 16:59:36 +0300 Subject: [PATCH] WIP split stores --- src/store.ts | 63 ---------------------------------------- src/stores/cart.ts | 27 +++++++++++++++++ src/stores/discounts.ts | 35 ++++++++++++++++++++++ src/stores/promocodes.ts | 27 +++++++++++++++++ src/stores/tariffs.ts | 31 ++++++++++++++++++++ 5 files changed, 120 insertions(+), 63 deletions(-) delete mode 100644 src/store.ts create mode 100644 src/stores/cart.ts create mode 100644 src/stores/discounts.ts create mode 100644 src/stores/promocodes.ts create mode 100644 src/stores/tariffs.ts diff --git a/src/store.ts b/src/store.ts deleted file mode 100644 index e4db8f5..0000000 --- a/src/store.ts +++ /dev/null @@ -1,63 +0,0 @@ -import create from "zustand"; -import { persist } from "zustand/middleware" -import { ArrayProps } from "./pages/dashboard/Content/Tariffs/types"; -import { PromocodeProps } from "./pages/dashboard/Content/Promocode/types"; -import { DiscountProps } from "./pages/dashboard/Content/Discounts/types"; - - -const useStore = create()( - persist( - (set, get) => ({ - tariffsArray: [], - tariffsArraySet: (array:Array) => set({ tariffsArray: array }), - - tariffsSelectedRowsData: [], - tariffsSelectedRowsDataSet: (array:Array) => set({ tariffsSelectedRowsData: array }), - - cartRowsData: [], - cartRowsDataSet: (array:Array) => set({ cartRowsData: array }), - - promocodeArray: [], - promocodeArraySet: (array:Array) => set({ promocodeArray: array }), - - discountsArray: [], - discountsArraySet: (array:Array) => set({ discountsArray: array }), - - discountsActiveArray: [], - discountsActiveArraySet: (array:Array) => set({ discountsActiveArray: array }), - - discountsSelectedRowsData: [], - discountsSelectedRowsDataSet: (array:Array) => set({ discountsSelectedRowsData: array }), - }), - { - name: "arrays-storage", - getStorage: () => localStorage, - } - ) -); - -export interface StoreState { - tariffsArray: Array, - tariffsArraySet: (array:Array) => void, - - tariffsSelectedRowsData: Array, - tariffsSelectedRowsDataSet: (array:Array) => void, - - cartRowsData: Array, - cartRowsDataSet: (array:Array) => void, - - promocodeArray: Array, - promocodeArraySet: (array:Array) => void, - - discountsArray: Array, - discountsArraySet: (array:Array) => void, - - discountsActiveArray: Array, - discountsActiveArraySet: (array:Array) => void, - - discountsSelectedRowsData: Array, - discountsSelectedRowsDataSet: (array:Array) => void, -} - - -export default useStore; \ No newline at end of file diff --git a/src/stores/cart.ts b/src/stores/cart.ts new file mode 100644 index 0000000..de9f3a8 --- /dev/null +++ b/src/stores/cart.ts @@ -0,0 +1,27 @@ +import create from "zustand"; +import { devtools, persist } from "zustand/middleware"; +import { ArrayProps } from "../model/tariff"; + + +interface CartStore { + cartRowsData: Array, + setCartRowsData: (array: Array) => void, +} + +export const useCartStore = create()( + devtools( + persist( + (set, get) => ({ + cartRowsData: [], + setCartRowsData: (array: Array) => set({ cartRowsData: array }), + }), + { + name: "cart-storage", + getStorage: () => localStorage, + } + ), + { + name: "Cart store" + } + ) +); \ No newline at end of file diff --git a/src/stores/discounts.ts b/src/stores/discounts.ts new file mode 100644 index 0000000..83736ed --- /dev/null +++ b/src/stores/discounts.ts @@ -0,0 +1,35 @@ +import create from "zustand"; +import { devtools, persist } from "zustand/middleware"; +import { Discount } from "../model/cart"; + + +interface DiscountStore { + discountsArray: Array, + setDiscountsArray: (array: Array) => void, + discountsActiveArray: Array, + setDiscountsActiveArray: (array: Array) => void, + discountsSelectedRowsData: Array, + setDiscountsSelectedRowsData: (array: Array) => void, +} + +export const useDiscountStore = create()( + devtools( + persist( + (set, get) => ({ + discountsArray: [], + setDiscountsArray: (array: Array) => set({ discountsArray: array }), + discountsActiveArray: [], + setDiscountsActiveArray: (array: Array) => set({ discountsActiveArray: array }), + discountsSelectedRowsData: [], + setDiscountsSelectedRowsData: (array: Array) => set({ discountsSelectedRowsData: array }), + }), + { + name: "discount-storage", + getStorage: () => localStorage, + } + ), + { + name: "Discount store" + } + ) +); \ No newline at end of file diff --git a/src/stores/promocodes.ts b/src/stores/promocodes.ts new file mode 100644 index 0000000..b05e809 --- /dev/null +++ b/src/stores/promocodes.ts @@ -0,0 +1,27 @@ +import create from "zustand"; +import { devtools, persist } from "zustand/middleware"; +import { Promocode } from "../model/cart"; + + +interface PromocodeStore { + promocodeArray: Array, + setPromocodeArray: (array: Array) => void, +} + +export const usePromocodeStore = create()( + devtools( + persist( + (set, get) => ({ + promocodeArray: [], + setPromocodeArray: (array: Array) => set({ promocodeArray: array }), + }), + { + name: "promocode-storage", + getStorage: () => localStorage, + } + ), + { + name: "Promocode store" + } + ) +); \ No newline at end of file diff --git a/src/stores/tariffs.ts b/src/stores/tariffs.ts new file mode 100644 index 0000000..0879fcd --- /dev/null +++ b/src/stores/tariffs.ts @@ -0,0 +1,31 @@ +import create from "zustand"; +import { devtools, persist } from "zustand/middleware"; +import { ArrayProps } from "../model/tariff"; + + +interface TariffStore { + tariffs: Array; + setTariffs: (array: Array) => void; + tariffsSelectedRowsData: Array; + setTariffsSelectedRowsData: (array: Array) => void; +} + +export const useTariffStore = create()( + devtools( + persist( + (set, get) => ({ + tariffs: [], + setTariffs: (array: Array) => set({ tariffs: array }), + tariffsSelectedRowsData: [], + setTariffsSelectedRowsData: (array: Array) => set({ tariffsSelectedRowsData: array }), + }), + { + name: "tariff-storage", + getStorage: () => localStorage, + } + ), + { + name: "Tariff store" + } + ) +); \ No newline at end of file