diff --git a/frontend/src/api/utils.ts b/frontend/src/api/utils.ts index 56867927a8..fdfa6c32a4 100644 --- a/frontend/src/api/utils.ts +++ b/frontend/src/api/utils.ts @@ -5,6 +5,7 @@ import history from 'lib/history'; import store from 'store'; import { LOGGED_IN, + UPDATE_ORG, UPDATE_USER, UPDATE_USER_ACCESS_REFRESH_ACCESS_TOKEN, UPDATE_USER_ORG_ROLE, @@ -51,5 +52,12 @@ export const Logout = (): void => { }, }); + store.dispatch({ + type: UPDATE_ORG, + payload: { + org: [], + }, + }); + history.push(ROUTES.LOGIN); }; diff --git a/frontend/src/container/OrganizationSettings/DisplayName/index.tsx b/frontend/src/container/OrganizationSettings/DisplayName/index.tsx index 394d42b76c..32b520cb4f 100644 --- a/frontend/src/container/OrganizationSettings/DisplayName/index.tsx +++ b/frontend/src/container/OrganizationSettings/DisplayName/index.tsx @@ -38,7 +38,7 @@ function DisplayName({ dispatch({ type: UPDATE_ORG_NAME, payload: { - index, + orgId, name: orgName, }, }); diff --git a/frontend/src/store/reducers/app.ts b/frontend/src/store/reducers/app.ts index 8c35b748b0..614179103f 100644 --- a/frontend/src/store/reducers/app.ts +++ b/frontend/src/store/reducers/app.ts @@ -12,6 +12,7 @@ import { UPDATE_CURRENT_VERSION, UPDATE_LATEST_VERSION, UPDATE_LATEST_VERSION_ERROR, + UPDATE_ORG, UPDATE_ORG_NAME, UPDATE_USER, UPDATE_USER_ACCESS_REFRESH_ACCESS_TOKEN, @@ -172,16 +173,19 @@ const appReducer = ( case UPDATE_ORG_NAME: { const stateOrg = state.org || ({} as OrgPayload); - const { index, name: updatedName } = action.payload; - const current = stateOrg[index]; + const { orgId, name: updatedName } = action.payload; + + const orgIndex = stateOrg.findIndex((e) => e.id === orgId); + + const current = stateOrg[orgIndex]; const updatedOrg: OrgPayload = [ - ...stateOrg.slice(0, index), + ...stateOrg.slice(0, orgIndex), { ...current, name: updatedName, }, - ...stateOrg.slice(index + 1, stateOrg.length), + ...stateOrg.slice(orgIndex + 1, stateOrg.length), ]; return { @@ -190,6 +194,13 @@ const appReducer = ( }; } + case UPDATE_ORG: { + return { + ...state, + org: action.payload.org, + }; + } + default: return state; } diff --git a/frontend/src/types/actions/app.ts b/frontend/src/types/actions/app.ts index 67036478c6..88e55fb772 100644 --- a/frontend/src/types/actions/app.ts +++ b/frontend/src/types/actions/app.ts @@ -20,6 +20,7 @@ export const UPDATE_USER_IS_FETCH = 'UPDATE_USER_IS_FETCH'; export const UPDATE_USER_ORG_ROLE = 'UPDATE_USER_ORG_ROLE'; export const UPDATE_USER = 'UPDATE_USER'; export const UPDATE_ORG_NAME = 'UPDATE_ORG_NAME'; +export const UPDATE_ORG = 'UPDATE_ORG'; export interface SwitchDarkMode { type: typeof SWITCH_DARK_MODE; @@ -98,7 +99,14 @@ export interface UpdateOrgName { type: typeof UPDATE_ORG_NAME; payload: { name: string; - index: number; + orgId: string; + }; +} + +export interface UpdateOrg { + type: typeof UPDATE_ORG; + payload: { + org: AppReducer['org']; }; } @@ -113,4 +121,5 @@ export type AppAction = | UpdateUserIsFetched | UpdateUserOrgRole | UpdateUser - | UpdateOrgName; + | UpdateOrgName + | UpdateOrg;