@@ -6,12 +6,12 @@ import InputField from "@/components/ui/InputField";
6
6
import { useAuth } from "@/context/AuthContext" ;
7
7
import { useRouter } from "next/navigation" ;
8
8
import api from "@/api" ;
9
- // import axios from "axios";
9
+ import axios from "axios" ;
10
10
import DangerButton from "@/components/ui/DangerButton" ;
11
11
import DialogBox from "@/components/ui/DialogBox" ;
12
12
13
13
const UpdateProject = ( ) => {
14
- // const [projectId, setProjectId] = useState(""); Uncomment this line on development
14
+ const [ projectId , setProjectId ] = useState ( "" ) ;
15
15
const [ name , setName ] = useState ( "" ) ;
16
16
const [ description , setDescription ] = useState ( "" ) ;
17
17
const [ repoUrl , setRepoUrl ] = useState ( "" ) ;
@@ -49,7 +49,7 @@ const UpdateProject = () => {
49
49
}
50
50
51
51
if ( response . data ) {
52
- // setProjectId(response.data.project.id || ""); Uncomment this line on development
52
+ setProjectId ( response . data . project . id || "" ) ;
53
53
setName ( response . data . project . name || "" ) ;
54
54
setDescription ( response . data . project . description || "" ) ;
55
55
setRepoUrl ( response . data . project . repoUrl || "" ) ;
@@ -72,41 +72,44 @@ const UpdateProject = () => {
72
72
}
73
73
74
74
const handleUpdateProject = async ( ) => {
75
- // Implement the update project functionality
76
- // try {
77
- // const response = await api.post(`/project/update`, {
78
- // name,
79
- // description,
80
- // repoUrl,
81
- // demoUrl,
82
- // reportUrl,
83
- // imageId,
84
- // });
85
- // if (response.status === 200) {
86
- // router.push("/projects");
87
- // }
88
- // } catch (error: unknown) {
89
- // if (axios.isAxiosError(error)) {
90
- // if (error.response) {
91
- // if (error.response.status === 403) {
92
- // setError(
93
- // "You do not have sufficient permissions to update this project."
94
- // );
95
- // } else if (error.response.status === 404) {
96
- // setError("Project not found. It may have been deleted.");
97
- // } else if (error.response.status === 500) {
98
- // setError("Internal Server Error. Please try again later.");
99
- // } else {
100
- // setError("An unexpected error occurred.");
101
- // }
102
- // } else {
103
- // setError(
104
- // "Failed to connect to the server. Check your internet connection."
105
- // );
106
- // }
107
- // setSuccess("");
108
- // }
109
- // }
75
+ if ( ! projectId ) {
76
+ setError ( "Project ID is missing." ) ;
77
+ return ;
78
+ }
79
+
80
+ try {
81
+ setError ( "" ) ;
82
+ const response = await api . post ( `/project/${ projectId } ` , {
83
+ name,
84
+ description,
85
+ repoUrl,
86
+ demoUrl,
87
+ reportUrl,
88
+ imageId,
89
+ } ) ;
90
+
91
+ if ( response . status === 201 ) {
92
+ router . push ( "/allprojects" ) ;
93
+ }
94
+ } catch ( err : unknown ) {
95
+ if ( axios . isAxiosError ( err ) ) {
96
+ if ( err . response ) {
97
+ if ( err . response . status === 403 ) {
98
+ setError (
99
+ "You do not have sufficient permissions to update this project." ,
100
+ ) ;
101
+ } else if ( err . response . status === 404 ) {
102
+ setError ( "Project not found." ) ;
103
+ } else if ( err . response . status === 500 ) {
104
+ setError ( "Internal Server Error." ) ;
105
+ } else {
106
+ setError ( "An unexpected error occurred." ) ;
107
+ }
108
+ } else {
109
+ setError ( "Failed to connect to the server." ) ;
110
+ }
111
+ }
112
+ }
110
113
} ;
111
114
112
115
const handleSubmit = ( ) => {
0 commit comments