mirror of
https://github.com/urosran/cally.git
synced 2025-07-16 01:56:16 +00:00
- Implemented connecting multiple accounts for microsoft
This commit is contained in:
@ -174,9 +174,12 @@ const CalendarSettingsPage = (props: {
|
|||||||
} else {
|
} else {
|
||||||
const outlookMail = userInfo.mail || userInfo.userPrincipalName;
|
const outlookMail = userInfo.mail || userInfo.userPrincipalName;
|
||||||
|
|
||||||
|
let microsoftAccounts = profileData?.microsoftAccounts;
|
||||||
|
const updatedMicrosoftAccounts = microsoftAccounts ? {...microsoftAccounts, [outlookMail]: tokenData.access_token} : {[outlookMail]: tokenData.access_token};
|
||||||
|
|
||||||
// Update user data with Microsoft token and email
|
// Update user data with Microsoft token and email
|
||||||
await updateUserData({
|
await updateUserData({
|
||||||
newUserData: {microsoftToken: tokenData.access_token, outlookMail: outlookMail},
|
newUserData: {microsoftAccounts: updatedMicrosoftAccounts},
|
||||||
});
|
});
|
||||||
|
|
||||||
await fetchAndSaveOutlookEvents(tokenData.access_token, outlookMail)
|
await fetchAndSaveOutlookEvents(tokenData.access_token, outlookMail)
|
||||||
@ -275,8 +278,11 @@ const CalendarSettingsPage = (props: {
|
|||||||
newUserData.googleAccounts = googleAccounts;
|
newUserData.googleAccounts = googleAccounts;
|
||||||
}
|
}
|
||||||
} else if (provider === "outlook") {
|
} else if (provider === "outlook") {
|
||||||
newUserData.microsoftToken = null;
|
let microsoftAccounts = profileData?.microsoftAccounts;
|
||||||
newUserData.outlookMail = null;
|
if (microsoftAccounts) {
|
||||||
|
microsoftAccounts[email] = null;
|
||||||
|
newUserData.microsoftAccounts = microsoftAccounts;
|
||||||
|
}
|
||||||
} else if (provider === "apple") {
|
} else if (provider === "apple") {
|
||||||
newUserData.appleToken = null;
|
newUserData.appleToken = null;
|
||||||
newUserData.appleMail = null;
|
newUserData.appleMail = null;
|
||||||
@ -294,6 +300,17 @@ const CalendarSettingsPage = (props: {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let isConnectedToMicrosoft = false;
|
||||||
|
const microsoftAccounts = profileData?.microsoftAccounts;
|
||||||
|
if (microsoftAccounts) {
|
||||||
|
Object.values(profileData?.microsoftAccounts).forEach((item) => {
|
||||||
|
if (item !== null) {
|
||||||
|
isConnectedToMicrosoft = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ScrollView>
|
<ScrollView>
|
||||||
<View marginH-30 marginB-30>
|
<View marginH-30 marginB-30>
|
||||||
@ -446,9 +463,10 @@ const CalendarSettingsPage = (props: {
|
|||||||
color="black"
|
color="black"
|
||||||
text70BL
|
text70BL
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
onPress={() => !profileData?.microsoftToken ? handleMicrosoftSignIn() : clearToken("outlook")}
|
onPress={() => handleMicrosoftSignIn()}
|
||||||
label={profileData?.microsoftToken ? `Disconnect ${profileData.outlookMail}` : "Connect Outlook"}
|
label={"Connect Outlook"}
|
||||||
labelStyle={styles.addCalLbl}
|
labelStyle={styles.addCalLbl}
|
||||||
labelProps={{
|
labelProps={{
|
||||||
numberOfLines: 2
|
numberOfLines: 2
|
||||||
@ -462,8 +480,27 @@ const CalendarSettingsPage = (props: {
|
|||||||
color="black"
|
color="black"
|
||||||
text70BL
|
text70BL
|
||||||
/>
|
/>
|
||||||
|
{profileData?.microsoftAccounts ? Object.keys(profileData?.microsoftAccounts)?.map((microsoftEmail) => {
|
||||||
|
const microsoftToken = profileData?.microsoftAccounts?.[microsoftEmail];
|
||||||
|
return microsoftToken && <Button
|
||||||
|
onPress={() => clearToken("outlook", microsoftEmail)}
|
||||||
|
label={`Disconnect ${microsoftEmail}`}
|
||||||
|
labelStyle={styles.addCalLbl}
|
||||||
|
labelProps={{
|
||||||
|
numberOfLines: 2
|
||||||
|
}}
|
||||||
|
iconSource={() => (
|
||||||
|
<View marginR-15>
|
||||||
|
<OutlookIcon/>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
style={styles.addCalBtn}
|
||||||
|
color="black"
|
||||||
|
text70BL
|
||||||
|
/>
|
||||||
|
}) : null}
|
||||||
|
|
||||||
{(isConnectedToGoogle || profileData?.outlookMail || profileData?.appleMail) && (
|
{(isConnectedToGoogle || isConnectedToMicrosoft || profileData?.appleMail) && (
|
||||||
<>
|
<>
|
||||||
<Text style={styles.subTitle} marginT-30 marginB-20>
|
<Text style={styles.subTitle} marginT-30 marginB-20>
|
||||||
Connected Calendars
|
Connected Calendars
|
||||||
@ -539,40 +576,43 @@ const CalendarSettingsPage = (props: {
|
|||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!!profileData?.outlookMail && (
|
{Object.keys(profileData?.microsoftAccounts)?.map((microsoftEmail) => {
|
||||||
<TouchableOpacity
|
const microsoftToken = profileData?.microsoftAccounts?.[microsoftEmail];
|
||||||
onPress={() => fetchAndSaveOutlookEvents({
|
return microsoftToken && (
|
||||||
token: profileData?.microsoftToken!,
|
<TouchableOpacity
|
||||||
email: profileData?.outlookMail!
|
onPress={() => fetchAndSaveOutlookEvents({
|
||||||
})}
|
token: microsoftToken,
|
||||||
>
|
email: microsoftEmail
|
||||||
<View row paddingR-20 center>
|
})}
|
||||||
<Button
|
>
|
||||||
disabled={isSyncingOutlook}
|
<View row paddingR-20 center>
|
||||||
onPress={() => fetchAndSaveOutlookEvents({
|
<Button
|
||||||
token: profileData?.microsoftToken!,
|
disabled={isSyncingOutlook}
|
||||||
email: profileData?.outlookMail!
|
onPress={() => fetchAndSaveOutlookEvents({
|
||||||
})}
|
token: microsoftToken,
|
||||||
label={`Sync ${profileData?.outlookMail}`}
|
email: microsoftEmail
|
||||||
labelStyle={styles.addCalLbl}
|
})}
|
||||||
labelProps={{numberOfLines: 3}}
|
label={`Sync ${microsoftEmail}`}
|
||||||
iconSource={() => (
|
labelStyle={styles.addCalLbl}
|
||||||
<View marginR-15>
|
labelProps={{numberOfLines: 3}}
|
||||||
<OutlookIcon/>
|
iconSource={() => (
|
||||||
</View>
|
<View marginR-15>
|
||||||
|
<OutlookIcon/>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
style={styles.addCalBtn}
|
||||||
|
color="black"
|
||||||
|
text70BL
|
||||||
|
/>
|
||||||
|
{isSyncingOutlook ? (
|
||||||
|
<ActivityIndicator/>
|
||||||
|
) : (
|
||||||
|
<Ionicons name={"refresh"} size={20} color={"#000000"}/>
|
||||||
)}
|
)}
|
||||||
style={styles.addCalBtn}
|
</View>
|
||||||
color="black"
|
</TouchableOpacity>
|
||||||
text70BL
|
)
|
||||||
/>
|
})}
|
||||||
{isSyncingOutlook ? (
|
|
||||||
<ActivityIndicator/>
|
|
||||||
) : (
|
|
||||||
<Ionicons name={"refresh"} size={20} color={"#000000"}/>
|
|
||||||
)}
|
|
||||||
</View>
|
|
||||||
</TouchableOpacity>
|
|
||||||
)}
|
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</>
|
</>
|
||||||
|
@ -204,11 +204,17 @@ exports.refreshTokens = functions.pubsub.schedule('every 12 hours').onRun(async
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (profileData.microsoftToken) {
|
if (profileData.microsoftAccounts) {
|
||||||
try {
|
try {
|
||||||
const refreshedMicrosoftToken = await refreshMicrosoftToken(profileData.microsoftToken);
|
for (const microsoftEmail of Object.keys(profileData?.microsoftAccounts)) {
|
||||||
await profileDoc.ref.update({microsoftToken: refreshedMicrosoftToken});
|
const microsoftToken = profileData?.microsoftAccounts?.[microsoftEmail];
|
||||||
console.log(`Microsoft token updated for user ${profileDoc.id}`);
|
if (microsoftToken) {
|
||||||
|
const refreshedMicrosoftToken = await refreshMicrosoftToken(microsoftToken);
|
||||||
|
const updatedMicrosoftAccounts = {...profileData.microsoftAccounts, [microsoftEmail]: refreshedMicrosoftToken};
|
||||||
|
await profileDoc.ref.update({microsoftAccounts: updatedMicrosoftAccounts});
|
||||||
|
console.log(`Microsoft token updated for user ${profileDoc.id}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error refreshing Microsoft token for user ${profileDoc.id}:`, error.message);
|
console.error(`Error refreshing Microsoft token for user ${profileDoc.id}:`, error.message);
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ export interface UserProfile {
|
|||||||
timeZone?: string | null;
|
timeZone?: string | null;
|
||||||
firstDayOfWeek?: string | null;
|
firstDayOfWeek?: string | null;
|
||||||
googleAccounts?: Object;
|
googleAccounts?: Object;
|
||||||
|
microsoftAccounts?: Object;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ParentProfile extends UserProfile {
|
export interface ParentProfile extends UserProfile {
|
||||||
|
Reference in New Issue
Block a user