diff --git a/components/pages/todos/AddChoreDialog.tsx b/components/pages/todos/AddChoreDialog.tsx index d93b20f..30bfaa7 100644 --- a/components/pages/todos/AddChoreDialog.tsx +++ b/components/pages/todos/AddChoreDialog.tsx @@ -48,12 +48,14 @@ const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => { ); const { width, height } = Dimensions.get("screen"); const [points, setPoints] = useState(todo.points); + const [selectedDays, setSelectedDays] = useState([]); const { data: members } = useGetFamilyMembers(); const handleClose = () => { setTodo(defaultTodo); setSelectedAssignees([]); + setSelectedDays([]); addChoreDialogProps.setIsVisible(false); }; @@ -67,6 +69,17 @@ const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => { } }; + const handleRepeatDaysChange = (day: string, set: boolean) => { + if (set) { + setSelectedDays((prevState) => [...prevState, day]); + } else { + const array = selectedDays; + let index = array.indexOf(day); + array.splice(index, 1); + setSelectedDays(array); + } + } + return ( { updateToDo({ ...todo, points: points, - assignees: selectedAssignees, + assignees: selectedAssignees }); } else { addToDo({ @@ -118,6 +131,7 @@ const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => { done: false, points: points, assignees: selectedAssignees, + repeatDays: selectedDays }); } handleClose(); @@ -199,7 +213,7 @@ const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => { ))} - {todo.repeatType == "Every week" && } + {todo.repeatType == "Every week" && } diff --git a/components/pages/todos/RepeatFreq.tsx b/components/pages/todos/RepeatFreq.tsx index fb2fea5..a7b9354 100644 --- a/components/pages/todos/RepeatFreq.tsx +++ b/components/pages/todos/RepeatFreq.tsx @@ -1,7 +1,8 @@ import { View, Text, TouchableOpacity, Picker } from "react-native-ui-lib"; import React, { useEffect, useState } from "react"; +import {DAYS_OF_WEEK_ENUM} from "@/hooks/firebase/types/todoData"; -const RepeatFreq = () => { +const RepeatFreq = ({ handleRepeatDaysChange }: { handleRepeatDaysChange: Function }) => { const [weeks, setWeeks] = useState(1); const weekOptions: number[] = Array.from({ length: 52 }, (_, i) => i + 1); @@ -9,21 +10,25 @@ const RepeatFreq = () => { return ( - - - - - - - + + + + + + + ); }; export default RepeatFreq; -const RepeatOption = ({ value }: { value: string }) => { +const RepeatOption = ({ value, handleRepeatDaysChange }: { value: string, handleRepeatDaysChange: Function }) => { const [isSet, setisSet] = useState(false); + + useEffect(() => { + handleRepeatDaysChange(value, isSet); + }, [isSet]) return ( setisSet(!isSet)}>