mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-12 04:17:16 +02:00
fix(ui): sync stored identity name when editing your own profile (#5388)
Signed-off-by: junkerderprovinz <jdp@braethoria.com>
This commit is contained in:
parent
5c5b849a4e
commit
7df4900e5b
2 changed files with 29 additions and 1 deletions
|
|
@ -94,6 +94,12 @@ const UserEdit = (props) => {
|
|||
notify('resources.user.notifications.updated', 'info', {
|
||||
smart_count: 1,
|
||||
})
|
||||
// Keep the locally stored identity name in sync when users edit their
|
||||
// own profile, so the app bar menu (and the ExtAuth logout/login reload,
|
||||
// which reads localStorage.name via getIdentity) reflect the new name.
|
||||
if (isMyself) {
|
||||
localStorage.setItem('name', values.name)
|
||||
}
|
||||
permissions === 'admin' ? redirect('/user') : refresh()
|
||||
} catch (error) {
|
||||
if (error?.body?.errors) {
|
||||
|
|
@ -102,7 +108,7 @@ const UserEdit = (props) => {
|
|||
notify('ra.page.error', 'warning')
|
||||
}
|
||||
},
|
||||
[mutate, notify, permissions, redirect, refresh],
|
||||
[isMyself, mutate, notify, permissions, redirect, refresh],
|
||||
)
|
||||
|
||||
// Custom validation function
|
||||
|
|
|
|||
|
|
@ -141,6 +141,7 @@ describe('<UserEdit />', () => {
|
|||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
hooks.save = null
|
||||
localStorage.clear()
|
||||
})
|
||||
|
||||
it('notifies success and redirects when the update succeeds', async () => {
|
||||
|
|
@ -191,5 +192,26 @@ describe('<UserEdit />', () => {
|
|||
expect(hooks.notify).toHaveBeenCalledWith('ra.page.error', 'warning')
|
||||
expect(hooks.redirect).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('syncs the stored identity name when editing your own profile', async () => {
|
||||
localStorage.setItem('userId', 'user1')
|
||||
hooks.mutate.mockResolvedValue({ data: defaultUser })
|
||||
render(<UserEdit id="user1" permissions="user" />)
|
||||
|
||||
await hooks.save({ id: 'user1', name: 'Renamed' })
|
||||
|
||||
expect(localStorage.getItem('name')).toBe('Renamed')
|
||||
})
|
||||
|
||||
it('does not touch the stored identity name when editing another user', async () => {
|
||||
localStorage.setItem('userId', 'admin1')
|
||||
localStorage.setItem('name', 'Admin User')
|
||||
hooks.mutate.mockResolvedValue({ data: defaultUser })
|
||||
render(<UserEdit id="user1" permissions="admin" />)
|
||||
|
||||
await hooks.save({ id: 'user1', name: 'Renamed' })
|
||||
|
||||
expect(localStorage.getItem('name')).toBe('Admin User')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue