Advertisement
Guest User

Untitled

a guest
Dec 19th, 2018
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.93 KB | None | 0 0
  1. import React from "react";
  2. import withStyles from "@material-ui/core/styles/withStyles";
  3. import DialogActions from "@material-ui/core/DialogActions";
  4. import InputAdornment from "@material-ui/core/InputAdornment";
  5. import { OldSocialLogin as SocialLogin } from 'react-social-login';
  6. import Icon from "@material-ui/core/Icon";
  7. import Close from "@material-ui/icons/Close";
  8. import Mail from "@material-ui/icons/Mail";
  9. import Button from "components/CustomButtons/Button.jsx";
  10. import { NavLink } from "reactstrap";
  11. import CardBody from "components/Card/CardBody.jsx";
  12. import CustomInput from "components/CustomInput/CustomInput.jsx";
  13. import { Link } from "react-router-dom";
  14. import javascriptStyles from "assets/jss/material-kit-pro-react/views/componentsSections/javascriptStyles.jsx";
  15. import GridItem from "components/Grid/GridItem.jsx";
  16. import serviceUser from "../../services/ServiceUser";
  17. import LoginNotification from "components/Loginpopup/LoginNotification.jsx";
  18. import SnackBar from "../../components/Snackbar/SnackbarContent";
  19. import "assets/css/components/Loginpopup/Loginpopup.css";
  20.  
  21.  
  22. class LoginPopUp extends React.Component {
  23. constructor(props) {
  24. super(props);
  25. this.state = {
  26. loginModal: false,
  27. email: "",
  28. password: "",
  29. notificationOpen: false,
  30. notificationTitle: null,
  31. notificationMessage: null,
  32. checked: false,
  33. status: null
  34. };
  35. this.handleToggle = this.handleToggle.bind(this);
  36. }
  37.  
  38.  
  39. handleToggle(value) {
  40. this.setState({
  41. checked: this.state.checked ? false : true
  42. });
  43. };
  44.  
  45. handleEmail = event => {
  46. this.setState({
  47. email: event.target.value
  48. });
  49. };
  50.  
  51. handlePassword = event => {
  52. this.setState({
  53. password: event.target.value
  54. });
  55. };
  56.  
  57. login = () => {
  58. const user = {
  59. email: this.state.email,
  60. password: this.state.password
  61. };
  62. serviceUser
  63. .apiLogin(user)
  64. .then(response => {
  65. localStorage.setItem("token", response.data);
  66. window.location.reload();
  67. this.setState({
  68. status: {
  69. success: true,
  70. message: "Login berhasil"
  71. }
  72. })
  73. })
  74. .catch(error => {
  75. // alert(error.data.message);
  76. this.setState({
  77. status: {
  78. success: false,
  79. message: error.data.message
  80. }
  81. })
  82. });
  83. };
  84.  
  85. loginSosmed = (user, err) => {
  86. const params = {
  87. platformId: user._profile.id
  88. }
  89. console.log(err)
  90. serviceUser.apiLogin(params).then(response => {
  91. localStorage.setItem("token", response.data);
  92. window.location.reload();
  93. this.setState({
  94. status: {
  95. success: true,
  96. message: "Login berhasil"
  97. }
  98. })
  99. })
  100. .catch(error => {
  101. alert(error.data.message);
  102. this.setState({
  103. status: {
  104. success: false,
  105. message: error.data.message
  106. }
  107. })
  108. });
  109. }
  110.  
  111. handleClose() {
  112. this.props.handleClose();
  113. }
  114.  
  115. handleNotificationClose() {
  116. this.setState({
  117. open: true,
  118. notificationOpen: !this.state.notificationOpen
  119. });
  120. }
  121.  
  122. render() {
  123. const { email, password } = this.state;
  124. const isEnabled = email.length > 0 && password.length > 0;
  125. const open = this.props.open;
  126. const { classes } = this.props;
  127. return (
  128. <div>
  129. <div className={"modal fade in " + (open ? "show" : "")}>
  130. <div className="modal-dialog">
  131. <div className="modal-content">
  132. <GridItem md={12}>
  133. <p
  134. className="modal-button-close-loginpopup"
  135. onClick={this.handleClose.bind(this)}
  136. >
  137. <Close className={classes.modalClose} />
  138. </p>
  139. </GridItem>
  140. <div className="modal-body">
  141. <h4 className="typography-title">Log In</h4>
  142. <div className={classes.socialLine}>
  143. <SocialLogin
  144. provider='facebook'
  145. appId='2144052345912887'
  146. callback={this.loginSosmed}>
  147.  
  148. <Button justIcon link>
  149. <i className="fab fa-facebook-square" />
  150. </Button>
  151.  
  152. </SocialLogin>
  153. <SocialLogin
  154. provider='google'
  155. appId='615585105258-0bokifsov91evfhuhjst3qnlc3ab1gvl.apps.googleusercontent.com'
  156. callback={this.loginSosmed}>
  157.  
  158. <Button justIcon link>
  159. <i className="fab fa-google-plus-g" />
  160. </Button>
  161.  
  162. </SocialLogin>
  163. </div>
  164. <p className={`${classes.description} ${classes.textCenter}`}>
  165. atau
  166. </p>
  167. <form onSubmit={this.handdleSubmit}>
  168. <CardBody className={classes.cardLoginBody}>
  169. <CustomInput
  170. id="login-modal-email"
  171. formControlProps={{
  172. fullWidth: true
  173. }}
  174. inputProps={{
  175. onChange: this.handleEmail,
  176. startAdornment: (
  177. <InputAdornment position="start">
  178. <Mail className={classes.icon} />
  179. </InputAdornment>
  180. ),
  181. placeholder: "Email..."
  182. }}
  183. />
  184. <CustomInput
  185. id="login-modal-pass"
  186. formControlProps={{
  187. fullWidth: true
  188. }}
  189. inputProps={{
  190. type: "password",
  191. onChange: this.handlePassword,
  192. startAdornment: (
  193. <InputAdornment position="start">
  194. <Icon className={classes.icon}>lock_outline</Icon>
  195. </InputAdornment>
  196. ),
  197. placeholder: "Password..."
  198. }}
  199. />
  200. </CardBody>
  201. <p style={{ textAlign: "left", paddingLeft: "20px" }}>
  202. <a href="/resetpassword">lupa password ?</a>
  203. </p>
  204. {
  205. this.state.status != null && <CardBody>
  206. <SnackBar
  207. classes={classes}
  208. color={this.state.status.success ? "success" : "danger"}
  209. close={true}
  210. message={
  211. <span>
  212. <b>{this.state.status.success ? "Berhasil" : "Gagal"}</b> {this.state.status.message}
  213. </span>
  214. }
  215. />
  216. </CardBody>
  217.  
  218. }
  219. <DialogActions
  220. className={`${classes.modalFooter} ${
  221. classes.justifyContentCenter
  222. }`}
  223. >
  224. <Button onClick={this.login} disabled={!isEnabled} justButton>
  225. Login
  226. </Button>
  227.  
  228. </DialogActions>
  229. </form>
  230. <p className={`${classes.description} ${classes.textCenter}`}>
  231. Belum punya Akun MonggoPesen ?{" "}
  232. <NavLink tag={Link} to="/signup">
  233. Daftar Sekarang
  234. </NavLink>
  235. </p>
  236. </div>
  237. </div>
  238. </div>
  239. </div>
  240. <div className="modal-backdrop fade show" />
  241. </div>
  242. );
  243. }
  244. }
  245.  
  246. export default withStyles(javascriptStyles)(LoginPopUp);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement