Fix default app in main appstore list (#7141)

This commit is contained in:
sean-brydon
2023-02-17 09:11:03 +00:00
committed by GitHub
parent 7c749299bb
commit 00ebda2fc6
3 changed files with 15 additions and 2 deletions
+13 -1
View File
@@ -1,5 +1,6 @@
import { appStoreMetadata } from "@calcom/app-store/appStoreMetaData";
import prisma, { safeAppSelect, safeCredentialSelect } from "@calcom/prisma";
import { userMetadata } from "@calcom/prisma/zod-utils";
import type { AppFrontendPayload as App } from "@calcom/types/App";
import type { CredentialFrontendPayload as Credential } from "@calcom/types/Credential";
@@ -61,8 +62,19 @@ export async function getAppRegistryWithCredentials(userId: number) {
},
},
});
const user = await prisma.user.findUnique({
where: {
id: userId,
},
select: {
metadata: true,
},
});
const usersDefaultApp = userMetadata.parse(user?.metadata)?.defaultConferencingApp?.appSlug;
const apps = [] as (App & {
credentials: Credential[];
isDefault?: boolean;
})[];
for await (const dbapp of dbApps) {
const app = await getAppWithMetadata(dbapp);
@@ -70,7 +82,6 @@ export async function getAppRegistryWithCredentials(userId: number) {
// Skip if app isn't installed
/* This is now handled from the DB */
// if (!app.installed) return apps;
const { rating, reviews, trending, verified, ...remainingAppProps } = app;
apps.push({
rating: rating || 0,
@@ -81,6 +92,7 @@ export async function getAppRegistryWithCredentials(userId: number) {
categories: dbapp.categories,
credentials: dbapp.credentials,
installed: true,
isDefault: usersDefaultApp === dbapp.slug,
});
}
return apps;
+1
View File
@@ -142,6 +142,7 @@ export interface App {
export type AppFrontendPayload = Omit<App, "key"> & {
/** We should type error if keys are leaked to the frontend */
isDefault?: boolean;
key?: never;
};
+1 -1
View File
@@ -149,7 +149,7 @@ export function AppCard({ app, credentials, searchText }: AppCardProps) {
<span className="rounded-md bg-red-100 px-2 py-1 text-sm font-normal text-red-800">Template</span>
)}
{app.isGlobal && (
{(app.isDefault || (!app.isDefault && app.isGlobal)) && (
<span className="flex items-center rounded-md bg-gray-100 px-2 py-1 text-sm font-normal text-gray-800">
{t("default")}
</span>