Skip to content

Commit d83bafe

Browse files
authored
Merge pull request #85 from suyu101/eval-project-api
Eval project api
2 parents c5a5469 + 93da9b7 commit d83bafe

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

app/projecteval/page.tsx

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ import React, { useState } from "react";
44
import InputField from "@/components/ui/InputField";
55
import Button from "@/components/ui/Button";
66
import DangerButton from "@/components/ui/DangerButton";
7-
// import api from "@/api"; Uncomment this line when you start development
7+
import api from "@/api";
88
import Link from "next/link";
9+
import axios from "axios";
10+
import { useRouter } from "next/navigation";
911

1012
const EvaluateProjectPage: React.FC = () => {
1113
const [projectId, setProjectId] = useState("");
1214
const [score, setScore] = useState<number | "">("");
1315
const [error, setError] = useState("");
16+
const router = useRouter();
1417

1518
const handleSubmit = async () => {
1619
if (projectId === "") {
@@ -24,22 +27,35 @@ const EvaluateProjectPage: React.FC = () => {
2427
}
2528

2629
setError("");
27-
console.log({ projectId, score });
2830

29-
// Rewrite this function with the correct API route and all the error codes
31+
try {
32+
const response = await api.post("/evaluation", {
33+
projectId,
34+
score,
35+
});
3036

31-
// try {
32-
// const response = await api.post("/evaluate-project", {
33-
// projectId,
34-
// score,
35-
// });
36-
37-
// if (response.status === 200) {
38-
// console.log("Evaluation submitted:", response.data);
39-
// }
40-
// } catch (err) {
41-
// console.error("Error submitting evaluation:", err);
42-
// }
37+
if (response.status === 201) {
38+
router.push("/allprojects");
39+
}
40+
} catch (err: unknown) {
41+
if (axios.isAxiosError(err)) {
42+
if (err.response) {
43+
if (err.response.status === 401) {
44+
setError("Unauthorized. Please log in.");
45+
} else if (err.response.status === 403) {
46+
setError("You do not have sufficient permissions.");
47+
} else if (err.response.status === 404) {
48+
setError("Project not found.");
49+
} else if (err.response.status === 500) {
50+
setError("Internal Server Error. Please try again later.");
51+
} else {
52+
setError("An unexpected error occurred.");
53+
}
54+
} else {
55+
setError("Failed to connect to the server.");
56+
}
57+
}
58+
}
4359
};
4460

4561
return (

0 commit comments

Comments
 (0)