Redirect to 404 page if user not found

This commit is contained in:
T'JAMPENS QUENTIN p2406187
2025-12-17 15:20:51 +01:00
parent 883d19d7c4
commit c2f4c9fa55
3 changed files with 22 additions and 7 deletions
@@ -4,20 +4,28 @@ import { useEffect, useState } from "react";
import getUserById from "../../utils/users/getUserById.js";
import formatDate from "../../utils/date/formatDate.js";
import Task from "../../components/Task/Task.jsx";
import { useNavigate } from "react-router";
export default function VolunteerProfilePage() {
const params = useParams();
const id = params.id;
const navigate = useNavigate();
const [user, setUser] = useState({});
useEffect(() => {
(async () => {
const data = await getUserById(id);
setUser(data);
}) ()
}, []);
const result = await getUserById(id);
if (result?.error === 'not_found') {
navigate("/404");
} else {
setUser(result);
}
})();
}, [id]);
return <div className={styles.container}>