Skip to content

Commit

Permalink
feat: extend UserListPage with new Button
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideIadeluca committed Oct 3, 2024
1 parent 645d207 commit 175e43e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions js/src/admin/extendUserListPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import app from 'flarum/admin/app';
import { extend } from 'flarum/common/extend';
import UserListPage from 'flarum/admin/components/UserListPage';
import LoginAsUserButton from '../common/components/LoginAsUserButton';

import type ItemList from 'flarum/common/utils/ItemList';
import type User from 'flarum/common/models/User';

import type Mithril from 'mithril';
export default function extendUserListPage() {
extend(UserListPage.prototype, 'userActionItems', function (items: ItemList<Mithril.Children>, user: User) {
const forumBaseUrl = app.forum.attribute('baseUrl');

items.add('impersonate', <LoginAsUserButton user={user} redirectTo={`${forumBaseUrl}/u/${user.slug()}`} />);
});
}
4 changes: 4 additions & 0 deletions js/src/admin/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import app from 'flarum/admin/app';
import extendUserListPage from './extendUserListPage';

export { default as extend } from './extend';

app.initializers.add('fof-impersonate', () => {
Expand All @@ -18,4 +20,6 @@ app.initializers.add('fof-impersonate', () => {
label: app.translator.trans('fof-impersonate.admin.settings.require_reason'),
});
}

extendUserListPage();
});

0 comments on commit 175e43e

Please sign in to comment.