fix: Set teamMemberEmail server side for CRM RR Skip (#16367)
Co-authored-by: Keith Williams <[email protected]> Co-authored-by: zomars <[email protected]>
This commit is contained in:
17 files changed
+140
-114
No files matched your search
@@ -1,14 +1,16 @@
|
||||
import type { GetServerSidePropsContext } from "next";
|
||||
import { z } from "zod";
|
||||
|
||||
import { getCRMContactOwnerForRRLeadSkip } from "@calcom/app-store/_utils/CRMRoundRobinSkip";
|
||||
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||
import { getBookingForReschedule } from "@calcom/features/bookings/lib/get-booking";
|
||||
import type { GetBookingType } from "@calcom/features/bookings/lib/get-booking";
|
||||
import { getSlugOrRequestedSlug } from "@calcom/features/ee/organizations/lib/orgDomains";
|
||||
import { orgDomainConfig } from "@calcom/features/ee/organizations/lib/orgDomains";
|
||||
import { getBookingForReschedule } from "@calcom/features/bookings/lib/get-booking";
|
||||
import { getSlugOrRequestedSlug, orgDomainConfig } from "@calcom/features/ee/organizations/lib/orgDomains";
|
||||
import slugify from "@calcom/lib/slugify";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { RedirectType } from "@calcom/prisma/client";
|
||||
import { SchedulingType } from "@calcom/prisma/enums";
|
||||
import type { RouterOutputs } from "@calcom/trpc";
|
||||
|
||||
import { getTemporaryOrgRedirect } from "@lib/getTemporaryOrgRedirect";
|
||||
|
||||
@@ -23,7 +25,12 @@ const paramsSchema = z.object({
|
||||
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
|
||||
const session = await getServerSession(context);
|
||||
const { slug: teamSlug, type: meetingSlug } = paramsSchema.parse(context.params);
|
||||
const { rescheduleUid, duration: queryDuration, isInstantMeeting: queryIsInstantMeeting } = context.query;
|
||||
const {
|
||||
rescheduleUid,
|
||||
duration: queryDuration,
|
||||
isInstantMeeting: queryIsInstantMeeting,
|
||||
email,
|
||||
} = context.query;
|
||||
const { ssrInit } = await import("@server/lib/ssr");
|
||||
const ssr = await ssrInit(context);
|
||||
const { currentOrgDomain, isValidOrgDomain } = orgDomainConfig(context.req, context.params?.orgSlug);
|
||||
@@ -97,6 +104,29 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||
isInstantMeeting: eventData.isInstantEvent && queryIsInstantMeeting ? true : false,
|
||||
themeBasis: null,
|
||||
orgBannerUrl: eventData?.team?.parent?.bannerUrl ?? "",
|
||||
teamMemberEmail: await getTeamMemberEmail(eventData, email as string),
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
type EventData = RouterOutputs["viewer"]["public"]["event"];
|
||||
|
||||
async function getTeamMemberEmail(eventData: EventData, email?: string): Promise<string | null> {
|
||||
// Pre-requisites
|
||||
if (!eventData || !email || eventData.schedulingType !== SchedulingType.ROUND_ROBIN) return null;
|
||||
const crmContactOwnerEmail = await getCRMContactOwnerForRRLeadSkip(email, eventData.id);
|
||||
if (!crmContactOwnerEmail) return null;
|
||||
// Determine if the contactOwner is a part of the event type
|
||||
const contactOwnerQuery = await prisma.user.findFirst({
|
||||
where: {
|
||||
email: crmContactOwnerEmail,
|
||||
hosts: {
|
||||
some: {
|
||||
eventTypeId: eventData.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!contactOwnerQuery) return null;
|
||||
return crmContactOwnerEmail;
|
||||
}
|
||||
@@ -35,6 +35,7 @@ export default function Type({
|
||||
eventData,
|
||||
isInstantMeeting,
|
||||
orgBannerUrl,
|
||||
teamMemberEmail,
|
||||
}: PageProps) {
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
@@ -67,6 +68,7 @@ export default function Type({
|
||||
eventData.length
|
||||
)}
|
||||
orgBannerUrl={orgBannerUrl}
|
||||
teamMemberEmail={teamMemberEmail}
|
||||
/>
|
||||
</main>
|
||||
);
|
||||
|
||||
@@ -175,12 +175,10 @@ describe("getSchedule", () => {
|
||||
endTime: `${plus2DateString}T18:29:59.999Z`,
|
||||
timeZone: Timezones["+5:30"],
|
||||
isTeamEvent: true,
|
||||
bookerEmail: "test@test.com",
|
||||
teamMemberEmail: "example@example.com",
|
||||
},
|
||||
});
|
||||
|
||||
expect(scheduleWithLeadSkip.teamMember).toBe("[email protected]");
|
||||
|
||||
// only slots where [email protected] is available
|
||||
expect(scheduleWithLeadSkip).toHaveTimeSlots(
|
||||
[`11:30:00.000Z`, `12:30:00.000Z`, `13:30:00.000Z`, `14:30:00.000Z`, `15:30:00.000Z`],
|
||||
@@ -197,12 +195,9 @@ describe("getSchedule", () => {
|
||||
endTime: `${plus2DateString}T18:29:59.999Z`,
|
||||
timeZone: Timezones["+5:30"],
|
||||
isTeamEvent: true,
|
||||
bookerEmail: "[email protected]",
|
||||
},
|
||||
});
|
||||
|
||||
expect(scheduleWithoutLeadSkip.teamMember).toBe(undefined);
|
||||
|
||||
// slots where either one of the rr hosts is available
|
||||
expect(scheduleWithoutLeadSkip).toHaveTimeSlots(
|
||||
[
|
||||
@@ -325,12 +320,10 @@ describe("getSchedule", () => {
|
||||
endTime: `${plus2DateString}T18:29:59.999Z`,
|
||||
timeZone: Timezones["+5:30"],
|
||||
isTeamEvent: true,
|
||||
bookerEmail: "test@test.com",
|
||||
teamMemberEmail: "example@example.com",
|
||||
},
|
||||
});
|
||||
|
||||
expect(scheduleFixedHostLead.teamMember).toBe("[email protected]");
|
||||
|
||||
// show normal slots, example@example + one RR host needs to be available
|
||||
expect(scheduleFixedHostLead).toHaveTimeSlots(
|
||||
[
|
||||
@@ -355,12 +348,10 @@ describe("getSchedule", () => {
|
||||
endTime: `${plus2DateString}T18:29:59.999Z`,
|
||||
timeZone: Timezones["+5:30"],
|
||||
isTeamEvent: true,
|
||||
bookerEmail: "test1@test.com",
|
||||
teamMemberEmail: "example1@example.com",
|
||||
},
|
||||
});
|
||||
|
||||
expect(scheduleRRHostLead.teamMember).toBe("[email protected]");
|
||||
|
||||
// slots where example@example (fixed host) + [email protected] are available together
|
||||
expect(scheduleRRHostLead).toHaveTimeSlots(
|
||||
[`07:30:00.000Z`, `08:30:00.000Z`, `09:30:00.000Z`, `10:30:00.000Z`, `11:30:00.000Z`],
|
||||
|
||||
Reference in new issue
Block a user