diff --git a/src/kitUI/Cart/calc.ts b/src/kitUI/Cart/calc.ts index b693d72..0904eb8 100644 --- a/src/kitUI/Cart/calc.ts +++ b/src/kitUI/Cart/calc.ts @@ -1,14 +1,6 @@ import { - CartItem, - AnyDiscount, - CartTotal, - CartItemTotal, - PrivilegeDiscount, - CartPurchasesAmountDiscount, - PurchasesAmountDiscount, - ServiceToPriceMap, - ServiceDiscount, - UserDiscount, + CartItem, CartTotal, + CartItemTotal, ServiceToPriceMap } from "@root/model/cart"; import { Discount } from "@root/model/discount"; import { User } from "../../model/user"; diff --git a/src/model/cart.ts b/src/model/cart.ts index 99e8849..50c3820 100644 --- a/src/model/cart.ts +++ b/src/model/cart.ts @@ -1,105 +1,6 @@ import { ServiceType, Privilege, Tariff } from "./tariff"; import { Discount } from "@root/model/discount"; -interface DiscountBase { - _id: string; - name: string; - description: string; - /** Этап применения скидки */ - layer?: number; - disabled?: boolean; -} - -export interface PurchasesAmountDiscount extends DiscountBase { - conditionType: "purchasesAmount"; - condition: { - purchasesAmount: number; - }; - /** Множитель, на который умножается сумма при применении скидки */ - factor: number; -} - -export interface CartPurchasesAmountDiscount extends DiscountBase { - conditionType: "cartPurchasesAmount"; - condition: { - cartPurchasesAmount: number; - }; - /** Множитель, на который умножается сумма при применении скидки */ - factor: number; -} - -export interface PrivilegeDiscount extends DiscountBase { - conditionType: "privilege"; - condition: { - privilege: { - id: string; - /** Скидка применяется, если значение больше или равно этому значению */ - value: number; - }; - }; - target: { - products: Array<{ - privilegeId: string; - /** Множитель, на который умножается сумма при применении скидки */ - factor: number; - }>; - }; -} - -export interface ServiceDiscount extends DiscountBase { - conditionType: "service"; - condition: { - service: { - id: ServiceType; - /** Скидка применяется, если значение больше или равно этому значению */ - value: number; - }; - }; - target: { - service: ServiceType; - /** Множитель, на который умножается сумма при применении скидки */ - factor: number; - }; -} - -export interface UserTypeDiscount extends DiscountBase { - conditionType: "userType"; - condition: { - userType: string; - }; - target: { - IsAllProducts: boolean; - /** Множитель, на который умножается сумма при применении скидки */ - factor: number; - }; - overwhelm: boolean; -} - -export interface UserDiscount extends DiscountBase { - conditionType: "user"; - condition: { - coupon: string; - user: string; - }; - target: { - products: Array<{ - privilegeId: string; - /** Множитель, на который умножается сумма при применении скидки */ - factor: number; - }>; - }; - overwhelm: boolean; -} - -export type AnyDiscount = - | PurchasesAmountDiscount - | CartPurchasesAmountDiscount - | PrivilegeDiscount - | ServiceDiscount - | UserTypeDiscount - | UserDiscount; - -export type DiscountConditionType = AnyDiscount["conditionType"]; export interface Promocode { id: string; diff --git a/src/stores/discounts.ts b/src/stores/discounts.ts index cf52de8..97b775f 100644 --- a/src/stores/discounts.ts +++ b/src/stores/discounts.ts @@ -1,8 +1,6 @@ import { GridSelectionModel } from "@mui/x-data-grid"; -import { AnyDiscount } from "@root/model/cart"; import { create } from "zustand"; import { devtools } from "zustand/middleware"; -import { exampleCartValues } from "./mocks/exampleCartValues"; import { Discount } from "@root/model/discount"; import { produce } from "immer"; @@ -49,58 +47,3 @@ export const setSelectedDiscountIds = (selectedDiscountIds: DiscountStore["selec export const openEditDiscountDialog = (editDiscountId: DiscountStore["editDiscountId"]) => useDiscountStore.setState({ editDiscountId }); export const closeEditDiscountDialog = () => useDiscountStore.setState({ editDiscountId: null }); - -/** @deprecated */ -interface MockDiscountStore { - discounts: AnyDiscount[]; - selectedDiscountIds: GridSelectionModel, -} - -/** @deprecated */ -export const useMockDiscountStore = create()( - devtools( - (set, get) => ({ - discounts: exampleCartValues.discounts, - selectedDiscountIds: [], - }), - { - name: "Discount store" - } - ) -); - -/** @deprecated */ -export const addMockDiscounts = (newDiscounts: AnyDiscount[]) => useMockDiscountStore.setState(state => ({ discounts: [...state.discounts, ...newDiscounts] })); - -/** @deprecated */ -export const setMockSelectedDiscountIds = (selectedDiscountIds: MockDiscountStore["selectedDiscountIds"]) => useMockDiscountStore.setState({ selectedDiscountIds }); - -/** @deprecated */ -export const activateMockDiscounts = () => useMockDiscountStore.setState(state => { - const discounts: AnyDiscount[] = []; - state.discounts.forEach(discount => { - if (!state.selectedDiscountIds.includes(discount._id)) return discounts.push(discount); - - discounts.push({ - ...discount, - disabled: false, - }); - }); - - return { discounts }; -}); - -/** @deprecated */ -export const deactivateMockDiscounts = () => useMockDiscountStore.setState(state => { - const discounts: AnyDiscount[] = []; - state.discounts.forEach(discount => { - if (!state.selectedDiscountIds.includes(discount._id)) return discounts.push(discount); - - discounts.push({ - ...discount, - disabled: true, - }); - }); - - return { discounts }; -}); diff --git a/src/stores/mocks/exampleCartValues.ts b/src/stores/mocks/exampleCartValues.ts index dcd7298..6aae34b 100644 --- a/src/stores/mocks/exampleCartValues.ts +++ b/src/stores/mocks/exampleCartValues.ts @@ -1,7 +1,8 @@ -import { AnyDiscount } from "@root/model/cart"; -import { Privilege } from "@root/model/tariff"; +// @ts-nocheck import { User } from "../../model/user"; + +/** @deprecated */ export type TestCase = { input: { UserInformation: User; @@ -17,12 +18,14 @@ export type TestCase = { }; }; +/** @deprecated */ type ExampleCartValues = { privileges: Privilege[]; discounts: AnyDiscount[]; testCases: TestCase[]; }; +/** @deprecated */ export const exampleCartValues: ExampleCartValues = { privileges: [ {