Merge branch 'dev' of penahub.gitlab.yandexcloud.net:frontend/admin into dev
This commit is contained in:
commit
5b2a0a55dc
@ -1,14 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
CartItem,
|
CartItem, CartTotal,
|
||||||
AnyDiscount,
|
CartItemTotal, ServiceToPriceMap
|
||||||
CartTotal,
|
|
||||||
CartItemTotal,
|
|
||||||
PrivilegeDiscount,
|
|
||||||
CartPurchasesAmountDiscount,
|
|
||||||
PurchasesAmountDiscount,
|
|
||||||
ServiceToPriceMap,
|
|
||||||
ServiceDiscount,
|
|
||||||
UserDiscount,
|
|
||||||
} from "@root/model/cart";
|
} from "@root/model/cart";
|
||||||
import { Discount } from "@root/model/discount";
|
import { Discount } from "@root/model/discount";
|
||||||
import { User } from "../../model/user";
|
import { User } from "../../model/user";
|
||||||
|
@ -1,105 +1,6 @@
|
|||||||
import { ServiceType, Privilege, Tariff } from "./tariff";
|
import { ServiceType, Privilege, Tariff } from "./tariff";
|
||||||
import { Discount } from "@root/model/discount";
|
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 {
|
export interface Promocode {
|
||||||
id: string;
|
id: string;
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import { GridSelectionModel } from "@mui/x-data-grid";
|
import { GridSelectionModel } from "@mui/x-data-grid";
|
||||||
import { AnyDiscount } from "@root/model/cart";
|
|
||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
import { devtools } from "zustand/middleware";
|
import { devtools } from "zustand/middleware";
|
||||||
import { exampleCartValues } from "./mocks/exampleCartValues";
|
|
||||||
import { Discount } from "@root/model/discount";
|
import { Discount } from "@root/model/discount";
|
||||||
import { produce } from "immer";
|
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 openEditDiscountDialog = (editDiscountId: DiscountStore["editDiscountId"]) => useDiscountStore.setState({ editDiscountId });
|
||||||
|
|
||||||
export const closeEditDiscountDialog = () => useDiscountStore.setState({ editDiscountId: null });
|
export const closeEditDiscountDialog = () => useDiscountStore.setState({ editDiscountId: null });
|
||||||
|
|
||||||
/** @deprecated */
|
|
||||||
interface MockDiscountStore {
|
|
||||||
discounts: AnyDiscount[];
|
|
||||||
selectedDiscountIds: GridSelectionModel,
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated */
|
|
||||||
export const useMockDiscountStore = create<MockDiscountStore>()(
|
|
||||||
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 };
|
|
||||||
});
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import { AnyDiscount } from "@root/model/cart";
|
// @ts-nocheck
|
||||||
import { Privilege } from "@root/model/tariff";
|
|
||||||
import { User } from "../../model/user";
|
import { User } from "../../model/user";
|
||||||
|
|
||||||
|
|
||||||
|
/** @deprecated */
|
||||||
export type TestCase = {
|
export type TestCase = {
|
||||||
input: {
|
input: {
|
||||||
UserInformation: User;
|
UserInformation: User;
|
||||||
@ -17,12 +18,14 @@ export type TestCase = {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** @deprecated */
|
||||||
type ExampleCartValues = {
|
type ExampleCartValues = {
|
||||||
privileges: Privilege[];
|
privileges: Privilege[];
|
||||||
discounts: AnyDiscount[];
|
discounts: AnyDiscount[];
|
||||||
testCases: TestCase[];
|
testCases: TestCase[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** @deprecated */
|
||||||
export const exampleCartValues: ExampleCartValues = {
|
export const exampleCartValues: ExampleCartValues = {
|
||||||
privileges: [
|
privileges: [
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user