Skip to content

Commit

Permalink
fix(frontend): User name is not updated after changing it in profile …
Browse files Browse the repository at this point in the history
…bb-375 (#383)

* fix(frontend): fix user not updated after change in profile bb-375

* refactor(frontend): move update auth user to user action bb-375

---------

Co-authored-by: Farid Shabanov <61088675+fshabanov@users.noreply.github.com>
  • Loading branch information
JD-Rosales and fshabanov authored Sep 11, 2024
1 parent 03f6e6c commit 8feacbd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions apps/frontend/src/modules/auth/slices/auth.slice.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createSlice } from "@reduxjs/toolkit";
import { createSlice, type PayloadAction } from "@reduxjs/toolkit";

import { DataStatus } from "~/libs/enums/enums.js";
import { type ValueOf } from "~/libs/types/types.js";
Expand Down Expand Up @@ -84,7 +84,11 @@ const { actions, name, reducer } = createSlice({
},
initialState,
name: "auth",
reducers: {},
reducers: {
udpateAuthUser(state, action: PayloadAction<UserDto>) {
state.user = action.payload;
},
},
});

export { actions, name, reducer };
4 changes: 3 additions & 1 deletion apps/frontend/src/modules/users/slices/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createAsyncThunk } from "@reduxjs/toolkit";

import { NotificationMessage } from "~/libs/enums/enums.js";
import { type AsyncThunkConfig } from "~/libs/types/types.js";
import { actions as authActions } from "~/modules/auth/auth.js";
import {
type UserDto,
type UserGetParametersDto,
Expand Down Expand Up @@ -34,11 +35,12 @@ const saveNotificationAnswers = createAsyncThunk<

const update = createAsyncThunk<UserDto, UserUpdatePayload, AsyncThunkConfig>(
`${sliceName}/update`,
async (payload, { extra }) => {
async (payload, { dispatch, extra }) => {
const { notification, usersApi } = extra;
const { data, id } = payload;

const response = await usersApi.update(id, data);
dispatch(authActions.udpateAuthUser(response));
notification.success(NotificationMessage.PROFILE_UPDATED);

return response;
Expand Down

0 comments on commit 8feacbd

Please sign in to comment.