mirror of
https://github.com/urosran/cally.git
synced 2025-11-26 16:34:54 +00:00
- Added validation when adding todos to restrict having todos without any assignees
This commit is contained in:
@ -111,6 +111,19 @@ const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => {
|
|||||||
repeatPickerRef.current?.toggleExpandable(true);
|
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 (
|
return (
|
||||||
<Dialog
|
<Dialog
|
||||||
bottom={true}
|
bottom={true}
|
||||||
@ -151,27 +164,28 @@ const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => {
|
|||||||
onPress={() => {
|
onPress={() => {
|
||||||
try {
|
try {
|
||||||
if (addChoreDialogProps.selectedTodo) {
|
if (addChoreDialogProps.selectedTodo) {
|
||||||
if (!todo?.title) {
|
|
||||||
Alert.alert('Alert', 'Title field cannot be empty');
|
if (validateTodo()) {
|
||||||
|
updateToDo({
|
||||||
|
...todo,
|
||||||
|
points: points,
|
||||||
|
assignees: selectedAssignees
|
||||||
|
});
|
||||||
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
updateToDo({
|
|
||||||
...todo,
|
|
||||||
points: points,
|
|
||||||
assignees: selectedAssignees
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
if (!todo?.title) {
|
if (validateTodo()) {
|
||||||
Alert.alert('Alert', 'Title field cannot be empty');
|
addToDo({
|
||||||
|
...todo,
|
||||||
|
done: false,
|
||||||
|
points: points,
|
||||||
|
assignees: selectedAssignees,
|
||||||
|
repeatDays: todo.repeatDays ?? []
|
||||||
|
});
|
||||||
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
addToDo({
|
|
||||||
...todo,
|
|
||||||
done: false,
|
|
||||||
points: points,
|
|
||||||
assignees: selectedAssignees,
|
|
||||||
repeatDays: todo.repeatDays ?? []
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
handleClose();
|
handleClose();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user