Guest User

Untitled

a guest
Jul 16th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import logo from './logo.svg';
  3. import './App.css';
  4.  
  5. class App extends Component {
  6.  
  7. constructor() {
  8. super();
  9.  
  10. this.state= {
  11. otpContent: "",
  12. input: "",
  13. tempPhone:"123",
  14. tempPin: "123456",
  15. errorMsg: ""
  16. }
  17.  
  18. this.handleChange = this.handleChange.bind(this);
  19. this.handlePhoneSubmit = this.handlePhoneSubmit.bind(this);
  20. this.handlePinSubmit = this.handlePinSubmit.bind(this);
  21. }
  22.  
  23. handleChange(e) {
  24. this.setState({[e.target.name]: e.target.value});
  25. }
  26.  
  27. phoneInput() {
  28. this.setState(
  29. {
  30. otpContent: <div>
  31. <input type="text" name="input" onChange={this.handleChange}/>
  32. <button onClick={this.handlePhoneSubmit}> Dogrula!</button>
  33. </div>
  34. }
  35. );
  36. }
  37.  
  38. handlePhoneSubmit() {
  39. if(this.state.input === this.state.tempPhone){
  40. this.setState(
  41. {
  42. input: ''
  43. }
  44. );
  45. this.pinInput();
  46.  
  47. }
  48. else {
  49. this.setState({
  50. errorMsg: "wrong phone"
  51. });
  52. }
  53. }
  54.  
  55. pinInput() {
  56. this.setState(
  57. {
  58. input: '',
  59. otpContent: (<div>
  60. <input
  61. type="text" name="input" onChange={this.handleChange}/>
  62. <button onClick={this.handlePinSubmit}> Pin Dogrula!</button>
  63. </div>)
  64. }
  65. );
  66. }
  67.  
  68. handlePinSubmit() {
  69. if(this.state.input === this.state.tempPin){
  70. this.setSuccess();
  71. }
  72. else {
  73. this.setState({
  74. errorMsg: "wrong pin"
  75. });
  76. }
  77. }
  78.  
  79. setSuccess() {
  80. this.setState(
  81. {
  82. otpContent: (<div>
  83. <h3>Success!</h3>
  84. </div>)
  85. }
  86. );
  87. }
  88.  
  89. componentDidMount() {
  90. this.phoneInput();
  91. }
  92.  
  93. render() {
  94. return (
  95. <div className="App">
  96. <header className="App-header">
  97. <img src={logo} className="App-logo" alt="logo" />
  98. <h1 className="App-title">Hi</h1>
  99. </header>
  100. <div className="App-intro">
  101. {this.state.otpContent}
  102. {this.state.errorMsg}
  103. </div>
  104. </div>
  105. );
  106. }
  107. }
  108. export default App;
Add Comment
Please, Sign In to add comment