Skip to content

Commit 56bd221

Browse files
authored
Merge pull request #106 from coding-blocks/unstable
Unstable
2 parents 63b4c1b + 154b0ba commit 56bd221

File tree

9 files changed

+293
-105
lines changed

9 files changed

+293
-105
lines changed

controllers/products.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,12 @@ const getUserCartDetailsUrls = (data) => {
142142
}
143143

144144
const getProductBuyLinkData = (data) => {
145-
return Promise.all ([
146-
getUserCartDetailsUrls({id: data.userId}),
147-
handleCalculatePrice({
145+
return handleCalculatePrice({
148146
oneauthId: data.oneauthId,
149147
productId: data.productId,
150148
quantity: data.quantity,
151149
useCredits: data.useCredits
152150
})
153-
])
154151
}
155152

156153
module.exports = {

controllers/v2/couponsV2.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ const handleAddBulkCoupons = (data) => {
147147
return response;
148148
}
149149

150+
const fetchCouponsApplicableForAUserAndProduct = (data) => {
151+
return axios.get(`/api/v2/admin/couponsv2/userAndProductSpecificCoupons`, {params: data})
152+
}
153+
150154
export {
151155
fetchAddCouponData,
152156
generateRandomCouponCode,
@@ -163,5 +167,6 @@ export {
163167
getCodeAvailability,
164168
getAppliedCouponUsersList,
165169
fetchBulkSubCategories,
166-
handleAddBulkCoupons
170+
handleAddBulkCoupons,
171+
fetchCouponsApplicableForAUserAndProduct
167172
}

forms/BulkCoupon.js

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import FieldWithElement from '../components/FieldWithElement';
77
import * as controller from '../controllers/v2/couponsV2'
88
import Swal from 'sweetalert2';
99
import config from "../config";
10+
import Tooltip from '@material-ui/core/Tooltip';
1011

1112
const bulkCouponSchema = Yup.object().shape({
1213
authority_doc: Yup.string().min(3)
@@ -67,6 +68,9 @@ const bulkCouponSchema = Yup.object().shape({
6768
.max(Number.MAX_SAFE_INTEGER, 'entered value to large')
6869
.moreThan(Yup.ref('min_product_mrp'),
6970
"must be greater than min product mrp")
71+
.nullable().notRequired(),
72+
cashback: Yup.number()
73+
.min(1).max(100)
7074
.nullable().notRequired()
7175
});
7276

@@ -90,7 +94,8 @@ const initialValues = {
9094
valid_start: Date.now(),
9195
valid_end: new Date().setMonth(new Date().getMonth() + 1),
9296
min_product_mrp: null,
93-
max_product_mrp: null
97+
max_product_mrp: null,
98+
cashback: null
9499
}
95100

96101
class BulkCouponForm extends React.Component {
@@ -338,6 +343,8 @@ class BulkCouponForm extends React.Component {
338343
setFieldTouched("percentage", false)
339344
setFieldValue("max_discount", null)
340345
setFieldTouched("max_discount", false)
346+
setFieldValue("cashback", null)
347+
setFieldTouched("cashback", false)
341348
}}
342349
>
343350
<option value="flat">Flat</option>
@@ -373,7 +380,11 @@ class BulkCouponForm extends React.Component {
373380
placeholder="Enter Percentage"
374381
name="percentage"
375382
onBlur={handleBlur}
376-
onChange={handleChange}
383+
onChange={(e) => {
384+
handleChange(e)
385+
if (e.target.value == 100)
386+
setFieldValue("cashback" , "")
387+
}}
377388
value={values.percentage}
378389
/>
379390
</FieldWithElement>
@@ -393,6 +404,26 @@ class BulkCouponForm extends React.Component {
393404
/>
394405
</FieldWithElement>
395406

407+
<FieldWithElement
408+
name={"cashback(%)"} nameCols={3} elementCols={9}
409+
elementClassName={"pl-4"} errorColor={'tomato'}
410+
errors={touched.cashback && errors.cashback}>
411+
412+
<Tooltip title={<span className={"mui-tooltip"}>% of product price to be added as cashback</span>}
413+
placement="bottom-end">
414+
<input
415+
type="number"
416+
className={"input-text"}
417+
id={values.percentage === 100 ? "disabled-cashback" : "cashback"}
418+
placeholder="Enter cashback"
419+
name="cashback"
420+
onBlur={handleBlur}
421+
onChange={handleChange}
422+
value={values.cashback}
423+
/>
424+
</Tooltip>
425+
</FieldWithElement>
426+
396427
</div>
397428
}
398429

@@ -403,7 +434,7 @@ class BulkCouponForm extends React.Component {
403434
<input
404435
type="number"
405436
className={"input-text"}
406-
placeholder="Enter min product price"
437+
placeholder="Enter min product mrp"
407438
name="min_product_mrp"
408439
onBlur={handleBlur}
409440
onChange={handleChange}
@@ -412,20 +443,22 @@ class BulkCouponForm extends React.Component {
412443
</FieldWithElement>
413444

414445
<FieldWithElement
415-
name={"Min product Mrp"} nameCols={3} elementCols={9}
446+
name={"Max product Mrp"} nameCols={3} elementCols={9}
416447
elementClassName={"pl-4"} errorColor={'tomato'}
417448
errors={touched.max_product_mrp && errors.max_product_mrp}>
418449
<input
419450
type="number"
420451
className={"input-text"}
421-
placeholder="Enter min product price"
452+
placeholder="Enter max product mrp"
422453
name="max_product_mrp"
423454
onBlur={handleBlur}
424455
onChange={handleChange}
425456
value={values.max_product_mrp}
426457
/>
427458
</FieldWithElement>
428459

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

forms/Coupon.js

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import SelectedUsers from "../components/SelectedUsers";
1111
import config from "../config";
1212
import CouponProductsNotice from '../components/CouponProductsNotice'
1313
import withReactContent from "sweetalert2-react-content";
14+
import Tooltip from '@material-ui/core/Tooltip';
1415

1516
const ReactSwal = withReactContent(Swal);
1617

@@ -62,6 +63,9 @@ const couponSchema = Yup.object().shape({
6263
.max(Number.MAX_SAFE_INTEGER, 'entered value to large')
6364
.moreThan(Yup.ref('min_product_mrp'),
6465
"must be greater than min product mrp")
66+
.nullable().notRequired(),
67+
cashback: Yup.number()
68+
.min(1).max(100)
6569
.nullable().notRequired()
6670
});
6771

@@ -82,7 +86,8 @@ const initialValues = {
8286
valid_start: Date.now(),
8387
valid_end: new Date().setMonth(new Date().getMonth() + 1),
8488
min_product_mrp: null,
85-
max_product_mrp: null
89+
max_product_mrp: null,
90+
cashback: null
8691
}
8792

8893
class CouponForm extends React.Component {
@@ -123,7 +128,8 @@ class CouponForm extends React.Component {
123128
valid_end: new Date(this.props.data.coupon.valid_end),
124129
comment: this.props.data.coupon.comment,
125130
min_product_mrp: this.props.data.coupon.min_product_mrp,
126-
max_product_mrp: this.props.data.coupon.max_product_mrp
131+
max_product_mrp: this.props.data.coupon.max_product_mrp,
132+
cashback: this.props.data.coupon.cashback
127133
}
128134
}
129135

@@ -508,6 +514,8 @@ class CouponForm extends React.Component {
508514
setFieldTouched("percentage", false)
509515
setFieldValue("max_discount", null)
510516
setFieldTouched("max_discount", false)
517+
setFieldValue("cashback", null)
518+
setFieldTouched("cashback", false)
511519
}}
512520
value={values.mode}>
513521
<option value="flat">Flat</option>
@@ -546,7 +554,11 @@ class CouponForm extends React.Component {
546554
placeholder="Enter Percentage"
547555
name="percentage"
548556
onBlur={handleBlur}
549-
onChange={handleChange}
557+
onChange={(e) => {
558+
handleChange(e)
559+
if (e.target.value == 100)
560+
setFieldValue("cashback" , '')
561+
}}
550562
value={values.percentage}
551563
/>
552564
</FieldWithElement>
@@ -565,6 +577,28 @@ class CouponForm extends React.Component {
565577
value={values.max_discount}
566578
/>
567579
</FieldWithElement>
580+
581+
<FieldWithElement
582+
name={"cashback(%)"} nameCols={3} elementCols={9}
583+
elementClassName={"pl-4"} errorColor={'tomato'}
584+
errors={touched.cashback && errors.cashback}>
585+
586+
<Tooltip title={<span className={"mui-tooltip"}>% of product price to be added as cashback</span>}
587+
placement="bottom-end">
588+
<input
589+
type="number"
590+
className={"input-text"}
591+
id={values.percentage === 100 ? "disabled-cashback" : "cashback"}
592+
placeholder="Enter cashback"
593+
name="cashback"
594+
onBlur={handleBlur}
595+
onChange={handleChange}
596+
value={values.cashback}
597+
disabled={values.percentage === 100}
598+
/>
599+
</Tooltip>
600+
</FieldWithElement>
601+
568602
</div>
569603
}
570604

@@ -575,7 +609,7 @@ class CouponForm extends React.Component {
575609
<input
576610
type="number"
577611
className={"input-text"}
578-
placeholder="Enter min product price"
612+
placeholder="Enter min product mrp"
579613
name="min_product_mrp"
580614
onBlur={handleBlur}
581615
onChange={handleChange}
@@ -590,14 +624,16 @@ class CouponForm extends React.Component {
590624
<input
591625
type="number"
592626
className={"input-text"}
593-
placeholder="Enter min product price"
627+
placeholder="Enter max product mrp"
594628
name="max_product_mrp"
595629
onBlur={handleBlur}
596630
onChange={handleChange}
597631
value={values.max_product_mrp}
598632
/>
599633
</FieldWithElement>
600634

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

0 commit comments

Comments
 (0)