fix: use destination calendar email (#6886)
* fix: use destination calendar email to display correct primary email Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in> * fix: simplify logic Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in> --------- Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>pull/6944/head
parent
39040fca9a
commit
6877d0f693
|
@ -119,7 +119,7 @@ const DestinationCalendarSelector = ({
|
|||
|
||||
// Get primary calendar, which is shown in the placeholder since this is the calendar that will
|
||||
// be used when no destination calendar is selected.
|
||||
const primaryCalendar = query.data.connectedCalendars.filter((cal) => Boolean(cal.primary))[0];
|
||||
const primaryCalendar = query.data.destinationCalendarEmail;
|
||||
|
||||
return (
|
||||
<div className="relative" title={`${t("select_destination_calendar")}: ${selectedOption?.label || ""}`}>
|
||||
|
@ -130,8 +130,7 @@ const DestinationCalendarSelector = ({
|
|||
`${t("select_destination_calendar")}`
|
||||
) : (
|
||||
<span>
|
||||
{t("default_calendar_selected")}{" "}
|
||||
{primaryCalendar?.primary?.externalId && `(${primaryCalendar?.primary?.externalId})`}
|
||||
{t("default_calendar_selected")} {primaryCalendar && `(${primaryCalendar})`}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
|
|
@ -322,6 +322,9 @@ const loggedInViewerRouter = router({
|
|||
// get all the connected integrations' calendars (from third party)
|
||||
const connectedCalendars = await getConnectedCalendars(calendarCredentials, user.selectedCalendars);
|
||||
|
||||
// store email of the destination calendar to display
|
||||
let destinationCalendarEmail = null;
|
||||
|
||||
if (connectedCalendars.length === 0) {
|
||||
/* As there are no connected calendars, delete the destination calendar if it exists */
|
||||
if (user.destinationCalendar) {
|
||||
|
@ -335,7 +338,7 @@ const loggedInViewerRouter = router({
|
|||
There are connected calendars, but no destination calendar
|
||||
So create a default destination calendar with the first primary connected calendar
|
||||
*/
|
||||
const { integration = "", externalId = "", credentialId } = connectedCalendars[0].primary ?? {};
|
||||
const { integration = "", externalId = "", credentialId, email } = connectedCalendars[0].primary ?? {};
|
||||
user.destinationCalendar = await ctx.prisma.destinationCalendar.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
|
@ -344,6 +347,7 @@ const loggedInViewerRouter = router({
|
|||
credentialId,
|
||||
},
|
||||
});
|
||||
destinationCalendarEmail = email ?? user.destinationCalendar?.externalId;
|
||||
} else {
|
||||
/* There are connected calendars and a destination calendar */
|
||||
|
||||
|
@ -354,6 +358,7 @@ const loggedInViewerRouter = router({
|
|||
cal.externalId === user.destinationCalendar?.externalId &&
|
||||
cal.integration === user.destinationCalendar?.integration
|
||||
);
|
||||
|
||||
if (!destinationCal) {
|
||||
// If destinationCalendar is out of date, update it with the first primary connected calendar
|
||||
const { integration = "", externalId = "" } = connectedCalendars[0].primary ?? {};
|
||||
|
@ -365,11 +370,13 @@ const loggedInViewerRouter = router({
|
|||
},
|
||||
});
|
||||
}
|
||||
destinationCalendarEmail = destinationCal?.email ?? user.destinationCalendar?.externalId;
|
||||
}
|
||||
|
||||
return {
|
||||
connectedCalendars,
|
||||
destinationCalendar: user.destinationCalendar,
|
||||
destinationCalendarEmail,
|
||||
};
|
||||
}),
|
||||
setDestinationCalendar: authedProcedure
|
||||
|
|
Loading…
Reference in New Issue