diff --git a/forms/BulkCoupon.js b/forms/BulkCoupon.js index 4daacad..31e80e7 100644 --- a/forms/BulkCoupon.js +++ b/forms/BulkCoupon.js @@ -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 = { @@ -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 { @@ -386,6 +395,36 @@ class BulkCouponForm extends React.Component { } + + + + + + + + {/* Total number of times a coupon can be used*/} 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 = { @@ -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 { @@ -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, @@ -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 } } @@ -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) { @@ -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) { @@ -364,8 +376,8 @@ class CouponForm extends React.Component { { (!this.props.data.isEverUsed && !this.props.data.isSubCategoryBulk) && setFieldValue("code", this.setRandomCouponCode())}> - Generate Random Code - + Generate Random Code + } @@ -374,7 +386,7 @@ class CouponForm extends React.Component { elementClassName={"pl-4"} errors={touched.authority_doc && errors.authority_doc} errorColor={'tomato'}> -