- Introduced a button for syncing Microsoft calendar

- Implemented saving of the microsoft event data in db
This commit is contained in:
Dejan
2024-10-05 00:32:57 +02:00
parent 59efcc16c5
commit 8161accdb6
2 changed files with 87 additions and 9 deletions

View File

@ -5,6 +5,7 @@ import { StyleSheet } from "react-native";
import { colorMap } from "@/contexts/SettingsContext";
import { TouchableOpacity } from "react-native-gesture-handler";
import { fetchGoogleCalendarEvents } from "@/calendar-integration/google-calendar-utils";
import { fetchMicrosoftCalendarEvents } from "@/calendar-integration/microsoft-calendar-utils";
import { useCreateEvent } from "@/hooks/firebase/useCreateEvent";
import { GoogleSignin } from "@react-native-google-signin/google-signin";
@ -25,18 +26,27 @@ const CalendarSettingsPage = (props: {
});
};
const fetchAndSaveMicrosoftEvents = (token: string) => {
const startDateTime = new Date(new Date().setHours(0, 0, 0, 0));
const endDateTime = new Date(
new Date(new Date().setHours(0, 0, 0, 0)).setDate(
startDateTime.getDate() + 30,
),
);
fetchMicrosoftCalendarEvents(
token,
startDateTime.toISOString().slice(0, -5) + "Z",
endDateTime.toISOString().slice(0, -5) + "Z",
).then((response) => {
response?.forEach((item) => createEvent(item));
});
};
async function saveData(item) {
await createEvent(item);
}
// Note: Right key
GoogleSignin.configure({
webClientId:
"406146460310-81gld1b58ujsoe6a2t3ht0haprv5pa69.apps.googleusercontent.com",
scopes: ["profile", "email", "calendar"],
offlineAccess: true,
});
return (
<View marginH-30>
<TouchableOpacity onPress={() => props.setSelectedPage(0)}>
@ -150,7 +160,7 @@ const CalendarSettingsPage = (props: {
{/** Note: Should check for the user if it has connected calendars **/}
<View style={{ marginTop: 20 }}>
<Button
label={"Sync Calendar"}
label={"Sync Google"}
iconSource={() => (
<View
backgroundColor="#ededed"
@ -170,6 +180,27 @@ const CalendarSettingsPage = (props: {
borderRadius={15}
onPress={fetchAndSaveGoogleEvents}
/>
<Button
label={"Sync Outlook"}
iconSource={() => (
<View
backgroundColor="#ededed"
width={40}
height={40}
style={{ borderRadius: 50 }}
marginR-10
centerV
centerH
>
<AntDesign name="google" size={30} color="#6c645b" />
</View>
)}
icon={<AntDesign name="checkcircleo" size={30} color="#8005eb" />}
backgroundColor="white"
color="#464039"
borderRadius={15}
onPress={fetchAndSaveMicrosoftEvents}
/>
</View>
</View>
</View>
@ -177,6 +208,13 @@ const CalendarSettingsPage = (props: {
};
const signInGoogle = async () => {
GoogleSignin.configure({
webClientId:
"406146460310-81gld1b58ujsoe6a2t3ht0haprv5pa69.apps.googleusercontent.com",
scopes: ["profile", "email", "calendar"],
offlineAccess: true,
});
try {
await GoogleSignin.hasPlayServices();
let userInfo = await GoogleSignin.signIn();