Skip to content

Commit 0f011aa

Browse files
committed
Move login as logic to the user usage table
1 parent d8e6fb4 commit 0f011aa

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/client/components/Admin/Usage/UserTable.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
import { enqueueSnackbar } from 'notistack'
1616
import { useTranslation } from 'react-i18next'
1717

18-
import { ChatInstanceUsage, ChatInstance } from '../../../types'
18+
import { ChatInstanceUsage, ChatInstance, User } from '../../../types'
1919
import useChatInstanceUsage from '../../../hooks/useChatInstanceUsage'
2020
import useUsers from '../../../hooks/useUsers'
2121
import { useDeleteChatInstanceUsageMutation } from '../../../hooks/useChatInstanceUsageMutation'
@@ -28,6 +28,11 @@ type Usage = Omit<ChatInstanceUsage, 'chatInstance'> & {
2828
const sortUsage = (a: Usage, b: Usage) =>
2929
a.user.username.localeCompare(b.user.username)
3030

31+
const handleLoginAs = (user: User) => () => {
32+
localStorage.setItem('adminLoggedInAs', user.id)
33+
window.location.reload()
34+
}
35+
3136
const UserTable = () => {
3237
const { usage: chatInstanceUsage, isLoading } = useChatInstanceUsage()
3338
const { users, isLoading: usersLoading } = useUsers()
@@ -136,6 +141,11 @@ const UserTable = () => {
136141
{t('admin:reset')}
137142
</Button>
138143
</TableCell>
144+
<TableCell>
145+
<Button variant="outlined" onClick={handleLoginAs(user)}>
146+
Kirjaudu käyttäjällä
147+
</Button>
148+
</TableCell>
139149
</TableRow>
140150
)
141151
)}

src/client/components/Admin/index.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { get } from 'lodash'
1414
import ChatInstances from './ChatInstances'
1515
import Usage from './Usage'
1616
import Updater from './Updater'
17-
import LoginAsSelector from './Usage/UserSearch'
1817
import EditTexts from './EditTexts'
1918

2019
const stripSearch = (path: string) => path.split('?')[0]
@@ -47,11 +46,6 @@ const Admin = () => {
4746
to="/admin/updater"
4847
component={Link}
4948
/>
50-
<Tab
51-
label={t('admin:searchUsers')}
52-
to="/admin/search"
53-
component={Link}
54-
/>
5549
<Tab
5650
label={t('admin:editTexts')}
5751
to="/admin/edit-texts"
@@ -64,7 +58,6 @@ const Admin = () => {
6458
<Route path="/chatinstances" element={<ChatInstances />} />
6559
<Route path="/usage" element={<Usage />} />
6660
<Route path="/updater" element={<Updater />} />
67-
<Route path="/search" element={<LoginAsSelector />} />
6861
<Route path="/edit-texts" element={<EditTexts />} />
6962
</Routes>
7063
</Box>

0 commit comments

Comments
 (0)