From cc2a649f8cf7cf3abf7f9285c125597cbe8e0c5b Mon Sep 17 00:00:00 2001 From: Dejan Date: Wed, 20 Nov 2024 19:27:14 +0100 Subject: [PATCH 1/4] - Reverted the Add todo press functionality to open the Add todo dialog instead of redirecting to Todos page --- components/pages/calendar/AddEventDialog.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/components/pages/calendar/AddEventDialog.tsx b/components/pages/calendar/AddEventDialog.tsx index e6aa012..702b571 100644 --- a/components/pages/calendar/AddEventDialog.tsx +++ b/components/pages/calendar/AddEventDialog.tsx @@ -1,5 +1,4 @@ import React, {useState} from "react"; -import {MaterialIcons,} from "@expo/vector-icons"; import {Button, Card, Dialog, PanningProvider, Text, View,} from "react-native-ui-lib"; import {StyleSheet, TouchableOpacity} from "react-native"; import AddChoreDialog from "../todos/AddChoreDialog"; @@ -11,7 +10,6 @@ import NavToDosIcon from "@/assets/svgs/NavToDosIcon"; import {useSetAtom} from "jotai"; import {selectedNewEventDateAtom} from "@/components/pages/calendar/atoms"; import PlusIcon from "@/assets/svgs/PlusIcon"; -import {useNavigation} from "expo-router"; export const AddEventDialog = () => { const [show, setShow] = useState(false); @@ -33,7 +31,6 @@ export const AddEventDialog = () => { }, 100); }; - const navigation = useNavigation() return ( <> @@ -118,7 +115,7 @@ export const AddEventDialog = () => { }} label="Add To Do" labelStyle={styles.btnLabel} - onPress={() => navigation.navigate("todos")} + onPress={() => setChoreDialogVisible(true)} iconSource={() => ( Date: Wed, 20 Nov 2024 20:04:23 +0100 Subject: [PATCH 2/4] - Allowed selecting date when Repeat type is set to "None" - Enabled opening the repeat freq picker with click on the Repeat todo icon --- components/pages/todos/AddChoreDialog.tsx | 26 +++++++++++------------ 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/components/pages/todos/AddChoreDialog.tsx b/components/pages/todos/AddChoreDialog.tsx index d095dc9..6f2aa32 100644 --- a/components/pages/todos/AddChoreDialog.tsx +++ b/components/pages/todos/AddChoreDialog.tsx @@ -106,6 +106,11 @@ const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => { }, 500) }, []); + const repeatPickerRef = useRef(); + const showRepeatPicker = () => { + repeatPickerRef.current?.toggleExpandable(true); + } + return ( { )} - + { if (value) { - if (value.toString() == "None") { - setTodo((oldValue) => ({ - ...oldValue, - date: null, - repeatType: "None", - })); - } else { - setTodo((oldValue) => ({ - ...oldValue, - date: new Date(), - repeatType: value.toString(), - })); - } + setTodo((oldValue) => ({ + ...oldValue, + date: new Date(), + repeatType: value.toString(), + })); } }} topBarProps={{title: "Repeat"}} From e113d78575a2df8d464e39d7d1a528d1f102b272 Mon Sep 17 00:00:00 2001 From: Dejan Date: Wed, 20 Nov 2024 20:24:37 +0100 Subject: [PATCH 3/4] - Added todo filter option for Everyone to show all the family's tasks --- components/pages/todos/ToDosList.tsx | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/components/pages/todos/ToDosList.tsx b/components/pages/todos/ToDosList.tsx index 22a33c4..45bc481 100644 --- a/components/pages/todos/ToDosList.tsx +++ b/components/pages/todos/ToDosList.tsx @@ -8,9 +8,14 @@ import {IToDo} from "@/hooks/firebase/types/todoData"; import DropdownIcon from "@/assets/svgs/DropdownIcon"; import {Dropdown} from "react-native-element-dropdown"; import {useGetFamilyMembers} from "@/hooks/firebase/useGetFamilyMembers"; -import {ProfileType, useAuthContext} from "@/contexts/AuthContext"; +import {useAuthContext} from "@/contexts/AuthContext"; import {StyleSheet} from "react-native"; +const FILTER_OPTIONS = { + ME: "Me", + EVERYONE: "Everyone" +}; + const groupToDosByDate = (toDos: IToDo[]) => { let sortedTodos = toDos.sort((a, b) => a.date - b.date); return sortedTodos.reduce( @@ -75,13 +80,16 @@ const groupToDosByDate = (toDos: IToDo[]) => { const resolveFilterOptions = (members, user) => { - return members?.map((member) => { + let options = members?.map((member) => { let label = member?.firstName; if (member.uid === user?.uid) { - label = "Me"; + label = FILTER_OPTIONS.ME; } - return (member.uid !== user?.uid || member.profileType !== ProfileType.PARENT) && {value: member?.uid, label: label}; + return {value: member?.uid, label: label}; }); + options.push({value: FILTER_OPTIONS.EVERYONE, label: FILTER_OPTIONS.EVERYONE}) + + return options; } const ToDosList = ({ isSettings }: { isSettings?: boolean }) => { @@ -110,10 +118,15 @@ const ToDosList = ({ isSettings }: { isSettings?: boolean }) => { useEffect(() => { if (toDos && selectedFilter) { - let filtered = toDos?.filter((todo) => todo.assignees?.includes(selectedFilter.value) || todo.creatorId === selectedFilter.value) || []; + let resolvedGroupedTodos; + if (selectedFilter?.value === FILTER_OPTIONS.EVERYONE) { + resolvedGroupedTodos = groupToDosByDate(toDos ?? []); + } else { + let filtered = toDos?.filter((todo) => todo.assignees?.includes(selectedFilter.value)) || []; - let filteredGroupedTodos = groupToDosByDate(filtered || []); - setGroupedToDos(filteredGroupedTodos || []); + resolvedGroupedTodos = groupToDosByDate(filtered || []); + } + setGroupedToDos(resolvedGroupedTodos || []); } }, [selectedFilter, JSON.stringify(toDos)]); From b1a5d4c171cf9bf09806f9d71a54b1bb0be27184 Mon Sep 17 00:00:00 2001 From: Dejan Date: Wed, 20 Nov 2024 20:36:09 +0100 Subject: [PATCH 4/4] - Added validation when adding todos to restrict having todos without any assignees --- components/pages/todos/AddChoreDialog.tsx | 46 +++++++++++++++-------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/components/pages/todos/AddChoreDialog.tsx b/components/pages/todos/AddChoreDialog.tsx index 6f2aa32..e5149f9 100644 --- a/components/pages/todos/AddChoreDialog.tsx +++ b/components/pages/todos/AddChoreDialog.tsx @@ -111,6 +111,19 @@ const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => { repeatPickerRef.current?.toggleExpandable(true); } + const validateTodo = () => { + if (!todo?.title) { + Alert.alert('Alert', 'Title field cannot be empty'); + return false; + } + if (!selectedAssignees || selectedAssignees?.length === 0) { + Alert.alert('Alert', 'Cannot have a todo without any assignees'); + return false; + } + + return true; + } + return ( { onPress={() => { try { if (addChoreDialogProps.selectedTodo) { - if (!todo?.title) { - Alert.alert('Alert', 'Title field cannot be empty'); + + if (validateTodo()) { + updateToDo({ + ...todo, + points: points, + assignees: selectedAssignees + }); + } else { return; } - updateToDo({ - ...todo, - points: points, - assignees: selectedAssignees - }); } else { - if (!todo?.title) { - Alert.alert('Alert', 'Title field cannot be empty'); + if (validateTodo()) { + addToDo({ + ...todo, + done: false, + points: points, + assignees: selectedAssignees, + repeatDays: todo.repeatDays ?? [] + }); + } else { return; } - addToDo({ - ...todo, - done: false, - points: points, - assignees: selectedAssignees, - repeatDays: todo.repeatDays ?? [] - }); } handleClose(); } catch (error) {