diff --git a/app/create/task/_components/form.tsx b/app/create/task/_components/form.tsx new file mode 100644 index 0000000..f60fd39 --- /dev/null +++ b/app/create/task/_components/form.tsx @@ -0,0 +1,182 @@ +"use client"; + +import React from "react"; +import { Button } from "@nextui-org/button"; +import { Input, Textarea } from "@nextui-org/input"; +import { Select, SelectItem } from "@nextui-org/select"; +import { Form } from "@nextui-org/form"; +import { container } from "@/components/primitives"; +import { Project } from "@/types/project"; +import { getIconSrc } from "@/utils/icons"; +import { Avatar } from "@nextui-org/avatar"; + +export default function TaskForm({ projects }: { projects: Project[] }) { + const [submitted, setSubmitted] = React.useState(null); + const [errors, setErrors] = React.useState({}); + + const onSubmit = (e: any) => { + e.preventDefault(); + const data = Object.fromEntries(new FormData(e.currentTarget)); + + // Custom validation checks + const newErrors: any = {}; + + // Username validation + if (data.title === "admin") { + newErrors.title = "Nice try! Choose a different username"; + } + + if (Object.keys(newErrors).length > 0) { + setErrors(newErrors); + + return; + } + + // Clear errors and submit + setErrors({}); + setSubmitted(data); + }; + + return ( +
setSubmitted(null)} + onSubmit={onSubmit} + > +
+
+

+ Create a new task +

+ + Submit a task manually for a project you maintain or{" "} + + import directly from a GitHub issue + {" "} + for faster input. + +
+ + Required fields are marked with an asterisk (*). + +
+
+
+ + + { + if (validationDetails.valueMissing) { + return "Please enter the task's title"; + } + + return errors.name; + }} + label="Title" + labelPlacement="outside" + name="title" + placeholder="Enter task title" + type="text" + classNames={{ + base: "basis-3/4", + inputWrapper: "data-[hover=true]:bg-opacity-hover", + }} + /> +
+ +