Skip to content

Commit 52c229f

Browse files
committed
refactor: simplify user menu settings component and improve routing logic
1 parent 568a56c commit 52c229f

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

adminforth/modules/codeInjector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ class CodeInjector implements ICodeInjector {
484484

485485
if (this.adminforth.config.auth.userMenuSettingsPages) {
486486
for (const settingPage of this.adminforth.config.auth.userMenuSettingsPages) {
487-
checkInjections([{ file: settingPage.component, meta: settingPage.pageLabel }]);
487+
checkInjections([{ file: settingPage.component }]);
488488
}
489489
}
490490

adminforth/modules/configValidator.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,14 +1001,7 @@ export default class ConfigValidator implements IConfigValidator {
10011001
}
10021002
if (newConfig.auth.userMenuSettingsPages) {
10031003
for (const page of newConfig.auth.userMenuSettingsPages) {
1004-
if (!page.component.startsWith('@@')) {
1005-
errors.push(`Menu item component must start with @@ : ${JSON.stringify(page)}`);
1006-
}
1007-
1008-
const path = page.component.replace('@@', newConfig.customization.customComponentsDir);
1009-
if (!fs.existsSync(path)) {
1010-
errors.push(`Menu item component "${page.component.replace('@@', '')}" does not exist in "${newConfig.customization.customComponentsDir}"`);
1011-
}
1004+
this.validateComponent({file: page.component}, errors);
10121005
}
10131006
}
10141007

adminforth/spa/src/components/UserMenuSettingsButton.vue

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@
1414

1515
<div v-if="showDropdown" >
1616

17-
<div class="cursor-pointer flex items-center gap-1 block px-4 py-1 text-sm
17+
<router-link class="cursor-pointer flex items-center gap-1 block px-4 py-1 text-sm
1818
text-black dark:text-darkSidebarTextHover
1919
bg-black bg-opacity-10
2020
hover:brightness-110
2121
hover:text-lightPrimary dark:hover:text-darkPrimary
2222
hover:bg-lightPrimaryContrast dark:hover:bg-darkPrimaryContrast
2323
w-full text-select-none pl-5 select-none"
2424
v-for="option in options"
25-
@click="navigateTo(option)"
25+
:to="getRoute(option)"
2626
>
2727
<span class="mr-1">
2828
<component v-if="option.icon" :is="getIcon(option.icon)" class="w-5 h-5 transition duration-75" ></component>
2929
</span>
3030
<span>{{ option.pageLabel }}</span>
31-
</div>
31+
</router-link>
3232
</div>
3333

3434

@@ -67,12 +67,10 @@ function slugifyString(str: string): string {
6767
.replace(/[^a-z0-9-_]/g, '-');
6868
}
6969
70-
function navigateTo(option: { slug?: string | null | undefined, pageLabel: string }) {
71-
if (option.slug) {
72-
router.push({ name: 'settings', params: { page: option.slug } });
73-
} else {
74-
const destinationSlug = slugifyString(option.pageLabel);
75-
router.push({ name: 'settings', params: { page: destinationSlug } });
70+
function getRoute(option: { slug?: string | null, pageLabel: string }) {
71+
return {
72+
name: 'settings',
73+
params: { page: option.slug ?? slugifyString(option.pageLabel) }
7674
}
7775
}
7876

0 commit comments

Comments
 (0)