Guest User

Untitled

a guest
Oct 21st, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. import React, { Component, Fragment } from "react";
  2. import styles from "./styles.css";
  3. import { HashRouter as Router, Link } from "react-router-dom";
  4. import api from "../../../services/api";
  5. import Button from "@material-ui/core/Button";
  6. import PropTypes from "prop-types";
  7. import Table from "@material-ui/core/Table";
  8. import TableBody from "@material-ui/core/TableBody";
  9. import TableCell from "@material-ui/core/TableCell";
  10. import TableHead from "@material-ui/core/TableHead";
  11. import TableRow from "@material-ui/core/TableRow";
  12. import Paper from "@material-ui/core/Paper";
  13. import { withStyles } from "@material-ui/core/styles";
  14.  
  15. import TextField from '@material-ui/core/TextField';
  16. import Dialog from '@material-ui/core/Dialog';
  17. import DialogActions from '@material-ui/core/DialogActions';
  18. import DialogContent from '@material-ui/core/DialogContent';
  19. import DialogContentText from '@material-ui/core/DialogContentText';
  20. import DialogTitle from '@material-ui/core/DialogTitle';
  21.  
  22. class AddIgAccount extends React.Component {
  23. constructor(props) {
  24. super(props)
  25. this.handleClickOpen = this.handleClickOpen.bind(this)
  26. this.handleClose = this.handleClose.bind(this)
  27. this.handleChangeValue = this.handleChangeValue.bind(this)
  28. }
  29. state = {
  30. open: false,
  31. };
  32.  
  33. handleClickOpen = () => {
  34. this.setState({ open: true });
  35. };
  36.  
  37. handleClose = () => {
  38. this.setState({ open: false });
  39. };
  40.  
  41. handleChangeValue = (event) => {
  42. console.log(this.props)
  43. if (event.target.name === 'ig_username') {
  44. this.props.new_username = event.target.value
  45. } else if (event.target.name === 'ig_password') {
  46. // this.setState({
  47. // // this.props.password: event.target.value
  48. // })
  49. }
  50. }
  51.  
  52.  
  53. render() {
  54. return (
  55. <div>
  56. <Button onClick={this.handleClickOpen}>Add Instagram Account</Button>
  57. <Dialog
  58. open={this.state.open}
  59. onClose={this.handleClose}
  60. aria-labelledby="form-dialog-title">
  61. <DialogTitle id="form-dialog-title">Add Instagram Account</DialogTitle>
  62. <DialogContent>
  63. <TextField id="username" name="ig_username" onChange={event => this.handleChangeValue(event)}autoFocus type="text" margin="dense" />
  64. <TextField id="password" name="ig_password" onChange={event => this.handleChangeValue(event)} type="password" margin="dense" fullWidth />
  65. </DialogContent>
  66. <DialogActions>
  67. <Button onClick={this.props.triggerCreateIgAccount} color="primary">
  68. Add
  69. </Button>
  70. <Button onClick={this.handleClose} color="primary">
  71. Cancel
  72. </Button>
  73. </DialogActions>
  74. </Dialog>
  75. </div>
  76. );
  77. }
  78. }
  79.  
  80.  
  81. export default class InstagramAccounts extends React.Component {
  82. constructor(props) {
  83. super(props);
  84. this.state = {
  85. data: [],
  86. new_username: [],
  87. password: []
  88. };
  89. this.loadUsernames = this.loadUsernames.bind(this)
  90. // this.createIgAccount = this.createIgAccount.bind(this)
  91. }
  92.  
  93. componentDidMount() {
  94. this.loadUsernames()
  95. // this.createIgAccount()
  96. }
  97.  
  98. componentWillUnmount() {
  99. this.loadUsernames()
  100. // this.createIgAccount()
  101. }
  102.  
  103. loadUsernames = async () => {
  104. const response = await api.get("/get_usernames");
  105. this.setState({
  106. data: response.data.data
  107. });
  108. };
  109.  
  110. createIgAccount = async () => {
  111. console.log('chamou chamou!')
  112. // console.log(this.state.username)
  113. // console.log(this.state.password)
  114. // const response = await api.post('/create_ig_account', {
  115. // username: this.state.username,
  116. // password: this.state.password
  117. // })
  118. }
  119.  
  120. render() {
  121. let rows = this.state.data.map(username => {
  122. return <Usernames key={username.id} data={username} />;
  123. });
  124. return (
  125. <Fragment>
  126. <div className={styles.sidebar}>
  127. <Paper>
  128. <Table>
  129. <TableHead>
  130. <TableRow>
  131. <TableCell>id</TableCell>
  132. <TableCell>username</TableCell>
  133. <TableCell>created</TableCell>
  134. </TableRow>
  135. </TableHead>
  136. <TableBody>{rows}</TableBody>
  137. </Table>
  138. </Paper>
  139. <br/>
  140. <AddIgAccount triggerCreateIgAccount={this.createIgAccount} new_username={this.new_username} />
  141. </div>
  142. </Fragment>
  143. );
  144. }
  145. }
  146.  
  147. const Usernames = props => {
  148. return (
  149. <TableRow>
  150. <TableCell>{props.data.id}</TableCell>
  151. <TableCell>{props.data.username}</TableCell>
  152. <TableCell>{props.data.created}</TableCell>
  153. </TableRow>
  154. );
  155. };
Add Comment
Please, Sign In to add comment