void;
onRuleSubmit: (data: Rule, ruleEditIndex: number | null) => void;
submitHandler: () => void;
@@ -35,13 +37,15 @@ export const DiscountCreateForm = ({
resolver: zodResolver(getValidationSchema(intl)),
});
+ const discountType = methods.watch("type");
+
const richText = useRichText({
initial: "",
loading: false,
triggerChange: methods.trigger,
});
- const { rules, onDeleteRule, onRuleSubmit } = useRulesHandlers("catalog");
+ const { rules, onDeleteRule, onRuleSubmit } = useRulesHandlers(discountType);
const handleSubmit: SubmitHandler
= data => {
onSubmit({
@@ -59,6 +63,7 @@ export const DiscountCreateForm = ({
{children({
onDeleteRule,
onRuleSubmit,
+ discountType,
submitHandler: submitHandlerWithValidation,
rules,
})}
diff --git a/src/discounts/components/DiscountCreateForm/hooks/useRulesHandlers.test.ts b/src/discounts/components/DiscountCreateForm/hooks/useRulesHandlers.test.ts
index 23bf9629d73..b621c7a8f75 100644
--- a/src/discounts/components/DiscountCreateForm/hooks/useRulesHandlers.test.ts
+++ b/src/discounts/components/DiscountCreateForm/hooks/useRulesHandlers.test.ts
@@ -1,5 +1,5 @@
import { Rule } from "@dashboard/discounts/models";
-import { RewardValueTypeEnum } from "@dashboard/graphql";
+import { PromotionTypeEnum, RewardValueTypeEnum } from "@dashboard/graphql";
import { act, renderHook } from "@testing-library/react-hooks";
import { useRulesHandlers } from "./useRulesHandlers";
@@ -16,7 +16,9 @@ const rule = {
describe("DiscountCreateForm useRulesHandlers", () => {
it("should allow to add new rule ", () => {
// Arrange
- const { result } = renderHook(() => useRulesHandlers("catalog"));
+ const { result } = renderHook(() =>
+ useRulesHandlers(PromotionTypeEnum.CATALOGUE),
+ );
// Act
act(() => {
@@ -29,7 +31,9 @@ describe("DiscountCreateForm useRulesHandlers", () => {
it("should allow to edit rule at index", () => {
// Arrange
- const { result } = renderHook(() => useRulesHandlers("catalog"));
+ const { result } = renderHook(() =>
+ useRulesHandlers(PromotionTypeEnum.CATALOGUE),
+ );
const rule = {
name: "Rule 1",
@@ -55,7 +59,9 @@ describe("DiscountCreateForm useRulesHandlers", () => {
it("should allow to delete rule at index", () => {
// Arrange
- const { result } = renderHook(() => useRulesHandlers("catalog"));
+ const { result } = renderHook(() =>
+ useRulesHandlers(PromotionTypeEnum.CATALOGUE),
+ );
const rule = {
name: "Rule 1",
diff --git a/src/discounts/components/DiscountCreateForm/hooks/useRulesHandlers.ts b/src/discounts/components/DiscountCreateForm/hooks/useRulesHandlers.ts
index 0ee68e28f4d..85b970bb30e 100644
--- a/src/discounts/components/DiscountCreateForm/hooks/useRulesHandlers.ts
+++ b/src/discounts/components/DiscountCreateForm/hooks/useRulesHandlers.ts
@@ -1,9 +1,10 @@
import { Rule } from "@dashboard/discounts/models";
import { sortRules } from "@dashboard/discounts/utils";
+import { PromotionTypeEnum } from "@dashboard/graphql";
import { useEffect, useState } from "react";
export const useRulesHandlers = (
- discountType: "catalog", // to be replaced by PromotionTypeEnum when API return this field
+ discountType: PromotionTypeEnum = PromotionTypeEnum.CATALOGUE,
) => {
const [rules, setRules] = useState([]);
diff --git a/src/discounts/components/DiscountCreateForm/initialFormValues.ts b/src/discounts/components/DiscountCreateForm/initialFormValues.ts
index b1d62d9918d..8ed199d9822 100644
--- a/src/discounts/components/DiscountCreateForm/initialFormValues.ts
+++ b/src/discounts/components/DiscountCreateForm/initialFormValues.ts
@@ -1,9 +1,10 @@
import { DiscoutFormData } from "@dashboard/discounts/types";
+import { PromotionTypeEnum } from "@dashboard/graphql";
export const initialFormValues: DiscoutFormData = {
+ type: PromotionTypeEnum.CATALOGUE,
name: "",
description: "",
- type: "catalog",
dates: {
endDate: "",
endTime: "",
diff --git a/src/discounts/components/DiscountCreateForm/validationSchema.ts b/src/discounts/components/DiscountCreateForm/validationSchema.ts
index 055ab93297b..7c4b15e952e 100644
--- a/src/discounts/components/DiscountCreateForm/validationSchema.ts
+++ b/src/discounts/components/DiscountCreateForm/validationSchema.ts
@@ -1,3 +1,4 @@
+import { PromotionTypeEnum } from "@dashboard/graphql";
import { defineMessages, IntlShape } from "react-intl";
import * as z from "zod";
@@ -10,10 +11,10 @@ const validationMessages = defineMessages({
export const getValidationSchema = (intl: IntlShape) => {
return z.object({
+ type: z.enum([PromotionTypeEnum.CATALOGUE, PromotionTypeEnum.ORDER]),
name: z
.string()
.min(1, intl.formatMessage(validationMessages.nameRequired)),
- type: z.string().optional(),
description: z.string().optional(),
dates: z
.object({
diff --git a/src/discounts/components/DiscountCreatePage/DiscountCreatePage.tsx b/src/discounts/components/DiscountCreatePage/DiscountCreatePage.tsx
index a10d2208b26..88aac66f17d 100644
--- a/src/discounts/components/DiscountCreatePage/DiscountCreatePage.tsx
+++ b/src/discounts/components/DiscountCreatePage/DiscountCreatePage.tsx
@@ -52,12 +52,18 @@ export const DiscountCreatePage = ({
/>
- {({ rules, onDeleteRule, onRuleSubmit, submitHandler }) => (
+ {({
+ rules,
+ discountType,
+ onDeleteRule,
+ onRuleSubmit,
+ submitHandler,
+ }) => (
<>
@@ -68,7 +74,8 @@ export const DiscountCreatePage = ({
/>
}
channels={channels}
disabled={disabled}
diff --git a/src/discounts/components/DiscountDetailsForm/DiscountDetailsForm.tsx b/src/discounts/components/DiscountDetailsForm/DiscountDetailsForm.tsx
index fdb20030738..bdd7e5d0d91 100644
--- a/src/discounts/components/DiscountDetailsForm/DiscountDetailsForm.tsx
+++ b/src/discounts/components/DiscountDetailsForm/DiscountDetailsForm.tsx
@@ -1,9 +1,11 @@
import { Rule } from "@dashboard/discounts/models";
import { DiscoutFormData } from "@dashboard/discounts/types";
+import { useLabelMapsContext } from "@dashboard/discounts/views/DiscountDetails/context/context";
import {
PromotionDetailsFragment,
PromotionRuleCreateErrorFragment,
PromotionRuleUpdateErrorFragment,
+ PromotionTypeEnum,
} from "@dashboard/graphql";
import { splitDateTime } from "@dashboard/misc";
import { CommonError } from "@dashboard/utils/errors/common";
@@ -20,6 +22,7 @@ import { useRulesHandlers } from "./hooks/useRulesHandlers";
interface DiscountDetailsFormRenderProps {
rulesErrors: Array>;
rules: Rule[];
+ discountType: PromotionTypeEnum;
onSubmit: () => void;
onRuleSubmit: (rule: Rule, ruleEditIndex: number | null) => Promise;
onDeleteRule: (ruleDeleteIndex: number) => Promise;
@@ -30,7 +33,6 @@ interface DiscountDetailsFormProps {
disabled: boolean;
data: PromotionDetailsFragment | undefined | null;
onSubmit: (data: DiscoutFormData) => void;
- ruleConditionsOptionsDetailsMap: Record;
onRuleUpdateSubmit: (
data: Rule,
) => Promise>>;
@@ -48,14 +50,13 @@ export const DiscountDetailsForm = ({
onRuleCreateSubmit,
onRuleDeleteSubmit,
onRuleUpdateSubmit,
- ruleConditionsOptionsDetailsMap,
}: DiscountDetailsFormProps) => {
const intl = useIntl();
const methods = useForm({
mode: "onBlur",
values: {
- type: "catalog", // TODO: type: data?.type ?? PromotionTypeEnum.CATALOGUE,
+ type: data?.type ?? PromotionTypeEnum.CATALOGUE,
dates: {
startDate: splitDateTime(data?.startDate ?? "").date,
startTime: splitDateTime(data?.startDate ?? "").time,
@@ -70,6 +71,8 @@ export const DiscountDetailsForm = ({
resolver: zodResolver(getValidationSchema(intl)),
});
+ const discountType = methods.watch("type");
+
const richText = useRichText({
initial: JSON.stringify(data?.description),
loading: disabled,
@@ -78,12 +81,14 @@ export const DiscountDetailsForm = ({
const handleSubmit = methods.handleSubmit(onSubmit);
+ const { ruleConditionsValues, gifts } = useLabelMapsContext();
const { onDeleteRule, onRuleSubmit, rules, rulesErrors } = useRulesHandlers({
data,
onRuleCreateSubmit,
onRuleDeleteSubmit,
onRuleUpdateSubmit,
- ruleConditionsOptionsDetailsMap,
+ ruleConditionsOptionsDetailsMap: ruleConditionsValues.labels,
+ giftsOptionsDetailsMap: gifts.labels,
});
return (
@@ -93,6 +98,7 @@ export const DiscountDetailsForm = ({
{children({
rulesErrors,
rules,
+ discountType,
onSubmit: handleSubmit,
onRuleSubmit,
onDeleteRule,
diff --git a/src/discounts/components/DiscountDetailsForm/hooks/useRulesHandlers.ts b/src/discounts/components/DiscountDetailsForm/hooks/useRulesHandlers.ts
index 4cd3f6255db..350094827c1 100644
--- a/src/discounts/components/DiscountDetailsForm/hooks/useRulesHandlers.ts
+++ b/src/discounts/components/DiscountDetailsForm/hooks/useRulesHandlers.ts
@@ -13,6 +13,7 @@ import { getCurrentConditionsValuesLabels } from "../utils";
interface UseRulesHandlersProps {
data: PromotionDetailsFragment | undefined | null;
ruleConditionsOptionsDetailsMap: Record;
+ giftsOptionsDetailsMap: Record;
onRuleUpdateSubmit: (
data: Rule,
) => Promise>>;
@@ -25,20 +26,27 @@ interface UseRulesHandlersProps {
export const useRulesHandlers = ({
data,
ruleConditionsOptionsDetailsMap,
+ giftsOptionsDetailsMap,
onRuleUpdateSubmit,
onRuleCreateSubmit,
onRuleDeleteSubmit,
}: UseRulesHandlersProps) => {
const [rulesErrors, setRulesErrors] = useState>>([]);
- const [labelsMap, setLabelMap] = useState>({});
+ const [conditionValuesLabelMap, setConditionValuesLabelMap] = useState<
+ Record
+ >({});
const rules = sortRules(
- data?.rules?.map(rule => mapAPIRuleToForm("catalog", rule, labelsMap)) ??
- [],
+ data?.rules?.map(rule =>
+ mapAPIRuleToForm(data?.type, rule, {
+ conditionsValues: conditionValuesLabelMap,
+ gifts: giftsOptionsDetailsMap,
+ }),
+ ) ?? [],
);
useEffect(() => {
- setLabelMap(labels => {
+ setConditionValuesLabelMap(labels => {
return {
...ruleConditionsOptionsDetailsMap,
...labels,
@@ -47,7 +55,7 @@ export const useRulesHandlers = ({
}, [ruleConditionsOptionsDetailsMap]);
const updateLabels = (rule: Rule) => {
- setLabelMap(labels => ({
+ setConditionValuesLabelMap(labels => ({
...labels,
...getCurrentConditionsValuesLabels([rule]),
}));
diff --git a/src/discounts/components/DiscountDetailsPage/DiscountDeletailsPage.stories.tsx b/src/discounts/components/DiscountDetailsPage/DiscountDeletailsPage.stories.tsx
index ea3234ec72b..028cb61bf03 100644
--- a/src/discounts/components/DiscountDetailsPage/DiscountDeletailsPage.stories.tsx
+++ b/src/discounts/components/DiscountDetailsPage/DiscountDeletailsPage.stories.tsx
@@ -1,6 +1,12 @@
import { MockedProvider } from "@apollo/client/testing";
import { channelsList } from "@dashboard/channels/fixtures";
-import { discount } from "@dashboard/discounts/fixtures";
+import { discount, orderDiscount } from "@dashboard/discounts/fixtures";
+import { LabelsMapsProvider } from "@dashboard/discounts/views/DiscountDetails/context/provider";
+import {
+ conditionsValuesLabelsMock,
+ emptyGiftsLabelsMock,
+ giftsLabelsMock,
+} from "@dashboard/discounts/views/DiscountDetails/hooks/mocks";
import React from "react";
import {
@@ -9,6 +15,7 @@ import {
searchProductsMock,
searchVariantsMock,
} from "../DiscountRules/componenets/RuleForm/components/RuleConditionValues/hooks/options/mocks";
+import { variantsWithProductDataMock } from "../DiscountRules/componenets/RuleForm/components/RuleRewardGifts/mock";
import {
DiscountDetailsPage,
DiscountDetailsPageProps,
@@ -20,17 +27,10 @@ const props: DiscountDetailsPageProps = {
onBack: () => undefined,
onSubmit: () => undefined,
onDelete: () => undefined,
- ruleConditionsOptionsDetailsMap: {
- "UHJvZHVjdDo3OQ==": "Bean Juice",
- "UHJvZHVjdDoxMTU=": "Black Hoodie",
- UHJvZHVjdFZhcmlhbnQ6OTg3: "45cm x 45cm",
- UHJvZHVjdFZhcmlhbnQ6MjE1: "1l",
- },
errors: [],
onRuleCreateSubmit: () => Promise.resolve([]),
onRuleDeleteSubmit: () => Promise.resolve([]),
onRuleUpdateSubmit: () => Promise.resolve([]),
- ruleConditionsOptionsDetailsLoading: false,
ruleCreateButtonState: "default",
ruleDeleteButtonState: "default",
ruleUpdateButtonState: "default",
@@ -47,10 +47,46 @@ export const Default = () => (
mocks={[
searchCategoriesMock,
searchProductsMock,
+ searchProductsMock,
+ searchProductsMock,
+ searchCollectionsMock,
+ searchVariantsMock,
+ emptyGiftsLabelsMock,
+ conditionsValuesLabelsMock,
+ ]}
+ >
+
+
+
+
+);
+
+export const OrderDiscounts = () => (
+
-
+
+
+
);
diff --git a/src/discounts/components/DiscountDetailsPage/DiscountDetailsPage.tsx b/src/discounts/components/DiscountDetailsPage/DiscountDetailsPage.tsx
index 33576c25fad..1344b109c90 100644
--- a/src/discounts/components/DiscountDetailsPage/DiscountDetailsPage.tsx
+++ b/src/discounts/components/DiscountDetailsPage/DiscountDetailsPage.tsx
@@ -28,8 +28,6 @@ import { DiscountSavebar } from "../DiscountSavebar";
export interface DiscountDetailsPageProps {
channels: ChannelFragment[];
- ruleConditionsOptionsDetailsMap: Record;
- ruleConditionsOptionsDetailsLoading: boolean;
data: PromotionDetailsFragment | undefined | null;
disabled: boolean;
errors: PromotionUpdateErrorFragment[];
@@ -51,8 +49,6 @@ export interface DiscountDetailsPageProps {
export const DiscountDetailsPage = ({
channels,
- ruleConditionsOptionsDetailsMap,
- ruleConditionsOptionsDetailsLoading,
disabled,
data,
errors,
@@ -79,12 +75,18 @@ export const DiscountDetailsPage = ({
data={data}
disabled={disabled}
onSubmit={onSubmit}
- ruleConditionsOptionsDetailsMap={ruleConditionsOptionsDetailsMap}
onRuleCreateSubmit={onRuleCreateSubmit}
onRuleDeleteSubmit={onRuleDeleteSubmit}
onRuleUpdateSubmit={onRuleUpdateSubmit}
>
- {({ rulesErrors, rules, onDeleteRule, onRuleSubmit, onSubmit }) => (
+ {({
+ rulesErrors,
+ rules,
+ discountType,
+ onDeleteRule,
+ onRuleSubmit,
+ onSubmit,
+ }) => (
<>
ruleEditIndex !== null
? ruleUpdateButtonState
diff --git a/src/discounts/components/DiscountGeneralInfo/DiscountGeneralInfo.tsx b/src/discounts/components/DiscountGeneralInfo/DiscountGeneralInfo.tsx
index 44a6983f14c..c4cc29596a5 100644
--- a/src/discounts/components/DiscountGeneralInfo/DiscountGeneralInfo.tsx
+++ b/src/discounts/components/DiscountGeneralInfo/DiscountGeneralInfo.tsx
@@ -1,5 +1,6 @@
import { DashboardCard } from "@dashboard/components/Card";
import { DiscoutFormData } from "@dashboard/discounts/types";
+import { PromotionTypeEnum } from "@dashboard/graphql";
import { Box, Input, Select } from "@saleor/macaw-ui-next";
import React, { useMemo } from "react";
import { useController, useFormContext } from "react-hook-form";
@@ -33,17 +34,16 @@ export const DiscountGeneralInfo = ({
id: "0khVBN",
description: "discount type",
}),
- value: "catalog",
+ value: PromotionTypeEnum.CATALOGUE,
+ },
+ {
+ label: intl.formatMessage({
+ defaultMessage: "Order",
+ id: "onUvP+",
+ description: "discount type",
+ }),
+ value: PromotionTypeEnum.ORDER,
},
- // Uncomment when API will support catalog discounts
- // {
- // label: intl.formatMessage({
- // defaultMessage: "Order",
- // id: "onUvP+",
- // description: "discount type",
- // }),
- // value: "order",
- // },
],
[intl],
);
@@ -54,7 +54,18 @@ export const DiscountGeneralInfo = ({
-
+
+
+
-
-
-
-
diff --git a/src/discounts/components/DiscountListDatagrid/DiscountListDatagrid.tsx b/src/discounts/components/DiscountListDatagrid/DiscountListDatagrid.tsx
index 7a837969240..8c8cff1ddcd 100644
--- a/src/discounts/components/DiscountListDatagrid/DiscountListDatagrid.tsx
+++ b/src/discounts/components/DiscountListDatagrid/DiscountListDatagrid.tsx
@@ -78,6 +78,7 @@ export const DiscountListDatagrid = ({
createGetCellContent({
promotions,
columns: visibleColumns,
+ intl,
}),
[promotions, visibleColumns],
);
diff --git a/src/discounts/components/DiscountListDatagrid/datagrid.ts b/src/discounts/components/DiscountListDatagrid/datagrid.ts
index 23b008c6073..c3a6ab54bbb 100644
--- a/src/discounts/components/DiscountListDatagrid/datagrid.ts
+++ b/src/discounts/components/DiscountListDatagrid/datagrid.ts
@@ -5,7 +5,7 @@ import {
} from "@dashboard/components/Datagrid/customCells/cells";
import { AvailableColumn } from "@dashboard/components/Datagrid/types";
import { DiscountListUrlSortField } from "@dashboard/discounts/discountsUrls";
-import { PromotionFragment } from "@dashboard/graphql";
+import { PromotionFragment, PromotionTypeEnum } from "@dashboard/graphql";
import { Sort } from "@dashboard/types";
import { getColumnSortDirectionIcon } from "@dashboard/utils/columns/getColumnSortDirectionIcon";
import { GridCell, Item } from "@glideapps/glide-data-grid";
@@ -25,6 +25,11 @@ export const dicountListStaticColumnsAdapter = (
title: intl.formatMessage(columnsMessages.name),
width: 350,
},
+ {
+ id: "type",
+ width: 150,
+ title: intl.formatMessage(columnsMessages.type),
+ },
{
id: "startDate",
title: intl.formatMessage(columnsMessages.starts),
@@ -44,9 +49,11 @@ export const createGetCellContent =
({
promotions,
columns,
+ intl,
}: {
promotions: PromotionFragment[];
columns: AvailableColumn[];
+ intl: IntlShape;
}) =>
([column, row]: Item): GridCell => {
const rowData = promotions[row];
@@ -67,7 +74,20 @@ export const createGetCellContent =
return rowData.endDate
? dateCell(rowData.endDate)
: readonlyTextCell(PLACEHOLDER);
+ case "type":
+ return readonlyTextCell(getDiscountType(rowData, intl));
default:
return readonlyTextCell("");
}
};
+
+function getDiscountType(promotion: PromotionFragment, intl: IntlShape) {
+ switch (promotion.type) {
+ case PromotionTypeEnum.CATALOGUE:
+ return intl.formatMessage({ defaultMessage: "Catalog", id: "GOdq5V" });
+ case PromotionTypeEnum.ORDER:
+ return intl.formatMessage({ defaultMessage: "Order", id: "XPruqs" });
+ default:
+ throw new Error(`Unhandled type for item: ${promotion.type}`);
+ }
+}
diff --git a/src/discounts/components/DiscountListDatagrid/messages.ts b/src/discounts/components/DiscountListDatagrid/messages.ts
index 7c859d9d925..bf5a2ca1387 100644
--- a/src/discounts/components/DiscountListDatagrid/messages.ts
+++ b/src/discounts/components/DiscountListDatagrid/messages.ts
@@ -16,6 +16,10 @@ export const columnsMessages = defineMessages({
defaultMessage: "Ends",
description: "sale end date",
},
+ type: {
+ id: "z/2AZY",
+ defaultMessage: "Discount type",
+ },
});
export const messages = defineMessages({
diff --git a/src/discounts/components/DiscountRules/DiscountRules.test.tsx b/src/discounts/components/DiscountRules/DiscountRules.test.tsx
index 6a6f884b1ea..eaeafdb2c32 100644
--- a/src/discounts/components/DiscountRules/DiscountRules.test.tsx
+++ b/src/discounts/components/DiscountRules/DiscountRules.test.tsx
@@ -1,7 +1,6 @@
import { MockedProvider } from "@apollo/client/testing";
import { mockResizeObserver } from "@dashboard/components/Datagrid/testUtils";
-import { Rule } from "@dashboard/discounts/models";
-import { ChannelFragment, RewardValueTypeEnum } from "@dashboard/graphql";
+import { PromotionTypeEnum } from "@dashboard/graphql";
import { ThemeProvider as LegacyThemeProvider } from "@saleor/macaw-ui";
import { ThemeProvider } from "@saleor/macaw-ui-next";
import { act, render, screen, waitFor } from "@testing-library/react";
@@ -14,7 +13,14 @@ import {
searchProductsMock,
searchVariantsMock,
} from "./componenets/RuleForm/components/RuleConditionValues/hooks/options/mocks";
+import { variantsWithProductDataMock } from "./componenets/RuleForm/components/RuleRewardGifts/mock";
import { DiscountRules } from "./DiscountRules";
+import {
+ catalogComplexRules,
+ catalogRules,
+ channels,
+ orderRules,
+} from "./mocksData";
jest.mock("react-intl", () => ({
useIntl: jest.fn(() => ({
@@ -31,6 +37,28 @@ jest.mock("@dashboard/hooks/useNotifier", () => ({
default: jest.fn(() => () => undefined),
}));
+jest.mock("@dashboard/discounts/views/DiscountDetails/context/context", () => ({
+ __esModule: true,
+ useLabelMapsContext: jest.fn(() => ({
+ ruleConditionsValues: {
+ labels: {},
+ loading: false,
+ },
+ gifts: {
+ labels: [],
+ loading: false,
+ },
+ })),
+}));
+
+jest.mock("./hooks/useGraphQLPlayground", () => ({
+ useGraphQLPlayground: jest.fn(() => ({
+ opepnGrapQLPlayground: jest.fn(),
+ })),
+}));
+
+jest.setTimeout(30000); // Timeout was increased because of error throw in update test when run all tests
+
const Wrapper = ({ children }: { children: ReactNode }) => {
return (
{
searchCollectionsMock,
searchProductsMock,
searchVariantsMock,
+ variantsWithProductDataMock,
]}
>
@@ -48,56 +77,6 @@ const Wrapper = ({ children }: { children: ReactNode }) => {
);
};
-const channels = [
- // Apollo mocks only work with test channel
- // oif you want to use different channel, you need to update mocks
- {
- currencyCode: "$",
- id: "Q2hhbm5lcDoy",
- name: "Test",
- slug: "test",
- isActive: true,
- },
-] as ChannelFragment[];
-
-const rules = [
- {
- id: "cat-1",
- name: "Catalog rule 1",
- description: "",
- channel: { label: "Test", value: "Q2hhbm5lcDoy" },
- conditions: [
- {
- id: "product",
- type: "is",
- value: [
- { label: "Product-1", value: "prod-1" },
- { label: "Product-2", value: "prod-2" },
- ],
- },
- ],
- rewardValue: 12,
- rewardType: null,
- rewardValueType: RewardValueTypeEnum.FIXED,
- },
- {
- id: "cat-2",
- name: "Catalog rule 2",
- description: "",
- channel: { label: "Test", value: "Q2hhbm5lcDoy" },
- conditions: [
- {
- id: "category",
- type: "is",
- value: [{ label: "Category-1", value: "cat-1" }],
- },
- ],
- rewardType: null,
- rewardValue: 34,
- rewardValueType: RewardValueTypeEnum.PERCENTAGE,
- },
-] as Rule[];
-
describe("DiscountRules", () => {
beforeAll(() => {
Object.defineProperty(window, "matchMedia", {
@@ -129,14 +108,14 @@ describe("DiscountRules", () => {
// Arrange & Act
render(
"default")}
/>,
@@ -149,18 +128,18 @@ describe("DiscountRules", () => {
).toBeInTheDocument();
});
- it("should render discount rules", async () => {
+ it("should render catalog discount rules", async () => {
// Arrange & Act
render(
"default")}
/>,
@@ -187,19 +166,51 @@ describe("DiscountRules", () => {
).toBe(2);
});
- it("should allow to add new rule", async () => {
+ it("should render order discount rules", async () => {
+ // Arrange & Act
+ render(
+ "default")}
+ />,
+ { wrapper: Wrapper },
+ );
+
+ await waitFor(() => {
+ expect(screen.getByText(/order rule: order rule 2/i)).toBeInTheDocument();
+ });
+
+ // Assert
+ expect(screen.getByText(/order rule: order rule 2/i)).toBeInTheDocument();
+ expect(screen.getByText(/order rule: order rule 1/i)).toBeInTheDocument();
+ expect(
+ screen.getAllByText(
+ /discount of {value} on the purchase of {conditions} through the {channel}/i,
+ ).length,
+ ).toBe(2);
+ });
+
+ it("should allow to add new catalog rule", async () => {
// Arrange
const onRuleAdd = jest.fn();
render(
"default")}
/>,
@@ -221,24 +232,28 @@ describe("DiscountRules", () => {
screen.getByRole("input", { name: "Name" }),
"Name 123",
);
- await userEvent.click(screen.getByRole("combobox"));
+
+ // Select channel
+ await userEvent.click(screen.getByTestId("channel-dropdown"));
expect(await screen.findByText(/test/i)).toBeInTheDocument();
await act(async () => {
await userEvent.click(screen.getAllByTestId("select-option")[0]);
});
+ // Add condition
await userEvent.click(
screen.getByRole("button", { name: /add condition/i }),
);
- await userEvent.click(await screen.findByTestId(/rule-type/i));
+ await userEvent.click(await screen.findByTestId(/condition-name-0/i));
await userEvent.click(screen.getAllByTestId("select-option")[0]);
- await userEvent.click(await screen.findByTestId(/rule-value/i));
+ await userEvent.click(await screen.findByTestId(/condition-value-0/i));
await userEvent.click(await screen.getAllByTestId("select-option")[0]);
+ // Add reward value
await userEvent.type(
- screen.getByRole("input", { name: "Discount value" }),
+ screen.getByRole("input", { name: "Reward value" }),
"22",
);
@@ -267,62 +282,121 @@ describe("DiscountRules", () => {
id: "",
name: "Name 123",
rewardValue: 22,
+ rewardGifts: [],
+ rewardType: null,
rewardValueType: "FIXED",
},
null,
);
});
- it("should allow to to handle delete rule", async () => {
+ it("should allow to add new order rule", async () => {
// Arrange
- const onRuleDelete = jest.fn();
-
+ const onRuleAdd = jest.fn();
render(
"default")}
/>,
{ wrapper: Wrapper },
);
+ await waitFor(() => {
+ expect(
+ screen.getByRole("button", { name: /add rule/i }),
+ ).toBeInTheDocument();
+ });
+
// Act
await act(async () => {
- await userEvent.click(screen.getAllByTestId("rule-delete-button")[0]);
+ await userEvent.click(screen.getByRole("button", { name: /add rule/i }));
});
- await screen.findByText(/delete rule/i);
+ await userEvent.type(
+ screen.getByRole("input", { name: "Name" }),
+ "Order rule 123",
+ );
+
+ // Channel select
+ await userEvent.click(screen.getByTestId("channel-dropdown"));
+ expect(await screen.findByText(/test/i)).toBeInTheDocument();
await act(async () => {
- await userEvent.click(screen.getByRole("button", { name: /delete/i }));
+ await userEvent.click(screen.getAllByTestId("select-option")[0]);
});
+ // Condition select
+ await userEvent.click(
+ screen.getByRole("button", { name: /add condition/i }),
+ );
+ await userEvent.click(await screen.findByTestId(/condition-name-0/i));
+ await userEvent.click(screen.getAllByTestId("select-option")[0]);
+
+ await userEvent.click(await screen.findByTestId(/condition-type-0/i));
+ await userEvent.click(screen.getAllByTestId("select-option")[2]);
+
+ await userEvent.type(
+ await screen.findByTestId(/condition-value-0/i),
+ "144",
+ );
+
+ // Reward value
+ await userEvent.click(screen.getByRole("radio", { name: "$" }));
+ await userEvent.type(
+ screen.getByRole("input", { name: "Reward value" }),
+ "22",
+ );
+
+ await userEvent.click(screen.getByRole("button", { name: /save/i }));
+
// Assert
- expect(onRuleDelete).toHaveBeenCalledWith(0);
- expect(screen.queryByText(/delete rule/i)).not.toBeInTheDocument();
+ expect(onRuleAdd).toHaveBeenCalledWith(
+ {
+ channel: {
+ label: "Test",
+ value: "Q2hhbm5lcDoy",
+ },
+ conditions: [
+ {
+ id: "baseSubtotalPrice",
+ type: "greater",
+ value: "144",
+ },
+ ],
+ description: "",
+ id: "",
+ name: "Order rule 123",
+ rewardValue: 22,
+ rewardGifts: [],
+ rewardType: "SUBTOTAL_DISCOUNT",
+ rewardValueType: "FIXED",
+ },
+ null,
+ );
});
- it("should allow to to handle update rule", async () => {
+ it("should allow to to handle update catalog rule", async () => {
// Arrange
const onRuleEdit = jest.fn();
render(
"default")}
/>,
@@ -340,14 +414,39 @@ describe("DiscountRules", () => {
await screen.findAllByText(/edit rule/i);
+ // Edit name
const nameField = screen.getByRole("input", { name: "Name" });
await userEvent.clear(nameField);
await userEvent.type(nameField, "New name");
- await userEvent.click(screen.getByRole("radio", { name: "$" }));
+ // Edit condition
+ await userEvent.click(await screen.findByTestId(/condition-name-0/i));
+ await userEvent.click(screen.getAllByTestId("select-option")[1]);
+
+ await userEvent.click(await screen.findByTestId(/condition-value-0/i));
+ await userEvent.click(await screen.getAllByTestId("select-option")[2]);
+
+ // Remove condition
+ await act(async () => {
+ await userEvent.click(await screen.findByTestId(/condition-remove-1/i));
+ });
+ // Add new condition
+ await act(async () => {
+ await userEvent.click(
+ screen.getByRole("button", { name: /add condition/i }),
+ );
+ });
+ await userEvent.click(await screen.findByTestId(/condition-name-1/i));
+ await userEvent.click(screen.getAllByTestId("select-option")[0]);
+
+ await userEvent.click(await screen.findByTestId(/condition-value-1/i));
+ await userEvent.click(await screen.getAllByTestId("select-option")[1]);
+
+ // Edit reward
+ await userEvent.click(screen.getByRole("radio", { name: "$" }));
const discountValueField = screen.getByRole("input", {
- name: "Discount value",
+ name: "Reward value",
});
await userEvent.clear(discountValueField);
await userEvent.type(discountValueField, "122");
@@ -365,35 +464,245 @@ describe("DiscountRules", () => {
},
conditions: [
{
- id: "product",
+ id: "variant",
type: "is",
value: [
{
- label: "Product-1",
- value: "prod-1",
+ label: "Carrot Juice - 1l",
+ value: "UHJvZHVjdFZhcmlhbnQ6MjA2",
},
+ ],
+ },
+ {
+ id: "product",
+ type: "is",
+ value: [
{
- label: "Product-2",
- value: "prod-2",
+ label: "Banana Juice",
+ value: "UHJvZHVjdDo3NA==",
},
],
},
],
description: "",
rewardValue: 122,
+ rewardGifts: [],
+ rewardType: null,
+ rewardValueType: "FIXED",
+ },
+ 0,
+ );
+ });
+
+ it("should allow to to handle update order rule", async () => {
+ // Arrange
+ const onRuleEdit = jest.fn();
+
+ render(
+ "default")}
+ />,
+ { wrapper: Wrapper },
+ );
+
+ await waitFor(() => {
+ expect(screen.getAllByTestId("rule-edit-button")[0]).toBeInTheDocument();
+ });
+
+ // Act
+ await act(async () => {
+ await userEvent.click(screen.getAllByTestId("rule-edit-button")[0]);
+ });
+
+ await screen.findAllByText(/edit rule/i);
+
+ // Edit name
+ const nameField = screen.getByRole("input", { name: "Name" });
+ await userEvent.clear(nameField);
+ await userEvent.type(nameField, "New name");
+
+ // Remove condition
+ await act(async () => {
+ await userEvent.click(await screen.findByTestId(/condition-remove-1/i));
+ });
+
+ // Edit condition
+ await userEvent.click(await screen.findByTestId(/condition-name-0/i));
+ await userEvent.click(screen.getAllByTestId("select-option")[0]);
+
+ await userEvent.click(await screen.findByTestId(/condition-type-0/i));
+ await userEvent.click(screen.getAllByTestId("select-option")[2]);
+
+ await userEvent.clear(await screen.findByTestId(/condition-value-0/i));
+ await userEvent.type(
+ await screen.findByTestId(/condition-value-0/i),
+ "144",
+ );
+
+ // Add new condition
+ await act(async () => {
+ await userEvent.click(
+ screen.getByRole("button", { name: /add condition/i }),
+ );
+ });
+ await userEvent.click(await screen.findByTestId(/condition-name-1/i));
+ await userEvent.click(screen.getAllByTestId("select-option")[0]);
+
+ await userEvent.click(await screen.findByTestId(/condition-type-1/i));
+ await userEvent.click(screen.getAllByTestId("select-option")[1]);
+
+ await userEvent.clear(await screen.findByTestId(/condition-value-1/i));
+ await userEvent.type(
+ await screen.findByTestId(/condition-value-1/i),
+ "100",
+ );
+
+ // Edit reward gifts
+ await userEvent.click(screen.getByTestId("reward-type-select"));
+ await userEvent.click(screen.getAllByTestId("select-option")[1]);
+
+ await userEvent.click(screen.getByTestId("reward-gifts-select"));
+ await userEvent.click(screen.getAllByTestId("select-option")[0]);
+ await userEvent.click(screen.getAllByTestId("select-option")[2]);
+ await userEvent.click(screen.getAllByTestId("select-option")[3]);
+
+ await userEvent.click(screen.getByRole("button", { name: /save/i }));
+
+ // Assert
+ expect(onRuleEdit).toHaveBeenCalledWith(
+ {
+ id: "order-1",
+ name: "New name",
+ channel: {
+ label: "Test",
+ value: "Q2hhbm5lcDoy",
+ },
+ conditions: [
+ {
+ id: "baseTotalPrice",
+ type: "greater",
+ value: "144",
+ },
+ {
+ id: "baseSubtotalPrice",
+ type: "lower",
+ value: "100",
+ },
+ ],
+ description: "",
+ rewardType: "GIFT",
+ rewardGifts: [
+ {
+ label: "Code Division T-shirt - L",
+ value: "UHJvZHVjdFZhcmlhbnQ6MjUz",
+ },
+ {
+ label: "Blue Hoodie - S",
+ value: "UHJvZHVjdFZhcmlhbnQ6MzAx",
+ },
+ {
+ label: "Black Hoodie - XL",
+ value: "UHJvZHVjdFZhcmlhbnQ6Mjk5",
+ },
+ ],
+ rewardValue: null,
rewardValueType: "FIXED",
},
0,
);
});
+ it("should allow to to handle delete rule", async () => {
+ // Arrange
+ const onRuleDelete = jest.fn();
+
+ render(
+ "default")}
+ />,
+ { wrapper: Wrapper },
+ );
+
+ // Act
+ await act(async () => {
+ await userEvent.click(screen.getAllByTestId("rule-delete-button")[0]);
+ });
+
+ await screen.findByText(/delete rule/i);
+
+ await act(async () => {
+ await userEvent.click(screen.getByRole("button", { name: /delete/i }));
+ });
+
+ // Assert
+ expect(onRuleDelete).toHaveBeenCalledWith(0);
+ expect(screen.queryByText(/delete rule/i)).not.toBeInTheDocument();
+ });
+
+ it("should display warning info when rule is too complex", async () => {
+ // Arrange
+ render(
+ "default")}
+ />,
+ { wrapper: Wrapper },
+ );
+
+ await waitFor(() => {
+ expect(screen.getAllByTestId("rule-edit-button")[0]).toBeInTheDocument();
+ });
+
+ // Act
+ await act(async () => {
+ await userEvent.click(screen.getAllByTestId("rule-edit-button")[2]);
+ });
+
+ await screen.findAllByText(/edit rule/i);
+
+ // Assert
+ expect(
+ screen.getByText(
+ /too complex conditions to display, use playground to see details/i,
+ ),
+ ).toBeInTheDocument();
+ expect(screen.getByTestId("openPlaygroundButton")).toBeInTheDocument();
+ });
+
it("should show error in rule", async () => {
// Arrange & Act
render(
{
onRuleSubmit={jest.fn()}
onRuleDelete={jest.fn()}
disabled={false}
- loading={false}
deleteButtonState="default"
getRuleConfirmButtonState={jest.fn(() => "default")}
/>,
diff --git a/src/discounts/components/DiscountRules/DiscountRules.tsx b/src/discounts/components/DiscountRules/DiscountRules.tsx
index f37af713bcc..7b1272be21c 100644
--- a/src/discounts/components/DiscountRules/DiscountRules.tsx
+++ b/src/discounts/components/DiscountRules/DiscountRules.tsx
@@ -1,7 +1,8 @@
import { DashboardCard } from "@dashboard/components/Card";
import { ConfirmButtonTransitionState } from "@dashboard/components/ConfirmButton";
import { Rule } from "@dashboard/discounts/models";
-import { ChannelFragment } from "@dashboard/graphql";
+import { useLabelMapsContext } from "@dashboard/discounts/views/DiscountDetails/context/context";
+import { ChannelFragment, PromotionTypeEnum } from "@dashboard/graphql";
import { CommonError } from "@dashboard/utils/errors/common";
import { Box } from "@saleor/macaw-ui-next";
import React, { useEffect, useMemo, useState } from "react";
@@ -13,6 +14,7 @@ import { RuleForm } from "./componenets/RuleForm";
import { RuleFormModal } from "./componenets/RuleFormModal";
import { RulesList } from "./componenets/RulesList";
import { DiscountRulesContextProvider } from "./context";
+import { useGraphQLPlayground } from "./hooks/useGraphQLPlayground";
import { messages } from "./messages";
export type DiscountRulesErrors = Array<
@@ -21,11 +23,11 @@ export type DiscountRulesErrors = Array<
interface DiscountRulesProps {
disabled: boolean;
- discountType: "catalog";
+ discountType: PromotionTypeEnum;
channels: ChannelFragment[];
rules: Rule[];
+ promotionId: string | null;
errors: Array>;
- loading?: boolean;
deleteButtonState: ConfirmButtonTransitionState;
getRuleConfirmButtonState: (
ruleEditIndex: number | null,
@@ -42,17 +44,21 @@ export const DiscountRules = ({
getRuleConfirmButtonState,
deleteButtonState,
discountType,
- loading,
onRuleSubmit,
onRuleDelete,
+ promotionId,
}: DiscountRulesProps) => {
const intl = useIntl();
+ const { ruleConditionsValues } = useLabelMapsContext();
+
const [isModalOpen, setIsModalOpen] = useState(false);
const [ruleEditIndex, setRuleEditIndex] = useState(null);
const [ruleDeleteIndex, setRuleDeleteIndex] = useState(null);
const [isLoaded, setIsLoaded] = useState(false);
+ const { opepnGrapQLPlayground } = useGraphQLPlayground();
+
useEffect(() => {
if (!isLoaded && !disabled) {
setIsLoaded(true);
@@ -87,6 +93,11 @@ export const DiscountRules = ({
setRuleDeleteIndex(null);
};
+ const handleOpenPlayground = () => {
+ setIsModalOpen(false);
+ opepnGrapQLPlayground(promotionId);
+ };
+
return (
({
({
initialFormValues={ruleInitialValues}
onSubmit={handleRuleModalSubmit}
>
-
+
)}
+ (menuItem: MenuItem): boolean => {
+ if (!discountType) {
+ return true;
+ }
+
+ if (discountType === menuItem.id) {
+ return true;
+ }
+
+ return false;
+ };
diff --git a/src/discounts/components/DiscountRules/componenets/RuleForm/RuleForm.tsx b/src/discounts/components/DiscountRules/componenets/RuleForm/RuleForm.tsx
index 0ed48cbb97f..e2e08c4be54 100644
--- a/src/discounts/components/DiscountRules/componenets/RuleForm/RuleForm.tsx
+++ b/src/discounts/components/DiscountRules/componenets/RuleForm/RuleForm.tsx
@@ -1,5 +1,7 @@
+import { Combobox } from "@dashboard/components/Combobox";
import { createEmptyCodition, Rule } from "@dashboard/discounts/models";
-import { RewardValueTypeEnum } from "@dashboard/graphql";
+import { PromotionTypeEnum, RewardValueTypeEnum } from "@dashboard/graphql";
+import { ChangeEvent } from "@dashboard/hooks/useForm";
import { commonMessages } from "@dashboard/intl";
import { getFormErrors } from "@dashboard/utils/errors";
import {
@@ -8,7 +10,7 @@ import {
} from "@dashboard/utils/errors/common";
import { RichTextContext } from "@dashboard/utils/richText/context";
import useRichText from "@dashboard/utils/richText/useRichText";
-import { Box, Input, Option, Select } from "@saleor/macaw-ui-next";
+import { Box, Input, Option } from "@saleor/macaw-ui-next";
import React, { useEffect, useMemo } from "react";
import { useController, useFormContext } from "react-hook-form";
import { useIntl } from "react-intl";
@@ -22,11 +24,15 @@ import { RuleReward } from "./components/RuleReward";
interface RuleFormProps {
errors: Array>;
+ openPlayground: () => void;
}
-export const RuleForm = ({ errors }: RuleFormProps) => {
+export const RuleForm = ({
+ errors,
+ openPlayground,
+}: RuleFormProps) => {
const intl = useIntl();
- const { disabled, channels } = useDiscountRulesContext();
+ const { disabled, channels, discountType } = useDiscountRulesContext();
const { watch, getValues, setValue, formState } = useFormContext();
const formErrors = getFormErrors(["rewardValue"], errors);
@@ -67,13 +73,24 @@ export const RuleForm = ({ errors }: RuleFormProps) => {
}
}, [currencySymbol]);
- const handleChannelChange = (selectedChannel: Option) => {
- setValue("channel", selectedChannel, { shouldValidate: true });
+ const handleChannelChange = (e: ChangeEvent) => {
+ const channelId = e.target.value;
+ const channel = channels.find(channel => channel.id === channelId);
- if (conditions.length > 0) {
- setValue("conditions", [createEmptyCodition()]);
- } else {
- setValue("conditions", []);
+ if (channel) {
+ setValue(
+ "channel",
+ { value: channel.id, label: channel.name },
+ { shouldValidate: true },
+ );
+ }
+ setValue("rewardGifts", []);
+
+ // Restart conditions when catalog promotion
+ if (discountType === PromotionTypeEnum.CATALOGUE) {
+ if (conditions.length > 0) {
+ setValue("conditions", [createEmptyCodition()]);
+ }
}
};
@@ -81,8 +98,8 @@ export const RuleForm = ({ errors }: RuleFormProps) => {
-
-
+
+
({ errors }: RuleFormProps) => {
/>
-
-
-
+
{
const { watch } = useFormContext();
- const { disabled } = useDiscountRulesContext();
- const { conditionNames } = useConditionNames();
+ const { discountType, disabled } = useDiscountRulesContext();
+ const conditionNames = useConditionNames(discountType);
const ruleConditionNameFieldName = `conditions.${conditionIndex}.id` as const;
const { field: nameField } = useController<
@@ -46,7 +46,7 @@ export const RuleConditionName = ({
nameField.onChange(e.target.value);
}}
size="medium"
- data-test-id="rule-type"
+ data-test-id={`condition-name-${conditionIndex}`}
onBlur={nameField.onBlur}
disabled={disabled}
/>
diff --git a/src/discounts/components/DiscountRules/componenets/RuleForm/components/RuleConditionName/hooks/useCatalogConditionNames.ts b/src/discounts/components/DiscountRules/componenets/RuleForm/components/RuleConditionName/hooks/useCatalogConditionNames.ts
new file mode 100644
index 00000000000..4f8c27dda40
--- /dev/null
+++ b/src/discounts/components/DiscountRules/componenets/RuleForm/components/RuleConditionName/hooks/useCatalogConditionNames.ts
@@ -0,0 +1,37 @@
+import { Option } from "@saleor/macaw-ui-next";
+import { useMemo } from "react";
+import { useIntl } from "react-intl";
+
+export const useCatalogConditionNames = (): Option[] => {
+ const intl = useIntl();
+
+ const options = useMemo(
+ () => [
+ {
+ label: intl.formatMessage({ defaultMessage: "Products", id: "7NFfmz" }),
+ value: "product",
+ },
+ {
+ label: intl.formatMessage({
+ defaultMessage: "Collections",
+ id: "ulh3kf",
+ }),
+ value: "collection",
+ },
+ {
+ label: intl.formatMessage({
+ defaultMessage: "Categories",
+ id: "VKb1MS",
+ }),
+ value: "category",
+ },
+ {
+ label: intl.formatMessage({ defaultMessage: "Variants", id: "h5P++h" }),
+ value: "variant",
+ },
+ ],
+ [intl],
+ );
+
+ return options;
+};
diff --git a/src/discounts/components/DiscountRules/componenets/RuleForm/components/RuleConditionName/hooks/useConditionNames.ts b/src/discounts/components/DiscountRules/componenets/RuleForm/components/RuleConditionName/hooks/useConditionNames.ts
new file mode 100644
index 00000000000..a77ee549429
--- /dev/null
+++ b/src/discounts/components/DiscountRules/componenets/RuleForm/components/RuleConditionName/hooks/useConditionNames.ts
@@ -0,0 +1,22 @@
+import { PromotionTypeEnum } from "@dashboard/graphql";
+import { Option } from "@saleor/macaw-ui-next";
+
+import { useCatalogConditionNames } from "./useCatalogConditionNames";
+import { useOrderConditionNames } from "./useOrderConditionNames";
+
+export const useConditionNames = (
+ discountType: PromotionTypeEnum,
+): Option[] => {
+ const catalogOptions = useCatalogConditionNames();
+ const orderOptions = useOrderConditionNames();
+
+ if (discountType === PromotionTypeEnum.CATALOGUE) {
+ return catalogOptions;
+ }
+
+ if (discountType === PromotionTypeEnum.ORDER) {
+ return orderOptions;
+ }
+
+ return [];
+};
diff --git a/src/discounts/components/DiscountRules/componenets/RuleForm/components/RuleConditionName/hooks/useOrderConditionNames.ts b/src/discounts/components/DiscountRules/componenets/RuleForm/components/RuleConditionName/hooks/useOrderConditionNames.ts
new file mode 100644
index 00000000000..db0bbd565e0
--- /dev/null
+++ b/src/discounts/components/DiscountRules/componenets/RuleForm/components/RuleConditionName/hooks/useOrderConditionNames.ts
@@ -0,0 +1,29 @@
+import { Option } from "@saleor/macaw-ui-next";
+import { useMemo } from "react";
+import { useIntl } from "react-intl";
+
+export const useOrderConditionNames = (): Option[] => {
+ const intl = useIntl();
+
+ const options = useMemo(
+ () => [
+ {
+ label: intl.formatMessage({
+ id: "6pPMp9",
+ defaultMessage: "Subtotal price",
+ }),
+ value: "baseSubtotalPrice",
+ },
+ {
+ label: intl.formatMessage({
+ id: "4VivsY",
+ defaultMessage: "Total price",
+ }),
+ value: "baseTotalPrice",
+ },
+ ],
+ [intl],
+ );
+
+ return options;
+};
diff --git a/src/discounts/components/DiscountRules/componenets/RuleForm/components/RuleConditionName/index.ts b/src/discounts/components/DiscountRules/componenets/RuleForm/components/RuleConditionName/index.ts
index 9d50c297a7d..a9e5d85ad35 100644
--- a/src/discounts/components/DiscountRules/componenets/RuleForm/components/RuleConditionName/index.ts
+++ b/src/discounts/components/DiscountRules/componenets/RuleForm/components/RuleConditionName/index.ts
@@ -1,2 +1,2 @@
+export * from "./hooks/useConditionNames";
export * from "./RuleConditionName";
-export * from "./useConditionNames";
diff --git a/src/discounts/components/DiscountRules/componenets/RuleForm/components/RuleConditionName/useConditionNames.ts b/src/discounts/components/DiscountRules/componenets/RuleForm/components/RuleConditionName/useConditionNames.ts
deleted file mode 100644
index 4098db9a9a7..00000000000
--- a/src/discounts/components/DiscountRules/componenets/RuleForm/components/RuleConditionName/useConditionNames.ts
+++ /dev/null
@@ -1,40 +0,0 @@
-import { CatalogConditions } from "@dashboard/discounts/types";
-import { Option } from "@saleor/macaw-ui-next";
-import { useState } from "react";
-import { IntlShape, useIntl } from "react-intl";
-
-export const useConditionNames = () => {
- const intl = useIntl();
- const [conditionNames] = useState
- } onClick={onRemove} />
+ }
+ onClick={onRemove}
+ />
);
};
diff --git a/src/discounts/components/DiscountRules/componenets/RuleForm/components/RuleConditionRow/utils.ts b/src/discounts/components/DiscountRules/componenets/RuleForm/components/RuleConditionRow/utils.ts
deleted file mode 100644
index 0db83bb4497..00000000000
--- a/src/discounts/components/DiscountRules/componenets/RuleForm/components/RuleConditionRow/utils.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-import { Option } from "@saleor/macaw-ui-next";
-
-export const getConditionTypeValue = (
- conditionType: string | undefined | null,
- conditionTypes: Option[],
-) => {
- if (!conditionType) {
- return null;
- }
-
- return conditionTypes.find(type => type.value === conditionType) || null;
-};
diff --git a/src/discounts/components/DiscountRules/componenets/RuleForm/components/RuleConditionType/RuleConditionType.tsx b/src/discounts/components/DiscountRules/componenets/RuleForm/components/RuleConditionType/RuleConditionType.tsx
index b5d02e399e0..83a1a92540e 100644
--- a/src/discounts/components/DiscountRules/componenets/RuleForm/components/RuleConditionType/RuleConditionType.tsx
+++ b/src/discounts/components/DiscountRules/componenets/RuleForm/components/RuleConditionType/RuleConditionType.tsx
@@ -29,6 +29,7 @@ export const RuleConditionType = ({
return (