Advertisement
Guest User

Untitled

a guest
Oct 9th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.41 KB | None | 0 0
  1. import React, {Component} from 'react';
  2. import {connect} from "react-redux";
  3.  
  4. import {
  5. retrieveUser,
  6. selectionUser,
  7. getAllUsers
  8. } from "../../actions/users";
  9.  
  10. import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
  11.  
  12. //import { Grid, Col } from 'react-bootstrap';
  13. import BootstrapTable from 'react-bootstrap-table-next';
  14. import paginationFactory from 'react-bootstrap-table2-paginator';
  15. import ToolkitProvider, { Search } from 'react-bootstrap-table2-toolkit';
  16. import { Glyphicon, Button } from 'react-bootstrap';
  17. import PropTypes from "prop-types";
  18.  
  19. const mapStateToProps = state => {
  20. console.log('mapStateToProps - USERS:', state.currentUser, 'state', state);
  21. return {
  22. //selectedUser: this.state.selectedUser
  23. //selectedUser: state.users,
  24. allUsers: state.users
  25. };
  26. };
  27.  
  28. const mapDispatchToProps = dispatch => {
  29. // qui non penso ci vada, non ha conseguenze sul db
  30. return {
  31. selectedUser: user_id => dispatch(selectionUser(user_id)),
  32. fetchAllUsers: () => dispatch(getAllUsers({}))
  33. //userSelected: this.state.selectedUser => dispatch()
  34. }
  35. /*
  36. * fetchData: () => dispatch(getAllGroups({})),
  37. * */
  38. /*
  39. addUser: user => dispatch(createUser(user)),
  40. updateUser: user => dispatch(updateUser(user.DN, user)),
  41. resetSelection: () => dispatch(resetSelection()),
  42. updateUserPassword: (id,password) => dispatch(updatePasswordUser(id,password))
  43. };
  44. * */
  45. };
  46. class ListUsers extends Component {
  47.  
  48. constructor(props) {
  49.  
  50. super(props);
  51.  
  52. this.state = {...this.props};
  53.  
  54. this.state = {selectedUser: null, users: []};
  55.  
  56. }
  57.  
  58. componentDidMount() {
  59.  
  60. console.log('componentDidMount() - listUsers.jsx - carico i dati');
  61. this.props.fetchAllUsers();
  62.  
  63. }
  64.  
  65. render() {
  66. const handleClick = (event, row) => {
  67. console.log(event.currentTarget);
  68. console.log('The link was clicked ar row: ', row);
  69. //console.log('The link was clicked: ', event.currentTarget.getAttribute('data-key'));
  70. console.log(event.currentTarget.getAttribute('data-key'));
  71. //this.setState({...this.state, selectedUser: event.currentTarget.getAttribute('data-key')});
  72. this.state.selectedUser = event.currentTarget.getAttribute('data-key');
  73. //this.props.selectedUser = this.state.selectedUser;
  74. this.props.selectedUser(this.state.selectedUser);
  75. console.log('Stato modificato dopo il click [o l editing]: ', this.state);
  76. };
  77.  
  78. const Info = (row) => (
  79. <FontAwesomeIcon icon="info-circle" onClick={(event, row) => handleClick(event, row)} />
  80. );
  81.  
  82. const Edit = () => (
  83. <FontAwesomeIcon icon="pencil-alt" />
  84. );
  85.  
  86. const { SearchBar } = Search;
  87.  
  88. // <span><Glyphicon glyph="zoom-in"/>cell</span>
  89. {/*<Button data-key={this.props.Uid} > Info </Button>*/}
  90. {/*<Button data-key={this.props} onClick={(e) => handleClick(e)}> Edit </Button>*/}
  91.  
  92. const formatWithIcon = (cell, row, d, da) => {
  93. console.log('formatWithIcon - cell: ', cell);
  94. console.log('formatWithIcon - row: ', row);
  95. console.log('formatWithIcon - d: ', d);
  96. console.log('formatWithIcon - da: ', da);
  97. return (
  98. <div>
  99. {Info(row)}
  100. {Edit(cell)}
  101. </div>
  102. );
  103. };
  104.  
  105. const rowEvents = () => {
  106. onClick: {
  107. console.log('asdasdasdsdasdaaaaaaaaaaaaaaaaaaaa');
  108. };
  109. };
  110.  
  111. const columns = [{
  112. dataField: 'Uid',
  113. text: 'Username',
  114. isKey: true
  115. }, {
  116. dataField: 'Sn',
  117. text: 'Sn'
  118. }, {
  119. dataField: 'asd',
  120. text: 'Product Price',
  121. formatter: formatWithIcon
  122. }];
  123.  
  124. console.log('ALLUSERS:', this.props);
  125. return (
  126. <div>
  127. <ToolkitProvider
  128. keyField="Uid"
  129. data={ this.props.allUsers }
  130. columns={ columns }
  131. search
  132. >
  133. {
  134. props => (
  135. <div>
  136. <h2>Lista utenti</h2>
  137. <SearchBar { ...props.searchProps } />
  138. <hr />
  139. <BootstrapTable
  140. { ...props.baseProps }
  141. keyField="Uid"
  142. pagination={ paginationFactory() }
  143. />
  144. </div>
  145. )
  146. }
  147. </ToolkitProvider>
  148. <ul className="users">
  149. <li data-key="a" onClick={(e) => handleClick(e)}>Utente 1</li>
  150. </ul>
  151. </div>
  152. );
  153. }
  154. }
  155.  
  156. // ListUsers.propTypes = {
  157. // fetchAllUsers: PropTypes.func.isRequired
  158. // //,groups: PropTypes.array,
  159. // //hasErrored: PropTypes.bool.isRequired,
  160. // //isLoading: PropTypes.bool.isRequired
  161. // };
  162.  
  163. const UsersList = connect(mapStateToProps, mapDispatchToProps)(ListUsers);
  164. export default UsersList;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement