1
1
import { UMB_USER_WORKSPACE_CONTEXT } from '../../user-workspace.context-token.js' ;
2
2
import type { UmbUserDetailModel } from '../../../types.js' ;
3
- import { html , customElement , state , ifDefined , css } from '@umbraco-cms/backoffice/external/lit' ;
3
+ import { html , customElement , state , ifDefined , css , nothing } from '@umbraco-cms/backoffice/external/lit' ;
4
4
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element' ;
5
5
import { UmbTextStyles } from '@umbraco-cms/backoffice/style' ;
6
6
import type { UmbChangeEvent } from '@umbraco-cms/backoffice/event' ;
@@ -11,6 +11,9 @@ export class UmbUserWorkspaceProfileSettingsElement extends UmbLitElement {
11
11
@state ( )
12
12
private _user ?: UmbUserDetailModel ;
13
13
14
+ @state ( )
15
+ private _usernameIsEmail = true ;
16
+
14
17
#userWorkspaceContext?: typeof UMB_USER_WORKSPACE_CONTEXT . TYPE ;
15
18
16
19
constructor ( ) {
@@ -19,9 +22,34 @@ export class UmbUserWorkspaceProfileSettingsElement extends UmbLitElement {
19
22
this . consumeContext ( UMB_USER_WORKSPACE_CONTEXT , ( instance ) => {
20
23
this . #userWorkspaceContext = instance ;
21
24
this . observe ( this . #userWorkspaceContext. data , ( user ) => ( this . _user = user ) , 'umbUserObserver' ) ;
25
+ this . observe (
26
+ this . #userWorkspaceContext. configRepository . part ( 'usernameIsEmail' ) ,
27
+ ( usernameIsEmail ) => ( this . _usernameIsEmail = usernameIsEmail ) ,
28
+ 'umbUsernameIsEmailObserver' ,
29
+ ) ;
22
30
} ) ;
23
31
}
24
32
33
+ #onEmailChange( event : UmbChangeEvent ) {
34
+ const target = event . target as HTMLInputElement ;
35
+
36
+ if ( typeof target ?. value === 'string' ) {
37
+ this . #userWorkspaceContext?. updateProperty ( 'email' , target . value ) ;
38
+
39
+ if ( this . _usernameIsEmail ) {
40
+ this . #userWorkspaceContext?. updateProperty ( 'userName' , target . value ) ;
41
+ }
42
+ }
43
+ }
44
+
45
+ #onUsernameChange( event : UmbChangeEvent ) {
46
+ const target = event . target as HTMLInputElement ;
47
+
48
+ if ( typeof target ?. value === 'string' ) {
49
+ this . #userWorkspaceContext?. updateProperty ( 'userName' , target . value ) ;
50
+ }
51
+ }
52
+
25
53
#onLanguageChange( event : UmbChangeEvent ) {
26
54
const target = event . target as UmbUiCultureInputElement ;
27
55
@@ -33,23 +61,48 @@ export class UmbUserWorkspaceProfileSettingsElement extends UmbLitElement {
33
61
override render ( ) {
34
62
return html `<uui- box>
35
63
<div slot= "headline" > <umb- localize key= "user_profile" > Profile </ umb- localize> </ div>
36
- ${ this . #renderEmailProperty( ) } ${ this . #renderUILanguageProperty( ) }
64
+ ${ this . #renderEmailProperty( ) } ${ this . #renderUsernameProperty ( ) } ${ this . # renderUILanguageProperty( ) }
37
65
</ uui- box> ` ;
38
66
}
39
67
40
68
#renderEmailProperty( ) {
41
69
return html `
42
- <umb- property- layout label= "${ this . localize . term ( 'general_email' ) } " >
70
+ <umb- property- layout
71
+ label= "${ this . localize . term ( 'general_email' ) } "
72
+ .description = ${ this . localize . term ( 'user_emailDescription' , this . _usernameIsEmail ) } >
43
73
<uui- input
44
74
slot= "editor"
45
75
name = "email"
46
76
label = "${ this . localize . term ( 'general_email' ) } "
47
- readonly
77
+ @change = "${ this . #onEmailChange} "
78
+ required
79
+ required-message = ${ this . localize . term ( 'user_emailRequired' ) }
48
80
value= ${ ifDefined ( this . _user ?. email ) } > </ uui- input>
49
81
</ umb- property- layout>
50
82
` ;
51
83
}
52
84
85
+ #renderUsernameProperty( ) {
86
+ if ( this . _usernameIsEmail ) {
87
+ return nothing ;
88
+ }
89
+
90
+ return html `
91
+ <umb- property- layout
92
+ label= "${ this . localize . term ( 'user_loginname' ) } "
93
+ description = ${ this . localize . term ( 'user_loginnameDescription' ) } >
94
+ <uui- input
95
+ slot= "editor"
96
+ name = "username"
97
+ label= "${ this . localize . term ( 'user_loginname' ) } "
98
+ @change = "${ this . #onUsernameChange} "
99
+ required
100
+ required- message= ${ this . localize . term ( 'user_loginnameRequired' ) }
101
+ value= ${ ifDefined ( this . _user ?. userName ) } > </ uui- input>
102
+ </ umb- property- layout>
103
+ ` ;
104
+ }
105
+
53
106
#renderUILanguageProperty( ) {
54
107
return html `
55
108
<umb- property- layout
0 commit comments