Tela de perfil exibe outro usuário corretamente
This commit is contained in:
@@ -50,7 +50,7 @@ const routes = (
|
||||
<Route exact path="/home" component={Home}></Route>
|
||||
<Route exact path="/perfil" component={Perfil}></Route>
|
||||
<Route exact path="/perfil/editar" component={PerfilEditar}></Route>
|
||||
<Route exact path="/perfil/:id" component={Perfil}></Route>
|
||||
<Route exact path="/usuario/:id" component={Perfil}></Route>
|
||||
<Route exact path="/cadastro-van" component={CadastroVan}></Route>
|
||||
<Route exact path="/">
|
||||
<Redirect to="/login" />
|
||||
|
||||
@@ -8,7 +8,7 @@ const Home: React.FC = () => {
|
||||
return (
|
||||
<IonPage>
|
||||
<IonContent>
|
||||
<IonButton onClick={() => { history.push({ pathname: '/perfil/1' }); }}>Ir para o perfil de outra pessoa</IonButton>
|
||||
<IonButton onClick={() => { history.push({ pathname: '/usuario/56520ae7-faf8-4444-a82b-7f3990ab02d8' }); }}>Ir para o perfil de outra pessoa</IonButton>
|
||||
</IonContent>
|
||||
</IonPage>
|
||||
);
|
||||
|
||||
@@ -66,31 +66,41 @@ const Perfil: React.FC<ScanNewProps> = (props) => {
|
||||
const logoff = () => {
|
||||
LocalStorage.clearToken()
|
||||
user.setIsLoggedIn(false);
|
||||
history.push('/login')
|
||||
history.push({ pathname: '/login' });
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const loadUserData = async () => {
|
||||
let userId = ''
|
||||
|
||||
|
||||
// verify if user is authenticated
|
||||
const refreshSessionRes = await sessionsService.refreshSession()
|
||||
if (props.match.params.id) {
|
||||
userId = props.match.params.id
|
||||
} else {
|
||||
const refreshSessionRes = await sessionsService.refreshSession()
|
||||
|
||||
if (refreshSessionRes.error) {
|
||||
redirectUserToLogin()
|
||||
return
|
||||
}
|
||||
|
||||
if (refreshSessionRes.userId) {
|
||||
userId = refreshSessionRes.userId
|
||||
if (refreshSessionRes.error) {
|
||||
redirectUserToLogin()
|
||||
return
|
||||
}
|
||||
|
||||
if (refreshSessionRes.userId) {
|
||||
userId = refreshSessionRes.userId
|
||||
}
|
||||
}
|
||||
|
||||
// get user info by ID
|
||||
const getByIdRes = await usersService.getById(userId)
|
||||
|
||||
if (getByIdRes.error) {
|
||||
setMessageToast(getByIdRes.error.errorMessage)
|
||||
setShowToast(true)
|
||||
if (isVisitor && props.match.params.id) {
|
||||
setMessageToast('Usuário não existe!')
|
||||
setShowToast(true)
|
||||
history.push({ pathname: '/home' })
|
||||
} else {
|
||||
setMessageToast(getByIdRes.error.errorMessage)
|
||||
setShowToast(true)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user