From 42be9a88d61a11db7aebde2d6f4d96d43f54ea79 Mon Sep 17 00:00:00 2001 From: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> Date: Tue, 8 Jul 2025 19:20:29 +0200 Subject: [PATCH] fix(medusa, core-flows): Update TIP on promotions (#12885) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Update TIP on promotions * Create warm-rings-look.md * only show for fixed discounts * fix: handle type change --------- Co-authored-by: fPolic Co-authored-by: Frane Polić <16856471+fPolic@users.noreply.github.com> --- .changeset/warm-rings-look.md | 7 ++++ .../promotions/admin/promotions.spec.ts | 2 ++ .../dashboard/src/i18n/translations/en.json | 9 +++-- .../edit-promotion-details-form.tsx | 36 +++++++++++++++++-- .../src/http/promotion/admin/payloads.ts | 4 +++ .../types/src/promotion/common/promotion.ts | 5 +++ .../src/api/admin/promotions/validators.ts | 1 + 7 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 .changeset/warm-rings-look.md diff --git a/.changeset/warm-rings-look.md b/.changeset/warm-rings-look.md new file mode 100644 index 0000000000..3fa3afe417 --- /dev/null +++ b/.changeset/warm-rings-look.md @@ -0,0 +1,7 @@ +--- +"@medusajs/medusa": patch +"@medusajs/types": patch +"@medusajs/dashboard": patch +--- + +fix: Update TIP on promotions diff --git a/integration-tests/http/__tests__/promotions/admin/promotions.spec.ts b/integration-tests/http/__tests__/promotions/admin/promotions.spec.ts index b00f113e42..3c1d753669 100644 --- a/integration-tests/http/__tests__/promotions/admin/promotions.spec.ts +++ b/integration-tests/http/__tests__/promotions/admin/promotions.spec.ts @@ -1731,6 +1731,7 @@ medusaIntegrationTestRunner({ { code: "TEST_TWO", application_method: { value: 200 }, + is_tax_inclusive: true, }, adminHeaders ) @@ -1743,6 +1744,7 @@ medusaIntegrationTestRunner({ application_method: expect.objectContaining({ value: 200, }), + is_tax_inclusive: true, }) ) }) diff --git a/packages/admin/dashboard/src/i18n/translations/en.json b/packages/admin/dashboard/src/i18n/translations/en.json index c3fdec353d..2b757f674f 100644 --- a/packages/admin/dashboard/src/i18n/translations/en.json +++ b/packages/admin/dashboard/src/i18n/translations/en.json @@ -2074,7 +2074,7 @@ }, "taxInclusive": { "title": "Does promotion include taxes?", - "description": "Enable this field to apply the promotion after taxes. If disabled, the promotion will be applied before taxes." + "description": "Enable this field to apply the promotion after taxes" }, "status": { "label": "Status", @@ -2697,7 +2697,10 @@ "placeholder": "wrong_size", "tooltip": "The value should be a unique identifier for the return reason." }, - "label": { "label": "Label", "placeholder": "Wrong size" }, + "label": { + "label": "Label", + "placeholder": "Wrong size" + }, "description": { "label": "Description", "placeholder": "Customer received the wrong size" @@ -3048,4 +3051,4 @@ "seconds_one": "Second", "seconds_other": "Seconds" } -} +} \ No newline at end of file diff --git a/packages/admin/dashboard/src/routes/promotions/promotion-edit-details/components/edit-promotion-form/edit-promotion-details-form.tsx b/packages/admin/dashboard/src/routes/promotions/promotion-edit-details/components/edit-promotion-form/edit-promotion-details-form.tsx index 9d92542a0e..3ffb35f7d3 100644 --- a/packages/admin/dashboard/src/routes/promotions/promotion-edit-details/components/edit-promotion-form/edit-promotion-details-form.tsx +++ b/packages/admin/dashboard/src/routes/promotions/promotion-edit-details/components/edit-promotion-form/edit-promotion-details-form.tsx @@ -1,8 +1,16 @@ import { zodResolver } from "@hookform/resolvers/zod" import { AdminPromotion } from "@medusajs/types" -import { Button, CurrencyInput, Input, RadioGroup, Text } from "@medusajs/ui" +import { + Button, + CurrencyInput, + Input, + RadioGroup, + Switch, + Text, +} from "@medusajs/ui" import { useForm, useWatch } from "react-hook-form" import { Trans, useTranslation } from "react-i18next" +import { useEffect } from "react" import * as zod from "zod" import { Form } from "../../../../../components/common/form" @@ -11,6 +19,7 @@ import { RouteDrawer, useRouteModal } from "../../../../../components/modals" import { KeyboundForm } from "../../../../../components/utilities/keybound-form" import { useUpdatePromotion } from "../../../../../hooks/api/promotions" import { getCurrencySymbol } from "../../../../../lib/data/currencies" +import { SwitchBox } from "../../../../../components/common/switch-box" type EditPromotionFormProps = { promotion: AdminPromotion @@ -19,6 +28,7 @@ type EditPromotionFormProps = { const EditPromotionSchema = zod.object({ is_automatic: zod.string().toLowerCase(), code: zod.string().min(1), + is_tax_inclusive: zod.boolean().optional(), status: zod.enum(["active", "inactive", "draft"]), value_type: zod.enum(["fixed", "percentage"]), value: zod.number(), @@ -34,6 +44,7 @@ export const EditPromotionDetailsForm = ({ const form = useForm>({ defaultValues: { is_automatic: promotion.is_automatic!.toString(), + is_tax_inclusive: promotion.is_tax_inclusive, code: promotion.code, status: promotion.status, value: promotion.application_method!.value, @@ -58,6 +69,7 @@ export const EditPromotionDetailsForm = ({ is_automatic: data.is_automatic === "true", code: data.code, status: data.status, + is_tax_inclusive: data.is_tax_inclusive, application_method: { value: data.value, type: data.value_type as any, @@ -72,6 +84,17 @@ export const EditPromotionDetailsForm = ({ ) }) + const allocationWatchValue = useWatch({ + control: form.control, + name: "value_type", + }) + + useEffect(() => { + if (!(allocationWatchValue === "fixed" && promotion.type === "standard")) { + form.setValue("is_tax_inclusive", false) + } + }, [allocationWatchValue, form, promotion]) + return ( + {allocationWatchValue === "fixed" && + promotion.type === "standard" && ( + + )} +
{t("promotions.form.code.title")} - diff --git a/packages/core/types/src/http/promotion/admin/payloads.ts b/packages/core/types/src/http/promotion/admin/payloads.ts index 46e442af54..0334edf510 100644 --- a/packages/core/types/src/http/promotion/admin/payloads.ts +++ b/packages/core/types/src/http/promotion/admin/payloads.ts @@ -197,6 +197,10 @@ export interface AdminUpdatePromotion { * by entering the code at checkout. */ is_automatic?: boolean + /** + * Whether the promotion is tax inclusive. + */ + is_tax_inclusive?: boolean /** * The type of promotion. */ diff --git a/packages/core/types/src/promotion/common/promotion.ts b/packages/core/types/src/promotion/common/promotion.ts index cb6f63c968..6f37c5598c 100644 --- a/packages/core/types/src/promotion/common/promotion.ts +++ b/packages/core/types/src/promotion/common/promotion.ts @@ -168,6 +168,11 @@ export interface UpdatePromotionDTO { */ type?: PromotionTypeValues + /** + * Whether the promotion is tax inclusive. + */ + is_tax_inclusive?: boolean + /** * The status of the promotion: * diff --git a/packages/medusa/src/api/admin/promotions/validators.ts b/packages/medusa/src/api/admin/promotions/validators.ts index 869525d4d4..93bdd36295 100644 --- a/packages/medusa/src/api/admin/promotions/validators.ts +++ b/packages/medusa/src/api/admin/promotions/validators.ts @@ -187,6 +187,7 @@ export const UpdatePromotion = z .object({ code: z.string().optional(), is_automatic: z.boolean().optional(), + is_tax_inclusive: z.boolean().optional(), type: z.nativeEnum(PromotionType).optional(), status: z.nativeEnum(PromotionStatus).optional(), campaign_id: z.string().nullish(),