Skip to content

Commit f80d743

Browse files
committed
feat(account-dropdown): add admin panel link for admin users
Add an "Admin Panel" link to the account dropdown menu visible only to admin users. The link opens the backend admin page in a new tab, using the backend URL from the environment config. This improves access and usability for admin users to quickly reach the admin interface. Also clean up unused admin-related code from the header index component, removing the admin link generation and adminPanelLink getter that were previously unused. This simplifies the codebase and consolidates admin link logic into the account dropdown component.
1 parent 783e97f commit f80d743

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

app/components/header/account-dropdown.hbs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@
7070
<DarkModeToggleWithUpgradePrompt @size="small" />
7171
</div>
7272

73+
{{#if this.currentUser.isAdmin}}
74+
<div class="h-px mt-2 mb-2 ml-3 mr-3 bg-gray-200 dark:bg-white/5" />
75+
<DropdownLink @text="Admin Panel" @icon="cog" {{on "click" (fn this.handleAdminPanelLinkClick dd.actions)}} />
76+
{{/if}}
77+
7378
<div class="h-px mt-2 mb-2 ml-3 mr-3 bg-gray-200 dark:bg-white/5" />
7479

7580
<DropdownLink @text="Logout" @icon="logout" {{on "click" this.handleLogoutClick}} />

app/components/header/account-dropdown.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type Store from '@ember-data/store';
88
import type TeamModel from 'codecrafters-frontend/models/team';
99
import type FeatureFlagsService from 'codecrafters-frontend/services/feature-flags';
1010
import type DarkModeService from 'codecrafters-frontend/services/dark-mode';
11+
import config from 'codecrafters-frontend/config/environment';
1112

1213
export default class AccountDropdown extends Component {
1314
@service declare authenticator: AuthenticatorService;
@@ -20,6 +21,12 @@ export default class AccountDropdown extends Component {
2021
return this.authenticator.currentUser;
2122
}
2223

24+
@action
25+
handleAdminPanelLinkClick(dropdownActions: { close: () => void }) {
26+
dropdownActions.close();
27+
window.open(`${config.x.backendUrl}/admin`, '_blank');
28+
}
29+
2330
@action
2431
handleCreateTeamClick(dropdownActions: { close: () => void }) {
2532
dropdownActions.close();

app/components/header/index.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import Component from '@glimmer/component';
2-
import { action } from '@ember/object';
3-
import { tracked } from '@glimmer/tracking';
4-
import { inject as service } from '@ember/service';
5-
import { htmlSafe } from '@ember/template';
6-
import { next } from '@ember/runloop';
2+
import PromotionalDiscountModel from 'codecrafters-frontend/models/promotional-discount';
73
import logoImage from '/assets/images/logo/logomark-color.svg';
8-
import config from 'codecrafters-frontend/config/environment';
94
import type AuthenticatorService from 'codecrafters-frontend/services/authenticator';
105
import type ContainerWidthService from 'codecrafters-frontend/services/container-width';
116
import type FeatureFlagsService from 'codecrafters-frontend/services/feature-flags';
127
import type RouterService from '@ember/routing/router-service';
138
import type VersionTrackerService from 'codecrafters-frontend/services/version-tracker';
14-
import PromotionalDiscountModel from 'codecrafters-frontend/models/promotional-discount';
159
import type { SafeString } from '@ember/template/-private/handlebars';
10+
import { action } from '@ember/object';
11+
import { htmlSafe } from '@ember/template';
12+
import { inject as service } from '@ember/service';
13+
import { next } from '@ember/runloop';
14+
import { tracked } from '@glimmer/tracking';
1615

1716
interface Signature {
1817
Element: HTMLDivElement;
@@ -35,10 +34,6 @@ export default class Header extends Component<Signature> {
3534
return this.currentUser?.activeDiscountForYearlyPlan || null;
3635
}
3736

38-
get adminPanelLink() {
39-
return `${config.x.backendUrl}/admin`;
40-
}
41-
4237
get currentUser() {
4338
return this.authenticator.currentUser;
4439
}
@@ -65,10 +60,6 @@ export default class Header extends Component<Signature> {
6560
{ text: 'Roadmap', route: 'roadmap', type: 'route' },
6661
];
6762

68-
if (this.currentUser && this.currentUser.isAdmin) {
69-
links.push({ text: 'Admin', route: this.adminPanelLink, type: 'link' });
70-
}
71-
7263
return links;
7364
}
7465

0 commit comments

Comments
 (0)