- Added validation for title and attendees when creation/updating event

This commit is contained in:
Dejan
2024-11-21 23:32:50 +01:00
parent 726668921b
commit fb27079f10

View File

@ -22,7 +22,7 @@ import { PickerMultiValue } from "react-native-ui-lib/src/components/picker/type
import { useCreateEvent } from "@/hooks/firebase/useCreateEvent";
import { EventData } from "@/hooks/firebase/types/eventData";
import DropModalIcon from "@/assets/svgs/DropModalIcon";
import { StyleSheet } from "react-native";
import {Alert, StyleSheet} from "react-native";
import ClockIcon from "@/assets/svgs/ClockIcon";
import LockIcon from "@/assets/svgs/LockIcon";
import MenuIcon from "@/assets/svgs/MenuIcon";
@ -266,12 +266,29 @@ export const ManuallyAddEventModal = () => {
if (editEvent?.id) eventData.id = editEvent?.id;
await createEvent(eventData);
setEditEvent(undefined);
if (validateEvent()) {
await createEvent(eventData);
setEditEvent(undefined);
close();
close();
} else {
return;
}
};
const validateEvent = () => {
if (!title) {
Alert.alert('Alert', 'Title field cannot be empty');
return false;
}
if (!selectedAttendees || selectedAttendees?.length === 0) {
Alert.alert('Alert', 'Cannot have an event without any attendees');
return false;
}
return true;
}
const getRepeatLabel = () => {
const selectedDays = repeatInterval;
const allDays = [