
* Type fixes * Type fixes * Attemp to prevent unknown error in prod * Type fixes * Type fixes for onboarding * Extracts ConnectIntegration * Extracts IntegrationListItem * Extracts CalendarsList * Uses CalendarList on onboarding * Removes deprecated Alert * Extracts DisconnectIntegration * Extracts CalendarSwitch * Extracts ConnectedCalendarsList * Extracted connectedCalendar logic for reuse * Extracted SubHeadingTitleWithConnections * Type fixes * Fetched connected calendars in onboarding * Refreshes data on when adding/removing calendars on onboarding * Removed testing code * Type fixes * Feedback * Moved integration helpers * I was sleepy Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
25 lines
821 B
TypeScript
25 lines
821 B
TypeScript
import { Credential } from "@prisma/client";
|
|
|
|
import { getCalendarAdapterOrNull } from "@lib/calendarClient";
|
|
import { ALL_INTEGRATIONS } from "@lib/integrations/getIntegrations";
|
|
|
|
export default function getCalendarCredentials(
|
|
credentials: Array<Omit<Credential, "userId">>,
|
|
userId: number
|
|
) {
|
|
const calendarCredentials = credentials
|
|
.filter((credential) => credential.type.endsWith("_calendar"))
|
|
.flatMap((credential) => {
|
|
const integration = ALL_INTEGRATIONS.find((integration) => integration.type === credential.type);
|
|
|
|
const adapter = getCalendarAdapterOrNull({
|
|
...credential,
|
|
userId,
|
|
});
|
|
return integration && adapter && integration.variant === "calendar"
|
|
? [{ integration, credential, adapter }]
|
|
: [];
|
|
});
|
|
|
|
return calendarCredentials;
|
|
}
|