Fix connected calendar list (#4743)
* Fix connected calendar list * Fixed invalid params in setDestinationCalendar * Attempt to fix tests by changing viewport size, bug on /booking pages * Fixes BookingListItem + another user.id param removed Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: Alex van Andel <me@alexvanandel.com>pull/4745/head
parent
b347f29d6c
commit
6017806763
|
@ -366,7 +366,7 @@ function BookingListItem(booking: BookingItemProps) {
|
|||
)}
|
||||
</div>
|
||||
</td>
|
||||
<td className="whitespace-nowrap py-4 text-right text-sm font-medium ltr:pr-4 rtl:pl-4">
|
||||
<td className="whitespace-nowrap py-4 pl-4 text-right text-sm font-medium ltr:pr-4 rtl:pl-4 sm:pl-0">
|
||||
{isUpcoming && !isCancelled ? (
|
||||
<>
|
||||
{isPending && user?.id === booking.user?.id && <TableActions actions={pendingActions} />}
|
||||
|
|
|
@ -76,7 +76,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||
});
|
||||
|
||||
// get user's credentials + their connected integrations
|
||||
const calendarCredentials = getCalendarCredentials(user.credentials, user.id);
|
||||
const calendarCredentials = getCalendarCredentials(user.credentials);
|
||||
// get all the connected integrations' calendars (from third party)
|
||||
const connectedCalendars = await getConnectedCalendars(calendarCredentials, user.selectedCalendars);
|
||||
const calendars = connectedCalendars.flatMap((c) => c.calendars).filter(notEmpty);
|
||||
|
|
|
@ -5,9 +5,7 @@ import cache from "memory-cache";
|
|||
|
||||
import { getCalendar } from "@calcom/app-store/_utils/getCalendar";
|
||||
import getApps from "@calcom/app-store/utils";
|
||||
import { sendBrokenIntegrationEmail } from "@calcom/emails";
|
||||
import { getUid } from "@calcom/lib/CalEventParser";
|
||||
import { getErrorFromUnknown } from "@calcom/lib/errors";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { performance } from "@calcom/lib/server/perfObserver";
|
||||
import type { CalendarEvent, EventBusyDate, NewCalendarEventType } from "@calcom/types/Calendar";
|
||||
|
@ -15,13 +13,13 @@ import type { EventResult } from "@calcom/types/EventManager";
|
|||
|
||||
const log = logger.getChildLogger({ prefix: ["CalendarManager"] });
|
||||
|
||||
export const getCalendarCredentials = (credentials: Array<Credential>, userId: number) => {
|
||||
export const getCalendarCredentials = (credentials: Array<Credential>) => {
|
||||
const calendarCredentials = getApps(credentials)
|
||||
.filter((app) => app.type.endsWith("_calendar"))
|
||||
.flatMap((app) => {
|
||||
const credentials = app.credentials.flatMap((credential) => {
|
||||
const calendar = getCalendar(credential);
|
||||
return [{ integration: app, credential, calendar }];
|
||||
return app.variant === "calendar" ? [{ integration: app, credential, calendar }] : [];
|
||||
});
|
||||
return credentials.length ? credentials : [];
|
||||
});
|
||||
|
@ -54,9 +52,15 @@ export const getConnectedCalendars = async (
|
|||
}))
|
||||
.sortBy(["primary"])
|
||||
.value();
|
||||
const primary = calendars.find((item) => item.primary) ?? calendars[0];
|
||||
const primary = calendars.find((item) => item.primary) ?? calendars.find((cal) => cal !== undefined);
|
||||
if (!primary) {
|
||||
throw new Error("No primary calendar found");
|
||||
return {
|
||||
integration,
|
||||
credentialId,
|
||||
error: {
|
||||
message: "No primary calendar found",
|
||||
},
|
||||
};
|
||||
}
|
||||
return {
|
||||
integration,
|
||||
|
|
|
@ -625,7 +625,7 @@ const loggedInViewerRouter = createProtectedRouter()
|
|||
async resolve({ ctx }) {
|
||||
const { user } = ctx;
|
||||
// get user's credentials + their connected integrations
|
||||
const calendarCredentials = getCalendarCredentials(user.credentials, user.id);
|
||||
const calendarCredentials = getCalendarCredentials(user.credentials);
|
||||
|
||||
// get all the connected integrations' calendars (from third party)
|
||||
const connectedCalendars = await getConnectedCalendars(calendarCredentials, user.selectedCalendars);
|
||||
|
@ -691,7 +691,7 @@ const loggedInViewerRouter = createProtectedRouter()
|
|||
async resolve({ ctx, input }) {
|
||||
const { user } = ctx;
|
||||
const { integration, externalId, eventTypeId } = input;
|
||||
const calendarCredentials = getCalendarCredentials(user.credentials, user.id);
|
||||
const calendarCredentials = getCalendarCredentials(user.credentials);
|
||||
const connectedCalendars = await getConnectedCalendars(calendarCredentials, user.selectedCalendars);
|
||||
const allCals = connectedCalendars.map((cal) => cal.calendars ?? []).flat();
|
||||
|
||||
|
|
Loading…
Reference in New Issue