diff --git a/frontend/src/components/common/CommonTable.tsx b/frontend/src/components/common/CommonTable.tsx index dc1146b..65a02e6 100644 --- a/frontend/src/components/common/CommonTable.tsx +++ b/frontend/src/components/common/CommonTable.tsx @@ -20,7 +20,7 @@ import ChevronRightOutlinedIcon from "@mui/icons-material/ChevronRightOutlined"; import KeyboardArrowUpOutlinedIcon from "@mui/icons-material/KeyboardArrowUpOutlined"; import KeyboardArrowDownOutlinedIcon from "@mui/icons-material/KeyboardArrowDownOutlined"; -type TableTypes = string | number | boolean | Date; +type TableTypes = string | number | boolean | Date | string[]; export type ColumnInfoTypes = { header: string; key: string }; diff --git a/frontend/src/components/pages/tasks/TaskModal.tsx b/frontend/src/components/pages/tasks/TaskModal.tsx index e9a454a..fb3a04d 100644 --- a/frontend/src/components/pages/tasks/TaskModal.tsx +++ b/frontend/src/components/pages/tasks/TaskModal.tsx @@ -1,12 +1,19 @@ -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; import { Button, Select, Flex, FormControl, FormLabel } from "@chakra-ui/react"; import colors from "../../../theme/colors"; import ModalContainer from "../../common/ModalContainer"; import FormField from "../../common/FormField"; +import { + TaskType, + Task, + CustomTask, + ChoreTask, +} from "../../../types/TaskTypes"; type Props = { isOpen: boolean; setIsOpen: React.Dispatch>; + task: Task | null; }; // returns an array of times in 30 minute increments @@ -32,7 +39,7 @@ const generateOptions = () => { const options = generateOptions(); -const TaskModal = ({ isOpen, setIsOpen }: Props): React.ReactElement => { +const TaskModal = ({ isOpen, setIsOpen, task }: Props): React.ReactElement => { const [taskType, setTaskType] = useState(""); const [recurrence, setRecurrence] = useState("Does Not Repeat"); const [marillacBucks, setMarillacBucks] = useState(""); @@ -49,6 +56,45 @@ const TaskModal = ({ isOpen, setIsOpen }: Props): React.ReactElement => { const [submitPressed, setSubmitPressed] = useState(false); + const dayIdMap = new Map([ + ["MONDAY", "M"], + ["TUESDAY", "Tu"], + ["WEDNESDAY", "W"], + ["THURSDAY", "Th"], + ["FRIDAY", "F"], + ["SATURDAY", "Sa"], + ["SUNDAY", "Su"], + ]) + + useEffect(() => { + if(task) { + setTaskType(task.type); + setRecurrence(task.recurrenceFrequency==="ONE_TIME"? "Does Not Repeat": "Repeats"); + setMarillacBucks(task.creditValue.toString()); + + if(task.specificDay) { + const day = dayIdMap.get(task.specificDay); + if(day) { + setSelectedDays([day]); + } + } else { + setSelectedDays(task.repeatDays.map(day => dayIdMap.get(task.specificDay || "")).filter(day => day !== undefined)); + } + + setTitle(task.title); + setDueDate(task.endDate? task.endDate.toString(): ""); + setDueTime(""); + } else { + setTaskType(""); + setRecurrence("Does Not Repeat"); + setMarillacBucks(""); + setSelectedDays([]); + setTitle(""); + setDueDate(""); + setDueTime(""); + } + }, [task]); + const handleSubmit = () => { setSubmitPressed(true); if (!title || !location || !dueDate || !dueTime || !marillacBucks) { diff --git a/frontend/src/components/pages/tasks/TasksPage.tsx b/frontend/src/components/pages/tasks/TasksPage.tsx index f889d47..4146ad1 100644 --- a/frontend/src/components/pages/tasks/TasksPage.tsx +++ b/frontend/src/components/pages/tasks/TasksPage.tsx @@ -77,6 +77,7 @@ const TasksPage = (): React.ReactElement => { const [taskDataColumns, setTaskDataColumns] = useState([]); const [taskFilter, setTaskFilter] = useState(""); + const [modalTask, setModalTask] = useState (null); // const [createTask] = useMutation<{ createTask: TaskResponse }>(CREATE_TASK); @@ -348,11 +349,13 @@ const TasksPage = (): React.ReactElement => { data={taskData} columnInfo={taskDataColumns} maxResults={8} - onEdit={() => { + onEdit={(row: any) => { + setModalTask(row); + console.log(row); setIsModalOpen(true); }} /> - + ); diff --git a/frontend/src/mocks/tasks.ts b/frontend/src/mocks/tasks.ts index 57aa31c..36e0e69 100644 --- a/frontend/src/mocks/tasks.ts +++ b/frontend/src/mocks/tasks.ts @@ -1,152 +1,304 @@ +import { RecurrenceFrequency } from "../APIClients/Types/TaskType"; + export const requiredTasksMockData = [ { + id: "34989382", + type: "REQUIRED", title: "Weekly Review with CM", dueDate: "Every Friday", creditValue: "$5.00", + locationId: 1, + recurrenceFrequency: "REPEATS_PER_WEEK_SELECTED", + specificDay: "", + repeatDays: ["MONDAY", "TUESDAY", "WEDNESDAY"], }, { + id: "34989383", + type: "REQUIRED", title: "Skills Session with PM", dueDate: "Every Friday", creditValue: "$5.00", + locationId: 1, + recurrenceFrequency: "ONE_TIME", + specificDay: "MONDAY", + repeatDays: [], }, { + id: "fhoudsahfo", + type: "REQUIRED", title: "Housing Plan", dueDate: "Every Friday", creditValue: "$5.00", + locationId: 1, + recurrenceFrequency: "ONE_TIME", + specificDay: "MONDAY", + repeatDays: [], }, ]; export const optionalTasksMockData = [ { + id: "xvzcpivpcxz", + type: "OPTIONAL", title: "Weekly House Meeting", dueDate: "Every Monday at 12:00pm", creditValue: "$5.00", + locationId: 1, + recurrenceFrequency: "ONE_TIME", + specificDay: "MONDAY", + repeatDays: [], }, { + id: "xcovzjxi", + type: "OPTIONAL", title: "Curfew", dueDate: "Everyday at 10:00pm", creditValue: "$5.00", + locationId: 1, + recurrenceFrequency: "ONE_TIME", + specificDay: "MONDAY", + repeatDays: [], }, { + id: "voixzczc", + type: "OPTIONAL", title: "Bedroom Inspection", dueDate: "Everyday at 10:00pm", creditValue: "$2.00", + locationId: 1, + recurrenceFrequency: "ONE_TIME", + specificDay: "MONDAY", + repeatDays: [], }, { + id: "43rt43rew", + type: "OPTIONAL", title: "Speaker's Corner", dueDate: "Everyday at 10:00pm", creditValue: "$10.00", + locationId: 1, + recurrenceFrequency: "ONE_TIME", + specificDay: "MONDAY", + repeatDays: [], }, { + id: "cxzvsd", + type: "OPTIONAL", title: "Counselling", dueDate: "Every Friday", creditValue: "$10.00", + locationId: 1, + recurrenceFrequency: "ONE_TIME", + specificDay: "MONDAY", + repeatDays: [], }, { + id: "vxz,cxvcxz", + type: "OPTIONAL", title: "Community Program/School", dueDate: "Everyday at 2:00pm", creditValue: "$10.00", + locationId: 1, + recurrenceFrequency: "ONE_TIME", + specificDay: "MONDAY", + repeatDays: [], }, ]; export const customTasksMockData = [ { + id: "oipuvxuczp", + type: "CUSTOM", title: "Room 1's custom task", roomNumber: 1, dueDate: "Every Monday at 10:00am", creditValue: "$5.00", + locationId: 1, + recurrenceFrequency: "ONE_TIME", + specificDay: "MONDAY", + repeatDays: [], }, { + id: "jijiljvcxz", + type: "CUSTOM", title: "Room 2's custom task", roomNumber: 2, dueDate: "Every Tuesday at 11:00am", creditValue: "$5.00", + locationId: 1, + recurrenceFrequency: "ONE_TIME", + specificDay: "MONDAY", + repeatDays: [], }, { + id: "asdasldasda", + type: "CUSTOM", title: "Room 3's custom task", roomNumber: 3, dueDate: "Every Wednesday at 12:00pm", creditValue: "$5.00", + locationId: 1, + recurrenceFrequency: "ONE_TIME", + specificDay: "MONDAY", + repeatDays: [], }, { + id: "xzcvcxzvxczvcx", + type: "CUSTOM", title: "Room 4's custom task", roomNumber: 4, dueDate: "Every Thursday at 1:00pm", creditValue: "$5.00", + locationId: 1, + recurrenceFrequency: "ONE_TIME", + specificDay: "MONDAY", + repeatDays: [], }, { + id: "qweoqweiuwoqe", + type: "CUSTOM", title: "Room 5's custom task", roomNumber: 5, dueDate: "Every Friday at 2:00pm", creditValue: "$5.00", + locationId: 1, + recurrenceFrequency: "ONE_TIME", + specificDay: "MONDAY", + repeatDays: [], }, { + id: "sdffjdsafjldsaflsad", + type: "CUSTOM", title: "Room 6's custom task", roomNumber: 6, dueDate: "Every Saturday at 3:00pm", creditValue: "$5.00", + locationId: 1, + recurrenceFrequency: "ONE_TIME", + specificDay: "MONDAY", + repeatDays: [], }, { + id: "31491331r1", + type: "CUSTOM", title: "Room 7's custom task", roomNumber: 7, dueDate: "Every Sunday at 4:00pm", creditValue: "$5.00", + locationId: 1, + recurrenceFrequency: "ONE_TIME", + specificDay: "MONDAY", + repeatDays: [], }, { + id: "safodsafhusda", + type: "CUSTOM", title: "Room 8's custom task", roomNumber: 8, dueDate: "Everyday at 5:00pm", creditValue: "$5.00", + locationId: 1, + recurrenceFrequency: "ONE_TIME", + specificDay: "MONDAY", + repeatDays: [], }, { + id: "Sfhosadfuhdsaf", + type: "CUSTOM", title: "Room 9's custom task", roomNumber: 9, dueDate: "Everyday at 6:00pm", creditValue: "$5.00", + locationId: 1, + recurrenceFrequency: "ONE_TIME", + specificDay: "MONDAY", + repeatDays: [], }, { + id: "asdfosaudfhsdaofuhsdaf", + type: "CUSTOM", title: "Room 10's custom task", roomNumber: 10, dueDate: "Everyday at 7:00pm", creditValue: "$5.00", + locationId: 1, + recurrenceFrequency: "ONE_TIME", + specificDay: "MONDAY", + repeatDays: [], }, ]; export const choreTasksMockData = [ { + id: "aosdfasdfsda", + type: "CHORE", title: "Wash the dishes", location: "Kitchen", dueDate: "Everyday at 11:00am", creditValue: "$5.00", + locationId: 1, + recurrenceFrequency: "ONE_TIME", + specificDay: "MONDAY", + repeatDays: [], }, { + id: "ofhosduafsda", + type: "CHORE", title: "Clean the bathroom", location: "Bathroom", dueDate: "Everyday at 11:00am", creditValue: "$5.00", + locationId: 1, + recurrenceFrequency: "ONE_TIME", + specificDay: "MONDAY", + repeatDays: [], }, { + id: "avsuhoudvs", + type: "CHORE", title: "Mop the floors", location: "Living Room", dueDate: "Everyday at 11:00am", creditValue: "$5.00", + locationId: 1, + recurrenceFrequency: "ONE_TIME", + specificDay: "MONDAY", + repeatDays: [], }, { + id: "sdfdsaf", + type: "CHORE", title: "Take out the trash", location: "Kitchen", dueDate: "Everyday at 11:00am", creditValue: "$5.00", + locationId: 1, + recurrenceFrequency: "ONE_TIME", + specificDay: "MONDAY", + repeatDays: [], }, { + id: "asofusad", + type: "CHORE", title: "Vacuum the carpets", location: "Living Room", dueDate: "Everyday at 11:00am", creditValue: "$5.00", + locationId: 1, + recurrenceFrequency: "ONE_TIME", + specificDay: "MONDAY", + repeatDays: [], }, { + id: "1892419413", + type: "CHORE", title: "Dust the furniture", location: "Living Room", dueDate: "Everyday at 11:00am", creditValue: "$5.00", + locationId: 1, + recurrenceFrequency: "ONE_TIME", + specificDay: "MONDAY", + repeatDays: [], }, ]; diff --git a/frontend/src/types/TaskTypes.ts b/frontend/src/types/TaskTypes.ts index 24a5d4a..99712da 100644 --- a/frontend/src/types/TaskTypes.ts +++ b/frontend/src/types/TaskTypes.ts @@ -1,9 +1,18 @@ export type TaskType = "REQUIRED" | "OPTIONAL" | "CUSTOM" | "CHORE"; +export type RecurrenceFrequency = "ONE_TIME" | "REPEATS_PER_WEEK_SELECTED" | "REPEATS_PER_WEEK_ONCE"; +export type DaysOfWeek = "MONDAY" | "TUESDAY" | "WEDNESDAY" | "THURSDAY" | "FRIDAY" | "SATURDAY" | "SUNDAY"; export interface Task { + id: string; + type: TaskType; title: string; description: string; creditValue: number; + locationId: number; + endDate?: Date; + recurrenceFrequency: RecurrenceFrequency; + specificDay?: DaysOfWeek; + repeatDays: DaysOfWeek[]; } export interface CustomTask extends Task {