@@ -5,7 +5,7 @@ import CircularProgress from '@material-ui/core/CircularProgress';
55import Checkbox from "@material-ui/core/Checkbox" ;
66import CheckBoxOutlineBlankIcon from '@material-ui/icons/CheckBoxOutlineBlank' ;
77import CheckBoxIcon from '@material-ui/icons/CheckBox' ;
8- import config from " ../config" ;
8+ import * as controller from ' ../controllers/buyLink'
99import FormControl from "@material-ui/core/FormControl" ;
1010import FormControlLabel from '@material-ui/core/FormControlLabel' ;
1111import { Formik , Field } from 'formik' ;
@@ -65,24 +65,22 @@ class ProductLinkForm extends React.Component {
6565 }
6666
6767 generateLink = ( fields ) => {
68- const productId = fields . product . id
69- const oneauthId = fields . user . oneauth_id
7068
71- let useCreditsQueryParams = ''
72- if ( fields . applyCredits )
73- useCreditsQueryParams = '&useCredits=true'
74-
75- let couponQueryParams = ''
76- if ( fields . coupon )
77- couponQueryParams = `&coupon= ${ fields . coupon . code } `
78-
79- let stateQueryParams = ''
80- if ( fields . state )
81- stateQueryParams = `&state= ${ fields . state } `
82-
83- const link = `https://dukaan.codingblocks.com/buy?productId= ${ productId } &oneauthId= ${ oneauthId } ${ useCreditsQueryParams } ${ couponQueryParams } ${ stateQueryParams } `
84-
85- this . props . ongenerateLink ( link )
69+ controller . handleAddBuyLink ( {
70+ user_id : fields . user . id ,
71+ product_id : fields . product . id ,
72+ coupon_id : fields . coupon ? fields . coupon . id : '' ,
73+ use_credits : fields . applyCredits ,
74+ state_id : fields . state ,
75+ } ) . then ( ( response ) => {
76+ this . props . ongenerateLink ( response . data . short_url )
77+ } ) . catch ( ( error ) => {
78+ Swal . fire ( {
79+ title : "Error while creating link!" ,
80+ type : "error" ,
81+ text : error
82+ } ) ;
83+ } ) ;
8684 }
8785
8886 handleCustomCouponCreation = ( coupon ) => {
@@ -388,7 +386,7 @@ class ProductLinkForm extends React.Component {
388386 return (
389387 < MenuItem
390388 key = { state . id }
391- value = { state . state_code } > {
389+ value = { state . id } > {
392390 state . name
393391 } </ MenuItem >
394392 )
0 commit comments