@@ -15,48 +15,6 @@ import { UserContext } from "../user-context";
15
15
import { isGitpodIo } from "../utils" ;
16
16
17
17
export namespace ProfileState {
18
- export interface ProfileState {
19
- name : string ;
20
- email : string ;
21
- company ?: string ;
22
- avatarURL ?: string ;
23
- }
24
-
25
- export function getProfileState ( user : User ) : ProfileState {
26
- return {
27
- name : User . getName ( user ! ) || "" ,
28
- email : User . getPrimaryEmail ( user ! ) || "" ,
29
- company : user ?. additionalData ?. profile ?. companyName ,
30
- avatarURL : user ?. avatarUrl ,
31
- } ;
32
- }
33
-
34
- export function setProfileState ( user : User , profileState : ProfileState ) : User {
35
- user . fullName = profileState . name ;
36
- user . avatarUrl = profileState . avatarURL ;
37
-
38
- if ( ! user . additionalData ) {
39
- user . additionalData = { } ;
40
- }
41
- if ( ! user . additionalData . profile ) {
42
- user . additionalData . profile = { } ;
43
- }
44
- user . additionalData . profile . emailAddress = profileState . email ;
45
- user . additionalData . profile . companyName = profileState . company ;
46
- user . additionalData . profile . lastUpdatedDetailsNudge = new Date ( ) . toISOString ( ) ;
47
-
48
- return user ;
49
- }
50
-
51
- export function hasChanges ( before : ProfileState , after : ProfileState ) {
52
- return (
53
- before . name !== after . name ||
54
- before . email !== after . email ||
55
- before . company !== after . company ||
56
- before . avatarURL !== after . avatarURL
57
- ) ;
58
- }
59
-
60
18
function shouldNudgeForUpdate ( user : User ) : boolean {
61
19
if ( ! isGitpodIo ( ) ) {
62
20
return false ;
@@ -79,7 +37,7 @@ export namespace ProfileState {
79
37
* @param state
80
38
* @returns error message or empty string when valid
81
39
*/
82
- export function validate ( state : ProfileState ) : string {
40
+ export function validate ( state : User . Profile ) : string {
83
41
if ( state . name . trim ( ) === "" ) {
84
42
return "Name must not be empty." ;
85
43
}
@@ -98,7 +56,7 @@ export namespace ProfileState {
98
56
99
57
export function NudgeForProfileUpdateModal ( ) {
100
58
const { user, setUser } = useContext ( UserContext ) ;
101
- const original = ProfileState . getProfileState ( user ! ) ;
59
+ const original = User . getProfile ( user ! ) ;
102
60
const [ profileState , setProfileState ] = useState ( original ) ;
103
61
const [ errorMessage , setErrorMessage ] = useState ( "" ) ;
104
62
const [ visible , setVisible ] = useState ( shouldNudgeForUpdate ( user ! ) ) ;
@@ -109,7 +67,7 @@ export namespace ProfileState {
109
67
if ( error ) {
110
68
return ;
111
69
}
112
- const updatedUser = ProfileState . setProfileState ( user ! , profileState ) ;
70
+ const updatedUser = User . setProfile ( user ! , profileState ) ;
113
71
setUser ( updatedUser ) ;
114
72
getGitpodService ( ) . server . updateLoggedInUser ( updatedUser ) ;
115
73
setVisible ( shouldNudgeForUpdate ( updatedUser ! ) ) ;
@@ -150,8 +108,8 @@ export namespace ProfileState {
150
108
}
151
109
152
110
export default function ProfileInformation ( props : {
153
- profileState : ProfileState . ProfileState ;
154
- setProfileState : ( newState : ProfileState . ProfileState ) => void ;
111
+ profileState : User . Profile ;
112
+ setProfileState : ( newState : User . Profile ) => void ;
155
113
errorMessage : string ;
156
114
updated : boolean ;
157
115
children ?: React . ReactChild [ ] | React . ReactChild ;
0 commit comments