Editing calendar events

- Added new hook for updating events
- Updated the selected event in db
- Added document id as id to the event object when fetching events
- Removed unused react-native-google sign-in library
This commit is contained in:
Dejan
2024-10-11 13:24:25 +02:00
parent 7d9d41acfc
commit 562da49806
6 changed files with 39 additions and 42 deletions
+1 -1
View File
@@ -47,7 +47,7 @@ export default function CalendarPage() {
},
});
const [isFamilyView, setIsFamilyView] = useState<boolean>(true);
const [isFamilyView, setIsFamilyView] = useState<boolean>(false);
const [calendarHeight, setCalendarHeight] = useState(0);
const [mode, setMode] = useState<"week" | "month" | "day">("week");
const [selectedDate, setSelectedDate] = useState<Date>(new Date());
@@ -1,7 +1,5 @@
import { View, Text, Button, Switch } from "react-native-ui-lib";
import React, { useEffect, useState } from "react";
import PointsSlider from "@/components/shared/PointsSlider";
import { repeatOptions, useToDosContext } from "@/contexts/ToDosContext";
import { Feather, AntDesign, Ionicons } from "@expo/vector-icons";
import {
Dialog,
@@ -13,11 +11,11 @@ import {
import { PanningDirectionsEnum } from "react-native-ui-lib/src/incubator/panView";
import { StyleSheet } from "react-native";
import DropModalIcon from "@/assets/svgs/DropModalIcon";
import { CalendarEvent, useCalendarContext } from "@/contexts/CalendarContext";
import { CalendarEvent } from "@/contexts/CalendarContext";
import ClockIcon from "@/assets/svgs/ClockIcon";
import LockIcon from "@/assets/svgs/LockIcon";
import MenuIcon from "@/assets/svgs/MenuIcon";
import { eventCellCss } from "react-native-big-calendar";
import { useUpdateEvent } from "@/hooks/firebase/useUpdateEvent";
interface IEditEventDialog {
event: CalendarEvent;
@@ -25,9 +23,10 @@ interface IEditEventDialog {
setIsVisible: (value: boolean) => void;
}
const EditEventDialog = (editEventProps: IEditEventDialog) => {
const { updateEvent } = useCalendarContext();
const [event, setEvent] = useState<CalendarEvent>(editEventProps.event);
const { mutateAsync: updateEvent } = useUpdateEvent();
useEffect(() => {
setEvent(editEventProps.event);
}, [editEventProps.isVisible]);
@@ -72,8 +71,7 @@ const EditEventDialog = (editEventProps: IEditEventDialog) => {
onPress={() => {
try {
if (event.id) {
updateEvent(event, event.id);
editEventProps.setIsVisible(false);
updateEvent(event).then(() => editEventProps.setIsVisible(false));
}
} catch (error) {
console.error(error);