@@ -4,13 +4,16 @@ import React, { useState } from "react";
4
4
import InputField from "@/components/ui/InputField" ;
5
5
import Button from "@/components/ui/Button" ;
6
6
import DangerButton from "@/components/ui/DangerButton" ;
7
- // import api from "@/api"; Uncomment this line when you start development
7
+ import api from "@/api" ;
8
8
import Link from "next/link" ;
9
+ import axios from "axios" ;
10
+ import { useRouter } from "next/navigation" ;
9
11
10
12
const EvaluateProjectPage : React . FC = ( ) => {
11
13
const [ projectId , setProjectId ] = useState ( "" ) ;
12
14
const [ score , setScore ] = useState < number | "" > ( "" ) ;
13
15
const [ error , setError ] = useState ( "" ) ;
16
+ const router = useRouter ( ) ;
14
17
15
18
const handleSubmit = async ( ) => {
16
19
if ( projectId === "" ) {
@@ -24,22 +27,35 @@ const EvaluateProjectPage: React.FC = () => {
24
27
}
25
28
26
29
setError ( "" ) ;
27
- console . log ( { projectId, score } ) ;
28
30
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
+ } ) ;
30
36
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
+ }
43
59
} ;
44
60
45
61
return (
0 commit comments