Tela de perfil exibe outro usuário corretamente

This commit is contained in:
Matheus Albino Brunhara
2022-05-28 17:37:55 -05:00
parent 4c6aacfd12
commit b5d6f8ef34
3 changed files with 24 additions and 14 deletions

View File

@@ -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" />

View File

@@ -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>
);

View File

@@ -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
}