11import { zodResolver } from "@hookform/resolvers/zod"
22import { 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"
411import { useForm , useWatch } from "react-hook-form"
512import { Trans , useTranslation } from "react-i18next"
13+ import { useEffect } from "react"
614import * as zod from "zod"
715
816import { Form } from "../../../../../components/common/form"
@@ -11,6 +19,7 @@ import { RouteDrawer, useRouteModal } from "../../../../../components/modals"
1119import { KeyboundForm } from "../../../../../components/utilities/keybound-form"
1220import { useUpdatePromotion } from "../../../../../hooks/api/promotions"
1321import { getCurrencySymbol } from "../../../../../lib/data/currencies"
22+ import { SwitchBox } from "../../../../../components/common/switch-box"
1423
1524type EditPromotionFormProps = {
1625 promotion : AdminPromotion
@@ -19,6 +28,7 @@ type EditPromotionFormProps = {
1928const 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 >
0 commit comments