Skip to content

Commit b481c86

Browse files
authored
Merge pull request #97 from coding-blocks/coupons_max_product_mrp
Coupons max product mrp
2 parents eebfb73 + 0d4869b commit b481c86

File tree

2 files changed

+94
-13
lines changed

2 files changed

+94
-13
lines changed

forms/BulkCoupon.js

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@ const bulkCouponSchema = Yup.object().shape({
5959
applicable_all_users: Yup.boolean()
6060
.required("Field is required."),
6161
active: Yup.boolean()
62-
.required("Field is required.")
62+
.required("Field is required."),
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()
6370
});
6471

6572
const initialValues = {
@@ -80,7 +87,9 @@ const initialValues = {
8087
starts_with: '',
8188
ends_with: '',
8289
valid_start: Date.now(),
83-
valid_end: new Date().setMonth(new Date().getMonth() + 1)
90+
valid_end: new Date().setMonth(new Date().getMonth() + 1),
91+
min_product_mrp: null,
92+
max_product_mrp: null
8493
}
8594

8695
class BulkCouponForm extends React.Component {
@@ -386,6 +395,36 @@ class BulkCouponForm extends React.Component {
386395
</div>
387396
}
388397

398+
<FieldWithElement
399+
name={"Min product Mrp"} nameCols={3} elementCols={9}
400+
elementClassName={"pl-4"} errorColor={'tomato'}
401+
errors={touched.min_product_mrp && errors.min_product_mrp}>
402+
<input
403+
type="number"
404+
className={"input-text"}
405+
placeholder="Enter min product price"
406+
name="min_product_mrp"
407+
onBlur={handleBlur}
408+
onChange={handleChange}
409+
value={values.min_product_mrp}
410+
/>
411+
</FieldWithElement>
412+
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+
389428
{/* Total number of times a coupon can be used*/}
390429
<FieldWithElement name={"How many times it can be used?"} nameCols={6}
391430
elementCols={6} elementClassName={"pl-4"} errorColor={'tomato'}

forms/Coupon.js

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,22 @@ const couponSchema = Yup.object().shape({
4646
}),
4747
max_discount: Yup.number().when('mode', {
4848
is: (val) => val == "percentage",
49-
then: Yup.number().min(1)
49+
then: Yup.number()
50+
.min(1, 'must be greater or eqauls to 1')
5051
.nullable().notRequired(),
5152
otherwise: Yup.number().nullable().notRequired()
5253
}),
5354
applicable_all_users: Yup.boolean()
5455
.required("Field is required."),
5556
active: Yup.boolean()
56-
.required("Field is required.")
57+
.required("Field is required."),
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()
5765
});
5866

5967
const initialValues = {
@@ -71,7 +79,9 @@ const initialValues = {
7179
percentage: null,
7280
amount: null,
7381
valid_start: Date.now(),
74-
valid_end: new Date().setMonth(new Date().getMonth() + 1)
82+
valid_end: new Date().setMonth(new Date().getMonth() + 1),
83+
min_product_mrp: null,
84+
max_product_mrp: null
7585
}
7686

7787
class CouponForm extends React.Component {
@@ -94,7 +104,6 @@ class CouponForm extends React.Component {
94104

95105

96106
makeEditCouponContext = () => {
97-
98107
return {
99108
authority_doc: this.props.data.coupon.authority_doc,
100109
code: this.props.data.coupon.code,
@@ -111,7 +120,9 @@ class CouponForm extends React.Component {
111120
amount: parseInt(this.props.data.coupon.amount),
112121
valid_start: new Date(this.props.data.coupon.valid_start),
113122
valid_end: new Date(this.props.data.coupon.valid_end),
114-
comment: this.props.data.coupon.comment
123+
comment: this.props.data.coupon.comment,
124+
min_product_mrp: this.props.data.coupon.min_product_mrp,
125+
max_product_mrp: this.props.data.coupon.max_product_mrp
115126
}
116127
}
117128

@@ -162,7 +173,7 @@ class CouponForm extends React.Component {
162173

163174
onSubmit = async (fields) => {
164175
if (fields.amount)
165-
if( !(await this.getProductsWithMrpLessThanDiscount(fields)) )
176+
if( !(await this.freeProductsNotice(fields)) )
166177
return
167178

168179
if (this.props.data.isEditMode) {
@@ -172,14 +183,15 @@ class CouponForm extends React.Component {
172183
}
173184
}
174185

175-
getProductsWithMrpLessThanDiscount = async (formValues) => {
186+
freeProductsNotice = async (formValues) => {
176187
try {
177188
const payload = {
178189
amount: formValues.amount,
179190
product_ids: await this.getCouponProductIds(),
180191
category: formValues.category,
181192
sub_category_id: formValues.sub_category_id,
182-
mode: formValues.mode
193+
mode: formValues.mode,
194+
min_product_mrp: formValues.min_product_mrp
183195
}
184196
const response = await controller.getProductsWithMrpLessThanDiscount(payload)
185197
if (!response.data.length) {
@@ -364,8 +376,8 @@ class CouponForm extends React.Component {
364376
{ (!this.props.data.isEverUsed && !this.props.data.isSubCategoryBulk) &&
365377
<span id="random_coupon" className="red pull-right mt-2 ml-2"
366378
onClick={() => setFieldValue("code", this.setRandomCouponCode())}>
367-
Generate Random Code
368-
</span>
379+
Generate Random Code
380+
</span>
369381
}
370382
</FieldWithElement>
371383

@@ -374,7 +386,7 @@ class CouponForm extends React.Component {
374386
elementClassName={"pl-4"}
375387
errors={touched.authority_doc && errors.authority_doc}
376388
errorColor={'tomato'}>
377-
<textarea
389+
<textarea
378390
type="text"
379391
className="input-textarea"
380392
placeholder="Enter Description"
@@ -555,6 +567,36 @@ class CouponForm extends React.Component {
555567
</div>
556568
}
557569

570+
<FieldWithElement
571+
name={"Min product Mrp"} nameCols={3} elementCols={9}
572+
elementClassName={"pl-4"} errorColor={'tomato'}
573+
errors={touched.min_product_mrp && errors.min_product_mrp}>
574+
<input
575+
type="number"
576+
className={"input-text"}
577+
placeholder="Enter min product price"
578+
name="min_product_mrp"
579+
onBlur={handleBlur}
580+
onChange={handleChange}
581+
value={values.min_product_mrp}
582+
/>
583+
</FieldWithElement>
584+
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+
558600
{/* Total number of times a coupon can be used*/}
559601
<FieldWithElement name={"How many times it can be used?*"} nameCols={6}
560602
elementCols={6} elementClassName={"pl-4"} errorColor={'tomato'}

0 commit comments

Comments
 (0)