diff --git a/frontend/src/app/tasks/__tests__/components/CreateTask.test.tsx b/frontend/src/app/tasks/__tests__/components/CreateTask.test.tsx index 2b853f25c..425f3c650 100644 --- a/frontend/src/app/tasks/__tests__/components/CreateTask.test.tsx +++ b/frontend/src/app/tasks/__tests__/components/CreateTask.test.tsx @@ -280,7 +280,8 @@ describe('TaskForm', () => { date: '2023-01-01', description: 'description!', endTime: '13:00', - projectId: '1', + projectId: 1, + projectName: 'Holidays', startTime: '12:00', story: 'story!', taskType: 'mock-test', @@ -316,7 +317,8 @@ describe('TaskForm', () => { date: '2023-01-01', description: 'description!', endTime: '13:00', - projectId: '1', + projectId: 1, + projectName: 'Holidays', startTime: '12:00', story: 'story!', taskType: 'mock-test', @@ -352,7 +354,8 @@ describe('TaskForm', () => { date: '2023-01-01', description: 'description!', endTime: '13:00', - projectId: '1', + projectId: 1, + projectName: 'Holidays', startTime: '12:00', story: 'story!', taskType: 'mock-test', diff --git a/frontend/src/app/tasks/components/CreateTask.tsx b/frontend/src/app/tasks/components/CreateTask.tsx index b0960691a..437ddd7ec 100644 --- a/frontend/src/app/tasks/components/CreateTask.tsx +++ b/frontend/src/app/tasks/components/CreateTask.tsx @@ -31,7 +31,10 @@ export const CreateTask = ({ projects, taskTypes, templates }: CreateTaskProps) isTimerRunning, selectStartTime, handleSubmit, - formRef + formRef, + selectTemplate, + handleProject, + templateName } = useTaskForm() return ( @@ -39,8 +42,10 @@ export const CreateTask = ({ projects, taskTypes, templates }: CreateTaskProps) handleChange('projectId', value)} - value={task.projectId} + onChange={(value) => handleProject(value, projects)} + value={task.projectName} name="projectId" label="Select project" placeholder="Select project" - options={projects.map((project) => ({ - label: project.description, - value: project.id.toString() - }))} + options={projects.map((project) => project.description)} required /> @@ -131,7 +133,7 @@ export const CreateTask = ({ projects, taskTypes, templates }: CreateTaskProps) label="Task description" sx={{ minHeight: '208px' }} placeholder="Task description..." - value={task.description} + value={task.description || ''} > handleChange('story', e.target.value)} name="story" placeholder="Story" diff --git a/frontend/src/app/tasks/components/EditTask.tsx b/frontend/src/app/tasks/components/EditTask.tsx index a42521aed..7e0885878 100644 --- a/frontend/src/app/tasks/components/EditTask.tsx +++ b/frontend/src/app/tasks/components/EditTask.tsx @@ -81,10 +81,10 @@ export const EditTask = ({ task, tasks, projects, taskTypes, closeForm }: EditTa onChange={(e) => handleChange('description', e.target.value)} label="Task description" placeholder="Task description..." - value={formState.description} + value={formState.description || ''} /> handleChange('story', e.target.value)} name="story" placeholder="Story" diff --git a/frontend/src/app/tasks/components/TaskBox.tsx b/frontend/src/app/tasks/components/TaskBox.tsx index c316f1781..6594f441a 100644 --- a/frontend/src/app/tasks/components/TaskBox.tsx +++ b/frontend/src/app/tasks/components/TaskBox.tsx @@ -4,15 +4,20 @@ import { useState } from 'react' import Box from '@mui/joy/Box' import Button from '@mui/joy/Button' import Typography from '@mui/joy/Typography' -import { Delete24Filled, Edit24Filled } from '@fluentui/react-icons' +import { + Delete24Filled, + Edit24Filled, + ArrowMaximize24Filled, + ArrowMinimize24Filled +} from '@fluentui/react-icons' import { Project } from '@/domain/Project' import { TaskType } from '@/domain/TaskType' +import { Task } from '@/domain/Task' import { ScreenReaderOnly } from '@/ui/ScreenReaderOnly/ScreenReaderOnly' import { ConfirmationModal } from '@/ui/ConfirmationModal/ConfirmationModal' import { styled } from '@mui/joy/styles' -import { Task } from '@/domain/Task' import { getTimeDifference, convertTimeToMinutes } from '../utils/time' import { EditTask } from './EditTask' @@ -30,6 +35,7 @@ export const TaskBox = ({ task, projects, taskTypes, tasks }: TaskProps) => { const [deleteModalOpen, setDeleteModalOpen] = useState(false) const [editMode, setEditMode] = useState(false) + const [expandedTask, setExpandedTask] = useState(false) const timeDifference = () => { const startMinutes = convertTimeToMinutes(task.startTime) @@ -68,11 +74,22 @@ export const TaskBox = ({ task, projects, taskTypes, tasks }: TaskProps) => { {task.startTime}-{task.endTime} ({timeDifference()}) + {expandedTask && ( + <> + {task.description} + {task.story} + + )} )} - setEditMode(true)}> + { + setEditMode(true) + setExpandedTask(false) + }} + > Edit task @@ -80,6 +97,16 @@ export const TaskBox = ({ task, projects, taskTypes, tasks }: TaskProps) => { Delete task {task.id} + + setExpandedTask((prevState) => !prevState)}> + {expandedTask ? ( + + ) : ( + + )} + Expand Task + + setDeleteModalOpen(false)} diff --git a/frontend/src/app/tasks/hooks/useCreateTaskForm.ts b/frontend/src/app/tasks/hooks/useCreateTaskForm.ts index b84c7dd24..fbd609600 100644 --- a/frontend/src/app/tasks/hooks/useCreateTaskForm.ts +++ b/frontend/src/app/tasks/hooks/useCreateTaskForm.ts @@ -1,5 +1,5 @@ import { format } from 'date-fns' -import { useEffect, useRef, useCallback } from 'react' +import { useEffect, useRef, useCallback, useState } from 'react' import { useForm } from '@/hooks/useForm/useForm' import { useTimer } from '@/hooks/useTimer/useTimer' @@ -9,6 +9,8 @@ import { useGetTasks } from './useGetTasks' import { useCreateTask } from './useCreateTask' import { useAlert } from '@/ui/Alert/useAlert' +import { Template } from '@/domain/Template' +import { Project } from '@/domain/Project' import { TaskIntent, getOverlappingTasks } from '@/domain/Task' import { convertTimeToMinutes, getTimeDifference } from '../utils/time' @@ -18,18 +20,20 @@ export const useTaskForm = () => { const { addTask } = useCreateTask() const { showError } = useAlert() const { tasks } = useGetTasks() + const [templateName, setTemplateName] = useState('') const { startTimer, stopTimer, seconds, minutes, hours, isTimerRunning } = useTimer() - const { formState, handleChange, resetForm } = useForm({ + const { formState, handleChange, resetForm, setFormState } = useForm({ initialValues: { userId, - projectId: '', + projectId: null, + projectName: '', taskType: '', story: '', description: '', startTime: '', endTime: '', - date: '' + date: format(new Date(), 'yyyy-MM-dd') } }) @@ -54,19 +58,41 @@ export const useTaskForm = () => { addTask(formState) }, [addTask, formState, showError, tasks]) - const setDate = () => handleChange('date', format(new Date(), 'yyyy-MM-dd')) + const handleProject = (value: string, projects: Array) => { + const project = projects.find((project) => project.description === value) + handleChange('projectName', value) + if (project) { + handleChange('projectId', project.id) + } else { + handleChange('projectId', null) + } + } + + const selectTemplate = (templateId: number, templates: Array