feat: navigate back if request fails for get user

This commit is contained in:
Zamitto 2024-06-28 12:23:46 -03:00
parent 1ceabb00be
commit c27182c618

View file

@ -1,6 +1,6 @@
import { UserProfile } from "@types"; import { UserProfile } from "@types";
import { useCallback, useEffect, useState } from "react"; import { useCallback, useEffect, useState } from "react";
import { useParams } from "react-router-dom"; import { useNavigate, useParams } from "react-router-dom";
import { setHeaderTitle } from "@renderer/features"; import { setHeaderTitle } from "@renderer/features";
import { useAppDispatch } from "@renderer/hooks"; import { useAppDispatch } from "@renderer/hooks";
import { UserSkeleton } from "./user-skeleton"; import { UserSkeleton } from "./user-skeleton";
@ -12,6 +12,7 @@ import * as styles from "./user.css";
export const User = () => { export const User = () => {
const { userId } = useParams(); const { userId } = useParams();
const [userProfile, setUserProfile] = useState<UserProfile>(); const [userProfile, setUserProfile] = useState<UserProfile>();
const navigate = useNavigate();
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
@ -20,6 +21,8 @@ export const User = () => {
if (userProfile) { if (userProfile) {
dispatch(setHeaderTitle(userProfile.displayName)); dispatch(setHeaderTitle(userProfile.displayName));
setUserProfile(userProfile); setUserProfile(userProfile);
} else {
navigate(-1);
} }
}); });
}, [dispatch, userId]); }, [dispatch, userId]);