Routes back to home page on created project + design and alert updates
This commit is contained in:
		
							parent
							
								
									b71da1a698
								
							
						
					
					
						commit
						35a9c750d1
					
				
					 1 changed files with 40 additions and 26 deletions
				
			
		|  | @ -1,9 +1,13 @@ | ||||||
| import { useState } from "react"; | import { useState } from "react"; | ||||||
| import { api } from "../API/API"; | import { api } from "../API/API"; | ||||||
| import { NewProject } from "../Types/goTypes"; | import { NewProject } from "../Types/goTypes"; | ||||||
| import InputField from "./InputField"; |  | ||||||
| import Logo from "../assets/Logo.svg"; | import Logo from "../assets/Logo.svg"; | ||||||
| import Button from "./Button"; | 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. |  * Provides UI for adding a project to the system. | ||||||
|  | @ -12,11 +16,26 @@ import Button from "./Button"; | ||||||
| function AddProject(): JSX.Element { | function AddProject(): JSX.Element { | ||||||
|   const [name, setName] = useState(""); |   const [name, setName] = useState(""); | ||||||
|   const [description, setDescription] = useState(""); |   const [description, setDescription] = useState(""); | ||||||
|  |   const navigate = useNavigate(); | ||||||
| 
 | 
 | ||||||
|   /** |   /** | ||||||
|    * Tries to add a project to the system |    * Tries to add a project to the system | ||||||
|    */ |    */ | ||||||
|   const handleCreateProject = async (): Promise<void> => { |   const handleCreateProject = async (): Promise<void> => { | ||||||
|  |     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 = { |     const project: NewProject = { | ||||||
|       name: name.replace(/ /g, ""), |       name: name.replace(/ /g, ""), | ||||||
|       description: description.trim(), |       description: description.trim(), | ||||||
|  | @ -30,6 +49,7 @@ function AddProject(): JSX.Element { | ||||||
|         alert(`${project.name} added!`); |         alert(`${project.name} added!`); | ||||||
|         setDescription(""); |         setDescription(""); | ||||||
|         setName(""); |         setName(""); | ||||||
|  |         navigate("/admin"); | ||||||
|       } else { |       } else { | ||||||
|         alert("Project not added, name could be taken"); |         alert("Project not added, name could be taken"); | ||||||
|         console.error(response.message); |         console.error(response.message); | ||||||
|  | @ -44,7 +64,7 @@ function AddProject(): JSX.Element { | ||||||
|     <div className="flex flex-col h-fit w-screen items-center justify-center"> |     <div className="flex flex-col h-fit w-screen items-center justify-center"> | ||||||
|       <div className="border-4 border-black bg-white flex flex-col items-center justify-center h-fit w-fit rounded-3xl content-center pl-20 pr-20"> |       <div className="border-4 border-black bg-white flex flex-col items-center justify-center h-fit w-fit rounded-3xl content-center pl-20 pr-20"> | ||||||
|         <form |         <form | ||||||
|           className="bg-white rounded px-8 pt-6 pb-8 mb-4 items-center justify-center flex flex-col w-fit h-fit" |           className="bg-white rounded px-8 pt-6 pb-8 mb-4 justify-center flex flex-col w-fit h-fit" | ||||||
|           onSubmit={(e) => { |           onSubmit={(e) => { | ||||||
|             e.preventDefault(); |             e.preventDefault(); | ||||||
|             void handleCreateProject(); |             void handleCreateProject(); | ||||||
|  | @ -52,35 +72,29 @@ function AddProject(): JSX.Element { | ||||||
|         > |         > | ||||||
|           <img |           <img | ||||||
|             src={Logo} |             src={Logo} | ||||||
|             className="logo w-[7vw] mb-10 mt-10" |             className="logo w-[7vw] self-center mb-10 mt-10" | ||||||
|             alt="TTIME Logo" |             alt="TTIME Logo" | ||||||
|           /> |           /> | ||||||
|           <h3 className="pb-4 mb-2 text-center font-bold text-[18px]"> |           <h3 className="pb-4 mb-2 text-center font-bold text-[18px]"> | ||||||
|             Create a new project |             Create a new project | ||||||
|           </h3> |           </h3> | ||||||
|           <div className="space-y-3"> |           <ProjectNameInput | ||||||
|             <InputField |             name={name} | ||||||
|               label="Name" |  | ||||||
|               type="text" |  | ||||||
|               value={name} |  | ||||||
|             onChange={(e) => { |             onChange={(e) => { | ||||||
|               e.preventDefault(); |               e.preventDefault(); | ||||||
|               setName(e.target.value); |               setName(e.target.value); | ||||||
|             }} |             }} | ||||||
|               placeholder={"Name"} |  | ||||||
|           /> |           /> | ||||||
|             <InputField |           <div className="p-2"></div> | ||||||
|               label="Description" |           <DescriptionInput | ||||||
|               type="text" |             desc={description} | ||||||
|               value={description} |  | ||||||
|             onChange={(e) => { |             onChange={(e) => { | ||||||
|               e.preventDefault(); |               e.preventDefault(); | ||||||
|               setDescription(e.target.value); |               setDescription(e.target.value); | ||||||
|             }} |             }} | ||||||
|               placeholder={"Description"} |             placeholder={"Description (Optional)"} | ||||||
|           /> |           /> | ||||||
|           </div> |           <div className="flex self-center mt-4 justify-between"> | ||||||
|           <div className="flex items-center justify-between"> |  | ||||||
|             <Button |             <Button | ||||||
|               text="Create" |               text="Create" | ||||||
|               onClick={(): void => { |               onClick={(): void => { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Peter KW
						Peter KW