mirror of
https://github.com/sasjs/server.git
synced 2026-01-16 02:10:05 +00:00
fix(web): show display name instead of username
This commit is contained in:
@@ -12,7 +12,7 @@ import {
|
|||||||
} from '@mui/material'
|
} from '@mui/material'
|
||||||
import OpenInNewIcon from '@mui/icons-material/OpenInNew'
|
import OpenInNewIcon from '@mui/icons-material/OpenInNew'
|
||||||
|
|
||||||
import UserName from './userName'
|
import Username from './username'
|
||||||
import { AppContext } from '../context/appContext'
|
import { AppContext } from '../context/appContext'
|
||||||
|
|
||||||
const NODE_ENV = process.env.NODE_ENV
|
const NODE_ENV = process.env.NODE_ENV
|
||||||
@@ -113,8 +113,8 @@ const Header = (props: any) => {
|
|||||||
justifyContent: 'flex-end'
|
justifyContent: 'flex-end'
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<UserName
|
<Username
|
||||||
userName={appContext.userName}
|
username={appContext.displayName || appContext.username}
|
||||||
onClickHandler={handleMenu}
|
onClickHandler={handleMenu}
|
||||||
/>
|
/>
|
||||||
<Menu
|
<Menu
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const login = async (payload: { username: string; password: string }) =>
|
|||||||
const Login = ({ getCodeOnly }: any) => {
|
const Login = ({ getCodeOnly }: any) => {
|
||||||
const location = useLocation()
|
const location = useLocation()
|
||||||
const appContext = useContext(AppContext)
|
const appContext = useContext(AppContext)
|
||||||
const [username, setUserName] = useState('')
|
const [username, setUsername] = useState('')
|
||||||
const [password, setPassword] = useState('')
|
const [password, setPassword] = useState('')
|
||||||
const [errorMessage, setErrorMessage] = useState('')
|
const [errorMessage, setErrorMessage] = useState('')
|
||||||
let error: boolean
|
let error: boolean
|
||||||
@@ -57,8 +57,8 @@ const Login = ({ getCodeOnly }: any) => {
|
|||||||
|
|
||||||
if (loggedIn) {
|
if (loggedIn) {
|
||||||
appContext.setLoggedIn?.(loggedIn)
|
appContext.setLoggedIn?.(loggedIn)
|
||||||
appContext.setUserName?.(user.username)
|
appContext.setUsername?.(user.username)
|
||||||
appContext.setDisplayName?.(user.displayname)
|
appContext.setDisplayName?.(user.displayName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ const Login = ({ getCodeOnly }: any) => {
|
|||||||
label="Username"
|
label="Username"
|
||||||
type="text"
|
type="text"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
onChange={(e: any) => setUserName(e.target.value)}
|
onChange={(e: any) => setUsername(e.target.value)}
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
<TextField
|
<TextField
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import React from 'react'
|
|||||||
import { Typography, IconButton } from '@mui/material'
|
import { Typography, IconButton } from '@mui/material'
|
||||||
import AccountCircle from '@mui/icons-material/AccountCircle'
|
import AccountCircle from '@mui/icons-material/AccountCircle'
|
||||||
|
|
||||||
const UserName = (props: any) => {
|
const Username = (props: any) => {
|
||||||
return (
|
return (
|
||||||
<IconButton
|
<IconButton
|
||||||
aria-label="account of current user"
|
aria-label="account of current user"
|
||||||
@@ -21,10 +21,10 @@ const UserName = (props: any) => {
|
|||||||
<AccountCircle></AccountCircle>
|
<AccountCircle></AccountCircle>
|
||||||
)}
|
)}
|
||||||
<Typography variant="h6" sx={{ color: 'white', padding: '0 8px' }}>
|
<Typography variant="h6" sx={{ color: 'white', padding: '0 8px' }}>
|
||||||
{props.userName}
|
{props.username}
|
||||||
</Typography>
|
</Typography>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default UserName
|
export default Username
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ interface AppContextProps {
|
|||||||
checkingSession: boolean
|
checkingSession: boolean
|
||||||
loggedIn: boolean
|
loggedIn: boolean
|
||||||
setLoggedIn: Dispatch<SetStateAction<boolean>> | null
|
setLoggedIn: Dispatch<SetStateAction<boolean>> | null
|
||||||
userName: string
|
username: string
|
||||||
setUserName: Dispatch<SetStateAction<string>> | null
|
setUsername: Dispatch<SetStateAction<string>> | null
|
||||||
displayName: string
|
displayName: string
|
||||||
setDisplayName: Dispatch<SetStateAction<string>> | null
|
setDisplayName: Dispatch<SetStateAction<string>> | null
|
||||||
logout: (() => void) | null
|
logout: (() => void) | null
|
||||||
@@ -24,8 +24,8 @@ export const AppContext = createContext<AppContextProps>({
|
|||||||
checkingSession: false,
|
checkingSession: false,
|
||||||
loggedIn: false,
|
loggedIn: false,
|
||||||
setLoggedIn: null,
|
setLoggedIn: null,
|
||||||
userName: '',
|
username: '',
|
||||||
setUserName: null,
|
setUsername: null,
|
||||||
displayName: '',
|
displayName: '',
|
||||||
setDisplayName: null,
|
setDisplayName: null,
|
||||||
logout: null
|
logout: null
|
||||||
@@ -35,7 +35,7 @@ const AppContextProvider = (props: { children: ReactNode }) => {
|
|||||||
const { children } = props
|
const { children } = props
|
||||||
const [checkingSession, setCheckingSession] = useState(false)
|
const [checkingSession, setCheckingSession] = useState(false)
|
||||||
const [loggedIn, setLoggedIn] = useState(false)
|
const [loggedIn, setLoggedIn] = useState(false)
|
||||||
const [userName, setUserName] = useState('')
|
const [username, setUsername] = useState('')
|
||||||
const [displayName, setDisplayName] = useState('')
|
const [displayName, setDisplayName] = useState('')
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -43,11 +43,12 @@ const AppContextProvider = (props: { children: ReactNode }) => {
|
|||||||
|
|
||||||
axios
|
axios
|
||||||
.get('/SASjsApi/session')
|
.get('/SASjsApi/session')
|
||||||
.then((response: any) => {
|
.then((res) => res.data)
|
||||||
|
.then((data: any) => {
|
||||||
setCheckingSession(false)
|
setCheckingSession(false)
|
||||||
setLoggedIn(true)
|
setLoggedIn(true)
|
||||||
setUserName(response.userName)
|
setUsername(data.username)
|
||||||
setDisplayName(response.displayName)
|
setDisplayName(data.displayName)
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
setLoggedIn(false)
|
setLoggedIn(false)
|
||||||
@@ -57,7 +58,7 @@ const AppContextProvider = (props: { children: ReactNode }) => {
|
|||||||
const logout = useCallback(() => {
|
const logout = useCallback(() => {
|
||||||
axios.get('/logout').then(() => {
|
axios.get('/logout').then(() => {
|
||||||
setLoggedIn(false)
|
setLoggedIn(false)
|
||||||
setUserName('')
|
setUsername('')
|
||||||
setDisplayName('')
|
setDisplayName('')
|
||||||
})
|
})
|
||||||
}, [])
|
}, [])
|
||||||
@@ -68,8 +69,8 @@ const AppContextProvider = (props: { children: ReactNode }) => {
|
|||||||
checkingSession,
|
checkingSession,
|
||||||
loggedIn,
|
loggedIn,
|
||||||
setLoggedIn,
|
setLoggedIn,
|
||||||
userName,
|
username,
|
||||||
setUserName,
|
setUsername,
|
||||||
displayName,
|
displayName,
|
||||||
setDisplayName,
|
setDisplayName,
|
||||||
logout
|
logout
|
||||||
|
|||||||
Reference in New Issue
Block a user