- Generate
+ Generate Buy Link
@@ -96,7 +105,7 @@ class ProductLinkForm extends React.Component {
onClose={() => { this.props.onAutoCompleteClose('user') }}
loading={this.props.selectUserOpen && !this.props.userSearchResults.length}
value={values.user}
- onChange={(e, value) => {
+ onChange={ (e, value) => {
this.props.handleUserChange(e, value)
setFieldValue("user", value) }
}
diff --git a/pages/admin/products/generateLink.js b/pages/admin/products/generateLink.js
index 134cf54..69a7d94 100644
--- a/pages/admin/products/generateLink.js
+++ b/pages/admin/products/generateLink.js
@@ -1,5 +1,7 @@
import React from 'react'
import Head from '../../../components/head';
+import Backdrop from '@material-ui/core/Backdrop';
+import CircularProgress from '@material-ui/core/CircularProgress';
import Layout from "../../../components/layout";
import ProductLinkForm from "../../../forms/ProductLink";
import CheckLogin from "../../../components/CheckLogin";
@@ -8,8 +10,27 @@ import * as userController from '../../../controllers/users'
import ProductLinkCard from "../../../components/ProductLinkCard"
import ErrorHandler from "../../../helpers/ErrorHandler";
import Swal from 'sweetalert2';
+import { withStyles } from '@material-ui/core';
+import Table from '@material-ui/core/Table';
+import TableBody from '@material-ui/core/TableBody';
+import TableCell from '@material-ui/core/TableCell';
+import TableContainer from '@material-ui/core/TableContainer';
+import Paper from '@material-ui/core/Paper';
+import TableHead from '@material-ui/core/TableHead';
+import TableRow from '@material-ui/core/TableRow';
+import Typography from '@material-ui/core/Typography';
+const useStyles = theme => ({
+ backdrop: {
+ zIndex: theme.zIndex.drawer + 1,
+ color: '#fff',
+ },
+ title: {
+ // minWidth: 650,
+ },
+});
+
class GenerateLink extends React.Component {
constructor(props) {
@@ -28,12 +49,19 @@ class GenerateLink extends React.Component {
product:'',
user:'',
useCredits:false,
- generateLinkClicked:false
+ generatedLink: '',
+ generateLinkClicked:false,
+ activeCartIframeUrl: '',
+ purchasedProductIframeurl: '',
+ calculatedAmountDetails: '',
+ loading: false,
}
}
componentDidMount() {
- controller.fetchGenerateLinkData().then((organizations) => {
+ controller.fetchGenerateLinkData({
+ user_id: this.state.user_id
+ }).then((organizations) => {
this.setState({
organizations: organizations.data,
})
@@ -126,8 +154,10 @@ class GenerateLink extends React.Component {
handleProductChange = async (event, value) => {
this.setState({
- product: value
- });
+ product: value,
+ })
+
+ this.unsetGeneratedLink()
}
@@ -157,37 +187,90 @@ class GenerateLink extends React.Component {
}
}
- handleUserChange = (event, value) => {
+ handleUserChange = (event, value) => {
+
this.setState({
user: value,
- });
+ })
+ this.unsetGeneratedLink()
}
onApplyCreditsChange = (event) => {
this.setState({
useCredits: !JSON.parse(event.target.value)
})
+ this.unsetGeneratedLink()
+ }
+
+ ongenerateLink = (link) => {
+
+ controller.getProductBuyLinkData({
+ userId: this.state.user.id,
+ oneauthId: this.state.user.oneauth_id,
+ productId: this.state.product.id,
+ quantity: 1,
+ useCredits: this.state.useCredits
+ }).then(([ [activeCartDetails, purchasedProductDetails], calculatedAmountDetails]) => {
+ this.setState({
+ activeCartIframeUrl: activeCartDetails.data.iframeUrl,
+ purchasedProductIframeurl: purchasedProductDetails.data.iframeUrl,
+ generatedLink: link,
+ generateLinkClicked: true,
+ calculatedAmountDetails: calculatedAmountDetails.data,
+ loading: true
+ })
+ })
}
- ongenerateLinkClick = () => {
+ unsetGeneratedLink = () => {
this.setState({
- generateLinkClicked: true
+ generatedLink: '',
+ generateLinkClicked: false
})
}
+ onSendEmailClick = () => {
+ controller.sendBuyLinkEmail({
+ user_id: this.state.user.id,
+ link: this.state.generatedLink
+ }).then((response) => {
+ Swal.fire({
+ title: "Success",
+ text: "Email sent successfully!",
+ icon: "success",
+ });
+ }).catch((err) => {
+ Swal.fire({
+ type: "error",
+ title: "Error",
+ text: "Error sending email!"
+ });
+ })
+ }
+
+ hideSpinner = () => {
+ this.setState({
+ loading: false
+ });
+ };
+
render() {
+ const { classes } = this.props;
+
return (
+
+
-
-
-
Create Buy Link
-
-
-
+
+
+
+
+
+
-
+ { this.state.generateLinkClicked &&
+
- { this.state.generateLinkClicked && this.state.product && this.state.user &&
-
- }
-
+ {!this.state.loading &&
+
+
+
+
+ User Details
+
+
+
+
+
+ Name
+ Username
+ Wallet Amount
+ Oneauth Id
+ Email
+ Mobile Number
+ Address
+
+
+
+
+
+ {this.state.user.firstname} {this.state.user.lastname}
+
+ {this.state.user.username}
+ {this.state.user.wallet_amount /100}
+ {this.state.user.oneauth_id}
+ {this.state.user.email}
+ {this.state.user.mobile_number}
+ {this.state.user.permanent_address}
+
+
+
+
+
+ }
+
+
+
+
+
+
+
+
+
+
+ {!this.state.loading &&
+
+ }
+
+
+
+ }
+
)
}
}
-export default GenerateLink
+export default withStyles(useStyles)(GenerateLink)