Fixed editing self as user
This commit is contained in:
parent
50bfb2c4d0
commit
2b00c8425d
2 changed files with 31 additions and 24 deletions
|
@ -148,26 +148,28 @@ export const Table = <T extends Record<string, unknown>>({
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
) : (
|
) : (
|
||||||
<td colSpan={4} className="py-24">
|
<tr>
|
||||||
<div className="flex flex-col justify-center items-center">
|
<td colSpan={4} className="py-24">
|
||||||
<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 flex-col justify-center items-center">
|
||||||
<svg
|
<div className="flex justify-center items-center border border-transparent text-base font-medium rounded-md text-white transition ease-in-out duration-150">
|
||||||
className="animate-spin h-6 w-6 text-primary"
|
<svg
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
className="animate-spin h-6 w-6 text-primary"
|
||||||
fill="none"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
viewBox="0 0 24 24"
|
fill="none"
|
||||||
>
|
viewBox="0 0 24 24"
|
||||||
<circle className="opacity-50" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
|
>
|
||||||
<path
|
<circle className="opacity-50" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
|
||||||
className="opacity-100"
|
<path
|
||||||
fill="currentColor"
|
className="opacity-100"
|
||||||
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
fill="currentColor"
|
||||||
/>
|
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
||||||
</svg>
|
/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<p className="text-sm text-primary-600 mt-2">Loading users</p>
|
||||||
</div>
|
</div>
|
||||||
<p className="text-sm text-primary-600 mt-2">Loading users</p>
|
</td>
|
||||||
</div>
|
</tr>
|
||||||
</td>
|
|
||||||
)}
|
)}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -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),
|
||||||
});
|
});
|
||||||
|
|
||||||
dispatch({
|
if (state.auth.userInfo.id === user.id) {
|
||||||
type: AuthActionTypes.UPDATE_AUTH_USER,
|
dispatch({
|
||||||
payload: transformUser(data),
|
type: AuthActionTypes.UPDATE_AUTH_USER,
|
||||||
});
|
payload: transformUser(data),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
showToast('User updated successfully.', ToastType.Success);
|
showToast('User updated successfully.', ToastType.Success);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue