From 8e5be0d6f74f4adb26e7a74573e130ab8281f7c5 Mon Sep 17 00:00:00 2001 From: Hamza Farooq Date: Tue, 30 May 2023 19:17:24 -0400 Subject: [PATCH 01/11] first commit --- .../MyHistory/HistoryTasksContainer.tsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/frontend/src/Components/MyHistory/HistoryTasksContainer.tsx b/frontend/src/Components/MyHistory/HistoryTasksContainer.tsx index b38f81c6..97fcc9f4 100644 --- a/frontend/src/Components/MyHistory/HistoryTasksContainer.tsx +++ b/frontend/src/Components/MyHistory/HistoryTasksContainer.tsx @@ -2,6 +2,8 @@ import React from "react"; import { Box, Typography } from "@mui/material"; import SingleDayTasksContainer from "./SingleDayTasksContainer"; import { useState, useEffect } from "react"; +import { getAllTasks } from "../../services"; +import { TaskInterface } from "../../Contexts/Tasks"; // ------------------------- LINES AFTER THIS WILL BE REMOVED LATER WHEN BACKEND WORKS -----------------------------// const day1 = new Date("2023-04-13T00:00:00Z"); @@ -139,8 +141,23 @@ const HistoryTasksContainer = (props: { startDate: Date | null; endDate: Date | null; }) => { + + const [allTasks, setAllTasks] = useState([]); + + useEffect(() => { + const fetchTasks = async () => { + try { + const tasks = await getAllTasks(); // Fetch tasks from the backend + setAllTasks(tasks); + } catch (error) { + console.error("Error fetching tasks:", error); + } + }; + + fetchTasks(); + }, []); // startdate and enddate can be null, if no dates are chosen. - const [historyTasks, setHistoryTasks] = useState(dummyTasks.filter(task => { + const [historyTasks, setHistoryTasks] = useState(allTasks?.filter(task => { // filter out tasks that don't fall within the selected date range return (props.startDate === null || task.deliveryTime >= props.startDate) && (props.endDate === null || task.deliveryTime <= props.endDate) From f0531d303b38ce5b0cefb5d1d967047a247a2ec1 Mon Sep 17 00:00:00 2001 From: Hamza Farooq Date: Tue, 30 May 2023 19:23:12 -0400 Subject: [PATCH 02/11] first commit --- .../MyHistory/HistoryTasksContainer.tsx | 200 +++--------------- 1 file changed, 25 insertions(+), 175 deletions(-) diff --git a/frontend/src/Components/MyHistory/HistoryTasksContainer.tsx b/frontend/src/Components/MyHistory/HistoryTasksContainer.tsx index 97fcc9f4..c8e436e3 100644 --- a/frontend/src/Components/MyHistory/HistoryTasksContainer.tsx +++ b/frontend/src/Components/MyHistory/HistoryTasksContainer.tsx @@ -1,147 +1,13 @@ -import React from "react"; -import { Box, Typography } from "@mui/material"; +import React, { useState, useEffect } from "react"; +import { Box } from "@mui/material"; import SingleDayTasksContainer from "./SingleDayTasksContainer"; -import { useState, useEffect } from "react"; import { getAllTasks } from "../../services"; import { TaskInterface } from "../../Contexts/Tasks"; -// ------------------------- LINES AFTER THIS WILL BE REMOVED LATER WHEN BACKEND WORKS -----------------------------// -const day1 = new Date("2023-04-13T00:00:00Z"); -const day2 = new Date("2023-04-14T00:00:00Z"); -const day3 = new Date("2023-04-15T00:00:00Z"); -const day4 = new Date("2023-04-16T00:00:00Z"); -const day5 = new Date("2023-04-17T00:00:00Z"); -const day6 = new Date("2023-04-18T00:00:00Z"); -const day7 = new Date("2023-04-19T00:00:00Z"); - -const dummyTasks = [ - { - id: 1, - deliveryTime: day1, - isCompleted: true, - name: "Leopold Bennett", - deliveries: [], - }, - { - id: 2, - deliveryTime: day1, - isCompleted: false, - name: "Avi Sharp", - deliveries: [], - }, - { - id: 3, - deliveryTime: day1, - isCompleted: true, - name: "Zahara Lott", - deliveries: [], - }, - { - id: 4, - deliveryTime: day1, - isCompleted: true, - name: "John Doe", - deliveries: [], - }, - { - id: 5, - deliveryTime: day2, - isCompleted: false, - name: "Jane Doe", - deliveries: [], - }, - { - id: 6, - deliveryTime: day3, - isCompleted: true, - name: "Thomas Walker", - deliveries: [], - }, - { - id: 7, - deliveryTime: day3, - isCompleted: false, - name: "William Maguire", - deliveries: [], - }, - { - id: 8, - deliveryTime: day3, - isCompleted: false, - name: "Tony McLennan", - deliveries: [], - }, - { - id: 9, - deliveryTime: day4, - isCompleted: false, - name: "Harry Park", - deliveries: [], - }, - { - id: 10, - deliveryTime: day4, - isCompleted: true, - name: "Christian D'Silva", - deliveries: [], - }, - { - id: 11, - deliveryTime: day4, - isCompleted: false, - name: "Joseph Kim", - deliveries: [], - }, - { - id: 12, - deliveryTime: day5, - isCompleted: false, - name: "Martin Brooks", - deliveries: [], - }, - { - id: 13, - deliveryTime: day6, - isCompleted: false, - name: "Emmanuel Tan", - deliveries: [], - }, - { - id: 14, - deliveryTime: day7, - isCompleted: false, - name: "Lionel Ronaldo", - deliveries: [], - }, - { - id: 15, - deliveryTime: day7, - isCompleted: false, - name: "Stephanie Han", - deliveries: [], - }, -]; - -// Would have been better if we could just request backend API -// to just query tasks within the range of dates... :D - -// Getting All Tasks Algorithm choice: -// First Method: -// 1. Get All Tasks from a single user (will be an array of all tasks from a user) -// 2. Go through that tasks array and for each task, if that task's deliveryTime is -// within the range of dates (startDate ~ endDate) store it in another array -// 3. Sort the new array with the tasks that are within the desired range of dates. -// -// Second Method: -// 1. Get ONLY Tasks that are within the desired range of dates from the backend database. -// 2. Sort in frontend -// ---------------------------------- LINES BEFORE THIS WILL BE REMOVED LATER ON ---------------------------------------// - const HistoryTasksContainer = (props: { startDate: Date | null; endDate: Date | null; }) => { - const [allTasks, setAllTasks] = useState([]); useEffect(() => { @@ -156,70 +22,54 @@ const HistoryTasksContainer = (props: { fetchTasks(); }, []); - // startdate and enddate can be null, if no dates are chosen. - const [historyTasks, setHistoryTasks] = useState(allTasks?.filter(task => { - // filter out tasks that don't fall within the selected date range - return (props.startDate === null || task.deliveryTime >= props.startDate) && - (props.endDate === null || task.deliveryTime <= props.endDate) - })); - // get the range of dates for given start date and end date + const filterTasksByDateRange = (task: TaskInterface) => { + return ( + (!props.startDate || task.deliveryTime >= props.startDate) && + (!props.endDate || task.deliveryTime <= props.endDate) + ); + }; + + const historyTasks = allTasks.filter(filterTasksByDateRange); + const getRangeOfDates = (startDate: Date | null, endDate: Date | null) => { - if (startDate == null || endDate == null) { - // if no dates were selected, do not return range of dates. + if (!startDate || !endDate) { return []; } - const date = new Date(startDate); - const currentDate = new Date(startDate); + const rangeOfDates = []; + const currentDate = new Date(startDate); - let followingDay = new Date(currentDate); while (currentDate <= endDate) { - rangeOfDates.push(followingDay); - date.setDate(date.getDate() + 1); // get next date - followingDay = new Date(date); + rangeOfDates.push(new Date(currentDate)); currentDate.setDate(currentDate.getDate() + 1); } + return rangeOfDates; }; - const [rangeOfDates, setRangeOfDates] = useState( - getRangeOfDates(props.startDate, props.endDate) - ); + const rangeOfDates = getRangeOfDates(props.startDate, props.endDate); useEffect(() => { - // when startDate and endDate states change in the parent component, update the rangeOfDates that need to be displayed. setRangeOfDates(getRangeOfDates(props.startDate, props.endDate)); - - // also update the historyTasks state by filtering out tasks that don't fall within the selected date range - setHistoryTasks(dummyTasks.filter(task => { - return (props.startDate === null || task.deliveryTime >= props.startDate) && - (props.endDate === null || task.deliveryTime <= props.endDate) - })); }, [props.startDate, props.endDate]); return ( - {/* when no proper date range is given, display help message. */} {!props.startDate || !props.endDate ? ( Please Select A Date Range To Filter Tasks. ) : null} - {rangeOfDates.map((date: Date) => { - return ( - - ); - { - /* use date as key */ - } - })} + {rangeOfDates.map((date: Date) => ( + + ))} ); }; -export default HistoryTasksContainer; +export default HistoryTasksContainer; \ No newline at end of file From f12427a577ad0ef657bbcde19c44fe9fdd8307a1 Mon Sep 17 00:00:00 2001 From: Hamza Farooq Date: Thu, 1 Jun 2023 19:24:00 -0400 Subject: [PATCH 03/11] first commit --- .../MyHistory/HistoryTasksContainer.tsx | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/frontend/src/Components/MyHistory/HistoryTasksContainer.tsx b/frontend/src/Components/MyHistory/HistoryTasksContainer.tsx index c8e436e3..39cb67ef 100644 --- a/frontend/src/Components/MyHistory/HistoryTasksContainer.tsx +++ b/frontend/src/Components/MyHistory/HistoryTasksContainer.tsx @@ -9,6 +9,7 @@ const HistoryTasksContainer = (props: { endDate: Date | null; }) => { const [allTasks, setAllTasks] = useState([]); + const [rangeOfDates, setRangeOfDates] = useState([]); useEffect(() => { const fetchTasks = async () => { @@ -23,14 +24,8 @@ const HistoryTasksContainer = (props: { fetchTasks(); }, []); - const filterTasksByDateRange = (task: TaskInterface) => { - return ( - (!props.startDate || task.deliveryTime >= props.startDate) && - (!props.endDate || task.deliveryTime <= props.endDate) - ); - }; - - const historyTasks = allTasks.filter(filterTasksByDateRange); + console.log(allTasks); + console.log("Type of", typeof allTasks) const getRangeOfDates = (startDate: Date | null, endDate: Date | null) => { if (!startDate || !endDate) { @@ -48,11 +43,29 @@ const HistoryTasksContainer = (props: { return rangeOfDates; }; - const rangeOfDates = getRangeOfDates(props.startDate, props.endDate); - useEffect(() => { setRangeOfDates(getRangeOfDates(props.startDate, props.endDate)); }, [props.startDate, props.endDate]); + + useEffect(() => { + const filteredTasks = []; + + for (let i = 0; i < allTasks.length; i++) { + const task = allTasks[i]; + const taskDate = new Date(task.deliveryTime); // Assuming each task has a 'deliveryTime' property + console.log("Task Date", taskDate); + if ( + props.startDate && + props.endDate && + taskDate >= props.startDate && + taskDate <= props.endDate + ) { + filteredTasks.push(task); + } + } + + console.log("filteredTasks", filteredTasks); + }, [allTasks, props.startDate, props.endDate]); return ( @@ -64,7 +77,7 @@ const HistoryTasksContainer = (props: { {rangeOfDates.map((date: Date) => ( ))} From a4f082917fb2f6ae958402e1603ab57d3e536da3 Mon Sep 17 00:00:00 2001 From: Hamza Farooq Date: Thu, 8 Jun 2023 00:43:53 -0400 Subject: [PATCH 04/11] added task filtering --- .../MyHistory/HistoryTasksContainer.tsx | 73 +++++++++++-------- .../MyHistory/SingleDayTasksContainer.tsx | 22 +++--- .../MyTasks/DeliveriesContainer.tsx | 65 +++++++++-------- frontend/src/Components/MyTasks/Delivery.tsx | 4 +- frontend/src/Contexts/Tasks.tsx | 11 ++- 5 files changed, 95 insertions(+), 80 deletions(-) diff --git a/frontend/src/Components/MyHistory/HistoryTasksContainer.tsx b/frontend/src/Components/MyHistory/HistoryTasksContainer.tsx index 39cb67ef..2e7c56f7 100644 --- a/frontend/src/Components/MyHistory/HistoryTasksContainer.tsx +++ b/frontend/src/Components/MyHistory/HistoryTasksContainer.tsx @@ -8,24 +8,38 @@ const HistoryTasksContainer = (props: { startDate: Date | null; endDate: Date | null; }) => { - const [allTasks, setAllTasks] = useState([]); + const [allTasks, setAllTasks] = useState<{ [date: string]: TaskInterface[] }>({}); const [rangeOfDates, setRangeOfDates] = useState([]); useEffect(() => { const fetchTasks = async () => { try { - const tasks = await getAllTasks(); // Fetch tasks from the backend - setAllTasks(tasks); + const response = await getAllTasks(); // Fetch tasks from the backend + const tasks = response.tasks; + + const tasksByDate: { [date: string]: TaskInterface[] } = {}; + + tasks.forEach((task: TaskInterface) => { + const date = convertDate(new Date(task.date)).join('-'); // convert to string format "YYYY-MM-DD" + if (!tasksByDate[date]) { + tasksByDate[date] = []; + } + tasksByDate[date].push(task); + }); + + setAllTasks(tasksByDate); } catch (error) { console.error("Error fetching tasks:", error); } }; - + fetchTasks(); }, []); + + - console.log(allTasks); - console.log("Type of", typeof allTasks) + console.log("allTasks", allTasks) + const getRangeOfDates = (startDate: Date | null, endDate: Date | null) => { if (!startDate || !endDate) { @@ -43,29 +57,21 @@ const HistoryTasksContainer = (props: { return rangeOfDates; }; + console.log("RANGEOFDATES", rangeOfDates); + + function convertDate(input: Date): number[] { + // JavaScript months are 0-indexed, so we need to add 1 to get the correct month number. + const year = input.getFullYear(); + const month = input.getMonth() + 1; + const day = input.getDate(); + + return [year, month, day]; + } + useEffect(() => { setRangeOfDates(getRangeOfDates(props.startDate, props.endDate)); }, [props.startDate, props.endDate]); - useEffect(() => { - const filteredTasks = []; - - for (let i = 0; i < allTasks.length; i++) { - const task = allTasks[i]; - const taskDate = new Date(task.deliveryTime); // Assuming each task has a 'deliveryTime' property - console.log("Task Date", taskDate); - if ( - props.startDate && - props.endDate && - taskDate >= props.startDate && - taskDate <= props.endDate - ) { - filteredTasks.push(task); - } - } - - console.log("filteredTasks", filteredTasks); - }, [allTasks, props.startDate, props.endDate]); return ( @@ -74,13 +80,16 @@ const HistoryTasksContainer = (props: { Please Select A Date Range To Filter Tasks. ) : null} - {rangeOfDates.map((date: Date) => ( - - ))} + {rangeOfDates.map((date: Date) => { + const dateString = convertDate(date).join('-'); + return ( + + ); +})} ); }; diff --git a/frontend/src/Components/MyHistory/SingleDayTasksContainer.tsx b/frontend/src/Components/MyHistory/SingleDayTasksContainer.tsx index 65f24a50..1589944b 100644 --- a/frontend/src/Components/MyHistory/SingleDayTasksContainer.tsx +++ b/frontend/src/Components/MyHistory/SingleDayTasksContainer.tsx @@ -7,27 +7,29 @@ const SingleDayTasksContainer = (props: { date: Date; historyTasks: TaskInterface[]; }) => { - const filteredTasks = props.historyTasks.filter( - (task) => task.deliveryTime.toDateString() === props.date.toDateString() - ); + console.log(Array.isArray(props.historyTasks)); + console.log("props.historyTasks:", props.historyTasks); + console.log(props.date); + if (props.historyTasks.length > 0){ return ( - {filteredTasks.map((task) => ( + {props.historyTasks.map((task) => ( - {task.name} + {task.id} {/*USING ID FOR NOW */} - {"Delivered at " + task.deliveryTime.toLocaleTimeString([], { - hour: "2-digit", - minute: "2-digit", - })} + {"Delivered at " + new Date(task.date).toLocaleTimeString()} ))} ); -}; +} +else { + return
+} +} export default SingleDayTasksContainer; diff --git a/frontend/src/Components/MyTasks/DeliveriesContainer.tsx b/frontend/src/Components/MyTasks/DeliveriesContainer.tsx index 989f07a2..b5ca2e1b 100644 --- a/frontend/src/Components/MyTasks/DeliveriesContainer.tsx +++ b/frontend/src/Components/MyTasks/DeliveriesContainer.tsx @@ -30,113 +30,114 @@ const DeliveriesContainer = (props: { date.setDate(day1.getDate() + 6); const day7 = new Date(date); - const dummyTasks = [ + const dummyTasks: TaskInterface[] = [ { id: 1, - deliveryTime: day1, + date: day1, isCompleted: true, - name: "Leopold Bennett", + volunteer: "Leopold Bennett", deliveries: [], }, { id: 2, - deliveryTime: day1, + date: day1, isCompleted: false, - name: "Avi Sharp", + volunteer: "Avi Sharp", deliveries: [], }, { id: 3, - deliveryTime: day1, + date: day1, isCompleted: true, - name: "Zahara Lott", + volunteer: "Zahara Lott", deliveries: [], }, { id: 4, - deliveryTime: day1, + date: day1, isCompleted: true, - name: "John Doe", + volunteer: "John Doe", deliveries: [], }, { id: 5, - deliveryTime: day2, + date: day2, isCompleted: false, - name: "Jane Doe", + volunteer: "Jane Doe", deliveries: [], }, { id: 6, - deliveryTime: day3, + date: day3, isCompleted: true, - name: "Thomas Walker", + volunteer: "Thomas Walker", deliveries: [], }, { id: 7, - deliveryTime: day3, + date: day3, isCompleted: false, - name: "William Maguire", + volunteer: "William Maguire", deliveries: [], }, { id: 8, - deliveryTime: day3, + date: day3, isCompleted: false, - name: "Tony McLennan", + volunteer: "Tony McLennan", deliveries: [], }, { id: 9, - deliveryTime: day4, + date: day4, isCompleted: false, - name: "Harry Park", + volunteer: "Harry Park", deliveries: [], }, { id: 10, - deliveryTime: day4, + date: day4, isCompleted: true, - name: "Christian D'Silva", + volunteer: "Christian D'Silva", deliveries: [], }, { id: 11, - deliveryTime: day4, + date: day4, isCompleted: false, - name: "Joseph Kim", + volunteer: "Joseph Kim", deliveries: [], }, { id: 12, - deliveryTime: day5, + date: day5, isCompleted: false, - name: "Martin Brooks", + volunteer: "Martin Brooks", deliveries: [], }, { id: 13, - deliveryTime: day6, + date: day6, isCompleted: false, - name: "Emmanuel Tan", + volunteer: "Emmanuel Tan", deliveries: [], }, { id: 14, - deliveryTime: day7, + date: day7, isCompleted: false, - name: "Lionel Ronaldo", + volunteer: "Lionel Ronaldo", deliveries: [], }, { id: 15, - deliveryTime: day7, + date: day7, isCompleted: false, - name: "Stephanie Han", + volunteer: "Stephanie Han", deliveries: [], }, ]; + // ---------------------------------- LINES BEFORE THIS WILL BE REMOVED LATER ON ---------------------------------------// // function that formats date to desired form: e.g. 8 Dec 2023 @@ -150,7 +151,7 @@ const DeliveriesContainer = (props: { // filtering logic const dateFilteredTasks = dummyTasks.filter( - (task) => formatDate(task.deliveryTime) == props.dateFilter + (task) => formatDate(task.date) == props.dateFilter ); let filteredTasks = dateFilteredTasks; // ALLTASKS filter if (props.completionFilter === "COMPLETED") { diff --git a/frontend/src/Components/MyTasks/Delivery.tsx b/frontend/src/Components/MyTasks/Delivery.tsx index 0932e2b9..20201285 100644 --- a/frontend/src/Components/MyTasks/Delivery.tsx +++ b/frontend/src/Components/MyTasks/Delivery.tsx @@ -56,8 +56,8 @@ const Delivery = (props: { task: TaskInterface }) => { label={ } /> diff --git a/frontend/src/Contexts/Tasks.tsx b/frontend/src/Contexts/Tasks.tsx index a7292d53..8ba6f46a 100644 --- a/frontend/src/Contexts/Tasks.tsx +++ b/frontend/src/Contexts/Tasks.tsx @@ -9,17 +9,20 @@ import { getAllTasks } from "../services"; export interface TaskInterface { id: number; - deliveryTime: Date; + date: Date; isCompleted: boolean; + volunteer: string; deliveries: MealDeliveryInterface[]; - name: string; // I will just assume the recipient's name is part of the Task entity for now. } export interface MealDeliveryInterface { id: number; - quantity: number; + isCompleted: boolean; + routePosition: number; mealType: string; - task: TaskInterface; + program: any + task: any; + client: any; } // create a type for TaskContext From a4dbc54957d17ebebd569e4c9ec4747ddffe73fb Mon Sep 17 00:00:00 2001 From: Hamza Farooq Date: Thu, 8 Jun 2023 00:48:19 -0400 Subject: [PATCH 05/11] small comment --- frontend/src/Contexts/Tasks.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/Contexts/Tasks.tsx b/frontend/src/Contexts/Tasks.tsx index 8ba6f46a..fdbafe23 100644 --- a/frontend/src/Contexts/Tasks.tsx +++ b/frontend/src/Contexts/Tasks.tsx @@ -11,7 +11,7 @@ export interface TaskInterface { id: number; date: Date; isCompleted: boolean; - volunteer: string; + volunteer: string; // REPLACE WITH VOLUNTEER TYPE WHEN EVERYTHING IS FIXED deliveries: MealDeliveryInterface[]; } From 480ff5448b3ced301f1cca9ec089b1f1b335bea4 Mon Sep 17 00:00:00 2001 From: Hamza Farooq Date: Tue, 20 Jun 2023 18:21:33 -0400 Subject: [PATCH 06/11] fixed interfaces --- .../MyHistory/SingleDayTasksContainer.tsx | 2 +- .../MyTasks/DeliveriesContainer.tsx | 181 ++++++++++++++++-- frontend/src/Components/MyTasks/Delivery.tsx | 2 +- frontend/src/Contexts/Tasks.tsx | 3 +- frontend/src/Contexts/Volunteer.tsx | 12 +- 5 files changed, 179 insertions(+), 21 deletions(-) diff --git a/frontend/src/Components/MyHistory/SingleDayTasksContainer.tsx b/frontend/src/Components/MyHistory/SingleDayTasksContainer.tsx index 1589944b..696c6752 100644 --- a/frontend/src/Components/MyHistory/SingleDayTasksContainer.tsx +++ b/frontend/src/Components/MyHistory/SingleDayTasksContainer.tsx @@ -17,7 +17,7 @@ const SingleDayTasksContainer = (props: { {props.historyTasks.map((task) => ( - {task.id} {/*USING ID FOR NOW */} + {task.volunteer ? task.volunteer.name : task.id} {/*USING ID FOR NOW */} {"Delivered at " + new Date(task.date).toLocaleTimeString()} diff --git a/frontend/src/Components/MyTasks/DeliveriesContainer.tsx b/frontend/src/Components/MyTasks/DeliveriesContainer.tsx index b5ca2e1b..ff763614 100644 --- a/frontend/src/Components/MyTasks/DeliveriesContainer.tsx +++ b/frontend/src/Components/MyTasks/DeliveriesContainer.tsx @@ -35,109 +35,260 @@ const DeliveriesContainer = (props: { id: 1, date: day1, isCompleted: true, - volunteer: "Leopold Bennett", + volunteer: { + id: 1, + name: "Leopold Bennett", + startDate: day1, + profilePicture: "", + availabilities: [], + password: "", + token: "", + email: "", + phoneNumber: "" + }, deliveries: [], }, { id: 2, date: day1, isCompleted: false, - volunteer: "Avi Sharp", + volunteer: { + id: 2, + name: "Avi Sharp", + startDate: day1, + profilePicture: "", + availabilities: [], + password: "", + token: "", + email: "", + phoneNumber: "" + }, deliveries: [], }, { id: 3, date: day1, isCompleted: true, - volunteer: "Zahara Lott", + volunteer: { + id: 3, + name: "Zahara Lott", + startDate: day1, + profilePicture: "", + availabilities: [], + password: "", + token: "", + email: "", + phoneNumber: "" + }, deliveries: [], }, { id: 4, date: day1, isCompleted: true, - volunteer: "John Doe", + volunteer: { + id: 4, + name: "John Doe", + startDate: day1, + profilePicture: "", + availabilities: [], + password: "", + token: "", + email: "", + phoneNumber: "" + }, deliveries: [], }, { id: 5, date: day2, isCompleted: false, - volunteer: "Jane Doe", + volunteer: { + id: 5, + name: "Jane Doe", + startDate: day2, + profilePicture: "", + availabilities: [], + password: "", + token: "", + email: "", + phoneNumber: "" + }, deliveries: [], }, { id: 6, date: day3, isCompleted: true, - volunteer: "Thomas Walker", + volunteer: { + id: 6, + name: "Thomas Walker", + startDate: day3, + profilePicture: "", + availabilities: [], + password: "", + token: "", + email: "", + phoneNumber: "" + }, deliveries: [], }, { id: 7, date: day3, isCompleted: false, - volunteer: "William Maguire", + volunteer: { + id: 7, + name: "William Maguire", + startDate: day3, + profilePicture: "", + availabilities: [], + password: "", + token: "", + email: "", + phoneNumber: "" + }, deliveries: [], }, { id: 8, date: day3, isCompleted: false, - volunteer: "Tony McLennan", + volunteer: { + id: 8, + name: "Tony McLennan", + startDate: day3, + profilePicture: "", + availabilities: [], + password: "", + token: "", + email: "", + phoneNumber: "" + }, deliveries: [], }, { id: 9, date: day4, isCompleted: false, - volunteer: "Harry Park", + volunteer: { + id: 9, + name: "Harry Park", + startDate: day4, + profilePicture: "", + availabilities: [], + password: "", + token: "", + email: "", + phoneNumber: "" + }, deliveries: [], }, { id: 10, date: day4, isCompleted: true, - volunteer: "Christian D'Silva", + volunteer: { + id: 10, + name: "Christian D'Silva", + startDate: day4, + profilePicture: "", + availabilities: [], + password: "", + token: "", + email: "", + phoneNumber: "" + }, deliveries: [], }, { id: 11, date: day4, isCompleted: false, - volunteer: "Joseph Kim", + volunteer: { + id: 11, + name: "Joseph Kim", + startDate: day4, + profilePicture: "", + availabilities: [], + password: "", + token: "", + email: "", + phoneNumber: "" + }, deliveries: [], }, { id: 12, date: day5, isCompleted: false, - volunteer: "Martin Brooks", + volunteer: { + id: 12, + name: "Martin Brooks", + startDate: day5, + profilePicture: "", + availabilities: [], + password: "", + token: "", + email: "", + phoneNumber: "" + }, deliveries: [], }, { id: 13, date: day6, isCompleted: false, - volunteer: "Emmanuel Tan", + volunteer: { + id: 13, + name: "Emmanuel Tan", + startDate: day6, + profilePicture: "", + availabilities: [], + password: "", + token: "", + email: "", + phoneNumber: "" + }, deliveries: [], }, { id: 14, date: day7, isCompleted: false, - volunteer: "Lionel Ronaldo", + volunteer: { + id: 14, + name: "Lionel Ronaldo", + startDate: day7, + profilePicture: "", + availabilities: [], + password: "", + token: "", + email: "", + phoneNumber: "" + }, deliveries: [], }, { id: 15, date: day7, isCompleted: false, - volunteer: "Stephanie Han", + volunteer: { + id: 15, + name: "Stephanie Han", + startDate: day7, + profilePicture: "", + availabilities: [], + password: "", + token: "", + email: "", + phoneNumber: "" + }, deliveries: [], }, ]; + // ---------------------------------- LINES BEFORE THIS WILL BE REMOVED LATER ON ---------------------------------------// // function that formats date to desired form: e.g. 8 Dec 2023 diff --git a/frontend/src/Components/MyTasks/Delivery.tsx b/frontend/src/Components/MyTasks/Delivery.tsx index 20201285..3dd87d17 100644 --- a/frontend/src/Components/MyTasks/Delivery.tsx +++ b/frontend/src/Components/MyTasks/Delivery.tsx @@ -57,7 +57,7 @@ const Delivery = (props: { task: TaskInterface }) => { } /> diff --git a/frontend/src/Contexts/Tasks.tsx b/frontend/src/Contexts/Tasks.tsx index fdbafe23..52b7930d 100644 --- a/frontend/src/Contexts/Tasks.tsx +++ b/frontend/src/Contexts/Tasks.tsx @@ -1,5 +1,6 @@ import { createContext, useState, useEffect } from "react"; import { getAllTasks } from "../services"; +import { Volunteer } from "./Volunteer"; // define interfaces and define Task context provider // expecting deliveries field to be populatd with MealDeliveryEntity's fields and not just their ids. @@ -11,7 +12,7 @@ export interface TaskInterface { id: number; date: Date; isCompleted: boolean; - volunteer: string; // REPLACE WITH VOLUNTEER TYPE WHEN EVERYTHING IS FIXED + volunteer: Volunteer deliveries: MealDeliveryInterface[]; } diff --git a/frontend/src/Contexts/Volunteer.tsx b/frontend/src/Contexts/Volunteer.tsx index a6146dca..ade6e949 100644 --- a/frontend/src/Contexts/Volunteer.tsx +++ b/frontend/src/Contexts/Volunteer.tsx @@ -1,3 +1,5 @@ +import { TaskInterface } from "./Tasks"; + export enum DayOfWeek { MONDAY = "monday", TUESDAY = "tuesday", @@ -27,9 +29,13 @@ export interface Availabilities { } export interface Volunteer { + availabilities: Availabilities[]; + email: string; id: number; name: string; - email: string; - phone: string; - availabilities: Availabilities; + password: string; + phoneNumber: string; + profilePicture: string; + startDate: Date; + token: string; } From 049ee39db5ba32567543ec970d1275fbed1ca5a7 Mon Sep 17 00:00:00 2001 From: Hamza Farooq Date: Tue, 20 Jun 2023 18:32:52 -0400 Subject: [PATCH 07/11] fixed deliveries --- .../MyTasks/DeliveriesContainer.tsx | 330 ++---------------- frontend/src/Components/MyTasks/Delivery.tsx | 7 +- 2 files changed, 39 insertions(+), 298 deletions(-) diff --git a/frontend/src/Components/MyTasks/DeliveriesContainer.tsx b/frontend/src/Components/MyTasks/DeliveriesContainer.tsx index c0a82879..4c3a1889 100644 --- a/frontend/src/Components/MyTasks/DeliveriesContainer.tsx +++ b/frontend/src/Components/MyTasks/DeliveriesContainer.tsx @@ -13,289 +13,11 @@ import { FormGroup } from "@mui/material"; const DeliveriesContainer = (props: { completionFilter: string; }) => { - // will use context later on - // const {tasks} = React.useContext(TaskContext) as TaskContextType; - - // use dummy data for now, and use Context when backend apis are ready. - // dummyTasks holds tasks for 7 upcomming days including today. - // NOTE: The following 7 upcoming days are just there for dummy data. Will be removed when using Context. - - // ------------------------- LINES AFTER THIS WILL BE REMOVED LATER WHEN BACKEND WORKS -----------------------------// - const date = new Date(); // date variable is used to get the following 6 days. - const day1 = new Date(); - date.setDate(day1.getDate() + 1); - const day2 = new Date(date); - date.setDate(day1.getDate() + 2); - const day3 = new Date(date); - date.setDate(day1.getDate() + 3); - const day4 = new Date(date); - date.setDate(day1.getDate() + 4); - const day5 = new Date(date); - date.setDate(day1.getDate() + 5); - const day6 = new Date(date); - date.setDate(day1.getDate() + 6); - const day7 = new Date(date); - - const dummyTasks: TaskInterface[] = [ - { - id: 1, - date: day1, - isCompleted: true, - volunteer: { - id: 1, - name: "Leopold Bennett", - startDate: day1, - profilePicture: "", - availabilities: [], - password: "", - token: "", - email: "", - phoneNumber: "" - }, - deliveries: [], - }, - { - id: 2, - date: day1, - isCompleted: false, - volunteer: { - id: 2, - name: "Avi Sharp", - startDate: day1, - profilePicture: "", - availabilities: [], - password: "", - token: "", - email: "", - phoneNumber: "" - }, - deliveries: [], - }, - { - id: 3, - date: day1, - isCompleted: true, - volunteer: { - id: 3, - name: "Zahara Lott", - startDate: day1, - profilePicture: "", - availabilities: [], - password: "", - token: "", - email: "", - phoneNumber: "" - }, - deliveries: [], - }, - { - id: 4, - date: day1, - isCompleted: true, - volunteer: { - id: 4, - name: "John Doe", - startDate: day1, - profilePicture: "", - availabilities: [], - password: "", - token: "", - email: "", - phoneNumber: "" - }, - deliveries: [], - }, - { - id: 5, - date: day2, - isCompleted: false, - volunteer: { - id: 5, - name: "Jane Doe", - startDate: day2, - profilePicture: "", - availabilities: [], - password: "", - token: "", - email: "", - phoneNumber: "" - }, - deliveries: [], - }, - { - id: 6, - date: day3, - isCompleted: true, - volunteer: { - id: 6, - name: "Thomas Walker", - startDate: day3, - profilePicture: "", - availabilities: [], - password: "", - token: "", - email: "", - phoneNumber: "" - }, - deliveries: [], - }, - { - id: 7, - date: day3, - isCompleted: false, - volunteer: { - id: 7, - name: "William Maguire", - startDate: day3, - profilePicture: "", - availabilities: [], - password: "", - token: "", - email: "", - phoneNumber: "" - }, - deliveries: [], - }, - { - id: 8, - date: day3, - isCompleted: false, - volunteer: { - id: 8, - name: "Tony McLennan", - startDate: day3, - profilePicture: "", - availabilities: [], - password: "", - token: "", - email: "", - phoneNumber: "" - }, - deliveries: [], - }, - { - id: 9, - date: day4, - isCompleted: false, - volunteer: { - id: 9, - name: "Harry Park", - startDate: day4, - profilePicture: "", - availabilities: [], - password: "", - token: "", - email: "", - phoneNumber: "" - }, - deliveries: [], - }, - { - id: 10, - date: day4, - isCompleted: true, - volunteer: { - id: 10, - name: "Christian D'Silva", - startDate: day4, - profilePicture: "", - availabilities: [], - password: "", - token: "", - email: "", - phoneNumber: "" - }, - deliveries: [], - }, - { - id: 11, - date: day4, - isCompleted: false, - volunteer: { - id: 11, - name: "Joseph Kim", - startDate: day4, - profilePicture: "", - availabilities: [], - password: "", - token: "", - email: "", - phoneNumber: "" - }, - deliveries: [], - }, - { - id: 12, - date: day5, - isCompleted: false, - volunteer: { - id: 12, - name: "Martin Brooks", - startDate: day5, - profilePicture: "", - availabilities: [], - password: "", - token: "", - email: "", - phoneNumber: "" - }, - deliveries: [], - }, - { - id: 13, - date: day6, - isCompleted: false, - volunteer: { - id: 13, - name: "Emmanuel Tan", - startDate: day6, - profilePicture: "", - availabilities: [], - password: "", - token: "", - email: "", - phoneNumber: "" - }, - deliveries: [], - }, - { - id: 14, - date: day7, - isCompleted: false, - volunteer: { - id: 14, - name: "Lionel Ronaldo", - startDate: day7, - profilePicture: "", - availabilities: [], - password: "", - token: "", - email: "", - phoneNumber: "" - }, - deliveries: [], - }, - { - id: 15, - date: day7, - isCompleted: false, - volunteer: { - id: 15, - name: "Stephanie Han", - startDate: day7, - profilePicture: "", - availabilities: [], - password: "", - token: "", - email: "", - phoneNumber: "" - }, - deliveries: [], - }, - ]; - - - // ---------------------------------- LINES BEFORE THIS WILL BE REMOVED LATER ON ---------------------------------------// + const tasksContext = useContext(TaskContext); // fetchedTasks is an object with tasks array as a field. + const fetchedTasks = tasksContext?.tasks; + // May 9: Now we assume one task per day, no more, no less. IMPORTANT ASSUMPTION. + const dateContext = useContext(DateContext); // fetchedTasks is an object with tasks array as a field. + const dateFilter = dateContext?.dateFilter; // function that formats date to desired form: e.g. 8 Dec 2023 const formatDate = (date: Date) => { @@ -306,16 +28,36 @@ const DeliveriesContainer = (props: { }); }; - // filtering logic - const dateFilteredTasks = dummyTasks.filter( - (task) => formatDate(task.date) == props.dateFilter - ); - let filteredTasks = dateFilteredTasks; // ALLTASKS filter - if (props.completionFilter === "COMPLETED") { - // if filter is set as COMPLETED, apply filter - filteredTasks = dateFilteredTasks.filter((task) => task.isCompleted); - } else if (props.completionFilter === "UPCOMING") { - filteredTasks = dateFilteredTasks.filter((task) => !task.isCompleted); + // function passed to sort function to sort deliveries based on routePosition + const compareDeliveries = ( + delivery1: MealDeliveryInterface, + delivery2: MealDeliveryInterface + ) => { + if (delivery1.routePosition < delivery2.routePosition) { + return -1; + } else if (delivery1.routePosition > delivery2.routePosition) { + return 1; + } + return 0; + }; + + let oneDayTask: TaskInterface | null = null; // will be selected date's task + + // filtering based on date + if (fetchedTasks) { + console.log("in deliveriesContainter ", fetchedTasks); + // we now assume that there is only one task associated to one date. + for (let task of fetchedTasks) { + console.log( + "date filtering now: ", + formatDate(new Date(task.date)), + dateFilter + ); + if (task.date && formatDate(new Date(task.date)) == dateFilter) { + oneDayTask = task; // filter the task + break; + } + } } let filteredDeliveries: MealDeliveryInterface[] = []; @@ -362,4 +104,4 @@ const DeliveriesContainer = (props: { ); }; -export default DeliveriesContainer; +export default DeliveriesContainer; \ No newline at end of file diff --git a/frontend/src/Components/MyTasks/Delivery.tsx b/frontend/src/Components/MyTasks/Delivery.tsx index 1a5342df..a6f7f913 100644 --- a/frontend/src/Components/MyTasks/Delivery.tsx +++ b/frontend/src/Components/MyTasks/Delivery.tsx @@ -68,9 +68,8 @@ const Delivery = (props: { } label={ } /> @@ -84,4 +83,4 @@ const Delivery = (props: { ); }; -export default Delivery; +export default Delivery; \ No newline at end of file From 5b4117ac83d3eb29f590bace294dfff13d6b3792 Mon Sep 17 00:00:00 2001 From: Hamza Farooq Date: Tue, 20 Jun 2023 18:45:30 -0400 Subject: [PATCH 08/11] fixed history --- frontend/src/Components/MyHistory/HistoryTasksContainer.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/Components/MyHistory/HistoryTasksContainer.tsx b/frontend/src/Components/MyHistory/HistoryTasksContainer.tsx index 2e7c56f7..d2cfdda5 100644 --- a/frontend/src/Components/MyHistory/HistoryTasksContainer.tsx +++ b/frontend/src/Components/MyHistory/HistoryTasksContainer.tsx @@ -15,7 +15,7 @@ const HistoryTasksContainer = (props: { const fetchTasks = async () => { try { const response = await getAllTasks(); // Fetch tasks from the backend - const tasks = response.tasks; + const tasks = response; const tasksByDate: { [date: string]: TaskInterface[] } = {}; From 6880e811ebf88f2db892b695fd0f8b142aee5ce8 Mon Sep 17 00:00:00 2001 From: Hamza Farooq Date: Tue, 20 Jun 2023 19:05:04 -0400 Subject: [PATCH 09/11] updated seeder --- backend/src/scripts/seeders/task.seeder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/scripts/seeders/task.seeder.ts b/backend/src/scripts/seeders/task.seeder.ts index 0bc88460..c992bb36 100644 --- a/backend/src/scripts/seeders/task.seeder.ts +++ b/backend/src/scripts/seeders/task.seeder.ts @@ -31,7 +31,7 @@ export const generateTask = async ( ) => { const task = new TaskEntity(); task.isCompleted = false; - task.date = faker.date.future(0.01); + task.date = faker.date.future(0.005); const repository = dataSource.getRepository(TaskEntity); await repository.insert(task); await dataSource From f3e3887206ffdf1ec5cc570509a20549013f67eb Mon Sep 17 00:00:00 2001 From: Hamza Farooq Date: Tue, 20 Jun 2023 20:09:57 -0400 Subject: [PATCH 10/11] fixed history for one volunteer --- .../MyHistory/HistoryTasksContainer.tsx | 60 ++++++++++--------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/frontend/src/Components/MyHistory/HistoryTasksContainer.tsx b/frontend/src/Components/MyHistory/HistoryTasksContainer.tsx index d2cfdda5..31f9265b 100644 --- a/frontend/src/Components/MyHistory/HistoryTasksContainer.tsx +++ b/frontend/src/Components/MyHistory/HistoryTasksContainer.tsx @@ -1,8 +1,9 @@ -import React, { useState, useEffect } from "react"; +import React, { useState, useEffect, useContext } from "react"; import { Box } from "@mui/material"; import SingleDayTasksContainer from "./SingleDayTasksContainer"; import { getAllTasks } from "../../services"; -import { TaskInterface } from "../../Contexts/Tasks"; +import { TaskContext, TaskInterface } from "../../Contexts/Tasks"; +import { getCurrentUserId } from "../../helper"; const HistoryTasksContainer = (props: { startDate: Date | null; @@ -10,36 +11,42 @@ const HistoryTasksContainer = (props: { }) => { const [allTasks, setAllTasks] = useState<{ [date: string]: TaskInterface[] }>({}); const [rangeOfDates, setRangeOfDates] = useState([]); + const user = Number(getCurrentUserId()); + const tasksContext = useContext(TaskContext); useEffect(() => { const fetchTasks = async () => { try { const response = await getAllTasks(); // Fetch tasks from the backend const tasks = response; - + + console.log("initialtasks", tasks); + const tasksByDate: { [date: string]: TaskInterface[] } = {}; - + tasks.forEach((task: TaskInterface) => { - const date = convertDate(new Date(task.date)).join('-'); // convert to string format "YYYY-MM-DD" - if (!tasksByDate[date]) { - tasksByDate[date] = []; + if (task.volunteer?.id === user) { + const date = convertDate(new Date(task.date)).join('-'); // convert to string format "YYYY-MM-DD" + if (!tasksByDate[date]) { + tasksByDate[date] = []; + } + tasksByDate[date].push(task); } - tasksByDate[date].push(task); }); - + setAllTasks(tasksByDate); + + // Update the tasksContext with the fetched tasks + tasksContext?.setTasks(tasks); } catch (error) { console.error("Error fetching tasks:", error); } }; - - fetchTasks(); - }, []); - + fetchTasks(); + }, []); // Empty dependency array to run only once on mount - console.log("allTasks", allTasks) - + console.log("allTasks", allTasks); const getRangeOfDates = (startDate: Date | null, endDate: Date | null) => { if (!startDate || !endDate) { @@ -64,14 +71,13 @@ const HistoryTasksContainer = (props: { const year = input.getFullYear(); const month = input.getMonth() + 1; const day = input.getDate(); - + return [year, month, day]; } useEffect(() => { setRangeOfDates(getRangeOfDates(props.startDate, props.endDate)); }, [props.startDate, props.endDate]); - return ( @@ -81,17 +87,17 @@ const HistoryTasksContainer = (props: { ) : null} {rangeOfDates.map((date: Date) => { - const dateString = convertDate(date).join('-'); - return ( - - ); -})} + const dateString = convertDate(date).join('-'); + return ( + + ); + })} ); }; -export default HistoryTasksContainer; \ No newline at end of file +export default HistoryTasksContainer; From f58fdbc194db719923ade76bad79eadda26a71af Mon Sep 17 00:00:00 2001 From: Hamza Farooq Date: Tue, 20 Jun 2023 20:22:04 -0400 Subject: [PATCH 11/11] fixed user profile --- frontend/src/Containers/UserProfileContainer.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/frontend/src/Containers/UserProfileContainer.tsx b/frontend/src/Containers/UserProfileContainer.tsx index 07f2150b..d40ae425 100644 --- a/frontend/src/Containers/UserProfileContainer.tsx +++ b/frontend/src/Containers/UserProfileContainer.tsx @@ -9,10 +9,11 @@ import { useNavigate, useParams } from "react-router-dom"; import { VolunteerType } from "./UserContainer"; import { editVolunteer, getVolunteer } from "../services"; import { setDefaultResultOrder } from "dns"; +import { getCurrentUserId } from "../helper"; const UserProfileContainer = () => { const navigate = useNavigate(); - const id = localStorage.getItem("userId"); + const id = Number(getCurrentUserId()); const [volunteer, setVolunteer] = useState(); const [email, setEmail] = useState(""); const [validEmail, setValidEmail] = useState(false); @@ -26,7 +27,7 @@ const UserProfileContainer = () => { const fetchVolunteer = async () => { try { - const volunteerData = await getVolunteer(Number(id)); + const volunteerData = await getVolunteer(id); setVolunteer(volunteerData.volunteer); console.log(volunteerData); console.log(volunteer); @@ -71,12 +72,12 @@ const UserProfileContainer = () => { } else { try { const updatedVolunteer = { - id: volunteer?.id, + id: id, email, phoneNumber, }; - await editVolunteer(volunteer?.id, updatedVolunteer); + await editVolunteer(id, updatedVolunteer); navigate(`/profile`); } catch (error) { console.error("Error updating volunteer:", error);