Event creation

This commit is contained in:
Milan Paunovic
2024-08-26 13:42:28 +02:00
parent 64ae88a732
commit 96168316b5
22 changed files with 1129 additions and 1191 deletions
+13
View File
@@ -0,0 +1,13 @@
export interface EventData {
title: string,
startDate: Date,
endDate: Date,
allDay: boolean,
repeatDays: string[],
creatorId: string[],
userIds: string[],
timeZone?: string,
surpriseEvent?: boolean,
notes?: string,
reminders?: string[]
}
+25
View File
@@ -0,0 +1,25 @@
import {useAuthContext} from "@/contexts/AuthContext";
import {useMutation, useQueryClient} from "react-query";
import firestore from "@react-native-firebase/firestore";
import {EventData} from "@/hooks/firebase/types/eventData";
export const useCreateEvent = () => {
const {user: currentUser} = useAuthContext()
const queryClients = useQueryClient()
return useMutation({
mutationKey: ["createEvent"],
mutationFn: async (eventData: Partial<EventData>) => {
try {
await firestore()
.collection("Events")
.add({...eventData, creatorId: currentUser?.uid})
} catch (e) {
console.error(e)
}
},
onSuccess: () => {
queryClients.invalidateQueries("events")
}
})
}
+31
View File
@@ -0,0 +1,31 @@
import {useQuery} from "react-query";
import firestore from "@react-native-firebase/firestore";
import {ReactElement} from "react";
import {useAuthContext} from "@/contexts/AuthContext";
import {ICalendarEventBase} from "react-native-big-calendar";
export const useGetEvents = () => {
const {user} = useAuthContext()
return useQuery({
queryKey: ["events", user?.uid],
queryFn: async () => {
const snapshot = await firestore()
.collection("Events")
.where("creatorId", "==", user?.uid)
.get();
const events: ICalendarEventBase[] = snapshot.docs.map((doc) => {
const data = doc.data();
return {
title: data.title,
start: new Date(data.startDate.seconds * 1000),
end: new Date(data.endDate.seconds * 1000),
hideHours: data.allDay,
};
});
return events;
}
})
}
-6
View File
@@ -14,18 +14,12 @@ export const useUpdateUserData = () => {
if (user) {
try {
console.log("yall don't even");
console.log(newUserData)
await firestore()
.collection("Profiles")
.doc(user.uid)
.set(newUserData);
console.log("wtf")
const profileData = await firestore().collection("Profiles").doc(user?.uid!).get()
console.log("wtf222")
console.log(profileData)
setProfileData(profileData.data() as UserProfile)
} catch (e) {
console.error(e)