integration page follow ups (#912)

### Internals

- Replace `lodash.*` packages with plain `lodash` & replace `lodash.*` imports with `lodash/` - should have no impact on bundle size and opens up for us to use all of lodash
- Update `viewer.me` to cherry-pick what we actually need on that query to avoid leaking extra context info
- Update `getIntegrations` to never include `.key`-property to avoid leaking 

### Visual

- Update calendars so `primary` is displayed last
- Update connected calendars so they are in ascending order in which you connected them
This commit is contained in:
Alex Johansson authored and GitHub committed 2021-10-13 13:35:25 +02:00
1 parent 9e2f8de313
commit ec6b897191
18 files changed
+146 -147

No files matched your search

+32 -13
View File
@@ -1,9 +1,10 @@
import { Prisma } from "@prisma/client";
import _ from "lodash";
import { validJson } from "@lib/jsonUtils";
const credentialData = Prisma.validator<Prisma.CredentialArgs>()({
select: { id: true, type: true, key: true },
select: { id: true, type: true },
});
type CredentialData = Prisma.CredentialGetPayload<typeof credentialData>;
@@ -33,6 +34,14 @@ export const ALL_INTEGRATIONS = [
description: "Video Conferencing",
variant: "conferencing",
},
{
installed: !!process.env.DAILY_API_KEY,
type: "daily_video",
title: "Daily.co Video",
imageSrc: "integrations/daily.svg",
description: "Video Conferencing",
variant: "conferencing",
},
{
installed: true,
type: "caldav_calendar",
@@ -62,23 +71,33 @@ export const ALL_INTEGRATIONS = [
variant: "payment",
},
] as const;
function getIntegrations(credentials: CredentialData[]) {
const integrations = ALL_INTEGRATIONS.map((integration) => ({
...integration,
/**
* @deprecated use `credentials.
*/
credential: credentials.find((credential) => credential.type === integration.type) || null,
credentials: credentials.filter((credential) => credential.type === integration.type) || null,
}));
function getIntegrations(userCredentials: CredentialData[]) {
const integrations = ALL_INTEGRATIONS.map((integration) => {
const credentials = userCredentials
.filter((credential) => credential.type === integration.type)
.map((credential) => _.pick(credential, ["id", "type"])); // ensure we don't leak `key` to frontend
const credential: typeof credentials[number] | null = credentials[0] || null;
return {
...integration,
/**
* @deprecated use `credentials`
*/
credential,
credentials,
};
});
return integrations;
}
export type IntegraionMeta = ReturnType<typeof getIntegrations>;
export type IntegrationMeta = ReturnType<typeof getIntegrations>;
export function hasIntegration(integrations: ReturnType<typeof getIntegrations>, type: string): boolean {
return !!integrations.find((i) => i.type === type && !!i.installed && !!i.credential);
export function hasIntegration(integrations: IntegrationMeta, type: string): boolean {
return !!integrations.find(
(i) => i.type === type && !!i.installed && (type === "daily_video" || i.credentials.length > 0)
);
}
export default getIntegrations;