Skip to content

Commit 42be9a8

Browse files
olivermrblfPolic
andauthored
fix(medusa, core-flows): Update TIP on promotions (#12885)
* fix: Update TIP on promotions * Create warm-rings-look.md * only show for fixed discounts * fix: handle type change --------- Co-authored-by: fPolic <mainacc.polic@gmail.com> Co-authored-by: Frane Polić <16856471+fPolic@users.noreply.github.com>
1 parent 1438b39 commit 42be9a8

7 files changed

Lines changed: 59 additions & 5 deletions

File tree

.changeset/warm-rings-look.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@medusajs/medusa": patch
3+
"@medusajs/types": patch
4+
"@medusajs/dashboard": patch
5+
---
6+
7+
fix: Update TIP on promotions

integration-tests/http/__tests__/promotions/admin/promotions.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,6 +1731,7 @@ medusaIntegrationTestRunner({
17311731
{
17321732
code: "TEST_TWO",
17331733
application_method: { value: 200 },
1734+
is_tax_inclusive: true,
17341735
},
17351736
adminHeaders
17361737
)
@@ -1743,6 +1744,7 @@ medusaIntegrationTestRunner({
17431744
application_method: expect.objectContaining({
17441745
value: 200,
17451746
}),
1747+
is_tax_inclusive: true,
17461748
})
17471749
)
17481750
})

packages/admin/dashboard/src/i18n/translations/en.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,7 +2074,7 @@
20742074
},
20752075
"taxInclusive": {
20762076
"title": "Does promotion include taxes?",
2077-
"description": "Enable this field to apply the promotion after taxes. If disabled, the promotion will be applied before taxes."
2077+
"description": "Enable this field to apply the promotion after taxes"
20782078
},
20792079
"status": {
20802080
"label": "Status",
@@ -2697,7 +2697,10 @@
26972697
"placeholder": "wrong_size",
26982698
"tooltip": "The value should be a unique identifier for the return reason."
26992699
},
2700-
"label": { "label": "Label", "placeholder": "Wrong size" },
2700+
"label": {
2701+
"label": "Label",
2702+
"placeholder": "Wrong size"
2703+
},
27012704
"description": {
27022705
"label": "Description",
27032706
"placeholder": "Customer received the wrong size"
@@ -3048,4 +3051,4 @@
30483051
"seconds_one": "Second",
30493052
"seconds_other": "Seconds"
30503053
}
3051-
}
3054+
}

packages/admin/dashboard/src/routes/promotions/promotion-edit-details/components/edit-promotion-form/edit-promotion-details-form.tsx

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import { zodResolver } from "@hookform/resolvers/zod"
22
import { AdminPromotion } from "@medusajs/types"
3-
import { Button, CurrencyInput, Input, RadioGroup, Text } from "@medusajs/ui"
3+
import {
4+
Button,
5+
CurrencyInput,
6+
Input,
7+
RadioGroup,
8+
Switch,
9+
Text,
10+
} from "@medusajs/ui"
411
import { useForm, useWatch } from "react-hook-form"
512
import { Trans, useTranslation } from "react-i18next"
13+
import { useEffect } from "react"
614
import * as zod from "zod"
715

816
import { Form } from "../../../../../components/common/form"
@@ -11,6 +19,7 @@ import { RouteDrawer, useRouteModal } from "../../../../../components/modals"
1119
import { KeyboundForm } from "../../../../../components/utilities/keybound-form"
1220
import { useUpdatePromotion } from "../../../../../hooks/api/promotions"
1321
import { getCurrencySymbol } from "../../../../../lib/data/currencies"
22+
import { SwitchBox } from "../../../../../components/common/switch-box"
1423

1524
type EditPromotionFormProps = {
1625
promotion: AdminPromotion
@@ -19,6 +28,7 @@ type EditPromotionFormProps = {
1928
const EditPromotionSchema = zod.object({
2029
is_automatic: zod.string().toLowerCase(),
2130
code: zod.string().min(1),
31+
is_tax_inclusive: zod.boolean().optional(),
2232
status: zod.enum(["active", "inactive", "draft"]),
2333
value_type: zod.enum(["fixed", "percentage"]),
2434
value: zod.number(),
@@ -34,6 +44,7 @@ export const EditPromotionDetailsForm = ({
3444
const form = useForm<zod.infer<typeof EditPromotionSchema>>({
3545
defaultValues: {
3646
is_automatic: promotion.is_automatic!.toString(),
47+
is_tax_inclusive: promotion.is_tax_inclusive,
3748
code: promotion.code,
3849
status: promotion.status,
3950
value: promotion.application_method!.value,
@@ -58,6 +69,7 @@ export const EditPromotionDetailsForm = ({
5869
is_automatic: data.is_automatic === "true",
5970
code: data.code,
6071
status: data.status,
72+
is_tax_inclusive: data.is_tax_inclusive,
6173
application_method: {
6274
value: data.value,
6375
type: data.value_type as any,
@@ -72,6 +84,17 @@ export const EditPromotionDetailsForm = ({
7284
)
7385
})
7486

87+
const allocationWatchValue = useWatch({
88+
control: form.control,
89+
name: "value_type",
90+
})
91+
92+
useEffect(() => {
93+
if (!(allocationWatchValue === "fixed" && promotion.type === "standard")) {
94+
form.setValue("is_tax_inclusive", false)
95+
}
96+
}, [allocationWatchValue, form, promotion])
97+
7598
return (
7699
<RouteDrawer.Form form={form}>
77100
<KeyboundForm
@@ -161,6 +184,16 @@ export const EditPromotionDetailsForm = ({
161184
}}
162185
/>
163186

187+
{allocationWatchValue === "fixed" &&
188+
promotion.type === "standard" && (
189+
<SwitchBox
190+
control={form.control}
191+
name="is_tax_inclusive"
192+
label={t("promotions.form.taxInclusive.title")}
193+
description={t("promotions.form.taxInclusive.description")}
194+
/>
195+
)}
196+
164197
<div className="flex flex-col gap-y-4">
165198
<Form.Field
166199
control={form.control}
@@ -169,7 +202,6 @@ export const EditPromotionDetailsForm = ({
169202
return (
170203
<Form.Item>
171204
<Form.Label>{t("promotions.form.code.title")}</Form.Label>
172-
173205
<Form.Control>
174206
<Input {...field} />
175207
</Form.Control>

packages/core/types/src/http/promotion/admin/payloads.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ export interface AdminUpdatePromotion {
197197
* by entering the code at checkout.
198198
*/
199199
is_automatic?: boolean
200+
/**
201+
* Whether the promotion is tax inclusive.
202+
*/
203+
is_tax_inclusive?: boolean
200204
/**
201205
* The type of promotion.
202206
*/

packages/core/types/src/promotion/common/promotion.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ export interface UpdatePromotionDTO {
168168
*/
169169
type?: PromotionTypeValues
170170

171+
/**
172+
* Whether the promotion is tax inclusive.
173+
*/
174+
is_tax_inclusive?: boolean
175+
171176
/**
172177
* The status of the promotion:
173178
*

packages/medusa/src/api/admin/promotions/validators.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ export const UpdatePromotion = z
187187
.object({
188188
code: z.string().optional(),
189189
is_automatic: z.boolean().optional(),
190+
is_tax_inclusive: z.boolean().optional(),
190191
type: z.nativeEnum(PromotionType).optional(),
191192
status: z.nativeEnum(PromotionStatus).optional(),
192193
campaign_id: z.string().nullish(),

0 commit comments

Comments
 (0)