Advertisement
Guest User

Untitled

a guest
Nov 16th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. Index: src/components/UserList.js
  2. IDEA additional info:
  3. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  4. <+>UTF-8
  5. ===================================================================
  6. --- src/components/UserList.js (date 1542354421000)
  7. +++ src/components/UserList.js (date 1542355166504)
  8. @@ -20,7 +20,7 @@
  9. }
  10. });
  11.  
  12. -const UserList = ({ classes, onSelect, users }) => (
  13. +const UserList = ({ classes, onApplyButtonClick, onSelect, users }) => (
  14. <Paper>
  15. <Table>
  16. <TableHead>
  17. @@ -65,7 +65,7 @@
  18. <TableCell
  19. numeric
  20. className={classes.lastTableCell}>
  21. - <DeleteButton />
  22. + <DeleteButton handleApplyButtonClick={onApplyButtonClick.bind(this, user)} />
  23. </TableCell>
  24. </TableRow>
  25. );
  26. Index: src/containers/UserListContainer.js
  27. IDEA additional info:
  28. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  29. <+>UTF-8
  30. ===================================================================
  31. --- src/containers/UserListContainer.js (date 1542354421000)
  32. +++ src/containers/UserListContainer.js (date 1542355657223)
  33. @@ -1,4 +1,5 @@
  34. import React from 'react';
  35. +import { connect } from 'react-redux';
  36. import { Link } from 'react-router-dom';
  37. import Button from '@material-ui/core/Button';
  38. import CircularProgress from '@material-ui/core/CircularProgress';
  39. @@ -6,6 +7,7 @@
  40.  
  41. import UserList from '../components/UserList';
  42. import usersService from '../services/users.service';
  43. +import { addToastNotification } from '../store/actions/toastNotificationActions';
  44. import routePathBuilder from '../utils/route-path-builder';
  45.  
  46. const styles = theme => ({
  47. @@ -48,16 +50,46 @@
  48. }));
  49. }
  50.  
  51. + handleApplyButtonClick = userToDelete => {
  52. + usersService.deleteOne(userToDelete.id)
  53. + .then(response => {
  54. + this.removeUserFromLocalState(userToDelete);
  55. +
  56. + this.props.addToastNotification({
  57. + show: true,
  58. + variant: 'success',
  59. + message: 'Delete user operation was successful.'
  60. + });
  61. + })
  62. + .catch(error => {
  63. + this.props.addToastNotification({
  64. + show: true,
  65. + variant: 'error',
  66. + message: 'Delete user operation was not successful.'
  67. + });
  68. + });
  69. + };
  70. +
  71. handleSelect = selectedUser => {
  72. this.props.history.push(routePathBuilder('users', 'detail', selectedUser.id));
  73. };
  74.  
  75. + removeUserFromLocalState(userToRemove) {
  76. + const newUsersLocalState = this.state.data
  77. + .filter(user => user.id !== userToRemove.id);
  78. +
  79. + this.setState({
  80. + data: newUsersLocalState
  81. + });
  82. + }
  83. +
  84. renderCircularProgress = () => (
  85. <CircularProgress className={this.props.classes.circularProgress} />
  86. );
  87.  
  88. renderUserList = () => (
  89. <UserList
  90. + onApplyButtonClick={this.handleApplyButtonClick}
  91. onSelect={this.handleSelect}
  92. users={this.state.data}
  93. />
  94. @@ -80,4 +112,11 @@
  95. );
  96. }
  97.  
  98. -export default withStyles(styles)(UserListContainer);
  99. +const mapDispatchToProps = dispatch => ({
  100. + addToastNotification: notification => dispatch(addToastNotification(notification))
  101. +});
  102. +
  103. +const connected = connect(null, mapDispatchToProps)(UserListContainer);
  104. +const styled = withStyles(styles)(connected);
  105. +
  106. +export default styled;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement