Skip to content

Commit 4883955

Browse files
authored
Merge pull request #87 from koshambiB/feat/update-project-integration
feat: update project integration
2 parents 554be61 + 6d11cca commit 4883955

File tree

1 file changed

+41
-38
lines changed

1 file changed

+41
-38
lines changed

app/updateProject/page.tsx

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import InputField from "@/components/ui/InputField";
66
import { useAuth } from "@/context/AuthContext";
77
import { useRouter } from "next/navigation";
88
import api from "@/api";
9-
// import axios from "axios";
9+
import axios from "axios";
1010
import DangerButton from "@/components/ui/DangerButton";
1111
import DialogBox from "@/components/ui/DialogBox";
1212

1313
const UpdateProject = () => {
14-
// const [projectId, setProjectId] = useState(""); Uncomment this line on development
14+
const [projectId, setProjectId] = useState("");
1515
const [name, setName] = useState("");
1616
const [description, setDescription] = useState("");
1717
const [repoUrl, setRepoUrl] = useState("");
@@ -49,7 +49,7 @@ const UpdateProject = () => {
4949
}
5050

5151
if (response.data) {
52-
// setProjectId(response.data.project.id || ""); Uncomment this line on development
52+
setProjectId(response.data.project.id || "");
5353
setName(response.data.project.name || "");
5454
setDescription(response.data.project.description || "");
5555
setRepoUrl(response.data.project.repoUrl || "");
@@ -72,41 +72,44 @@ const UpdateProject = () => {
7272
}
7373

7474
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+
}
110113
};
111114

112115
const handleSubmit = () => {

0 commit comments

Comments
 (0)