Files
old-web/frontend-react/src/components/NotificationModal.js

74 lines
1.7 KiB
JavaScript
Raw Normal View History

2019-01-16 22:06:06 +01:00
import React from "react";
import { notificationmodalwrapper } from "utils/notificationmodalwrapper";
import axios from "axios";
2019-01-16 22:06:06 +01:00
const modalStyle = function() {
let top = 20;
let left = 20;
2019-01-16 22:06:06 +01:00
return {
position: "absolute",
width: 400,
zIndex: 1040,
top: top + "%",
left: left + "%",
border: "1px solid #e5e5e5",
backgroundColor: "white",
boxShadow: "0 5px 15px rgba(0,0,0,.5)",
padding: 20
};
};
class NotificationModal extends React.Component {
handleOpen = () => {
this.props.onModalOpen();
};
handleClose = () => {
this.props.onModalClose();
};
handleInput = e => {
this.props.onUserDataChange({ info: "email", value: e.target.value });
};
handleSaveMarketAlert = () => {
const {
userdata: { email, last_date, olx_url }
} = this.props;
axios
.post("/api/marketalerts", {
email,
last_date,
olx_url
})
.then(response => console.log(response.data))
.catch(error => console.log(error));
};
2019-01-16 22:06:06 +01:00
render() {
const { modal } = this.props;
return (
<div>
<button onClick={this.handleOpen}>Open Modal</button>
<div style={modalStyle()} aria-labelledby="modal-label" hidden={!modal}>
<div>
<input
type="email"
placeholder="email"
onChange={this.handleInput}
/>
<button onClick={this.handleSaveMarketAlert}>
Save Market Alert
</button>
2019-01-16 22:06:06 +01:00
<button onClick={this.handleClose}>Close Modal</button>
</div>
</div>
</div>
);
}
}
export default notificationmodalwrapper(NotificationModal);