diff --git a/blotztask-ui/src/app/task-dayview/page.tsx b/blotztask-ui/src/app/task-dayview/page.tsx index f39ab78..21231c4 100644 --- a/blotztask-ui/src/app/task-dayview/page.tsx +++ b/blotztask-ui/src/app/task-dayview/page.tsx @@ -4,37 +4,14 @@ import { Card, CardContent, CardHeader } from '@/components/ui/card'; // import { Checkbox } from '@/components/ui/checkbox'; import { useEffect, useState } from 'react'; import { z } from 'zod'; -import { taskDto } from './models/taskDto'; import { TaskDTO, taskDTOSchema } from './schema/schema'; import { Button } from '@/components/ui/button'; import { TaskForm } from './components/form'; import { H1, H5 } from '@/components/ui/heading-with-anchor'; +import { fetchTaskItemsDueToday } from '@/services/taskService'; -// Define mock data -const mockTasks: taskDto[] = [ - { - id: 1, - title: 'Complete project report', - description: 'Finalize the project report and submit it to the manager.', - isDone: false, - createdAt: '2024-07-20T08:30:00Z', - updatedAt: '2024-07-20T08:30:00Z', - }, - { - id: 2, - title: 'Meeting with the team', - description: 'Discuss the project milestones and deadlines with the team.', - isDone: false, - createdAt: '2024-07-21T10:00:00Z', - updatedAt: '2024-07-21T10:00:00Z', - }, -]; - -const validatedTasks = z.array(taskDTOSchema).parse(mockTasks); - -// Simulate a database read for tasks. export default function Dayview() { - const [tasks, setTasks] = useState(validatedTasks); + const [tasks, setTasks] = useState([]); //add a state for add task button deciding to hide or show the form const [isFormVisible, setIsFormVisible] = useState(false); @@ -54,9 +31,14 @@ export default function Dayview() { setIsFormVisible(!isFormVisible); }; - useEffect(() => { - // Simulate fetching tasks + const loadTasks = async () => { + const data = await fetchTaskItemsDueToday(); + const validatedTasks = z.array(taskDTOSchema).parse(data); setTasks(validatedTasks); +} + + useEffect(() => { + loadTasks(); }, []); return ( @@ -72,15 +54,15 @@ export default function Dayview() { -
+
{tasks.map((task) => (
-
+

{task.title}

-
+

{task.description}

diff --git a/blotztask-ui/src/services/taskService.ts b/blotztask-ui/src/services/taskService.ts index c1ee9ec..248fab3 100644 --- a/blotztask-ui/src/services/taskService.ts +++ b/blotztask-ui/src/services/taskService.ts @@ -1,3 +1,4 @@ +import { TaskDTO } from "@/app/task-dayview/schema/schema"; import { TaskItemDTO } from "@/model/task-Item-dto"; import { fetchWithAuth } from "@/utils/fetch-with-auth"; @@ -13,4 +14,21 @@ export const fetchAllTaskItems = async (): Promise => { ); return result; -}; \ No newline at end of file +}; + +export const fetchTaskItemsDueToday = async (): Promise => { + //Converting today's date to ISO String format + const date = new Date().toISOString().split('T')[0]; + + const result = await fetchWithAuth( + `${process.env.NEXT_PUBLIC_API_BASE_URL_WITH_API}/Task/due-date/${date}`, + { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + } + ); + + return result; + };