mirror of
https://github.com/urosran/cally.git
synced 2025-07-16 01:56:16 +00:00
- Implemented connecting multiple accounts for apple
This commit is contained in:
@ -284,8 +284,11 @@ const CalendarSettingsPage = (props: {
|
|||||||
newUserData.microsoftAccounts = microsoftAccounts;
|
newUserData.microsoftAccounts = microsoftAccounts;
|
||||||
}
|
}
|
||||||
} else if (provider === "apple") {
|
} else if (provider === "apple") {
|
||||||
newUserData.appleToken = null;
|
let appleAccounts = profileData?.appleAccounts;
|
||||||
newUserData.appleMail = null;
|
if (appleAccounts) {
|
||||||
|
appleAccounts[email] = null;
|
||||||
|
newUserData.appleAccounts = appleAccounts;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await updateUserData({newUserData});
|
await updateUserData({newUserData});
|
||||||
};
|
};
|
||||||
@ -311,6 +314,16 @@ const CalendarSettingsPage = (props: {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let isConnectedToApple = false;
|
||||||
|
if (profileData?.appleAccounts) {
|
||||||
|
Object.values(profileData?.appleAccounts).forEach((item) => {
|
||||||
|
if (item !== null) {
|
||||||
|
isConnectedToApple = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ScrollView>
|
<ScrollView>
|
||||||
<View marginH-30 marginB-30>
|
<View marginH-30 marginB-30>
|
||||||
@ -448,8 +461,8 @@ const CalendarSettingsPage = (props: {
|
|||||||
}) : null}
|
}) : null}
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
onPress={() => !profileData?.appleToken ? handleAppleSignIn() : clearToken("apple")}
|
onPress={() => handleAppleSignIn()}
|
||||||
label={profileData?.appleToken ? `Disconnect ${profileData.appleMail}` : "Connect Apple"}
|
label={"Connect Apple"}
|
||||||
labelStyle={styles.addCalLbl}
|
labelStyle={styles.addCalLbl}
|
||||||
labelProps={{
|
labelProps={{
|
||||||
numberOfLines: 2
|
numberOfLines: 2
|
||||||
@ -463,6 +476,26 @@ const CalendarSettingsPage = (props: {
|
|||||||
color="black"
|
color="black"
|
||||||
text70BL
|
text70BL
|
||||||
/>
|
/>
|
||||||
|
{profileData?.appleAccounts ? Object.keys(profileData?.appleAccounts)?.map((appleEmail) => {
|
||||||
|
const appleToken = profileData?.appleAccounts?.[appleEmail];
|
||||||
|
return appleToken && <Button
|
||||||
|
key={appleEmail}
|
||||||
|
onPress={() => clearToken("apple", appleEmail)}
|
||||||
|
label={`Disconnect ${appleEmail}`}
|
||||||
|
labelStyle={styles.addCalLbl}
|
||||||
|
labelProps={{
|
||||||
|
numberOfLines: 2
|
||||||
|
}}
|
||||||
|
iconSource={() => (
|
||||||
|
<View marginR-15>
|
||||||
|
<AppleIcon/>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
style={styles.addCalBtn}
|
||||||
|
color="black"
|
||||||
|
text70BL
|
||||||
|
/>
|
||||||
|
}) : null}
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
onPress={() => handleMicrosoftSignIn()}
|
onPress={() => handleMicrosoftSignIn()}
|
||||||
@ -483,6 +516,7 @@ const CalendarSettingsPage = (props: {
|
|||||||
{profileData?.microsoftAccounts ? Object.keys(profileData?.microsoftAccounts)?.map((microsoftEmail) => {
|
{profileData?.microsoftAccounts ? Object.keys(profileData?.microsoftAccounts)?.map((microsoftEmail) => {
|
||||||
const microsoftToken = profileData?.microsoftAccounts?.[microsoftEmail];
|
const microsoftToken = profileData?.microsoftAccounts?.[microsoftEmail];
|
||||||
return microsoftToken && <Button
|
return microsoftToken && <Button
|
||||||
|
key={microsoftEmail}
|
||||||
onPress={() => clearToken("outlook", microsoftEmail)}
|
onPress={() => clearToken("outlook", microsoftEmail)}
|
||||||
label={`Disconnect ${microsoftEmail}`}
|
label={`Disconnect ${microsoftEmail}`}
|
||||||
labelStyle={styles.addCalLbl}
|
labelStyle={styles.addCalLbl}
|
||||||
@ -500,7 +534,7 @@ const CalendarSettingsPage = (props: {
|
|||||||
/>
|
/>
|
||||||
}) : null}
|
}) : null}
|
||||||
|
|
||||||
{(isConnectedToGoogle || isConnectedToMicrosoft || profileData?.appleMail) && (
|
{(isConnectedToGoogle || isConnectedToMicrosoft || isConnectedToApple) && (
|
||||||
<>
|
<>
|
||||||
<Text style={styles.subTitle} marginT-30 marginB-20>
|
<Text style={styles.subTitle} marginT-30 marginB-20>
|
||||||
Connected Calendars
|
Connected Calendars
|
||||||
@ -508,7 +542,7 @@ const CalendarSettingsPage = (props: {
|
|||||||
|
|
||||||
<View style={styles.noPaddingCard}>
|
<View style={styles.noPaddingCard}>
|
||||||
<View style={{marginTop: 20}}>
|
<View style={{marginTop: 20}}>
|
||||||
{Object.keys(profileData?.googleAccounts)?.map((googleEmail) => {
|
{profileData?.googleAccounts && Object.keys(profileData?.googleAccounts)?.map((googleEmail) => {
|
||||||
const googleToken = profileData?.googleAccounts?.[googleEmail];
|
const googleToken = profileData?.googleAccounts?.[googleEmail];
|
||||||
return googleToken && (
|
return googleToken && (
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
@ -541,21 +575,22 @@ const CalendarSettingsPage = (props: {
|
|||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
|
|
||||||
|
{profileData?.appleAccounts && Object.keys(profileData?.appleAccounts)?.map((appleEmail) => {
|
||||||
{!!profileData?.appleMail && (
|
const appleToken = profileData?.appleAccounts?.[appleEmail];
|
||||||
|
return appleToken && (
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
onPress={() => fetchAndSaveAppleEvents({
|
onPress={() => fetchAndSaveAppleEvents({
|
||||||
email: profileData?.appleMail!,
|
email: appleEmail,
|
||||||
token: profileData?.appleToken!
|
token: appleToken
|
||||||
})}>
|
})}>
|
||||||
<View row paddingR-20 center>
|
<View row paddingR-20 center>
|
||||||
<Button
|
<Button
|
||||||
disabled={isSyncingApple}
|
disabled={isSyncingApple}
|
||||||
onPress={() => fetchAndSaveAppleEvents({
|
onPress={() => fetchAndSaveAppleEvents({
|
||||||
email: profileData?.appleMail!,
|
email: appleEmail,
|
||||||
token: profileData?.appleToken!
|
token: appleToken
|
||||||
})}
|
})}
|
||||||
label={`Sync ${profileData?.appleMail}`}
|
label={`Sync ${appleEmail}`}
|
||||||
labelStyle={styles.addCalLbl}
|
labelStyle={styles.addCalLbl}
|
||||||
labelProps={{numberOfLines: 3}}
|
labelProps={{numberOfLines: 3}}
|
||||||
iconSource={() => (
|
iconSource={() => (
|
||||||
@ -574,9 +609,10 @@ const CalendarSettingsPage = (props: {
|
|||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
)}
|
)
|
||||||
|
})}
|
||||||
|
|
||||||
{Object.keys(profileData?.microsoftAccounts)?.map((microsoftEmail) => {
|
{profileData?.microsoftAccounts && Object.keys(profileData?.microsoftAccounts)?.map((microsoftEmail) => {
|
||||||
const microsoftToken = profileData?.microsoftAccounts?.[microsoftEmail];
|
const microsoftToken = profileData?.microsoftAccounts?.[microsoftEmail];
|
||||||
return microsoftToken && (
|
return microsoftToken && (
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
|
@ -220,11 +220,15 @@ exports.refreshTokens = functions.pubsub.schedule('every 12 hours').onRun(async
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (profileData.appleToken) {
|
if (profileData.appleAccounts) {
|
||||||
try {
|
try {
|
||||||
const refreshedAppleToken = await refreshAppleToken(profileData.appleToken);
|
for (const appleEmail of Object.keys(profileData?.appleAccounts)) {
|
||||||
await profileDoc.ref.update({appleToken: refreshedAppleToken});
|
const appleToken = profileData?.appleAccounts?.[appleEmail];
|
||||||
|
const refreshedAppleToken = await refreshAppleToken(appleToken);
|
||||||
|
const updatedAppleAccounts = {...profileData.appleAccounts, [appleEmail]: refreshedAppleToken};
|
||||||
|
await profileDoc.ref.update({appleAccunts: updatedAppleAccounts});
|
||||||
console.log(`Apple token updated for user ${profileDoc.id}`);
|
console.log(`Apple token updated for user ${profileDoc.id}`);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error refreshing Apple token for user ${profileDoc.id}:`, error.message);
|
console.error(`Error refreshing Apple token for user ${profileDoc.id}:`, error.message);
|
||||||
}
|
}
|
||||||
|
@ -18,15 +18,12 @@ export interface UserProfile {
|
|||||||
familyId?: string;
|
familyId?: string;
|
||||||
uid?: string;
|
uid?: string;
|
||||||
pfp?: string;
|
pfp?: string;
|
||||||
microsoftToken?: string | null;
|
|
||||||
appleToken?: string | null;
|
|
||||||
eventColor?: string | null;
|
eventColor?: string | null;
|
||||||
outlookMail?: string | null;
|
|
||||||
appleMail?: string | null;
|
|
||||||
timeZone?: string | null;
|
timeZone?: string | null;
|
||||||
firstDayOfWeek?: string | null;
|
firstDayOfWeek?: string | null;
|
||||||
googleAccounts?: Object;
|
googleAccounts?: Object;
|
||||||
microsoftAccounts?: Object;
|
microsoftAccounts?: Object;
|
||||||
|
appleAccounts?: Object;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ParentProfile extends UserProfile {
|
export interface ParentProfile extends UserProfile {
|
||||||
|
Reference in New Issue
Block a user