@@ -10,6 +10,7 @@ import {
1010} from "@medusajs/ui"
1111import { useForm , useWatch } from "react-hook-form"
1212import { Trans , useTranslation } from "react-i18next"
13+ import { useEffect } from "react"
1314import * as zod from "zod"
1415
1516import { Form } from "../../../../../components/common/form"
@@ -27,7 +28,7 @@ type EditPromotionFormProps = {
2728const EditPromotionSchema = zod . object ( {
2829 is_automatic : zod . string ( ) . toLowerCase ( ) ,
2930 code : zod . string ( ) . min ( 1 ) ,
30- is_tax_inclusive : zod . boolean ( ) ,
31+ is_tax_inclusive : zod . boolean ( ) . optional ( ) ,
3132 status : zod . enum ( [ "active" , "inactive" , "draft" ] ) ,
3233 value_type : zod . enum ( [ "fixed" , "percentage" ] ) ,
3334 value : zod . number ( ) ,
@@ -83,6 +84,17 @@ export const EditPromotionDetailsForm = ({
8384 )
8485 } )
8586
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+
8698 return (
8799 < RouteDrawer . Form form = { form } >
88100 < KeyboundForm
@@ -172,15 +184,16 @@ export const EditPromotionDetailsForm = ({
172184 } }
173185 />
174186
175- { promotion ?. type === "standard" &&
176- promotion . application_method ?. type === "fixed" ? (
177- < SwitchBox
178- control = { form . control }
179- name = "is_tax_inclusive"
180- label = { t ( "promotions.form.taxInclusive.title" ) }
181- description = { t ( "promotions.form.taxInclusive.description" ) }
182- />
183- ) : null }
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+
184197 < div className = "flex flex-col gap-y-4" >
185198 < Form . Field
186199 control = { form . control }
@@ -189,7 +202,6 @@ export const EditPromotionDetailsForm = ({
189202 return (
190203 < Form . Item >
191204 < Form . Label > { t ( "promotions.form.code.title" ) } </ Form . Label >
192-
193205 < Form . Control >
194206 < Input { ...field } />
195207 </ Form . Control >
0 commit comments