From 68fbbb4b19b981ae968acbca4fa805302d3c3c6f Mon Sep 17 00:00:00 2001 From: Peter KW Date: Mon, 1 Apr 2024 02:09:28 +0200 Subject: [PATCH] Added some alerts + removed unused code --- frontend/src/Components/AddProject.tsx | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/frontend/src/Components/AddProject.tsx b/frontend/src/Components/AddProject.tsx index f5f4a08..c157b04 100644 --- a/frontend/src/Components/AddProject.tsx +++ b/frontend/src/Components/AddProject.tsx @@ -1,6 +1,6 @@ import { useState } from "react"; import { APIResponse, api } from "../API/API"; -import { NewProject, Project } from "../Types/goTypes"; +import { NewProject } from "../Types/goTypes"; import InputField from "./InputField"; import Logo from "../assets/Logo.svg"; import Button from "./Button"; @@ -10,27 +10,26 @@ import Button from "./Button"; * @param {Object} props - Project name and description * @returns {boolean} True if created, false if not */ -function CreateProject(props: { name: string; description: string }): boolean { +function CreateProject(props: { name: string; description: string }): void { const project: NewProject = { name: props.name, description: props.description, }; - let created = false; - api .createProject(project, localStorage.getItem("accessToken") ?? "") - .then((response: APIResponse) => { + .then((response: APIResponse) => { if (response.success) { - created = true; + alert("Project added!"); } else { + alert("Project NOT added!"); console.error(response.message); } }) .catch((error) => { + alert("Project NOT added!"); console.error("An error occurred during creation:", error); }); - return created; } /** @@ -48,7 +47,10 @@ function AddProject(): JSX.Element { className="bg-white rounded px-8 pt-6 pb-8 mb-4 items-center justify-center flex flex-col w-fit h-fit" onSubmit={(e) => { e.preventDefault(); - CreateProject({ name: name, description: description }); + CreateProject({ + name: name, + description: description, + }); }} > { + e.preventDefault(); setName(e.target.value); }} /> @@ -72,6 +75,7 @@ function AddProject(): JSX.Element { type="text" value={description} onChange={(e) => { + e.preventDefault(); setDescription(e.target.value); }} />