From e57443f1ed662a022494bb93d79c3d2f10a2d082 Mon Sep 17 00:00:00 2001 From: Saad Jutt Date: Thu, 28 Apr 2022 07:00:49 +0500 Subject: [PATCH] fix(web): show display name instead of username --- web/src/components/header.tsx | 6 +++--- web/src/components/login.tsx | 8 ++++---- web/src/components/userName.tsx | 6 +++--- web/src/context/appContext.tsx | 23 ++++++++++++----------- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/web/src/components/header.tsx b/web/src/components/header.tsx index f0654cc..c499ae3 100644 --- a/web/src/components/header.tsx +++ b/web/src/components/header.tsx @@ -12,7 +12,7 @@ import { } from '@mui/material' import OpenInNewIcon from '@mui/icons-material/OpenInNew' -import UserName from './userName' +import Username from './username' import { AppContext } from '../context/appContext' const NODE_ENV = process.env.NODE_ENV @@ -113,8 +113,8 @@ const Header = (props: any) => { justifyContent: 'flex-end' }} > - const Login = ({ getCodeOnly }: any) => { const location = useLocation() const appContext = useContext(AppContext) - const [username, setUserName] = useState('') + const [username, setUsername] = useState('') const [password, setPassword] = useState('') const [errorMessage, setErrorMessage] = useState('') let error: boolean @@ -57,8 +57,8 @@ const Login = ({ getCodeOnly }: any) => { if (loggedIn) { appContext.setLoggedIn?.(loggedIn) - appContext.setUserName?.(user.username) - appContext.setDisplayName?.(user.displayname) + appContext.setUsername?.(user.username) + appContext.setDisplayName?.(user.displayName) } } @@ -101,7 +101,7 @@ const Login = ({ getCodeOnly }: any) => { label="Username" type="text" variant="outlined" - onChange={(e: any) => setUserName(e.target.value)} + onChange={(e: any) => setUsername(e.target.value)} required /> { +const Username = (props: any) => { return ( { )} - {props.userName} + {props.username} ) } -export default UserName +export default Username diff --git a/web/src/context/appContext.tsx b/web/src/context/appContext.tsx index cac6cbd..dea218e 100644 --- a/web/src/context/appContext.tsx +++ b/web/src/context/appContext.tsx @@ -13,8 +13,8 @@ interface AppContextProps { checkingSession: boolean loggedIn: boolean setLoggedIn: Dispatch> | null - userName: string - setUserName: Dispatch> | null + username: string + setUsername: Dispatch> | null displayName: string setDisplayName: Dispatch> | null logout: (() => void) | null @@ -24,8 +24,8 @@ export const AppContext = createContext({ checkingSession: false, loggedIn: false, setLoggedIn: null, - userName: '', - setUserName: null, + username: '', + setUsername: null, displayName: '', setDisplayName: null, logout: null @@ -35,7 +35,7 @@ const AppContextProvider = (props: { children: ReactNode }) => { const { children } = props const [checkingSession, setCheckingSession] = useState(false) const [loggedIn, setLoggedIn] = useState(false) - const [userName, setUserName] = useState('') + const [username, setUsername] = useState('') const [displayName, setDisplayName] = useState('') useEffect(() => { @@ -43,11 +43,12 @@ const AppContextProvider = (props: { children: ReactNode }) => { axios .get('/SASjsApi/session') - .then((response: any) => { + .then((res) => res.data) + .then((data: any) => { setCheckingSession(false) setLoggedIn(true) - setUserName(response.userName) - setDisplayName(response.displayName) + setUsername(data.username) + setDisplayName(data.displayName) }) .catch(() => { setLoggedIn(false) @@ -57,7 +58,7 @@ const AppContextProvider = (props: { children: ReactNode }) => { const logout = useCallback(() => { axios.get('/logout').then(() => { setLoggedIn(false) - setUserName('') + setUsername('') setDisplayName('') }) }, []) @@ -68,8 +69,8 @@ const AppContextProvider = (props: { children: ReactNode }) => { checkingSession, loggedIn, setLoggedIn, - userName, - setUserName, + username, + setUsername, displayName, setDisplayName, logout