Skip to content

Commit 1dcd421

Browse files
committed
Add notification feature + fixes
1 parent 8bd8853 commit 1dcd421

File tree

29 files changed

+691
-186
lines changed

29 files changed

+691
-186
lines changed

App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import setupAxiosInterceptors from './src/App/shared/interceptors/axios.intercep
88
import initStore from './src/App/store';
99
// Screens
1010
import App from './src/App';
11-
import Dashboard from './src/App/features/Home/containers/DashboardContainer';
11+
import Home from './src/App/features/Home/containers/HomeContainer';
1212

1313
const RootStack = StackNavigator(
1414
{
1515
App,
16-
Dashboard
16+
Home
1717
},
1818
{
1919
initialRouteName: 'App'

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"react-redux": "^5.0.7",
4949
"react-redux-loading-bar": "^4.0.5",
5050
"react-router-dom": "^4.3.1",
51+
"react-toastify": "^4.1.0",
5152
"reactstrap": "^6.3.0",
5253
"redux": "^4.0.0",
5354
"redux-form": "^7.4.2",
@@ -108,4 +109,4 @@
108109
"^.+\\.tsx?$": "ts-jest"
109110
}
110111
}
111-
}
112+
}

src/App/features/Admin/UserManagement/actions/index.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from 'react-jhipster';
88

99
import { IUser } from '../models/user.model';
10+
import appConstants from '../../../../shared/constants';
1011

1112
export const ACTION_TYPES = {
1213
FETCH_ROLES: 'userManagement/FETCH_ROLES',
@@ -19,6 +20,7 @@ export const ACTION_TYPES = {
1920
};
2021

2122
const apiUrl = 'api/users';
23+
const { errorMessage } = appConstants;
2224

2325
// Actions
2426
export const getUsers: ICrudGetAllAction<IUser> = (page, size, sort) => {
@@ -45,16 +47,25 @@ export const getUser: ICrudGetAction<IUser> = id => {
4547
export const createUser: ICrudPutAction<IUser> = user => async dispatch => {
4648
const result = await dispatch({
4749
type: ACTION_TYPES.CREATE_USER,
48-
payload: axios.post(apiUrl, user)
50+
payload: axios.post(apiUrl, user),
51+
meta: {
52+
successMessage: `User has been created successfully`,
53+
errorMessage
54+
}
4955
});
5056
dispatch(getUsers());
5157
return result;
5258
};
5359

5460
export const updateUser: ICrudPutAction<IUser> = user => async dispatch => {
61+
const requestUrl = `${apiUrl}/${user.id}`;
5562
const result = await dispatch({
5663
type: ACTION_TYPES.UPDATE_USER,
57-
payload: axios.put(apiUrl, user)
64+
payload: axios.put(requestUrl, user),
65+
meta: {
66+
successMessage: `User has been updated successfully`,
67+
errorMessage
68+
}
5869
});
5970
dispatch(getUsers());
6071
return result;
@@ -64,7 +75,11 @@ export const deleteUser: ICrudDeleteAction<IUser> = id => async dispatch => {
6475
const requestUrl = `${apiUrl}/${id}`;
6576
const result = await dispatch({
6677
type: ACTION_TYPES.DELETE_USER,
67-
payload: axios.delete(requestUrl)
78+
payload: axios.delete(requestUrl),
79+
meta: {
80+
successMessage: `User has been deleted successfully`,
81+
errorMessage
82+
}
6883
});
6984
dispatch(getUsers());
7085
return result;

src/App/features/Admin/UserManagement/components/UserManagementDeleteModal/index.tsx

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/App/features/Admin/UserManagement/components/UserManagementList/index.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,20 @@ export class UserManagementList extends React.Component<IUserManagementProps | a
1717
sort,
1818
toggleActive,
1919
handlePagination,
20+
confirmDelete,
2021
itemsPerPage,
2122
activePage
2223
} = this.props;
2324

25+
const onConfirm = (id: number) => {
26+
const isOk = confirm(
27+
`Confirm delete operation\nAre you sure you want to delete this User?`
28+
);
29+
if (isOk) {
30+
confirmDelete(id);
31+
}
32+
};
33+
2434
return (
2535
<div>
2636
<h2 className="userManagement-page-heading">
@@ -142,8 +152,7 @@ export class UserManagementList extends React.Component<IUserManagementProps | a
142152
<span className="d-none d-md-inline">Edit</span>
143153
</Button>
144154
<Button
145-
tag={Link}
146-
to={`${match.url}/${user.id}/delete`}
155+
onClick={() => onConfirm(user.id)}
147156
color="danger"
148157
size="sm"
149158
disabled={account.login === user.login}

src/App/features/Admin/UserManagement/containers/UserManagementDeleteModalContainer.tsx

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/App/features/Admin/UserManagement/containers/UserManagementListContainer.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { RouteComponentProps } from 'react-router-dom';
44
import { getSortState, IPaginationBaseState } from 'react-jhipster';
55

66
import appConstants from '../../../../shared/constants';
7-
import { getUsers, updateUser } from '../actions';
7+
import { getUsers, updateUser, deleteUser } from '../actions';
88
import { IRootState } from '../../../../reducers';
99
import { selectUserManagementUsers, selectUserManagementTotalItems } from '../reducers';
1010
import { selectAuthUser } from '../../../../shared/reducers/auth.reducer';
@@ -48,6 +48,10 @@ export class UserManagementListContainer extends React.Component<
4848

4949
handlePagination = activePage => this.setState({ activePage }, () => this.sortUsers());
5050

51+
confirmDelete = (useId: number) => {
52+
this.props.deleteUser(useId);
53+
};
54+
5155
getUsers = () => {
5256
const { activePage, itemsPerPage, sort, order } = this.state;
5357
this.props.getUsers(activePage - 1, itemsPerPage, `${sort},${order}`);
@@ -70,6 +74,7 @@ export class UserManagementListContainer extends React.Component<
7074
account={account}
7175
sort={this.sort}
7276
handlePagination={this.handlePagination}
77+
confirmDelete={this.confirmDelete}
7378
itemsPerPage={this.state.itemsPerPage}
7479
activePage={this.state.activePage}
7580
toggleActive={this.toggleActive}
@@ -84,7 +89,7 @@ const mapStateToProps = (state: IRootState) => ({
8489
account: selectAuthUser(state)
8590
});
8691

87-
const mapDispatchToProps = { getUsers, updateUser };
92+
const mapDispatchToProps = { getUsers, updateUser, deleteUser };
8893

8994
type StateProps = ReturnType<typeof mapStateToProps | any>;
9095
type DispatchProps = typeof mapDispatchToProps;

src/App/features/Admin/UserManagement/routes/index.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import ErrorBoundaryRoute from '../../../../shared/helpers/error-boundary-route.
55
import UserManagement from '../containers/UserManagementListContainer';
66
import UserManagementDetail from '../containers/UserManagementDetailContainer';
77
import UserManagementUpdate from '../containers/UserManagementFormContainer';
8-
import UserManagementDeleteModal from '../containers/UserManagementDeleteModalContainer';
98

109
const Routes = ({ match }) => (
1110
<>
@@ -27,10 +26,6 @@ const Routes = ({ match }) => (
2726
/>
2827
<ErrorBoundaryRoute path={match.url} component={UserManagement} />
2928
</Switch>
30-
<ErrorBoundaryRoute
31-
path={`${match.url}/:id/delete`}
32-
component={UserManagementDeleteModal}
33-
/>
3429
</>
3530
);
3631

src/App/features/Home/components/Dashboard/index.native.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const styles = StyleSheet.create({
4444

4545
export default StackNavigator(
4646
{
47-
Dashboard: {
47+
Home: {
4848
screen: DashboardScreen
4949
}
5050
},

0 commit comments

Comments
 (0)