Skip to content

Commit 45deb02

Browse files
author
JasmeetLuthra
committed
coupon functionality added in buy link
1 parent 63b4c1b commit 45deb02

File tree

3 files changed

+152
-6
lines changed

3 files changed

+152
-6
lines changed

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/ProductLink.js

Lines changed: 107 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ const initialValues = {
5252
product: '',
5353
user: '',
5454
applyCredits: false,
55+
category: '',
56+
sub_category_id: '',
57+
coupon: ''
5558
}
5659

5760
class ProductLinkForm extends React.Component {
@@ -69,7 +72,13 @@ class ProductLinkForm extends React.Component {
6972
if (fields.applyCredits)
7073
useCreditsQueryParams = '&useCredits=true'
7174

72-
const link = `https://dukaan.codingblocks.com/buy?productId=${productId}&oneauthId=${oneauthId}${useCreditsQueryParams}`
75+
let couponQueryParams = ''
76+
if (fields.coupon)
77+
couponQueryParams = `&coupon=${fields.coupon}`
78+
79+
const link = `https://dukaan.codingblocks.com/buy?productId=${productId}&oneauthId=${oneauthId}${useCreditsQueryParams}
80+
${couponQueryParams}`
81+
7382
this.props.ongenerateLink(link)
7483
}
7584

@@ -107,8 +116,11 @@ class ProductLinkForm extends React.Component {
107116
value={values.user}
108117
onChange={ (e, value) => {
109118
this.props.handleUserChange(e, value)
110-
setFieldValue("user", value) }
111-
}
119+
setFieldValue("user", value)
120+
setFieldValue("category", '')
121+
setFieldValue("sub_category_id", '')
122+
setFieldValue("coupon", '')
123+
}}
112124
getOptionLabel={(option) => {
113125
return option.email
114126
}}
@@ -232,8 +244,11 @@ class ProductLinkForm extends React.Component {
232244
loading={this.props.selectProductOpen && !this.props.productSearchResults.length}
233245
onChange={(e, value) => {
234246
this.props.handleProductChange(e, value)
235-
setFieldValue("product", value) }
236-
}
247+
setFieldValue("product", value)
248+
setFieldValue("category", '')
249+
setFieldValue("sub_category_id", '')
250+
setFieldValue("coupon", '')
251+
}}
237252
value={values.product}
238253
getOptionLabel={(option) => {
239254
return option.description
@@ -281,6 +296,93 @@ class ProductLinkForm extends React.Component {
281296

282297
</FormControl>
283298

299+
300+
<FormControl variant="outlined" size={"medium"}
301+
fullWidth={true} className={"mb-4"}>
302+
<InputLabel id="category">Coupon category</InputLabel>
303+
304+
<Select
305+
value={values.category}
306+
name={"category"}
307+
label="Coupon category"
308+
onChange={(e) => {
309+
this.props.handleCategoryChange(e)
310+
setFieldValue("category", e.target.value)
311+
setFieldValue("sub_category_id", '')
312+
313+
}}
314+
disabled={!this.props.product || !this.props.user}
315+
>
316+
317+
<MenuItem value="">
318+
<em>Select</em>
319+
</MenuItem>
320+
<MenuItem value="special_discount"> Special Discount </MenuItem>
321+
<MenuItem value="telecounselor"> Telecounselor </MenuItem>
322+
</Select>
323+
</FormControl>
324+
325+
326+
<FormControl variant="outlined" size={"medium"}
327+
fullWidth={true} className={"mb-4"}>
328+
<InputLabel id="sub_category_id">Coupon sub category</InputLabel>
329+
330+
<Select
331+
value={values.sub_category_id}
332+
name={"Sub Category"}
333+
label="Coupon sub category"
334+
onChange={(e) => {
335+
this.props.handleSubCategoryChange(values.category, e.target.value)
336+
setFieldValue("sub_category_id", e.target.value)
337+
}}>
338+
339+
<MenuItem value="">
340+
<em>Select</em>
341+
</MenuItem>
342+
343+
{
344+
this.props.subCategories.map((subCategory) => {
345+
return (
346+
<MenuItem key={subCategory.id}
347+
value={subCategory.id}>
348+
{subCategory.name}
349+
</MenuItem>
350+
)
351+
})
352+
}
353+
</Select>
354+
</FormControl>
355+
356+
357+
<FormControl variant="outlined" size={"medium"}
358+
fullWidth={true} className={"mb-4"}>
359+
<InputLabel id="coupon">Coupon</InputLabel>
360+
361+
<Select
362+
value={values.coupon}
363+
name={"coupon"}
364+
label="coupon"
365+
onChange={handleChange}>
366+
367+
<MenuItem value="">
368+
<em>Select</em>
369+
</MenuItem>
370+
371+
{
372+
this.props.coupons.map((coupon) => {
373+
return (
374+
<MenuItem key={coupon.id}
375+
value={coupon.code}>
376+
{coupon.code}
377+
</MenuItem>
378+
)
379+
})
380+
}
381+
</Select>
382+
</FormControl>
383+
384+
385+
284386
<FormControlLabel
285387
className={"mb-4"}
286388
control={

pages/admin/products/generateLink.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import ProductLinkForm from "../../../forms/ProductLink";
77
import CheckLogin from "../../../components/CheckLogin";
88
import * as controller from '../../../controllers/products'
99
import * as userController from '../../../controllers/users'
10+
import * as couponController from '../../../controllers/v2/couponsV2'
1011
import ProductLinkCard from "../../../components/ProductLinkCard"
1112
import ErrorHandler from "../../../helpers/ErrorHandler";
1213
import Swal from 'sweetalert2';
@@ -55,6 +56,8 @@ class GenerateLink extends React.Component {
5556
purchasedProductIframeurl: '',
5657
calculatedAmountDetails: '',
5758
loading: false,
59+
subCategories: [],
60+
coupons: []
5861
}
5962
}
6063

@@ -155,6 +158,8 @@ class GenerateLink extends React.Component {
155158
handleProductChange = async (event, value) => {
156159
this.setState({
157160
product: value,
161+
subCategories: [],
162+
coupons: []
158163
})
159164

160165
this.unsetGeneratedLink()
@@ -191,6 +196,8 @@ class GenerateLink extends React.Component {
191196

192197
this.setState({
193198
user: value,
199+
subCategories: [],
200+
coupons: []
194201
})
195202
this.unsetGeneratedLink()
196203
}
@@ -202,6 +209,36 @@ class GenerateLink extends React.Component {
202209
this.unsetGeneratedLink()
203210
}
204211

212+
213+
fillSubCategories = (data) => {
214+
couponController.fetchSubCategories(data).then((subCategories) => {
215+
this.setState({
216+
subCategories: subCategories.data
217+
})
218+
}).catch((error) => {
219+
ErrorHandler.handle(error)
220+
})
221+
};
222+
223+
handleCategoryChange = (event) => {
224+
this.fillSubCategories({category: event.target.value})
225+
}
226+
227+
handleSubCategoryChange = (category, subCategoryId) => {
228+
couponController.fetchCouponsApplicableForAUserAndProduct({
229+
user_id: this.state.user.id,
230+
product_id: this.state.product.id,
231+
category: category,
232+
sub_category_id: subCategoryId
233+
}).then((response) => {
234+
this.setState({
235+
coupons: response.data
236+
})
237+
}).catch((error) => {
238+
ErrorHandler.handle(error)
239+
})
240+
}
241+
205242
ongenerateLink = (link) => {
206243

207244
controller.getProductBuyLinkData({
@@ -282,6 +319,8 @@ class GenerateLink extends React.Component {
282319
handleProductChange={this.handleProductChange}
283320
onApplyCreditsChange={this.onApplyCreditsChange}
284321
ongenerateLink={this.ongenerateLink}
322+
handleCategoryChange={this.handleCategoryChange}
323+
handleSubCategoryChange={this.handleSubCategoryChange}
285324
/>
286325
</div>
287326

0 commit comments

Comments
 (0)