Skip to content

Commit 288916e

Browse files
fix: update the avatar name when account is switched (#3834)
1 parent 8707424 commit 288916e

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

src/accounts/context/userAccount.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ import {isFlagEnabled} from 'src/shared/utils/featureFlag'
2828
import {useHistory} from 'react-router-dom'
2929
import {getErrorMessage} from 'src/utils/api'
3030

31+
// Actions
32+
import {setMe} from 'src/me/actions/creators'
33+
import {MeState} from 'src/me/reducers'
34+
3135
export type Props = {
3236
children: JSX.Element
3337
}
@@ -158,6 +162,16 @@ export const UserAccountProvider: FC<Props> = React.memo(({children}) => {
158162
// change the name, and reset the active accts:
159163
userAccounts[activeIndex].name = newName
160164
setUserAccounts(userAccounts)
165+
166+
if (
167+
isFlagEnabled('multiAccount') &&
168+
isFlagEnabled('avatarNameForMultiAccountFix')
169+
) {
170+
const name = resp.data.name
171+
const id = resp.data.id.toString()
172+
// update the state
173+
dispatch(setMe({name, id} as MeState))
174+
}
161175
}
162176
} catch (error) {
163177
dispatch(notify(accountRenameError(oldName)))

src/me/actions/thunks/index.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {Dispatch} from 'react'
55

66
// API
77
import {getMe as apiGetApiMe} from 'src/client'
8-
import {getMe as apiGetQuartzMe} from 'src/client/unityRoutes'
8+
import {getAccounts, getMe as apiGetQuartzMe} from 'src/client/unityRoutes'
99
// Utils
1010
import {gaEvent, updateReportingContext} from 'src/cloud/utils/reporting'
1111
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
@@ -28,12 +28,27 @@ export const getMe = () => async (
2828
getState: GetState
2929
) => {
3030
try {
31-
const resp = await apiGetApiMe({})
31+
let user
3232

33-
if (resp.status !== 200) {
34-
throw new Error(resp.data.message)
33+
if (
34+
isFlagEnabled('multiAccount') &&
35+
isFlagEnabled('avatarNameForMultiAccountFix')
36+
) {
37+
const resp = await getAccounts({})
38+
39+
if (resp.status !== 200) {
40+
throw new Error(resp.data.message)
41+
}
42+
user = resp.data.find(account => account.isActive)
43+
} else {
44+
const resp = await apiGetApiMe({})
45+
46+
if (resp.status !== 200) {
47+
throw new Error(resp.data.message)
48+
}
49+
user = resp.data
3550
}
36-
const user = resp.data
51+
3752
updateReportingContext({userID: user.id, userEmail: user.name})
3853

3954
gaEvent('cloudAppUserDataReady', {

0 commit comments

Comments
 (0)