convert the 'edit' and 'change password' buttons into currentUserAction's
This commit is contained in:
@@ -12,6 +12,7 @@ export class UmbCurrentUserContext extends UmbContextBase<UmbCurrentUserContext>
|
||||
#currentUser = new UmbObjectState<UmbCurrentUserModel | undefined>(undefined);
|
||||
readonly currentUser = this.#currentUser.asObservable();
|
||||
|
||||
readonly unique = this.#currentUser.asObservablePart((user) => user?.unique);
|
||||
readonly languageIsoCode = this.#currentUser.asObservablePart((user) => user?.languageIsoCode);
|
||||
|
||||
#authContext?: typeof UMB_AUTH_CONTEXT.TYPE;
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import { UMB_CURRENT_USER_CONTEXT } from '../current-user.context.js';
|
||||
import { UmbActionBase } from '@umbraco-cms/backoffice/action';
|
||||
import type { UmbCurrentUserAction, UmbCurrentUserActionArgs } from '@umbraco-cms/backoffice/extension-registry';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UMB_CHANGE_PASSWORD_MODAL, UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal';
|
||||
|
||||
export class UmbChangePasswordCurrentUserAction<ArgsMetaType = never>
|
||||
extends UmbActionBase<UmbCurrentUserActionArgs<ArgsMetaType>>
|
||||
implements UmbCurrentUserAction<ArgsMetaType>
|
||||
{
|
||||
#unique?: string;
|
||||
|
||||
constructor(host: UmbControllerHost, args: UmbCurrentUserActionArgs<ArgsMetaType>) {
|
||||
super(host, args);
|
||||
|
||||
this.consumeContext(UMB_CURRENT_USER_CONTEXT, (context) => {
|
||||
this.observe(
|
||||
context.unique,
|
||||
(unique) => {
|
||||
this.#unique = unique;
|
||||
},
|
||||
'umbEditCurrentUserActionObserver',
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
async getHref() {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
async execute() {
|
||||
if (!this.#unique) return;
|
||||
|
||||
const modalManager = await this.getContext(UMB_MODAL_MANAGER_CONTEXT);
|
||||
modalManager.open(this, UMB_CHANGE_PASSWORD_MODAL, {
|
||||
data: {
|
||||
user: {
|
||||
unique: this.#unique,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { UMB_CURRENT_USER_CONTEXT } from '../current-user.context.js';
|
||||
import { UmbActionBase } from '@umbraco-cms/backoffice/action';
|
||||
import type { UmbCurrentUserAction, UmbCurrentUserActionArgs } from '@umbraco-cms/backoffice/extension-registry';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
|
||||
export class UmbEditCurrentUserAction<ArgsMetaType = never>
|
||||
extends UmbActionBase<UmbCurrentUserActionArgs<ArgsMetaType>>
|
||||
implements UmbCurrentUserAction<ArgsMetaType>
|
||||
{
|
||||
#init;
|
||||
#unique?: string;
|
||||
|
||||
constructor(host: UmbControllerHost, args: UmbCurrentUserActionArgs<ArgsMetaType>) {
|
||||
super(host, args);
|
||||
|
||||
this.#init = new Promise<void>((res) => {
|
||||
this.consumeContext(UMB_CURRENT_USER_CONTEXT, (context) => {
|
||||
this.observe(
|
||||
context.unique,
|
||||
(unique) => {
|
||||
this.#unique = unique;
|
||||
res();
|
||||
},
|
||||
'umbEditCurrentUserActionObserver',
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async getHref() {
|
||||
await this.#init;
|
||||
return `section/user-management/view/users/user/edit/${this.#unique}`;
|
||||
}
|
||||
|
||||
async execute() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,11 @@
|
||||
import type { ManifestUserProfileApp } from '@umbraco-cms/backoffice/extension-registry';
|
||||
import { UmbChangePasswordCurrentUserAction } from './change-password-current-user.action.js';
|
||||
import { UmbEditCurrentUserAction } from './edit-current-user.action.js';
|
||||
import type {
|
||||
ManifestCurrentUserActionDefaultKind,
|
||||
ManifestUserProfileApp,
|
||||
} from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
export const userProfileApps: Array<ManifestUserProfileApp> = [
|
||||
const userProfileApps: Array<ManifestUserProfileApp> = [
|
||||
{
|
||||
type: 'userProfileApp',
|
||||
alias: 'Umb.UserProfileApp.CurrentUser.Profile',
|
||||
@@ -13,4 +18,38 @@ export const userProfileApps: Array<ManifestUserProfileApp> = [
|
||||
},
|
||||
},
|
||||
];
|
||||
export const manifests = [...userProfileApps];
|
||||
|
||||
const currentUserActions: Array<ManifestCurrentUserActionDefaultKind> = [
|
||||
{
|
||||
type: 'currentUserAction',
|
||||
kind: 'default',
|
||||
alias: 'Umb.CurrentUser.Button.Edit',
|
||||
name: 'Current User Edit Button',
|
||||
weight: 1000,
|
||||
api: UmbEditCurrentUserAction,
|
||||
meta: {
|
||||
label: '#general_edit',
|
||||
icon: 'edit',
|
||||
},
|
||||
conditions: [
|
||||
{
|
||||
alias: 'Umb.Condition.SectionUserPermission',
|
||||
match: 'Umb.Section.Users',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'currentUserAction',
|
||||
kind: 'default',
|
||||
alias: 'Umb.CurrentUser.Button.ChangePassword',
|
||||
name: 'Current User Change Password Button',
|
||||
weight: 900,
|
||||
api: UmbChangePasswordCurrentUserAction,
|
||||
meta: {
|
||||
label: '#general_changePassword',
|
||||
icon: 'lock',
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export const manifests = [...userProfileApps, ...currentUserActions];
|
||||
|
||||
Reference in New Issue
Block a user