import { useState } from "react"; import { APIResponse, api } from "../API/API"; import { NewProject } from "../Types/goTypes"; import InputField from "./InputField"; import Logo from "../assets/Logo.svg"; import Button from "./Button"; /** * Tries to add a project to the system * @param {Object} props - Project name and description * @returns {boolean} True if created, false if not */ function CreateProject(props: { name: string; description: string }): void { const project: NewProject = { name: props.name, description: props.description, }; api .createProject(project, localStorage.getItem("accessToken") ?? "") .then((response: APIResponse) => { if (response.success) { 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); }); } /** * Provides UI for adding a project to the system. * @returns {JSX.Element} - Returns the component UI for adding a project */ function AddProject(): JSX.Element { const [name, setName] = useState(""); const [description, setDescription] = useState(""); return (
{ e.preventDefault(); CreateProject({ name: name, description: description, }); }} > TTIME Logo

Create a new project

{ e.preventDefault(); setName(e.target.value); }} /> { e.preventDefault(); setDescription(e.target.value); }} />

); } export default AddProject;