@@ -2,7 +2,7 @@ import React from "react";
22import  {  Container ,  Title  }  from  "@mantine/core" ; 
33import  {  AuthGuard  }  from  "@ui/components/AuthGuard" ; 
44import  {  useApi  }  from  "@ui/util/api" ; 
5- import  {  UserProfileData ,   UserProfileDataBase  }  from  "@common/types/msGraphApi" ; 
5+ import  {  UserProfileData  }  from  "@common/types/msGraphApi" ; 
66import  {  ManageProfileComponent  }  from  "./ManageProfileComponent" ; 
77import  {  useNavigate ,  useSearchParams  }  from  "react-router-dom" ; 
88import  {  useAuth  }  from  "@ui/components/AuthContext" ; 
@@ -19,43 +19,24 @@ export const ManageProfilePage: React.FC = () => {
1919  const  getProfile  =  async  ( )  =>  { 
2020    const  raw  =  ( 
2121      await  graphApi . get ( 
22-         "/v1.0/me?$select=userPrincipalName,givenName,surname,displayName,otherMails, mail" , 
22+         "/v1.0/me?$select=userPrincipalName,givenName,surname,displayName,mail" , 
2323      ) 
24-     ) . data  as  UserProfileDataBase ; 
25-     const  discordUsername  =  raw . otherMails ?. filter ( ( x )  => 
26-       x . endsWith ( "@discord" ) , 
27-     ) ; 
28-     const  enhanced  =  raw  as  UserProfileData ; 
29-     if  ( discordUsername ?. length  ===  1 )  { 
30-       enhanced . discordUsername  =  discordUsername [ 0 ] . replace ( "@discord" ,  "" ) ; 
31-       enhanced . otherMails  =  enhanced . otherMails ?. filter ( 
32-         ( x )  =>  ! x . endsWith ( "@discord" ) , 
33-       ) ; 
34-     } 
35-     const  normalizedName  =  transformCommaSeperatedName ( 
36-       enhanced . displayName  ||  "" , 
37-     ) ; 
38-     const  extractedFirstName  = 
39-       enhanced . givenName  ||  normalizedName . split ( " " ) [ 0 ] ; 
40-     let  extractedLastName  =  enhanced . surname  ||  normalizedName . split ( " " ) [ 1 ] ; 
41-     if  ( ! enhanced . surname )  { 
24+     ) . data  as  UserProfileData ; 
25+     const  normalizedName  =  transformCommaSeperatedName ( raw . displayName  ||  "" ) ; 
26+     const  extractedFirstName  =  raw . givenName  ||  normalizedName . split ( " " ) [ 0 ] ; 
27+     let  extractedLastName  =  raw . surname  ||  normalizedName . split ( " " ) [ 1 ] ; 
28+     if  ( ! raw . surname )  { 
4229      extractedLastName  =  extractedLastName . slice ( 1 ,  extractedLastName . length ) ; 
4330    } 
4431    return  { 
45-       ...enhanced , 
32+       ...raw , 
4633      displayName : normalizedName , 
4734      givenName : extractedFirstName , 
4835      surname : extractedLastName , 
4936    } ; 
5037  } ; 
5138
5239  const  setProfile  =  async  ( data : UserProfileData )  =>  { 
53-     const  newOtherEmails  =  [ data . mail  ||  data . userPrincipalName ] ; 
54-     if  ( data . discordUsername  &&  data . discordUsername  !==  "" )  { 
55-       newOtherEmails . push ( `${ data . discordUsername }  @discord` ) ; 
56-     } 
57-     data . otherMails  =  newOtherEmails ; 
58-     delete  data . discordUsername ; 
5940    const  response  =  await  api . patch ( "/api/v1/iam/profile" ,  data ) ; 
6041    if  ( response . status  <  299  &&  firstTime )  { 
6142      setLoginStatus ( true ) ; 
0 commit comments