mirror of
https://github.com/urosran/cally.git
synced 2025-11-26 00:24:53 +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);
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user