fix: Unpublished screens (#10453)
* Implementation * Changes and e2e * Reverting launch.json * Reverting org create handler * Reverting yarn.lock * DRYness and nitpicks * Default org domain to undefined * Applying zomars suggestion * Suggestions * Fixing seed and type in suggestion * Fixing types --------- Co-authored-by: zomars <[email protected]>
This commit is contained in:
1 parent
4435451e9b
commit
4a6dc50909
29 files changed
+503
-161
No files matched your search
@@ -27,6 +27,7 @@ import { getQueryParam } from "./utils/query-param";
|
||||
import { useBrandColors } from "./utils/use-brand-colors";
|
||||
|
||||
const PoweredBy = dynamic(() => import("@calcom/ee/components/PoweredBy"));
|
||||
const UnpublishedEntity = dynamic(() => import("@calcom/ui").then((mod) => mod.UnpublishedEntity));
|
||||
const DatePicker = dynamic(() => import("./components/DatePicker").then((mod) => mod.DatePicker), {
|
||||
ssr: false,
|
||||
});
|
||||
@@ -38,7 +39,7 @@ const BookerComponent = ({
|
||||
bookingData,
|
||||
hideBranding = false,
|
||||
isTeamEvent,
|
||||
org,
|
||||
entity,
|
||||
}: BookerProps) => {
|
||||
const isMobile = useMediaQuery("(max-width: 768px)");
|
||||
const isTablet = useMediaQuery("(max-width: 1024px)");
|
||||
@@ -98,7 +99,7 @@ const BookerComponent = ({
|
||||
bookingData,
|
||||
layout: defaultLayout,
|
||||
isTeamEvent,
|
||||
org,
|
||||
org: entity.orgSlug,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
@@ -139,6 +140,10 @@ const BookerComponent = ({
|
||||
|
||||
const hideEventTypeDetails = isEmbed ? embedUiConfig.hideEventTypeDetails : false;
|
||||
|
||||
if (entity.isUnpublished) {
|
||||
return <UnpublishedEntity {...entity} />;
|
||||
}
|
||||
|
||||
if (event.isSuccess && !event.data) {
|
||||
return <NotFound />;
|
||||
}
|
||||
|
||||
@@ -5,8 +5,16 @@ import type { GetBookingType } from "../lib/get-booking";
|
||||
export interface BookerProps {
|
||||
eventSlug: string;
|
||||
username: string;
|
||||
// Make it optional later, once we figure out where we can possibly need to set org
|
||||
org: string | null;
|
||||
|
||||
/**
|
||||
* Whether is a team or org, we gather basic info from both
|
||||
*/
|
||||
entity: {
|
||||
isUnpublished?: boolean;
|
||||
orgSlug?: string | null;
|
||||
teamSlug?: string | null;
|
||||
name?: string | null;
|
||||
};
|
||||
|
||||
/**
|
||||
* If month is NOT set as a prop on the component, we expect a query parameter
|
||||
|
||||
@@ -8,14 +8,18 @@ interface BookerSeoProps {
|
||||
rescheduleUid: string | undefined;
|
||||
hideBranding?: boolean;
|
||||
isTeamEvent?: boolean;
|
||||
org: string | null;
|
||||
entity: {
|
||||
orgSlug?: string | null;
|
||||
teamSlug?: string | null;
|
||||
name?: string | null;
|
||||
};
|
||||
}
|
||||
|
||||
export const BookerSeo = (props: BookerSeoProps) => {
|
||||
const { eventSlug, username, rescheduleUid, hideBranding, isTeamEvent, org } = props;
|
||||
const { eventSlug, username, rescheduleUid, hideBranding, isTeamEvent, entity } = props;
|
||||
const { t } = useLocale();
|
||||
const { data: event } = trpc.viewer.public.event.useQuery(
|
||||
{ username, eventSlug, isTeamEvent, org },
|
||||
{ username, eventSlug, isTeamEvent, org: entity.orgSlug ?? null },
|
||||
{ refetchOnWindowFocus: false }
|
||||
);
|
||||
|
||||
|
||||
@@ -23,11 +23,20 @@ export function getOrgSlug(hostname: string) {
|
||||
return null;
|
||||
}
|
||||
|
||||
export function orgDomainConfig(hostname: string) {
|
||||
export function orgDomainConfig(hostname: string, fallback?: string | string[]) {
|
||||
const currentOrgDomain = getOrgSlug(hostname);
|
||||
const isValidOrgDomain = currentOrgDomain !== null && !RESERVED_SUBDOMAINS.includes(currentOrgDomain);
|
||||
if (isValidOrgDomain || !fallback) {
|
||||
return {
|
||||
currentOrgDomain: isValidOrgDomain ? currentOrgDomain : null,
|
||||
isValidOrgDomain,
|
||||
};
|
||||
}
|
||||
const fallbackOrgSlug = fallback as string;
|
||||
const isValidFallbackDomain = !RESERVED_SUBDOMAINS.includes(fallbackOrgSlug);
|
||||
return {
|
||||
currentOrgDomain,
|
||||
isValidOrgDomain: currentOrgDomain !== null && !RESERVED_SUBDOMAINS.includes(currentOrgDomain),
|
||||
currentOrgDomain: isValidFallbackDomain ? fallbackOrgSlug : null,
|
||||
isValidOrgDomain: isValidFallbackDomain,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -39,3 +48,17 @@ export function subdomainSuffix() {
|
||||
export function getOrgFullDomain(slug: string, options: { protocol: boolean } = { protocol: true }) {
|
||||
return `${options.protocol ? `${new URL(WEBAPP_URL).protocol}//` : ""}${slug}.${subdomainSuffix()}`;
|
||||
}
|
||||
|
||||
export function getSlugOrRequestedSlug(slug: string) {
|
||||
return {
|
||||
OR: [
|
||||
{ slug },
|
||||
{
|
||||
metadata: {
|
||||
path: ["requestedSlug"],
|
||||
equals: slug,
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import type { LocationObject } from "@calcom/app-store/locations";
|
||||
import { privacyFilteredLocations } from "@calcom/app-store/locations";
|
||||
import { getAppFromSlug } from "@calcom/app-store/utils";
|
||||
import { getBookingFieldsWithSystemFields } from "@calcom/features/bookings/lib/getBookingFields";
|
||||
import { getSlugOrRequestedSlug } from "@calcom/features/ee/organizations/lib/orgDomains";
|
||||
import { isRecurringEvent, parseRecurringEvent } from "@calcom/lib";
|
||||
import { getDefaultEvent, getUsernameList } from "@calcom/lib/defaultEvents";
|
||||
import { markdownToSafeHTML } from "@calcom/lib/markdownToSafeHTML";
|
||||
@@ -17,6 +18,7 @@ import {
|
||||
userMetadata as userMetadataSchema,
|
||||
bookerLayouts as bookerLayoutsSchema,
|
||||
BookerLayouts,
|
||||
teamMetadataSchema,
|
||||
} from "@calcom/prisma/zod-utils";
|
||||
|
||||
const publicEventSelect = Prisma.validator<Prisma.EventTypeSelect>()({
|
||||
@@ -38,7 +40,24 @@ const publicEventSelect = Prisma.validator<Prisma.EventTypeSelect>()({
|
||||
currency: true,
|
||||
seatsPerTimeSlot: true,
|
||||
bookingFields: true,
|
||||
team: true,
|
||||
team: {
|
||||
select: {
|
||||
parentId: true,
|
||||
metadata: true,
|
||||
brandColor: true,
|
||||
darkBrandColor: true,
|
||||
slug: true,
|
||||
name: true,
|
||||
logo: true,
|
||||
theme: true,
|
||||
parent: {
|
||||
select: {
|
||||
slug: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
successRedirectUrl: true,
|
||||
workflows: {
|
||||
include: {
|
||||
@@ -73,6 +92,12 @@ const publicEventSelect = Prisma.validator<Prisma.EventTypeSelect>()({
|
||||
metadata: true,
|
||||
brandColor: true,
|
||||
darkBrandColor: true,
|
||||
organization: {
|
||||
select: {
|
||||
name: true,
|
||||
slug: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
hidden: true,
|
||||
@@ -86,11 +111,7 @@ export const getPublicEvent = async (
|
||||
prisma: PrismaClient
|
||||
) => {
|
||||
const usernameList = getUsernameList(username);
|
||||
const orgQuery = org
|
||||
? {
|
||||
slug: org ?? null,
|
||||
}
|
||||
: null;
|
||||
const orgQuery = org ? getSlugOrRequestedSlug(org) : null;
|
||||
// In case of dynamic group event, we fetch user's data and use the default event.
|
||||
if (usernameList.length > 1) {
|
||||
const users = await prisma.user.findMany({
|
||||
@@ -108,6 +129,12 @@ export const getPublicEvent = async (
|
||||
brandColor: true,
|
||||
darkBrandColor: true,
|
||||
theme: true,
|
||||
organization: {
|
||||
select: {
|
||||
slug: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -133,6 +160,8 @@ export const getPublicEvent = async (
|
||||
defaultLayout: BookerLayouts.MONTH_VIEW,
|
||||
} as BookerLayoutSettings;
|
||||
const disableBookingTitle = !defaultEvent.isDynamic;
|
||||
const unPublishedOrgUser = users.find((user) => user.organization?.slug === null);
|
||||
|
||||
return {
|
||||
...defaultEvent,
|
||||
bookingFields: getBookingFieldsWithSystemFields({ ...defaultEvent, disableBookingTitle }),
|
||||
@@ -151,13 +180,18 @@ export const getPublicEvent = async (
|
||||
firstUsersMetadata?.defaultBookerLayouts || defaultEventBookerLayouts
|
||||
),
|
||||
},
|
||||
entity: {
|
||||
isUnpublished: unPublishedOrgUser !== undefined,
|
||||
orgSlug: org,
|
||||
name: unPublishedOrgUser?.organization?.name ?? null,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const usersOrTeamQuery = isTeamEvent
|
||||
? {
|
||||
team: {
|
||||
slug: username,
|
||||
...getSlugOrRequestedSlug(username),
|
||||
parent: orgQuery,
|
||||
},
|
||||
}
|
||||
@@ -183,6 +217,7 @@ export const getPublicEvent = async (
|
||||
if (!event) return null;
|
||||
|
||||
const eventMetaData = EventTypeMetaDataSchema.parse(event.metadata || {});
|
||||
const teamMetadata = teamMetadataSchema.parse(event.team?.metadata || {});
|
||||
|
||||
const users = getUsersFromEvent(event) || (await getOwnerFromUsersArray(prisma, event.id));
|
||||
if (users === null) {
|
||||
@@ -201,7 +236,15 @@ export const getPublicEvent = async (
|
||||
// Sets user data on profile object for easier access
|
||||
profile: getProfileFromEvent(event),
|
||||
users,
|
||||
orgDomain: org,
|
||||
entity: {
|
||||
isUnpublished:
|
||||
event.team?.slug === null ||
|
||||
event.owner?.organization?.slug === null ||
|
||||
event.team?.parent?.slug === null,
|
||||
orgSlug: org,
|
||||
teamSlug: (event.team?.slug || teamMetadata?.requestedSlug) ?? null,
|
||||
name: (event.owner?.organization?.name || event.team?.parent?.name || event.team?.name) ?? null,
|
||||
},
|
||||
isDynamic: false,
|
||||
};
|
||||
};
|
||||
@@ -218,20 +261,6 @@ function getProfileFromEvent(event: Event) {
|
||||
if (!profile) throw new Error("Event has no owner");
|
||||
|
||||
const username = "username" in profile ? profile.username : team?.slug;
|
||||
if (!username) {
|
||||
if (event.slug === "test") {
|
||||
// @TODO: This is a temporary debug statement that should be removed asap.
|
||||
throw new Error(
|
||||
"Ciaran event error" +
|
||||
JSON.stringify(team) +
|
||||
" -- " +
|
||||
JSON.stringify(hosts) +
|
||||
" -- " +
|
||||
JSON.stringify(owner)
|
||||
);
|
||||
}
|
||||
throw new Error("Event has no username/team slug");
|
||||
}
|
||||
const weekStart = hosts?.[0]?.user?.weekStart || owner?.weekStart || "Monday";
|
||||
const basePath = team ? `/team/${username}` : `/${username}`;
|
||||
const eventMetaData = EventTypeMetaDataSchema.parse(event.metadata || {});
|
||||
|
||||
@@ -26,7 +26,7 @@ describe("Org Domains Utils", () => {
|
||||
it("should return a non valid org domain", () => {
|
||||
setupEnvs();
|
||||
expect(orgDomainConfig("app.cal.com")).toEqual({
|
||||
currentOrgDomain: "app",
|
||||
currentOrgDomain: null,
|
||||
isValidOrgDomain: false,
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user