Feat/custom default video (#6971)

* Add queries to fetch metadata and update default

* Add to zod schema

* Change default rules on settings page

* Update query

* Initall override on create event type

* Working default

* Change schema to save locationLink too

* Update default conferncing to include link

* Rename tsx to ts. Fix metadata keys

* WIP on refactoring appstore installed

* Add this to appstore installed apps too

* Display only on conferencing apps

* Add i18n strings

* Change order in dropdown menu so delete is bottom

* Refactor query to not expose all of metadata

* Fix mr type checker

* Possible e2e fix

* Refactor metadata to use ctx

* Refactor back to query cell

* Alias schema

* Adding comment for more info

* Remove constant for clarity

* Update nextjs-bundle-analysis.yml

---------

Co-authored-by: Alex van Andel <[email protected]>
Co-authored-by: zomars <[email protected]>
This commit is contained in:
authored and GitHub committed 2023-02-13 22:55:32 +00:00
1 parent 6cad606ba1
commit 77600f8168
7 files changed
+377 -153

No files matched your search

+29 -1
View File
@@ -472,7 +472,6 @@ const loggedInViewerRouter = router({
const { credentials } = user;
const enabledApps = await getEnabledApps(credentials);
let apps = enabledApps.map(
({ credentials: _, credential: _1 /* don't leak to frontend */, ...app }) => {
const credentialIds = credentials.filter((c) => c.type === app.type).map((c) => c.id);
@@ -1181,6 +1180,35 @@ const loggedInViewerRouter = router({
});
}
}),
getUsersDefaultConferencingApp: authedProcedure.query(async ({ ctx }) => {
return userMetadata.parse(ctx.user.metadata)?.defaultConferencingApp;
}),
updateUserDefaultConferencingApp: authedProcedure
.input(
z.object({
appSlug: z.string().optional(),
appLink: z.string().optional(),
})
)
.mutation(async ({ ctx, input }) => {
const currentMetadata = userMetadata.parse(ctx.user.metadata);
await ctx.prisma.user.update({
where: {
id: ctx.user.id,
},
data: {
metadata: {
...currentMetadata,
defaultConferencingApp: {
appSlug: input.appSlug,
appLink: input.appLink,
},
},
},
});
return input;
}),
});
export const viewerRouter = mergeRouters(
@@ -7,6 +7,7 @@ import { z } from "zod";
import getAppKeysFromSlug from "@calcom/app-store/_utils/getAppKeysFromSlug";
import { DailyLocationType } from "@calcom/app-store/locations";
import { stripeDataSchema } from "@calcom/app-store/stripepayment/lib/server";
import getApps from "@calcom/app-store/utils";
import { validateBookingLimitOrder } from "@calcom/lib";
import { CAL_URL } from "@calcom/lib/constants";
import getEventTypeById from "@calcom/lib/getEventTypeById";
@@ -17,6 +18,7 @@ import {
CustomInputSchema,
EventTypeMetaDataSchema,
stringOrNumber,
userMetadata as userMetadataSchema,
} from "@calcom/prisma/zod-utils";
import { createEventTypeInput } from "@calcom/prisma/zod/custom/eventtype";
@@ -406,7 +408,29 @@ export const eventTypesRouter = router({
create: authedProcedure.input(createEventTypeInput).mutation(async ({ ctx, input }) => {
const { schedulingType, teamId, ...rest } = input;
const userId = ctx.user.id;
// Get Users default conferncing app
const defaultConferencingData = userMetadataSchema.parse(ctx.user.metadata)?.defaultConferencingApp;
const appKeys = await getAppKeysFromSlug("daily-video");
let locations: { type: string; link?: string }[] = [];
// If no locations are passed in and the user has a daily api key then default to daily
if (
(typeof rest?.locations === "undefined" || rest.locations?.length === 0) &&
typeof appKeys.api_key === "string"
) {
locations = [{ type: DailyLocationType }];
}
// If its defaulting to daily no point handling compute as its done
if (defaultConferencingData && defaultConferencingData.appSlug !== "daily-video") {
const credentials = ctx.user.credentials;
const foundApp = getApps(credentials).filter((app) => app.slug === defaultConferencingData.appSlug)[0]; // There is only one possible install here so index [0] is the one we are looking for ;
const locationType = foundApp?.locationOption?.value ?? DailyLocationType; // Default to Daily if no location type is found
locations = [{ type: locationType, link: defaultConferencingData.appLink }];
}
const data: Prisma.EventTypeCreateInput = {
...rest,
owner: teamId ? undefined : { connect: { id: userId } },
@@ -415,8 +439,7 @@ export const eventTypesRouter = router({
id: userId,
},
},
...((typeof rest?.locations === "undefined" || rest.locations?.length === 0) &&
typeof appKeys.api_key === "string" && { locations: [{ type: DailyLocationType }] }),
locations,
};
if (teamId && schedulingType) {