2023-03-20 19:46:28 +00:00
|
|
|
|
import { create } from "zustand";
|
|
|
|
|
import { persist } from "zustand/middleware";
|
|
|
|
|
|
2023-03-24 18:30:56 +00:00
|
|
|
|
export const basketStore = create<any>()(
|
|
|
|
|
persist(
|
|
|
|
|
(set, get) => ({
|
|
|
|
|
templ: {
|
|
|
|
|
id1: {
|
|
|
|
|
name: "Шаблонизатор",
|
|
|
|
|
desc: "Дисковое хранилище 5 гб",
|
|
|
|
|
id: "id1",
|
|
|
|
|
privelegeid: "1",
|
|
|
|
|
amount: 5,
|
|
|
|
|
price: 390,
|
|
|
|
|
},
|
|
|
|
|
id2: {
|
|
|
|
|
name: "Шаблонизатор",
|
|
|
|
|
desc: "Подписка на месяц",
|
|
|
|
|
id: "id2",
|
|
|
|
|
privelegeid: "2",
|
|
|
|
|
amount: 30,
|
|
|
|
|
price: 290,
|
|
|
|
|
},
|
2023-03-22 11:51:16 +00:00
|
|
|
|
},
|
2023-03-24 18:30:56 +00:00
|
|
|
|
squiz: {
|
|
|
|
|
id1: {
|
|
|
|
|
name: "Шаблонизатор",
|
|
|
|
|
desc: "Дисковое хранилище 5 гб",
|
|
|
|
|
id: "id1",
|
|
|
|
|
privelegeid: "1",
|
|
|
|
|
amount: 5,
|
|
|
|
|
price: 390,
|
|
|
|
|
},
|
|
|
|
|
id2: {
|
|
|
|
|
name: "Шаблонизатор",
|
|
|
|
|
desc: "Подписка на месяц",
|
|
|
|
|
id: "id2",
|
|
|
|
|
privelegeid: "2",
|
|
|
|
|
amount: 30,
|
|
|
|
|
price: 290,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
reducer: {},
|
|
|
|
|
openDrawer: false,
|
|
|
|
|
add: ({ id, obj, type }: any) => {
|
|
|
|
|
const store: any = get()[type] || {};
|
|
|
|
|
const newStore = {
|
|
|
|
|
[type]: {
|
|
|
|
|
...store,
|
|
|
|
|
[id]: obj,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
set(() => newStore);
|
|
|
|
|
},
|
|
|
|
|
remove: (type: string, id: string) => {
|
|
|
|
|
const store: any = get()[type] || {};
|
2023-03-21 18:52:19 +00:00
|
|
|
|
|
2023-03-24 18:30:56 +00:00
|
|
|
|
const newStore = Object.entries(store).reduce<any>((accamulator, [key, value], index, array) => {
|
|
|
|
|
if (key !== id) {
|
|
|
|
|
accamulator[key] = value;
|
|
|
|
|
}
|
2023-03-22 11:51:16 +00:00
|
|
|
|
|
2023-03-24 18:30:56 +00:00
|
|
|
|
return accamulator;
|
|
|
|
|
}, {});
|
2023-03-24 15:30:58 +00:00
|
|
|
|
|
2023-03-24 18:30:56 +00:00
|
|
|
|
set({ [type]: newStore });
|
|
|
|
|
},
|
|
|
|
|
open: (boolean: boolean) => (event: React.KeyboardEvent | React.MouseEvent) => {
|
|
|
|
|
set(() => ({ openDrawer: boolean }));
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
{
|
|
|
|
|
name: "basket",
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|