- Added validation when adding todos to restrict having todos without any assignees

This commit is contained in:
Dejan
2024-11-20 20:36:09 +01:00
parent e113d78575
commit b1a5d4c171

View File

@ -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 (
<Dialog
bottom={true}
@ -151,20 +164,18 @@ const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => {
onPress={() => {
try {
if (addChoreDialogProps.selectedTodo) {
if (!todo?.title) {
Alert.alert('Alert', 'Title field cannot be empty');
return;
}
if (validateTodo()) {
updateToDo({
...todo,
points: points,
assignees: selectedAssignees
});
} else {
if (!todo?.title) {
Alert.alert('Alert', 'Title field cannot be empty');
return;
}
} else {
if (validateTodo()) {
addToDo({
...todo,
done: false,
@ -172,6 +183,9 @@ const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => {
assignees: selectedAssignees,
repeatDays: todo.repeatDays ?? []
});
} else {
return;
}
}
handleClose();
} catch (error) {