From 2b00c8425d6f2de8670f95d495a91ee78b51dbc8 Mon Sep 17 00:00:00 2001 From: Valentino K Date: Mon, 16 May 2022 13:10:47 +0200 Subject: [PATCH] Fixed editing self as user --- src/components/Table/Table.tsx | 40 +++++++++++++++-------------- src/services/users/redux/actions.ts | 15 +++++++---- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/components/Table/Table.tsx b/src/components/Table/Table.tsx index 09eb629..157b728 100644 --- a/src/components/Table/Table.tsx +++ b/src/components/Table/Table.tsx @@ -148,26 +148,28 @@ export const Table = >({ ); }) ) : ( - -
-
- - - - + + +
+
+ + + + +
+

Loading users

-

Loading users

-
- + + )} diff --git a/src/services/users/redux/actions.ts b/src/services/users/redux/actions.ts index 67be7ee..79b409b 100644 --- a/src/services/users/redux/actions.ts +++ b/src/services/users/redux/actions.ts @@ -1,5 +1,6 @@ import { Dispatch } from 'redux'; import { showToast, ToastType } from 'src/common/util/show-toast'; +import { State } from 'src/redux/types'; import { performApiCall } from 'src/services/api'; import { AuthActionTypes } from 'src/services/auth'; import { transformRequestUser, transformUser } from '../transformations'; @@ -68,9 +69,11 @@ export const fetchUserById = (id: string) => async (dispatch: Dispatch) => dispatch(setUserModalLoading(false)); }; -export const updateUserById = (user: any) => async (dispatch: Dispatch) => { +export const updateUserById = (user: any) => async (dispatch: Dispatch, getState: any) => { dispatch(setUserModalLoading(true)); + const state: State = getState(); + try { const { data } = await performApiCall({ path: `/users/${user.id}`, @@ -83,10 +86,12 @@ export const updateUserById = (user: any) => async (dispatch: Dispatch) => payload: transformUser(data), }); - dispatch({ - type: AuthActionTypes.UPDATE_AUTH_USER, - payload: transformUser(data), - }); + if (state.auth.userInfo.id === user.id) { + dispatch({ + type: AuthActionTypes.UPDATE_AUTH_USER, + payload: transformUser(data), + }); + } showToast('User updated successfully.', ToastType.Success);