fix: Dynamic Group Booking link for organization (#12825)

Co-authored-by: Erik <[email protected]>
Co-authored-by: Omar López <[email protected]>
This commit is contained in:
authored and GitHub committed 2023-12-19 17:42:40 +00:00
1 parent 31b88c5537
commit a8975f541f
11 files changed
+106 -33

No files matched your search

@@ -57,7 +57,7 @@ export const EventMeta = () => {
: "text-bookinghighlight";
return (
<div className="relative z-10 p-6">
<div className="relative z-10 p-6" data-testid="event-meta">
{isLoading && (
<m.div {...fadeInUp} initial="visible" layout>
<EventMetaSkeleton />
@@ -11,5 +11,9 @@ interface EventTitleProps {
export const EventTitle = ({ children, as, className }: EventTitleProps) => {
const El = as || "h1";
return <El className={classNames("text-text text-xl font-semibold", className)}>{children}</El>;
return (
<El data-testid="event-title" className={classNames("text-text text-xl font-semibold", className)}>
{children}
</El>
);
};
@@ -1,6 +1,7 @@
import type { App, Attendee, DestinationCalendar, EventTypeCustomInput } from "@prisma/client";
import { Prisma } from "@prisma/client";
import async from "async";
import type { IncomingMessage } from "http";
import { isValidPhoneNumber } from "libphonenumber-js";
// eslint-disable-next-line no-restricted-imports
import { cloneDeep } from "lodash";
@@ -372,21 +373,16 @@ type IsFixedAwareUser = User & {
organization: { slug: string };
};
const loadUsers = async (
eventType: NewBookingEventType,
dynamicUserList: string[],
reqHeadersHost: string | undefined
) => {
const loadUsers = async (eventType: NewBookingEventType, dynamicUserList: string[], req: IncomingMessage) => {
try {
if (!eventType.id) {
if (!Array.isArray(dynamicUserList) || dynamicUserList.length === 0) {
throw new Error("dynamicUserList is not properly defined or empty.");
}
const users = await prisma.user.findMany({
where: {
username: { in: dynamicUserList },
organization: userOrgQuery(reqHeadersHost ? reqHeadersHost.replace(/^https?:\/\//, "") : ""),
organization: userOrgQuery(req),
},
select: {
...userSelect.select,
@@ -969,7 +965,7 @@ async function handler(
let users: (Awaited<ReturnType<typeof loadUsers>>[number] & {
isFixed?: boolean;
metadata?: Prisma.JsonValue;
})[] = await loadUsers(eventType, dynamicUserList, req.headers.host);
})[] = await loadUsers(eventType, dynamicUserList, req);
const isDynamicAllowed = !users.some((user) => !user.allowDynamicBooking);
if (!isDynamicAllowed && !eventTypeId) {
@@ -145,7 +145,7 @@ export function whereClauseForOrgWithSlugOrRequestedSlug(slug: string) {
} satisfies Prisma.TeamWhereInput;
}
export function userOrgQuery(hostname: string, fallback?: string | string[]) {
const { currentOrgDomain, isValidOrgDomain } = getOrgDomainConfigFromHostname({ hostname, fallback });
export function userOrgQuery(req: IncomingMessage | undefined, fallback?: string | string[]) {
const { currentOrgDomain, isValidOrgDomain } = orgDomainConfig(req, fallback);
return isValidOrgDomain && currentOrgDomain ? getSlugOrRequestedSlug(currentOrgDomain) : null;
}
@@ -31,6 +31,7 @@ export const AvatarGroup = function AvatarGroup(props: AvatarGroupProps) {
{displayedAvatars.map((item, idx) => (
<li key={idx} className="-mr-[4px] inline-block">
<Avatar
data-testid="avatar"
className="border-subtle"
imageSrc={item.image}
title={item.title}