perf: Server-Side Data Fetching in App Router: SettingsLayout / AdminLayout (#16537)
Co-authored-by: Joe Au-Yeung <[email protected]>
This commit is contained in:
1 parent
71443ef23d
commit
706d7dff42
25 files changed
+929
-874
No files matched your search
@@ -1,5 +1,4 @@
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import { teamMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||
import { OrganizationRepository } from "@calcom/lib/server/repository/organization";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
@@ -7,7 +6,6 @@ import { TRPCError } from "@trpc/server";
|
||||
type ListHandlerInput = {
|
||||
ctx: {
|
||||
user: NonNullable<TrpcSessionUser>;
|
||||
prisma: PrismaClient;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -16,52 +14,10 @@ export const listHandler = async ({ ctx }: ListHandlerInput) => {
|
||||
if (!ctx.user.organization?.id) {
|
||||
throw new TRPCError({ code: "BAD_REQUEST", message: "You do not belong to an organization" });
|
||||
}
|
||||
|
||||
const membership = await ctx.prisma.membership.findFirst({
|
||||
where: {
|
||||
userId: ctx.user.id,
|
||||
team: {
|
||||
id: ctx.user.organization.id,
|
||||
},
|
||||
},
|
||||
include: {
|
||||
team: true,
|
||||
},
|
||||
return await OrganizationRepository.findCurrentOrg({
|
||||
userId: ctx.user.id,
|
||||
orgId: ctx.user.organization.id,
|
||||
});
|
||||
|
||||
const organizationSettings = await ctx.prisma.organizationSettings.findUnique({
|
||||
where: {
|
||||
organizationId: ctx.user.organization.id,
|
||||
},
|
||||
select: {
|
||||
lockEventTypeCreationForUsers: true,
|
||||
adminGetsNoSlotsNotification: true,
|
||||
isAdminReviewed: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!membership) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "You do not have a membership to your organization",
|
||||
});
|
||||
}
|
||||
|
||||
const metadata = teamMetadataSchema.parse(membership?.team.metadata);
|
||||
|
||||
return {
|
||||
canAdminImpersonate: !!organizationSettings?.isAdminReviewed,
|
||||
organizationSettings: {
|
||||
lockEventTypeCreationForUsers: organizationSettings?.lockEventTypeCreationForUsers,
|
||||
adminGetsNoSlotsNotification: organizationSettings?.adminGetsNoSlotsNotification,
|
||||
},
|
||||
user: {
|
||||
role: membership?.role,
|
||||
accepted: membership?.accepted,
|
||||
},
|
||||
...membership?.team,
|
||||
metadata,
|
||||
};
|
||||
};
|
||||
|
||||
export default listHandler;
|
||||
@@ -1,4 +1,4 @@
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import { OrganizationRepository } from "@calcom/lib/server/repository/organization";
|
||||
|
||||
import type { TrpcSessionUser } from "../../../trpc";
|
||||
|
||||
@@ -12,18 +12,11 @@ export const listOtherTeamHandler = async ({ ctx: { user } }: ListOptions) => {
|
||||
if (!user?.organization?.isOrgAdmin) {
|
||||
return [];
|
||||
}
|
||||
const teamsInOrgIamNotPartOf = await prisma.team.findMany({
|
||||
where: {
|
||||
parentId: user?.organization?.id ?? null,
|
||||
members: {
|
||||
none: {
|
||||
userId: user.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return teamsInOrgIamNotPartOf;
|
||||
return await OrganizationRepository.findTeamsInOrgIamNotPartOf({
|
||||
userId: user.id,
|
||||
parentId: user?.organization?.id ?? null,
|
||||
});
|
||||
};
|
||||
|
||||
export default listOtherTeamHandler;
|
||||
Reference in new issue
Block a user