import React from "react"; import Dialog from "@material-ui/core/Dialog"; import DialogTitle from "@material-ui/core/DialogTitle"; import DialogContent from "@material-ui/core/DialogContent"; import DialogActions from "@material-ui/core/DialogActions"; import Slide from "@material-ui/core/Slide"; import withStyles from "@material-ui/core/styles/withStyles"; import { notificationmodalwrapper } from "utils/notificationmodalwrapper"; import modalStyle from "assets/modalStyle.js"; import Button from "@material-ui/core/Button"; import IconButton from "@material-ui/core/IconButton"; import Close from "@material-ui/icons/Close"; import Input from "@material-ui/core/Input"; import Checkbox from "@material-ui/core/Checkbox"; import FormControlLabel from "@material-ui/core/FormControlLabel"; import Typography from "@material-ui/core/Typography"; import Tooltip from "@material-ui/core/Tooltip"; import axios from "axios"; function Transition(props) { return ; } let token = ""; class NotificationModal extends React.Component { componentDidMount() { console.log("load sandbox"); window.TCO.loadPubKey("sandbox"); } handleOpen = () => { this.props.onModalOpen(); }; handleClose = () => { this.props.onModalClose(); }; checkEmail = email => /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test( email ); handleEmail = e => { this.props.onUserDataChange({ info: "email", value: e.target.value }); this.props.onUserDataChange({ info: "validEmail", value: this.checkEmail(e.target.value) }); }; handleInput = (e, infoName) => { this.props.onUserDataChange({ info: infoName, value: e.target.value }); }; isChecked = optionName => Boolean(this.props.userdata[optionName]); optionChange = optionName => { const { userdata } = this.props; this.props.onUserDataChange({ info: optionName, value: !userdata[optionName] }); }; successCallback = data => { token = data.response.token.token; const { userdata: { email, last_date, olx_url } } = this.props; axios .post("/marketalerts", { email, last_date, olx_url }) .then(response => axios .post("/payforalert", { email, token }) .then(response => { this.handleClose(); alert("Market Alert Created"); }) .catch(error => console.log(error)) ) .catch(error => console.log(error)); }; errorCallback = data => { if (data.errorCode === 200) { this.tokenRequest(); } else { alert(data.errorMsg); } }; tokenRequest = () => { const { userdata: { ccNo, expYear, expMonth, cvv } } = this.props; const sellerId = "901402692"; const publishableKey = "93546B8D-B726-4376-A6DF-F698FD8893CA"; var args = { sellerId, publishableKey, ccNo, cvv, expMonth, expYear }; window.TCO.requestToken(this.successCallback, this.errorCallback, args); }; handleSaveMarketAlert = () => { this.tokenRequest(); }; render() { const { modal, classes, userdata: { validEmail } } = this.props; return (
this.handleClose()} aria-labelledby="classic-modal-slide-title" aria-describedby="classic-modal-slide-description" > this.handleClose()} >

Save Market Alert

this.optionChange("emailChecked")} /> } label={Email} /> {this.isChecked("emailChecked") ? (
this.handleInput(e, "ccNo")} /> this.handleInput(e, "expYear")} /> this.handleInput(e, "expMonth")} /> this.handleInput(e, "cvv")} />
) : null}
{validEmail ? ( ) : (
)}
); } } export default withStyles(modalStyle)( notificationmodalwrapper(NotificationModal) );