diff --git a/client/src/components/forms/TaskForm/index.tsx b/client/src/components/forms/TaskForm/index.tsx index a487c60324207bab8c8654c4f3af8f2f71fe85fe..1bebf83703a8dcd4036ebf0f72bd987837eac2df 100644 --- a/client/src/components/forms/TaskForm/index.tsx +++ b/client/src/components/forms/TaskForm/index.tsx @@ -1,4 +1,4 @@ -import { Priority, Task } from 'adapters/task'; +import { Priority, Task, TaskAssignment, TaskRequirement } from 'adapters/task'; import { FormEvent, useCallback, useEffect, useState } from 'react'; import './task-form.scss'; import Callout from 'components/ui/Callout'; @@ -6,13 +6,14 @@ import TextInput from 'components/ui/TextInput'; import Picker from 'emoji-picker-react'; import { getProjectTasks, Project } from 'adapters/project'; import CheckboxGroup from 'components/ui/CheckboxGroup'; -import { getTeam, getTeamMembers, getTeamRoles, TeamMember } from 'adapters/team'; +import { getTeam, getTeamMembers, getTeamRoles } from 'adapters/team'; import RequirementsForm from './RequirementsForm'; import AssgineesForm from './AssigneesForm'; +import Button from 'components/ui/Button'; interface Props { task?: Task; - onSubmit: (name: string, text: string, icon: string, priority: string) => void; + onSubmit: (name: string, text: string, icon: string, priority: Priority, dependencies: string[], requirements: TaskRequirement[], assignees: TaskAssignment[]) => void; project: Project; } @@ -101,16 +102,18 @@ export default function TaskForm({ task, onSubmit, project }: Props) { const handleSubmit = useCallback(async (e: FormEvent) => { e.preventDefault(); + console.log(priority); + if (validateName(name ?? '') === null && validateText(text ?? '') === null && validateIcon(icon ?? '') === null && validatePriority(priority ?? '') === null ) { - onSubmit?.(name ?? '', text ?? '', icon ?? '', priority ?? ''); + onSubmit?.(name ?? '', text ?? '', icon ?? '', priority ?? Priority.LOW, tasks ?? [], requirements, assignees); } else { setError('Please fill in the mandatory fields.'); } - }, [onSubmit, setError, name, text, priority, icon]); + }, [onSubmit, setError, name, text, priority, icon, tasks, assignees, requirements]); return ( <form className="task-form" onSubmit={handleSubmit}> @@ -159,7 +162,9 @@ export default function TaskForm({ task, onSubmit, project }: Props) { <AssgineesForm members={allMembers} setAssignees={setAssignees} assignees={assignees} /> ) } - + <Button type="submit"> + Create Task + </Button> </form> ) diff --git a/client/src/pages/Tasks/TaskCreate/index.tsx b/client/src/pages/Tasks/TaskCreate/index.tsx index ab1aa6c48ca1aca88294f9ba4b8fc1cea6c87117..1f6fd0a13751216d7ca6966f80b86445b95656f3 100644 --- a/client/src/pages/Tasks/TaskCreate/index.tsx +++ b/client/src/pages/Tasks/TaskCreate/index.tsx @@ -1,7 +1,7 @@ import { useHistory, useParams } from "react-router"; import TaskForm from 'components/forms/TaskForm'; import { useCallback, useEffect, useState } from "react"; -import { createTask } from "adapters/task"; +import { createTask, Priority, TaskAssignment, TaskRequirement } from "adapters/task"; import Callout from "components/ui/Callout"; import { getProject, Project } from "adapters/project"; @@ -19,13 +19,13 @@ export default function TaskCreate() { getProject(projectId).then((project) => setProject(project)); }, []); - const handleSubmit = useCallback(async (name: string, text: string, icon: string, priority: string) => { + const handleSubmit = useCallback(async (name: string, text: string, icon: string, priority: Priority, dependencies: string[], requirements: TaskRequirement[], assignees: TaskAssignment[]) => { try { - //if (await createTask({ project: projectId name, text, icon, priority })) { + if (await createTask({ project: projectId, name, text, icon, priority, dependencies, requirements, assigned: assignees })) { history.push('/projects/' + projectId); - //} else { + } else { setError('There was an error with creating your project. Please try again!'); - //} + } } catch (e) { } }, [history, projectId]); return ( diff --git a/server/src/v1/task.ts b/server/src/v1/task.ts index e00c3ce06c063c8e6985112d914f2ef0ce389fd6..3d9259e505f4cf8cd28355ed2f55ade01450aa7b 100644 --- a/server/src/v1/task.ts +++ b/server/src/v1/task.ts @@ -390,7 +390,7 @@ interface AddTaskBody { text: string; icon: string; priority: string; - dependentcies: Array<string>; + dependencies: Array<string>; requirements: Array<TaskRequirement>; assigned: Array<TaskAssignment>; token: Token; @@ -399,11 +399,11 @@ interface AddTaskBody { task.post('/', async (req, res) => { if (isOfType<AddTaskBody>(req.body, [ ['project', 'string'], ['name', 'string'], ['text', 'string'], ['icon', 'string'], - ['priority', 'string'], ['dependentcies', 'object'], ['requirements', 'object'], + ['priority', 'string'], ['dependencies', 'object'], ['requirements', 'object'], ])) { try { const project_id = req.body.project; - const dependentcy_ids = req.body.dependentcies; + const dependentcy_ids = req.body.dependencies; const assigned = req.body.assigned; const assigned_ids = assigned.map(asg => asg.user); const requirements = req.body.requirements; @@ -500,7 +500,7 @@ interface UpdateTaskBody { remove_dependentcies?: Array<string>; remove_requirements?: Array<string>; remove_assigned?: Array<string>; - add_dependentcies?: Array<string>; + add_dependencies?: Array<string>; add_requirements?: Array<TaskRequirement>; add_assigned?: Array<TaskAssignment>; token: Token; @@ -513,7 +513,7 @@ task.put('/:uuid', async (req, res) => { const remove_dependentcy_ids = req.body.remove_dependentcies ?? []; const remove_assigned_ids = req.body.remove_assigned ?? []; const remove_requirement_ids = req.body.remove_requirements ?? []; - const add_dependentcy_ids = req.body.add_dependentcies ?? []; + const add_dependentcy_ids = req.body.add_dependencies ?? []; const add_assigned = req.body.add_assigned ?? []; const add_assigned_ids = add_assigned.map(asg => asg.user); const add_requirements = req.body.add_requirements ?? [];