Skip to content

Commit 0d4869b

Browse files
author
JasmeetLuthra
committed
max product field added in coupons form
1 parent 3698479 commit 0d4869b

File tree

2 files changed

+50
-25
lines changed

2 files changed

+50
-25
lines changed

forms/BulkCoupon.js

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,13 @@ const bulkCouponSchema = Yup.object().shape({
6060
.required("Field is required."),
6161
active: Yup.boolean()
6262
.required("Field is required."),
63-
min_product_mrp: Yup.number().when('mode', {
64-
is: (val) => val == "flat",
65-
then: Yup.number()
66-
.min(1, 'must be greater or eqauls to 1')
67-
.typeError('min product price is required')
68-
.required('min product price is required.'),
69-
otherwise: Yup.number()
70-
.min(1, 'must be greater or eqauls to 1')
71-
.nullable().notRequired()
72-
}),
63+
min_product_mrp: Yup.number()
64+
.positive().nullable().notRequired(),
65+
max_product_mrp: Yup.number()
66+
.positive()
67+
.moreThan(Yup.ref('min_product_mrp'),
68+
"must be greater than min product mrp")
69+
.nullable().notRequired()
7370
});
7471

7572
const initialValues = {
@@ -91,7 +88,8 @@ const initialValues = {
9188
ends_with: '',
9289
valid_start: Date.now(),
9390
valid_end: new Date().setMonth(new Date().getMonth() + 1),
94-
min_product_mrp: null
91+
min_product_mrp: null,
92+
max_product_mrp: null
9593
}
9694

9795
class BulkCouponForm extends React.Component {
@@ -339,7 +337,6 @@ class BulkCouponForm extends React.Component {
339337
setFieldTouched("percentage", false)
340338
setFieldValue("max_discount", null)
341339
setFieldTouched("max_discount", false)
342-
setFieldTouched("min_product_mrp", false)
343340
}}
344341
>
345342
<option value="flat">Flat</option>
@@ -413,6 +410,21 @@ class BulkCouponForm extends React.Component {
413410
/>
414411
</FieldWithElement>
415412

413+
<FieldWithElement
414+
name={"Min product Mrp"} nameCols={3} elementCols={9}
415+
elementClassName={"pl-4"} errorColor={'tomato'}
416+
errors={touched.max_product_mrp && errors.max_product_mrp}>
417+
<input
418+
type="number"
419+
className={"input-text"}
420+
placeholder="Enter min product price"
421+
name="max_product_mrp"
422+
onBlur={handleBlur}
423+
onChange={handleChange}
424+
value={values.max_product_mrp}
425+
/>
426+
</FieldWithElement>
427+
416428
{/* Total number of times a coupon can be used*/}
417429
<FieldWithElement name={"How many times it can be used?"} nameCols={6}
418430
elementCols={6} elementClassName={"pl-4"} errorColor={'tomato'}

forms/Coupon.js

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,13 @@ const couponSchema = Yup.object().shape({
5555
.required("Field is required."),
5656
active: Yup.boolean()
5757
.required("Field is required."),
58-
min_product_mrp: Yup.number().when('mode', {
59-
is: (val) => val == "flat",
60-
then: Yup.number()
61-
.min(1, 'must be greater or eqauls to 1')
62-
.typeError('min product price is required')
63-
.required('min product price is required.'),
64-
otherwise: Yup.number()
65-
.min(1, 'must be greater or eqauls to 1')
66-
.nullable().notRequired()
67-
}),
58+
min_product_mrp: Yup.number()
59+
.positive().nullable().notRequired(),
60+
max_product_mrp: Yup.number()
61+
.positive()
62+
.moreThan(Yup.ref('min_product_mrp'),
63+
"must be greater than min product mrp")
64+
.nullable().notRequired()
6865
});
6966

7067
const initialValues = {
@@ -83,7 +80,8 @@ const initialValues = {
8380
amount: null,
8481
valid_start: Date.now(),
8582
valid_end: new Date().setMonth(new Date().getMonth() + 1),
86-
min_product_mrp: null
83+
min_product_mrp: null,
84+
max_product_mrp: null
8785
}
8886

8987
class CouponForm extends React.Component {
@@ -123,7 +121,8 @@ class CouponForm extends React.Component {
123121
valid_start: new Date(this.props.data.coupon.valid_start),
124122
valid_end: new Date(this.props.data.coupon.valid_end),
125123
comment: this.props.data.coupon.comment,
126-
min_product_mrp: this.props.data.coupon.min_product_mrp
124+
min_product_mrp: this.props.data.coupon.min_product_mrp,
125+
max_product_mrp: this.props.data.coupon.max_product_mrp
127126
}
128127
}
129128

@@ -508,7 +507,6 @@ class CouponForm extends React.Component {
508507
setFieldTouched("percentage", false)
509508
setFieldValue("max_discount", null)
510509
setFieldTouched("max_discount", false)
511-
setFieldTouched("min_product_mrp", false)
512510
}}
513511
value={values.mode}>
514512
<option value="flat">Flat</option>
@@ -584,6 +582,21 @@ class CouponForm extends React.Component {
584582
/>
585583
</FieldWithElement>
586584

585+
<FieldWithElement
586+
name={"Max product Mrp"} nameCols={3} elementCols={9}
587+
elementClassName={"pl-4"} errorColor={'tomato'}
588+
errors={touched.max_product_mrp && errors.max_product_mrp}>
589+
<input
590+
type="number"
591+
className={"input-text"}
592+
placeholder="Enter min product price"
593+
name="max_product_mrp"
594+
onBlur={handleBlur}
595+
onChange={handleChange}
596+
value={values.max_product_mrp}
597+
/>
598+
</FieldWithElement>
599+
587600
{/* Total number of times a coupon can be used*/}
588601
<FieldWithElement name={"How many times it can be used?*"} nameCols={6}
589602
elementCols={6} elementClassName={"pl-4"} errorColor={'tomato'}

0 commit comments

Comments
 (0)