Fixed editing self as user

This commit is contained in:
Valentino K 2022-05-16 13:10:47 +02:00
parent 50bfb2c4d0
commit 2b00c8425d
2 changed files with 31 additions and 24 deletions

View file

@ -148,6 +148,7 @@ export const Table = <T extends Record<string, unknown>>({
); );
}) })
) : ( ) : (
<tr>
<td colSpan={4} className="py-24"> <td colSpan={4} className="py-24">
<div className="flex flex-col justify-center items-center"> <div className="flex flex-col justify-center items-center">
<div className="flex justify-center items-center border border-transparent text-base font-medium rounded-md text-white transition ease-in-out duration-150"> <div className="flex justify-center items-center border border-transparent text-base font-medium rounded-md text-white transition ease-in-out duration-150">
@ -168,6 +169,7 @@ export const Table = <T extends Record<string, unknown>>({
<p className="text-sm text-primary-600 mt-2">Loading users</p> <p className="text-sm text-primary-600 mt-2">Loading users</p>
</div> </div>
</td> </td>
</tr>
)} )}
</tbody> </tbody>
</table> </table>

View file

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