From 12c14f71baea84c7ea0fdf77256cb75ab32f537d Mon Sep 17 00:00:00 2001 From: Palash gupta Date: Fri, 13 May 2022 11:15:10 +0530 Subject: [PATCH 1/2] bug: bug double org is fixed --- .../OrganizationSettings/DisplayName/index.tsx | 2 +- frontend/src/store/reducers/app.ts | 11 +++++++---- frontend/src/types/actions/app.ts | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) 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..5d697f6004 100644 --- a/frontend/src/store/reducers/app.ts +++ b/frontend/src/store/reducers/app.ts @@ -172,16 +172,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 { diff --git a/frontend/src/types/actions/app.ts b/frontend/src/types/actions/app.ts index 67036478c6..829d8ad46f 100644 --- a/frontend/src/types/actions/app.ts +++ b/frontend/src/types/actions/app.ts @@ -98,7 +98,7 @@ export interface UpdateOrgName { type: typeof UPDATE_ORG_NAME; payload: { name: string; - index: number; + orgId: string; }; } From 429e3bbd0d59d6726a391cbec85b0a8ecc5f64de Mon Sep 17 00:00:00 2001 From: Palash gupta Date: Thu, 19 May 2022 13:43:54 +0530 Subject: [PATCH 2/2] fix: logout is fixed --- frontend/src/api/utils.ts | 8 ++++++++ frontend/src/store/reducers/app.ts | 8 ++++++++ frontend/src/types/actions/app.ts | 11 ++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) 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/store/reducers/app.ts b/frontend/src/store/reducers/app.ts index 5d697f6004..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, @@ -193,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 829d8ad46f..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; @@ -102,6 +103,13 @@ export interface UpdateOrgName { }; } +export interface UpdateOrg { + type: typeof UPDATE_ORG; + payload: { + org: AppReducer['org']; + }; +} + export type AppAction = | SwitchDarkMode | LoggedInUser @@ -113,4 +121,5 @@ export type AppAction = | UpdateUserIsFetched | UpdateUserOrgRole | UpdateUser - | UpdateOrgName; + | UpdateOrgName + | UpdateOrg;