diff --git a/frontend/src/Components/AddProject.tsx b/frontend/src/Components/AddProject.tsx index cbc3622..8c9c566 100644 --- a/frontend/src/Components/AddProject.tsx +++ b/frontend/src/Components/AddProject.tsx @@ -1,9 +1,13 @@ import { useState } from "react"; import { api } from "../API/API"; import { NewProject } from "../Types/goTypes"; -import InputField from "./InputField"; import Logo from "../assets/Logo.svg"; import Button from "./Button"; +import { useNavigate } from "react-router-dom"; +import ProjectNameInput from "./Inputs/ProjectNameInput"; +import DescriptionInput from "./Inputs/DescriptionInput"; +import { alphanumeric } from "../Data/regex"; +import { projNameHighLimit, projNameLowLimit } from "../Data/constants"; /** * Provides UI for adding a project to the system. @@ -12,11 +16,26 @@ import Button from "./Button"; function AddProject(): JSX.Element { const [name, setName] = useState(""); const [description, setDescription] = useState(""); + const navigate = useNavigate(); /** * Tries to add a project to the system */ const handleCreateProject = async (): Promise => { + if ( + !alphanumeric.test(name) || + name.length > projNameHighLimit || + name.length < projNameLowLimit + ) { + alert( + "Please provide valid project name: \n-Between 10-99 characters \n-No special characters (.-!?/*)", + ); + return; + } + if (description.length > projNameHighLimit) { + alert("Please provide valid description: \n-Max 100 characters"); + return; + } const project: NewProject = { name: name.replace(/ /g, ""), description: description.trim(), @@ -30,6 +49,7 @@ function AddProject(): JSX.Element { alert(`${project.name} added!`); setDescription(""); setName(""); + navigate("/admin"); } else { alert("Project not added, name could be taken"); console.error(response.message); @@ -44,7 +64,7 @@ function AddProject(): JSX.Element {
{ e.preventDefault(); void handleCreateProject(); @@ -52,35 +72,29 @@ function AddProject(): JSX.Element { > TTIME Logo

Create a new project

-
- { - e.preventDefault(); - setName(e.target.value); - }} - placeholder={"Name"} - /> - { - e.preventDefault(); - setDescription(e.target.value); - }} - placeholder={"Description"} - /> -
-
+ { + e.preventDefault(); + setName(e.target.value); + }} + /> +
+ { + e.preventDefault(); + setDescription(e.target.value); + }} + placeholder={"Description (Optional)"} + /> +