- Fixed an issue with the Tod dialog

- Implementation of update todo and adding new days in the rule for a repeatable todo
This commit is contained in:
Dejan
2024-10-25 14:04:13 +02:00
parent 04f9e31ce4
commit f35033f5e7
6 changed files with 115 additions and 20 deletions

View File

@ -31,7 +31,7 @@ const AddChore = () => {
</Text>
</Button>
</View>
<AddChoreDialog isVisible={isVisible} setIsVisible={setIsVisible} />
{isVisible && <AddChoreDialog isVisible={isVisible} setIsVisible={setIsVisible} />}
</LinearGradient>
);
};

View File

@ -36,6 +36,7 @@ const defaultTodo = {
rotate: false,
repeatType: "Every week",
assignees: [],
repeatDays: []
};
const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => {
@ -48,14 +49,12 @@ const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => {
);
const { width, height } = Dimensions.get("screen");
const [points, setPoints] = useState<number>(todo.points);
const [selectedDays, setSelectedDays] = useState([]);
const { data: members } = useGetFamilyMembers();
const handleClose = () => {
setTodo(defaultTodo);
setSelectedAssignees([]);
setSelectedDays([]);
addChoreDialogProps.setIsVisible(false);
};
@ -71,12 +70,20 @@ const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => {
const handleRepeatDaysChange = (day: string, set: boolean) => {
if (set) {
setSelectedDays((prevState) => [...prevState, day]);
const updatedTodo = {
...todo,
repeatDays: [...todo.repeatDays, day]
}
setTodo(updatedTodo);
} else {
const array = selectedDays;
const array = todo.repeatDays ?? [];
let index = array.indexOf(day);
array.splice(index, 1);
setSelectedDays(array);
const updatedTodo = {
...todo,
repeatDays: array
}
setTodo(updatedTodo);
}
}
@ -123,8 +130,7 @@ const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => {
updateToDo({
...todo,
points: points,
assignees: selectedAssignees,
repeatDays: selectedDays,
assignees: selectedAssignees
});
} else {
addToDo({
@ -132,7 +138,7 @@ const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => {
done: false,
points: points,
assignees: selectedAssignees,
repeatDays: selectedDays
repeatDays: todo.repeatDays ?? []
});
}
handleClose();

View File

@ -26,11 +26,14 @@ export default RepeatFreq;
const RepeatOption = ({ value, handleRepeatDaysChange, repeatDays }: { value: string, handleRepeatDaysChange: Function, repeatDays: string[] }) => {
const [isSet, setisSet] = useState(repeatDays.includes(value));
useEffect(() => {
handleRepeatDaysChange(value, isSet);
}, [isSet])
const handleDayChange = () => {
handleRepeatDaysChange(value, !isSet)
setisSet(!isSet);
}
return (
<TouchableOpacity onPress={() => setisSet(!isSet)}>
<TouchableOpacity onPress={handleDayChange}>
<View
center
marginT-8