WIP split stores
This commit is contained in:
parent
3176fdb21c
commit
490b84b0e6
63
src/store.ts
63
src/store.ts
@ -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<StoreState>()(
|
||||
persist(
|
||||
(set, get) => ({
|
||||
tariffsArray: [],
|
||||
tariffsArraySet: (array:Array<ArrayProps>) => set({ tariffsArray: array }),
|
||||
|
||||
tariffsSelectedRowsData: [],
|
||||
tariffsSelectedRowsDataSet: (array:Array<ArrayProps>) => set({ tariffsSelectedRowsData: array }),
|
||||
|
||||
cartRowsData: [],
|
||||
cartRowsDataSet: (array:Array<ArrayProps>) => set({ cartRowsData: array }),
|
||||
|
||||
promocodeArray: [],
|
||||
promocodeArraySet: (array:Array<PromocodeProps>) => set({ promocodeArray: array }),
|
||||
|
||||
discountsArray: [],
|
||||
discountsArraySet: (array:Array<DiscountProps>) => set({ discountsArray: array }),
|
||||
|
||||
discountsActiveArray: [],
|
||||
discountsActiveArraySet: (array:Array<number>) => set({ discountsActiveArray: array }),
|
||||
|
||||
discountsSelectedRowsData: [],
|
||||
discountsSelectedRowsDataSet: (array:Array<DiscountProps>) => set({ discountsSelectedRowsData: array }),
|
||||
}),
|
||||
{
|
||||
name: "arrays-storage",
|
||||
getStorage: () => localStorage,
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
export interface StoreState {
|
||||
tariffsArray: Array<ArrayProps>,
|
||||
tariffsArraySet: (array:Array<ArrayProps>) => void,
|
||||
|
||||
tariffsSelectedRowsData: Array<ArrayProps>,
|
||||
tariffsSelectedRowsDataSet: (array:Array<ArrayProps>) => void,
|
||||
|
||||
cartRowsData: Array<ArrayProps>,
|
||||
cartRowsDataSet: (array:Array<ArrayProps>) => void,
|
||||
|
||||
promocodeArray: Array<PromocodeProps>,
|
||||
promocodeArraySet: (array:Array<PromocodeProps>) => void,
|
||||
|
||||
discountsArray: Array<DiscountProps>,
|
||||
discountsArraySet: (array:Array<DiscountProps>) => void,
|
||||
|
||||
discountsActiveArray: Array<number>,
|
||||
discountsActiveArraySet: (array:Array<number>) => void,
|
||||
|
||||
discountsSelectedRowsData: Array<DiscountProps>,
|
||||
discountsSelectedRowsDataSet: (array:Array<DiscountProps>) => void,
|
||||
}
|
||||
|
||||
|
||||
export default useStore;
|
27
src/stores/cart.ts
Normal file
27
src/stores/cart.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import create from "zustand";
|
||||
import { devtools, persist } from "zustand/middleware";
|
||||
import { ArrayProps } from "../model/tariff";
|
||||
|
||||
|
||||
interface CartStore {
|
||||
cartRowsData: Array<ArrayProps>,
|
||||
setCartRowsData: (array: Array<ArrayProps>) => void,
|
||||
}
|
||||
|
||||
export const useCartStore = create<CartStore>()(
|
||||
devtools(
|
||||
persist(
|
||||
(set, get) => ({
|
||||
cartRowsData: [],
|
||||
setCartRowsData: (array: Array<ArrayProps>) => set({ cartRowsData: array }),
|
||||
}),
|
||||
{
|
||||
name: "cart-storage",
|
||||
getStorage: () => localStorage,
|
||||
}
|
||||
),
|
||||
{
|
||||
name: "Cart store"
|
||||
}
|
||||
)
|
||||
);
|
35
src/stores/discounts.ts
Normal file
35
src/stores/discounts.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import create from "zustand";
|
||||
import { devtools, persist } from "zustand/middleware";
|
||||
import { Discount } from "../model/cart";
|
||||
|
||||
|
||||
interface DiscountStore {
|
||||
discountsArray: Array<Discount>,
|
||||
setDiscountsArray: (array: Array<Discount>) => void,
|
||||
discountsActiveArray: Array<number>,
|
||||
setDiscountsActiveArray: (array: Array<number>) => void,
|
||||
discountsSelectedRowsData: Array<Discount>,
|
||||
setDiscountsSelectedRowsData: (array: Array<Discount>) => void,
|
||||
}
|
||||
|
||||
export const useDiscountStore = create<DiscountStore>()(
|
||||
devtools(
|
||||
persist(
|
||||
(set, get) => ({
|
||||
discountsArray: [],
|
||||
setDiscountsArray: (array: Array<Discount>) => set({ discountsArray: array }),
|
||||
discountsActiveArray: [],
|
||||
setDiscountsActiveArray: (array: Array<number>) => set({ discountsActiveArray: array }),
|
||||
discountsSelectedRowsData: [],
|
||||
setDiscountsSelectedRowsData: (array: Array<Discount>) => set({ discountsSelectedRowsData: array }),
|
||||
}),
|
||||
{
|
||||
name: "discount-storage",
|
||||
getStorage: () => localStorage,
|
||||
}
|
||||
),
|
||||
{
|
||||
name: "Discount store"
|
||||
}
|
||||
)
|
||||
);
|
27
src/stores/promocodes.ts
Normal file
27
src/stores/promocodes.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import create from "zustand";
|
||||
import { devtools, persist } from "zustand/middleware";
|
||||
import { Promocode } from "../model/cart";
|
||||
|
||||
|
||||
interface PromocodeStore {
|
||||
promocodeArray: Array<Promocode>,
|
||||
setPromocodeArray: (array: Array<Promocode>) => void,
|
||||
}
|
||||
|
||||
export const usePromocodeStore = create<PromocodeStore>()(
|
||||
devtools(
|
||||
persist(
|
||||
(set, get) => ({
|
||||
promocodeArray: [],
|
||||
setPromocodeArray: (array: Array<Promocode>) => set({ promocodeArray: array }),
|
||||
}),
|
||||
{
|
||||
name: "promocode-storage",
|
||||
getStorage: () => localStorage,
|
||||
}
|
||||
),
|
||||
{
|
||||
name: "Promocode store"
|
||||
}
|
||||
)
|
||||
);
|
31
src/stores/tariffs.ts
Normal file
31
src/stores/tariffs.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import create from "zustand";
|
||||
import { devtools, persist } from "zustand/middleware";
|
||||
import { ArrayProps } from "../model/tariff";
|
||||
|
||||
|
||||
interface TariffStore {
|
||||
tariffs: Array<ArrayProps>;
|
||||
setTariffs: (array: Array<ArrayProps>) => void;
|
||||
tariffsSelectedRowsData: Array<ArrayProps>;
|
||||
setTariffsSelectedRowsData: (array: Array<ArrayProps>) => void;
|
||||
}
|
||||
|
||||
export const useTariffStore = create<TariffStore>()(
|
||||
devtools(
|
||||
persist(
|
||||
(set, get) => ({
|
||||
tariffs: [],
|
||||
setTariffs: (array: Array<ArrayProps>) => set({ tariffs: array }),
|
||||
tariffsSelectedRowsData: [],
|
||||
setTariffsSelectedRowsData: (array: Array<ArrayProps>) => set({ tariffsSelectedRowsData: array }),
|
||||
}),
|
||||
{
|
||||
name: "tariff-storage",
|
||||
getStorage: () => localStorage,
|
||||
}
|
||||
),
|
||||
{
|
||||
name: "Tariff store"
|
||||
}
|
||||
)
|
||||
);
|
Loading…
Reference in New Issue
Block a user