Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions forms/BulkCoupon.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ const bulkCouponSchema = Yup.object().shape({
applicable_all_users: Yup.boolean()
.required("Field is required."),
active: Yup.boolean()
.required("Field is required.")
.required("Field is required."),
min_product_mrp: Yup.number()
.positive().nullable().notRequired(),
max_product_mrp: Yup.number()
.positive()
.moreThan(Yup.ref('min_product_mrp'),
"must be greater than min product mrp")
.nullable().notRequired()
});

const initialValues = {
Expand All @@ -80,7 +87,9 @@ const initialValues = {
starts_with: '',
ends_with: '',
valid_start: Date.now(),
valid_end: new Date().setMonth(new Date().getMonth() + 1)
valid_end: new Date().setMonth(new Date().getMonth() + 1),
min_product_mrp: null,
max_product_mrp: null
}

class BulkCouponForm extends React.Component {
Expand Down Expand Up @@ -386,6 +395,36 @@ class BulkCouponForm extends React.Component {
</div>
}

<FieldWithElement
name={"Min product Mrp"} nameCols={3} elementCols={9}
elementClassName={"pl-4"} errorColor={'tomato'}
errors={touched.min_product_mrp && errors.min_product_mrp}>
<input
type="number"
className={"input-text"}
placeholder="Enter min product price"
name="min_product_mrp"
onBlur={handleBlur}
onChange={handleChange}
value={values.min_product_mrp}
/>
</FieldWithElement>

<FieldWithElement
name={"Min product Mrp"} nameCols={3} elementCols={9}
elementClassName={"pl-4"} errorColor={'tomato'}
errors={touched.max_product_mrp && errors.max_product_mrp}>
<input
type="number"
className={"input-text"}
placeholder="Enter min product price"
name="max_product_mrp"
onBlur={handleBlur}
onChange={handleChange}
value={values.max_product_mrp}
/>
</FieldWithElement>

{/* Total number of times a coupon can be used*/}
<FieldWithElement name={"How many times it can be used?"} nameCols={6}
elementCols={6} elementClassName={"pl-4"} errorColor={'tomato'}
Expand Down
64 changes: 53 additions & 11 deletions forms/Coupon.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,22 @@ const couponSchema = Yup.object().shape({
}),
max_discount: Yup.number().when('mode', {
is: (val) => val == "percentage",
then: Yup.number().min(1)
then: Yup.number()
.min(1, 'must be greater or eqauls to 1')
.nullable().notRequired(),
otherwise: Yup.number().nullable().notRequired()
}),
applicable_all_users: Yup.boolean()
.required("Field is required."),
active: Yup.boolean()
.required("Field is required.")
.required("Field is required."),
min_product_mrp: Yup.number()
.positive().nullable().notRequired(),
max_product_mrp: Yup.number()
.positive()
.moreThan(Yup.ref('min_product_mrp'),
"must be greater than min product mrp")
.nullable().notRequired()
});

const initialValues = {
Expand All @@ -71,7 +79,9 @@ const initialValues = {
percentage: null,
amount: null,
valid_start: Date.now(),
valid_end: new Date().setMonth(new Date().getMonth() + 1)
valid_end: new Date().setMonth(new Date().getMonth() + 1),
min_product_mrp: null,
max_product_mrp: null
}

class CouponForm extends React.Component {
Expand All @@ -94,7 +104,6 @@ class CouponForm extends React.Component {


makeEditCouponContext = () => {

return {
authority_doc: this.props.data.coupon.authority_doc,
code: this.props.data.coupon.code,
Expand All @@ -111,7 +120,9 @@ class CouponForm extends React.Component {
amount: parseInt(this.props.data.coupon.amount),
valid_start: new Date(this.props.data.coupon.valid_start),
valid_end: new Date(this.props.data.coupon.valid_end),
comment: this.props.data.coupon.comment
comment: this.props.data.coupon.comment,
min_product_mrp: this.props.data.coupon.min_product_mrp,
max_product_mrp: this.props.data.coupon.max_product_mrp
}
}

Expand Down Expand Up @@ -162,7 +173,7 @@ class CouponForm extends React.Component {

onSubmit = async (fields) => {
if (fields.amount)
if( !(await this.getProductsWithMrpLessThanDiscount(fields)) )
if( !(await this.freeProductsNotice(fields)) )
return

if (this.props.data.isEditMode) {
Expand All @@ -172,14 +183,15 @@ class CouponForm extends React.Component {
}
}

getProductsWithMrpLessThanDiscount = async (formValues) => {
freeProductsNotice = async (formValues) => {
try {
const payload = {
amount: formValues.amount,
product_ids: await this.getCouponProductIds(),
category: formValues.category,
sub_category_id: formValues.sub_category_id,
mode: formValues.mode
mode: formValues.mode,
min_product_mrp: formValues.min_product_mrp
}
const response = await controller.getProductsWithMrpLessThanDiscount(payload)
if (!response.data.length) {
Expand Down Expand Up @@ -364,8 +376,8 @@ class CouponForm extends React.Component {
{ (!this.props.data.isEverUsed && !this.props.data.isSubCategoryBulk) &&
<span id="random_coupon" className="red pull-right mt-2 ml-2"
onClick={() => setFieldValue("code", this.setRandomCouponCode())}>
Generate Random Code
</span>
Generate Random Code
</span>
}
</FieldWithElement>

Expand All @@ -374,7 +386,7 @@ class CouponForm extends React.Component {
elementClassName={"pl-4"}
errors={touched.authority_doc && errors.authority_doc}
errorColor={'tomato'}>
<textarea
<textarea
type="text"
className="input-textarea"
placeholder="Enter Description"
Expand Down Expand Up @@ -555,6 +567,36 @@ class CouponForm extends React.Component {
</div>
}

<FieldWithElement
name={"Min product Mrp"} nameCols={3} elementCols={9}
elementClassName={"pl-4"} errorColor={'tomato'}
errors={touched.min_product_mrp && errors.min_product_mrp}>
<input
type="number"
className={"input-text"}
placeholder="Enter min product price"
name="min_product_mrp"
onBlur={handleBlur}
onChange={handleChange}
value={values.min_product_mrp}
/>
</FieldWithElement>

<FieldWithElement
name={"Max product Mrp"} nameCols={3} elementCols={9}
elementClassName={"pl-4"} errorColor={'tomato'}
errors={touched.max_product_mrp && errors.max_product_mrp}>
<input
type="number"
className={"input-text"}
placeholder="Enter min product price"
name="max_product_mrp"
onBlur={handleBlur}
onChange={handleChange}
value={values.max_product_mrp}
/>
</FieldWithElement>

{/* Total number of times a coupon can be used*/}
<FieldWithElement name={"How many times it can be used?*"} nameCols={6}
elementCols={6} elementClassName={"pl-4"} errorColor={'tomato'}
Expand Down