Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: src/components/UserList.js
- IDEA additional info:
- Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
- <+>UTF-8
- ===================================================================
- --- src/components/UserList.js (date 1542354421000)
- +++ src/components/UserList.js (date 1542355166504)
- @@ -20,7 +20,7 @@
- }
- });
- -const UserList = ({ classes, onSelect, users }) => (
- +const UserList = ({ classes, onApplyButtonClick, onSelect, users }) => (
- <Paper>
- <Table>
- <TableHead>
- @@ -65,7 +65,7 @@
- <TableCell
- numeric
- className={classes.lastTableCell}>
- - <DeleteButton />
- + <DeleteButton handleApplyButtonClick={onApplyButtonClick.bind(this, user)} />
- </TableCell>
- </TableRow>
- );
- Index: src/containers/UserListContainer.js
- IDEA additional info:
- Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
- <+>UTF-8
- ===================================================================
- --- src/containers/UserListContainer.js (date 1542354421000)
- +++ src/containers/UserListContainer.js (date 1542355657223)
- @@ -1,4 +1,5 @@
- import React from 'react';
- +import { connect } from 'react-redux';
- import { Link } from 'react-router-dom';
- import Button from '@material-ui/core/Button';
- import CircularProgress from '@material-ui/core/CircularProgress';
- @@ -6,6 +7,7 @@
- import UserList from '../components/UserList';
- import usersService from '../services/users.service';
- +import { addToastNotification } from '../store/actions/toastNotificationActions';
- import routePathBuilder from '../utils/route-path-builder';
- const styles = theme => ({
- @@ -48,16 +50,46 @@
- }));
- }
- + handleApplyButtonClick = userToDelete => {
- + usersService.deleteOne(userToDelete.id)
- + .then(response => {
- + this.removeUserFromLocalState(userToDelete);
- +
- + this.props.addToastNotification({
- + show: true,
- + variant: 'success',
- + message: 'Delete user operation was successful.'
- + });
- + })
- + .catch(error => {
- + this.props.addToastNotification({
- + show: true,
- + variant: 'error',
- + message: 'Delete user operation was not successful.'
- + });
- + });
- + };
- +
- handleSelect = selectedUser => {
- this.props.history.push(routePathBuilder('users', 'detail', selectedUser.id));
- };
- + removeUserFromLocalState(userToRemove) {
- + const newUsersLocalState = this.state.data
- + .filter(user => user.id !== userToRemove.id);
- +
- + this.setState({
- + data: newUsersLocalState
- + });
- + }
- +
- renderCircularProgress = () => (
- <CircularProgress className={this.props.classes.circularProgress} />
- );
- renderUserList = () => (
- <UserList
- + onApplyButtonClick={this.handleApplyButtonClick}
- onSelect={this.handleSelect}
- users={this.state.data}
- />
- @@ -80,4 +112,11 @@
- );
- }
- -export default withStyles(styles)(UserListContainer);
- +const mapDispatchToProps = dispatch => ({
- + addToastNotification: notification => dispatch(addToastNotification(notification))
- +});
- +
- +const connected = connect(null, mapDispatchToProps)(UserListContainer);
- +const styled = withStyles(styles)(connected);
- +
- +export default styled;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement