fix: email embed for org (#13917)
* fix: email embed for org * chore: use orgslig * chore: remove unused * fix: org details * test: add tests * chore: type err * fix: import missing * fix: check timeslots
This commit is contained in:
1 parent
5292dd2e66
commit
c6ee482478
7 files changed
+115
-5
No files matched your search
@@ -13,11 +13,15 @@ import {
|
||||
getDate,
|
||||
getGoogleCalendarCredential,
|
||||
createBookingScenario,
|
||||
createOrganization,
|
||||
getOrganizer,
|
||||
getScenarioData,
|
||||
} from "../utils/bookingScenario/bookingScenario";
|
||||
|
||||
vi.mock("@calcom/lib/constants", () => ({
|
||||
IS_PRODUCTION: true,
|
||||
WEBAPP_URL: "http://localhost:3000",
|
||||
RESERVED_SUBDOMAINS: ["auth", "docs"],
|
||||
}));
|
||||
|
||||
declare global {
|
||||
@@ -1255,5 +1259,73 @@ describe("getSchedule", () => {
|
||||
{ dateString: plus3DateString }
|
||||
);
|
||||
});
|
||||
|
||||
test("getSchedule can get slots of org's member event type when orgSlug, eventTypeSlug passed as input", async () => {
|
||||
const org = await createOrganization({ name: "acme", slug: "acme" });
|
||||
|
||||
const organizer = getOrganizer({
|
||||
name: "Organizer",
|
||||
email: "[email protected]",
|
||||
id: 101,
|
||||
// So, that it picks the first schedule from the list
|
||||
defaultScheduleId: null,
|
||||
organizationId: org.id,
|
||||
// Has morning shift with some overlap with morning shift
|
||||
schedules: [TestData.schedules.IstWorkHours],
|
||||
});
|
||||
|
||||
const scenario = await createBookingScenario(
|
||||
getScenarioData(
|
||||
{
|
||||
eventTypes: [
|
||||
{
|
||||
id: 1,
|
||||
slotInterval: 45,
|
||||
length: 45,
|
||||
users: [
|
||||
{
|
||||
id: 101,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
organizer,
|
||||
},
|
||||
{ id: org.id }
|
||||
)
|
||||
);
|
||||
|
||||
const { dateString: plus1DateString } = getDate({ dateIncrement: 1 });
|
||||
const { dateString: plus2DateString } = getDate({ dateIncrement: 2 });
|
||||
|
||||
const getScheduleRes = await getSchedule({
|
||||
input: {
|
||||
eventTypeSlug: scenario.eventTypes[0]?.slug,
|
||||
startTime: `${plus1DateString}T18:30:00.000Z`,
|
||||
endTime: `${plus2DateString}T18:29:59.999Z`,
|
||||
timeZone: Timezones["+5:30"],
|
||||
isTeamEvent: false,
|
||||
orgSlug: "acme",
|
||||
usernameList: [organizer.username],
|
||||
},
|
||||
});
|
||||
|
||||
expect(getScheduleRes).toHaveTimeSlots(
|
||||
[
|
||||
`04:00:00.000Z`,
|
||||
`04:45:00.000Z`,
|
||||
`05:30:00.000Z`,
|
||||
`06:15:00.000Z`,
|
||||
`07:00:00.000Z`,
|
||||
`07:45:00.000Z`,
|
||||
`08:30:00.000Z`,
|
||||
`09:15:00.000Z`,
|
||||
`10:00:00.000Z`,
|
||||
`10:45:00.000Z`,
|
||||
`11:30:00.000Z`,
|
||||
],
|
||||
{ dateString: plus2DateString }
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -9,6 +9,7 @@ import type Stripe from "stripe";
|
||||
import type { getMockRequestDataForBooking } from "test/utils/bookingScenario/getMockRequestDataForBooking";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import "vitest-fetch-mock";
|
||||
import type { z } from "zod";
|
||||
|
||||
import { appStoreMetadata } from "@calcom/app-store/appStoreMetaData";
|
||||
import { handleStripePaymentSuccess } from "@calcom/features/ee/payments/api/webhook";
|
||||
@@ -20,6 +21,7 @@ import { ProfileRepository } from "@calcom/lib/server/repository/profile";
|
||||
import type { WorkflowActions, WorkflowTemplates, WorkflowTriggerEvents } from "@calcom/prisma/client";
|
||||
import type { SchedulingType } from "@calcom/prisma/enums";
|
||||
import type { BookingStatus } from "@calcom/prisma/enums";
|
||||
import type { teamMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||
import type { userMetadataType } from "@calcom/prisma/zod-utils";
|
||||
import type { AppMeta } from "@calcom/types/App";
|
||||
import type { NewCalendarEventType } from "@calcom/types/Calendar";
|
||||
@@ -620,11 +622,19 @@ export async function createBookingScenario(data: ScenarioData) {
|
||||
};
|
||||
}
|
||||
|
||||
export async function createOrganization(orgData: { name: string; slug: string }) {
|
||||
export async function createOrganization(orgData: {
|
||||
name: string;
|
||||
slug: string;
|
||||
metadata?: z.infer<typeof teamMetadataSchema>;
|
||||
}) {
|
||||
const org = await prismock.team.create({
|
||||
data: {
|
||||
name: orgData.name,
|
||||
slug: orgData.slug,
|
||||
metadata: {
|
||||
...(orgData.metadata || {}),
|
||||
isOrganization: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
return org;
|
||||
|
||||
@@ -52,6 +52,7 @@ export const useScheduleForEvent = ({
|
||||
monthCount,
|
||||
dayCount,
|
||||
selectedDate,
|
||||
orgSlug,
|
||||
}: {
|
||||
prefetchNextMonth?: boolean;
|
||||
username?: string | null;
|
||||
@@ -62,6 +63,7 @@ export const useScheduleForEvent = ({
|
||||
monthCount?: number;
|
||||
dayCount?: number | null;
|
||||
selectedDate?: string | null;
|
||||
orgSlug?: string;
|
||||
} = {}) => {
|
||||
const { timezone } = useTimePreferences();
|
||||
const event = useEvent();
|
||||
@@ -69,6 +71,7 @@ export const useScheduleForEvent = ({
|
||||
(state) => [state.username, state.eventSlug, state.month, state.selectedDuration],
|
||||
shallow
|
||||
);
|
||||
|
||||
const searchParams = useCompatSearchParams();
|
||||
const rescheduleUid = searchParams?.get("rescheduleUid");
|
||||
|
||||
@@ -89,5 +92,6 @@ export const useScheduleForEvent = ({
|
||||
month: monthFromStore ?? month,
|
||||
duration: durationFromStore ?? duration,
|
||||
isTeamEvent: pathname?.indexOf("/team/") !== -1 || isTeam,
|
||||
orgSlug,
|
||||
});
|
||||
};
|
||||
@@ -127,7 +127,15 @@ const ChooseEmbedTypesDialogContent = ({ types }: { types: EmbedTypes }) => {
|
||||
);
|
||||
};
|
||||
|
||||
const EmailEmbed = ({ eventType, username }: { eventType?: EventType; username: string }) => {
|
||||
const EmailEmbed = ({
|
||||
eventType,
|
||||
username,
|
||||
orgSlug,
|
||||
}: {
|
||||
eventType?: EventType;
|
||||
username: string;
|
||||
orgSlug?: string;
|
||||
}) => {
|
||||
const { t, i18n } = useLocale();
|
||||
|
||||
const [timezone] = useTimePreferences((state) => [state.timezone]);
|
||||
@@ -153,7 +161,7 @@ const EmailEmbed = ({ eventType, username }: { eventType?: EventType; username:
|
||||
shallow
|
||||
);
|
||||
const event = useEvent();
|
||||
const schedule = useScheduleForEvent();
|
||||
const schedule = useScheduleForEvent({ orgSlug });
|
||||
const nonEmptyScheduleDays = useNonEmptyScheduleDays(schedule?.data?.slots);
|
||||
|
||||
const onTimeSelect = (time: string) => {
|
||||
@@ -516,6 +524,7 @@ const EmbedTypeCodeAndPreviewDialogContent = ({
|
||||
const dialogContentRef = useRef<HTMLDivElement>(null);
|
||||
const emailContentRef = useRef<HTMLDivElement>(null);
|
||||
const { data } = useSession();
|
||||
|
||||
const [month, selectedDatesAndTimes] = useBookerStore(
|
||||
(state) => [state.month, state.selectedDatesAndTimes],
|
||||
shallow
|
||||
@@ -710,7 +719,11 @@ const EmbedTypeCodeAndPreviewDialogContent = ({
|
||||
</h3>
|
||||
<h4 className="text-subtle mb-6 text-sm font-normal">{embed.subtitle}</h4>
|
||||
{eventTypeData?.eventType && embedType === "email" ? (
|
||||
<EmailEmbed eventType={eventTypeData?.eventType} username={data?.user.username as string} />
|
||||
<EmailEmbed
|
||||
eventType={eventTypeData?.eventType}
|
||||
username={data?.user.username as string}
|
||||
orgSlug={data?.user?.org?.slug}
|
||||
/>
|
||||
) : (
|
||||
<div className="flex flex-col">
|
||||
<div className={classNames("font-medium", embedType === "element-click" ? "hidden" : "")}>
|
||||
|
||||
@@ -15,6 +15,7 @@ type UseScheduleWithCacheArgs = {
|
||||
dayCount?: number | null;
|
||||
rescheduleUid?: string | null;
|
||||
isTeamEvent?: boolean;
|
||||
orgSlug?: string;
|
||||
};
|
||||
|
||||
export const useSchedule = ({
|
||||
@@ -30,6 +31,7 @@ export const useSchedule = ({
|
||||
dayCount,
|
||||
rescheduleUid,
|
||||
isTeamEvent,
|
||||
orgSlug,
|
||||
}: UseScheduleWithCacheArgs) => {
|
||||
const now = dayjs();
|
||||
const monthDayjs = month ? dayjs(month) : now;
|
||||
@@ -72,6 +74,7 @@ export const useSchedule = ({
|
||||
timeZone: timezone!,
|
||||
duration: duration ? `${duration}` : undefined,
|
||||
rescheduleUid,
|
||||
orgSlug,
|
||||
},
|
||||
{
|
||||
trpc: {
|
||||
|
||||
@@ -23,6 +23,7 @@ export const getScheduleSchema = z
|
||||
rescheduleUid: z.string().optional().nullable(),
|
||||
// whether to do team event or user event
|
||||
isTeamEvent: z.boolean().optional().default(false),
|
||||
orgSlug: z.string().optional(),
|
||||
})
|
||||
.transform((val) => {
|
||||
// Need this so we can pass a single username in the query string form public API
|
||||
|
||||
@@ -11,6 +11,7 @@ import dayjs from "@calcom/dayjs";
|
||||
import { getSlugOrRequestedSlug, orgDomainConfig } from "@calcom/ee/organizations/lib/orgDomains";
|
||||
import { isEventTypeLoggingEnabled } from "@calcom/features/bookings/lib/isEventTypeLoggingEnabled";
|
||||
import { parseBookingLimit, parseDurationLimit } from "@calcom/lib";
|
||||
import { RESERVED_SUBDOMAINS } from "@calcom/lib/constants";
|
||||
import { getDefaultEvent } from "@calcom/lib/defaultEvents";
|
||||
import isTimeOutOfBounds from "@calcom/lib/isOutOfBounds";
|
||||
import logger from "@calcom/lib/logger";
|
||||
@@ -296,7 +297,13 @@ function applyOccupiedSeatsToCurrentSeats(currentSeats: CurrentSeats, occupiedSe
|
||||
}
|
||||
|
||||
export async function getAvailableSlots({ input, ctx }: GetScheduleOptions) {
|
||||
const orgDetails = orgDomainConfig(ctx?.req);
|
||||
const orgDetails = input?.orgSlug
|
||||
? {
|
||||
currentOrgDomain: input.orgSlug,
|
||||
isValidOrgDomain: !!input.orgSlug && !RESERVED_SUBDOMAINS.includes(input.orgSlug),
|
||||
}
|
||||
: orgDomainConfig(ctx?.req);
|
||||
|
||||
if (process.env.INTEGRATION_TEST_MODE === "true") {
|
||||
logger.settings.minLevel = 2;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user