2023-03-20 19:46:28 +00:00
|
|
|
|
import { create } from "zustand";
|
|
|
|
|
import { persist } from "zustand/middleware";
|
|
|
|
|
|
2023-03-21 18:52:19 +00:00
|
|
|
|
export const basketStore = create<any>()((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,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
squiz: {
|
|
|
|
|
id1: {
|
|
|
|
|
name: "Квиз конструктор",
|
|
|
|
|
desc: "Дисковое хранилище 5 гб",
|
|
|
|
|
id: "id1",
|
|
|
|
|
privelegeid: "1",
|
|
|
|
|
amount: 5,
|
|
|
|
|
price: 300,
|
|
|
|
|
},
|
|
|
|
|
id2: {
|
|
|
|
|
name: "Квиз конструктор",
|
|
|
|
|
desc: "Подписка на месяц",
|
|
|
|
|
id: "id2",
|
|
|
|
|
privelegeid: "2",
|
|
|
|
|
amount: 30,
|
|
|
|
|
price: 90,
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-03-21 20:26:45 +00:00
|
|
|
|
reducer: {},
|
2023-03-22 11:51:16 +00:00
|
|
|
|
add: ({ id, obj, type }: any) => {
|
|
|
|
|
const store: any = get()[type] || {};
|
2023-03-21 20:26:45 +00:00
|
|
|
|
const newStore = {
|
2023-03-22 11:51:16 +00:00
|
|
|
|
[type]: {
|
2023-03-21 20:26:45 +00:00
|
|
|
|
...store,
|
2023-03-22 11:51:16 +00:00
|
|
|
|
[id]: obj,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
set(() => newStore);
|
2023-03-21 20:26:45 +00:00
|
|
|
|
},
|
2023-03-22 11:51:16 +00:00
|
|
|
|
remove: (type: any, id: string) => {
|
|
|
|
|
const store: any = get()[type] || {};
|
2023-03-20 22:06:09 +00:00
|
|
|
|
|
2023-03-22 11:51:16 +00:00
|
|
|
|
const newStore = Object.entries(store).reduce<any>((accamulator, [key, value], index, array) => {
|
|
|
|
|
if (key !== id) {
|
|
|
|
|
accamulator[key] = value;
|
2023-03-21 18:52:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-22 11:51:16 +00:00
|
|
|
|
return accamulator;
|
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
|
|
set({ [type]: newStore });
|
2023-03-21 18:52:19 +00:00
|
|
|
|
},
|
|
|
|
|
}));
|