Guest User

Untitled

a guest
Mar 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import { connect } from 'react-redux';
  3.  
  4. import logo from './logo.svg';
  5. import ModalRoot from './ModalRoot';
  6.  
  7. import './dist/css/template.css';
  8. import './App.css';
  9.  
  10. import { showModal, hideModal } from './actions/modal'
  11.  
  12. const MESSAGE = "A redux modal component.";
  13.  
  14. const mapDispatchToProps = dispatch => ({
  15. hideModal: () => dispatch(hideModal()),
  16. showModal: (modalProps, modalType) => {
  17. dispatch(showModal({ modalProps, modalType }))
  18. }
  19. })
  20.  
  21. class App extends Component {
  22. constructor(props) {
  23. super(props)
  24. this.closeModal = this.closeModal.bind(this);
  25. this.onInputChange = this.onInputChange.bind(this);
  26. this.openAlertModal = this.openAlertModal.bind(this);
  27. this.openConfirmModal = this.openConfirmModal.bind(this);
  28. this.openDeleteModal = this.openDeleteModal.bind(this);
  29. this.openPromptModal = this.openPromptModal.bind(this);
  30. this.showInput = this.showInput.bind(this);
  31. }
  32.  
  33. closeModal(event) {
  34. this.props.hideModal();
  35. }
  36.  
  37. onInputChange(event) {
  38. this.setState({
  39. [event.target.name]: event.target.value
  40. });
  41. }
  42.  
  43. showInput(event) {
  44. console.log(this.state);
  45. }
  46.  
  47. openAlertModal(event) {
  48. this.props.showModal({
  49. open: true,
  50. title: 'Alert Modal',
  51. message: MESSAGE,
  52. closeModal: this.closeModal
  53. }, 'alert')
  54. }
  55.  
  56. openConfirmModal(event) {
  57. this.props.showModal({
  58. open: true,
  59. title: 'Confirm Modal',
  60. message: MESSAGE,
  61. confirmAction: this.closeModal,
  62. closeModal: this.closeModal
  63. }, 'confirm')
  64. }
  65.  
  66. openDeleteModal(event) {
  67. this.props.showModal({
  68. open: true,
  69. title: 'Delete Modal',
  70. message: MESSAGE,
  71. deleteAction: this.closeModal,
  72. closeModal: this.closeModal
  73. }, 'delete')
  74. }
  75.  
  76. openPromptModal(event) {
  77. this.props.showModal({
  78. open: true,
  79. title: 'Prompt Modal',
  80. fields: [{
  81. label: 'Address name',
  82. name: 'addressName',
  83. placeholder: 'Enter address name',
  84. }],
  85. onInputChange: this.onInputChange,
  86. confirmAction: this.showInput
  87. }, 'prompt')
  88. }
  89.  
  90. render() {
  91. return (
  92. <div className="App">
  93. <header className="App-header">
  94. <img src={logo} className="App-logo" alt="logo" />
  95. <h1 className="App-title">A Redux Modal Component</h1>
  96. </header>
  97. <div className="container">
  98. <div className="modal-types row d-flex justify-content-center align-items-center">
  99. <div className="col">
  100. <button
  101. className="btn btn-outline-primary btn-block"
  102. onClick={this.openAlertModal}
  103. >alert</button>
  104. </div>
  105. <div className="col">
  106. <button
  107. className="btn btn-outline-primary btn-block"
  108. onClick={this.openConfirmModal}
  109. >confirm</button>
  110. </div>
  111. <div className="col">
  112. <button
  113. className="btn btn-outline-primary btn-block"
  114. onClick={this.openDeleteModal}
  115. >delete</button>
  116. </div>
  117. <div className="col">
  118. <button
  119. className="btn btn-outline-primary btn-block"
  120. onClick={this.openPromptModal}
  121. >prompt</button>
  122. </div>
  123. </div>
  124. </div>
  125. <p className="App-intro">
  126. To get started, edit <code>src/App.js</code> and save to reload.
  127. </p>
  128. <ModalRoot />
  129. </div>
  130. );
  131. }
  132. }
  133.  
  134. export default connect(null, mapDispatchToProps)(App);
Add Comment
Please, Sign In to add comment