Commit 4f12505c authored by ras19's avatar ras19
Browse files

Isolated project id using await and async. Now trying to post the project...

Isolated project id using await and async. Now trying to post the project assignment to relevant database [RS, EW]
parent 1192c2b7
Pipeline #202618 passed with stage
in 50 seconds
......@@ -17,34 +17,37 @@ const CreateProject = () => {
const { data: users, error, isPending } = useFetch("/users")
const handleSubmit = e => {
const handleSubmit = async e => {
e.preventDefault()
const newProject = { name, description, status, tag, location, files };
fetch("/projects", {
const response = await fetch("/projects", {
method: 'POST',
headers: { "Content-Type": "application/json" },
body: JSON.stringify(newProject)
}).then(response => {
console.log(response.json())
}).then(data => {
console.log(data)
})
});
// selectUsers.map(user => {
// setUsername(user.username)
// const assign_project = { username, project_id };
const responseJSON = await response.json();
console.log(responseJSON.id);
// console.log("The username is " + {username})
// console.log("The project_id is " + {project_id})
const project_id = responseJSON.id;
// fetch("/user_project", {
// method: 'POST',
// headers: { "Content-Type": "application/json" },
// body: JSON.stringify(assign_project)
// })
// })
selectUsers.map(user => {
setUsername(user.username)
const assign_project = { username, project_id };
// console.log(username)
// console.log(int(pid))
fetch("/user_project", {
method: 'POST',
headers: { "Content-Type": "application/json" },
body: JSON.stringify(assign_project)
})
});
history.push("/");
}
return (
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment