Skip to content

Commit 117bc93

Browse files
authored
Merge pull request #112 from coding-blocks/unstable
Unstable
2 parents d947edf + 1174640 commit 117bc93

File tree

6 files changed

+264
-38
lines changed

6 files changed

+264
-38
lines changed

components/ProductLinkCard.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import Typography from '@material-ui/core/Typography';
2323

2424

2525
const ProductLinkCard = ({ link, product, user, onSendEmailClick, calculatedAmountDetails }) => {
26-
26+
2727
const [open, setOpen] = React.useState(false);
2828

2929
const handleClick = () => {
@@ -45,7 +45,9 @@ const ProductLinkCard = ({ link, product, user, onSendEmailClick, calculatedAmo
4545

4646
<TableContainer>
4747
<Typography className={"ml-5 mt-2"} variant="h5" id="tableTitle" component="div">
48-
<b> {product.description} </b>
48+
<b> Buy Link </b>
49+
<br/>
50+
<p className={"red"}>{product.description}</p>
4951
</Typography>
5052

5153
<Table aria-label="simple table">
@@ -65,11 +67,11 @@ const ProductLinkCard = ({ link, product, user, onSendEmailClick, calculatedAmo
6567
<TableCell component="th" scope="row" align="center">
6668
{product.name}
6769
</TableCell>
68-
<TableCell align="center">{product.mrp / 100}</TableCell>
70+
<TableCell align="center">{calculatedAmountDetails.productMrp / 100}</TableCell>
6971
<TableCell align="center">{calculatedAmountDetails.discount / 100}</TableCell>
7072
<TableCell align="center">{calculatedAmountDetails.tax /100}</TableCell>
71-
<TableCell align="center">{calculatedAmountDetails.creditsApplied /100 }</TableCell>
72-
<TableCell align="center" className={"red"}>{calculatedAmountDetails.amount /100}</TableCell>
73+
<TableCell align="center">{calculatedAmountDetails.applicableCredits /100 }</TableCell>
74+
<TableCell align="center" className={"red"}>{calculatedAmountDetails.amountPayable /100}</TableCell>
7375
<TableCell align="center" className={"red"}><b>{product.type}</b></TableCell>
7476
</TableRow>
7577
</TableBody>

controllers/products.js

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

144144
const getProductBuyLinkData = (data) => {
145-
return handleCalculatePrice({
146-
oneauthId: data.oneauthId,
147-
productId: data.productId,
148-
quantity: data.quantity,
149-
useCredits: data.useCredits
150-
})
145+
if (!data.coupon)
146+
delete data.coupon
147+
148+
return handleCalculatePrice(data)
151149
}
152150

153151
module.exports = {

controllers/v2/couponsV2.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ const fetchCouponsApplicableForAUserAndProduct = (data) => {
151151
return axios.get(`/api/v2/admin/couponsv2/userAndProductSpecificCoupons`, {params: data})
152152
}
153153

154+
const handleAddCustomCoupon = (data) => {
155+
return axios.post(`/api/v2/admin/couponsv2/addCustomCoupon`, data)
156+
}
157+
154158
export {
155159
fetchAddCouponData,
156160
generateRandomCouponCode,
@@ -168,5 +172,6 @@ export {
168172
getAppliedCouponUsersList,
169173
fetchBulkSubCategories,
170174
handleAddBulkCoupons,
171-
fetchCouponsApplicableForAUserAndProduct
175+
fetchCouponsApplicableForAUserAndProduct,
176+
handleAddCustomCoupon
172177
}

forms/CustomCoupon.js

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
import React from 'react'
2+
import Button from '@material-ui/core/Button';
3+
import { Formik, Field, Form, ErrorMessage } from 'formik';
4+
import FormControl from "@material-ui/core/FormControl";
5+
import Grid from "@material-ui/core/Grid";
6+
import TextField from '@material-ui/core/TextField';
7+
import Tooltip from '@material-ui/core/Tooltip';
8+
import * as Yup from 'yup';
9+
import jwt from "jsonwebtoken";
10+
import Cookies from 'js-cookie';
11+
12+
const CustomCouponForm = ({handleAddCustomCoupon}) => {
13+
14+
const initialValues = {
15+
percentage: '',
16+
expiration: ''
17+
}
18+
19+
const admin_discount_limit = () => {
20+
const dukaanToken = Cookies.get("dukaan-token");
21+
const userInfo = jwt.decode(dukaanToken);
22+
return userInfo.data.admin_discount_limit
23+
}
24+
25+
const validationSchema = Yup.object().shape({
26+
percentage: Yup.number()
27+
.min(1, 'must be greater than 0')
28+
.max( admin_discount_limit() ? admin_discount_limit() : 100)
29+
.required('Discount is required'),
30+
expiration: Yup.number()
31+
.min(1).max(48)
32+
.required('Coupon Expiration is required')
33+
})
34+
35+
const handleAddCoupon = (formFields) => {
36+
handleAddCustomCoupon(formFields)
37+
}
38+
39+
return (
40+
41+
<div>
42+
{ !admin_discount_limit()
43+
44+
? <div className={"d-flex align-items-center justify-content-center red"}>
45+
<b>*You dont have permission to add custom discount. *</b>
46+
</div>
47+
48+
: <Formik initialValues={initialValues} validationSchema={validationSchema}
49+
onSubmit={handleAddCoupon}>
50+
51+
{({values, errors, touched, handleChange, handleBlur, handleSubmit, isSubmitting
52+
, setFieldValue, setFieldTouched}) => (
53+
54+
55+
56+
57+
<form onSubmit={handleSubmit}>
58+
<div className={"col-md-12"}>
59+
60+
61+
62+
<FormControl variant="outlined" size={"medium"}
63+
className={"col-md-8 mb-4 mt-3"}
64+
>
65+
<Tooltip title={<span className={"mui-tooltip"}>Discount as percentage</span>}
66+
placement="bottom-end">
67+
68+
<TextField name="percentage"
69+
type="number"
70+
label="Discount"
71+
variant="outlined"
72+
placeholder="Enter Discount in percentage"
73+
value={values.percentage}
74+
onBlur={handleBlur}
75+
onChange={handleChange}
76+
/>
77+
78+
</Tooltip>
79+
80+
{errors.percentage && touched.percentage && <span className="red mt-2 ml-auto">
81+
{errors.percentage}
82+
</span>}
83+
84+
</FormControl>
85+
86+
<FormControl variant="outlined" size={"medium"}
87+
className={"col-md-8 mb-4"}>
88+
<Tooltip title={<span className={"mui-tooltip"}>Expiration in hours</span>}
89+
placement="bottom-end">
90+
91+
<TextField name="expiration"
92+
type="number"
93+
label="Expiration"
94+
variant="outlined"
95+
placeholder="Enter Expiration in hours"
96+
value={values.expiration}
97+
onBlur={handleBlur}
98+
onChange={handleChange}
99+
inputProps={{
100+
maxLength: 4
101+
}}
102+
/>
103+
</Tooltip>
104+
105+
{errors.expiration && touched.expiration && <span className="red mt-2 ml-auto">
106+
{errors.expiration}
107+
</span>}
108+
109+
</FormControl>
110+
111+
112+
<Grid container justify="center">
113+
<Button
114+
id="submitBtn" type="submit"
115+
style={{background: "linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)" , color: 'white', border: 0,
116+
borderRadius: 3, boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)'}}>
117+
Save
118+
</Button>
119+
</Grid>
120+
121+
</div>
122+
</form>
123+
)}
124+
125+
</Formik>
126+
127+
}
128+
</div>
129+
130+
131+
132+
);
133+
}
134+
135+
export default CustomCouponForm

forms/ProductLink.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import Checkbox from "@material-ui/core/Checkbox";
66
import CheckBoxOutlineBlankIcon from '@material-ui/icons/CheckBoxOutlineBlank';
77
import CheckBoxIcon from '@material-ui/icons/CheckBox';
88
import config from "../config";
9-
import ErrorHandler from "../helpers/ErrorHandler";
109
import FormControl from "@material-ui/core/FormControl";
1110
import FormControlLabel from '@material-ui/core/FormControlLabel';
12-
import {Formik, Field} from 'formik';
11+
import { Formik, Field} from 'formik';
1312
import Grid from "@material-ui/core/Grid";
1413
import InputLabel from "@material-ui/core/InputLabel";
1514
import MenuItem from "@material-ui/core/MenuItem";
1615
import Select from "@material-ui/core/Select";
16+
import Swal from "sweetalert2";
1717
import Switch from '@material-ui/core/Switch';
1818
import TextField from '@material-ui/core/TextField';
1919
import { withStyles } from '@material-ui/core';
@@ -60,6 +60,7 @@ class ProductLinkForm extends React.Component {
6060

6161
constructor(props) {
6262
super(props)
63+
this.formik = React.createRef();
6364
}
6465

6566
generateLink = (fields) => {
@@ -79,10 +80,14 @@ class ProductLinkForm extends React.Component {
7980
this.props.ongenerateLink(link)
8081
}
8182

82-
render() {
83+
handleCustomCouponCreation = (coupon) => {
84+
this.formik.current.setFieldValue("category", coupon.category)
85+
this.formik.current.setFieldValue("coupon", coupon)
86+
this.props.handleCategoryChange(coupon.category)
87+
}
8388

89+
render() {
8490
const { classes } = this.props;
85-
8691
return (
8792
<div className={"d-flex col-md-11 offset-1 mt-5"}>
8893
<div className={"border-card"}>
@@ -93,7 +98,7 @@ class ProductLinkForm extends React.Component {
9398
</div>
9499

95100
<Formik initialValues={initialValues} validationSchema={ProductLinkSchema}
96-
onSubmit={this.generateLink}>
101+
onSubmit={this.generateLink} ref={this.formik}>
97102

98103
{({values, errors, touched, handleChange, handleBlur, handleSubmit, isSubmitting
99104
, setFieldValue, setFieldTouched}) => (
@@ -300,10 +305,12 @@ class ProductLinkForm extends React.Component {
300305
<Select
301306
value={values.category}
302307
name={"category"}
308+
id="category"
303309
label="Coupon category"
304310
onChange={(e) => {
305-
this.props.handleCategoryChange(e)
311+
this.props.handleCategoryChange(e.target.value)
306312
setFieldValue("category", e.target.value)
313+
setFieldValue("coupon", '')
307314
}}
308315
disabled={!this.props.product || !this.props.user}
309316
>
@@ -327,6 +334,7 @@ class ProductLinkForm extends React.Component {
327334
options={this.props.coupons}
328335
value={values.coupon}
329336
onChange={ (e, value) => {
337+
this.props.handleCouponChange(value)
330338
setFieldValue("coupon", value)
331339
}}
332340
getOptionLabel={(option) => {
@@ -343,7 +351,14 @@ class ProductLinkForm extends React.Component {
343351
variant="outlined" />
344352
}
345353
/>
346-
354+
355+
{values.user && values.product &&
356+
<span id="generateCoupon" className="red pull-right mt-3 ml-auto"
357+
style={{cursor: "pointer"}} onClick={() => this.props.onCustomCouponClick() }>
358+
ADD CUSTOM DISCOUNT
359+
</span>
360+
}
361+
347362
</FormControl>
348363

349364

0 commit comments

Comments
 (0)