- 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); 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) {