fix: team event type error when when no one is assigned (#13888)

* fix: team event when when no one is assigned

* chore: test

* chore: unfo

* chore: remove host while creating

* fix: unit tests

* fix: event in booking form

* chore: undo tests

* fix: type

* fix: move it inside
This commit is contained in:
Udit Takkar
2024-03-05 16:42:35 -03:00
committed by GitHub
parent 99fd4fe7a4
commit 531371bf55
5 changed files with 16 additions and 11 deletions
@@ -51,7 +51,6 @@ export const BookEventForm = ({
const timeslot = useBookerStore((state) => state.selectedTimeslot);
const username = useBookerStore((state) => state.username);
const isInstantMeeting = useBookerStore((state) => state.isInstantMeeting);
const [expiryTime, setExpiryTime] = useState<Date | undefined>();
const [responseVercelIdHeader] = useState<string | null>(null);
const { t } = useLocale();
@@ -88,7 +88,7 @@ export function Header({
const isSameYear = () => {
return selectedDate.format("YYYY") === endDate.format("YYYY");
};
const formattedMonth = new Intl.DateTimeFormat(i18n.language, { month: "short" });
const formattedMonth = new Intl.DateTimeFormat(i18n.language ?? "en", { month: "short" });
const FormattedSelectedDateRange = () => {
return (
<h3 className="min-w-[150px] text-base font-semibold leading-4">
@@ -124,7 +124,7 @@ export const useBookings = ({ event, hashedLink, bookingForm, metadata }: IUseBo
date: responseData?.startTime?.toString() || "",
duration: validDuration,
organizer: {
name: users?.[0].name || "Nameless",
name: users?.[0]?.name || "Nameless",
email: responseData?.userPrimaryEmail || responseData.user?.email || "Email-less",
timeZone: responseData.user?.timeZone || "Europe/London",
},
@@ -137,7 +137,7 @@ export const useBookings = ({ event, hashedLink, bookingForm, metadata }: IUseBo
date: responseData?.startTime?.toString() || "",
duration: validDuration,
organizer: {
name: users?.[0].name || "Nameless",
name: users?.[0]?.name || "Nameless",
email: responseData?.userPrimaryEmail || responseData.user?.email || "Email-less",
timeZone: responseData.user?.timeZone || "Europe/London",
},
@@ -244,7 +244,9 @@ export const getPublicEvent = async (
hosts: hosts,
};
const users = getUsersFromEvent(eventWithUserProfiles) || (await getOwnerFromUsersArray(prisma, event.id));
const users =
(await getUsersFromEvent(eventWithUserProfiles, prisma)) ||
(await getOwnerFromUsersArray(prisma, event.id));
if (users === null) {
throw new Error("Event has no owner");
@@ -330,7 +332,7 @@ function getProfileFromEvent(event: Event) {
),
};
}
function getUsersFromEvent(
async function getUsersFromEvent(
event: Omit<Event, "owner" | "hosts"> & {
owner:
| (Event["owner"] & {
@@ -342,11 +344,15 @@ function getUsersFromEvent(
profile: UserProfile;
};
})[];
}
},
prisma: PrismaClient
) {
const { team, hosts, owner } = event;
const { team, hosts, owner, id } = event;
if (team) {
return (hosts || []).filter((host) => host.user.username).map(mapHostsToUsers);
// getOwnerFromUsersArray is used here for backward compatibility when team event type has users[] but not hosts[]
return hosts.length
? hosts.filter((host) => host.user.username).map(mapHostsToUsers)
: (await getOwnerFromUsersArray(prisma, id)) ?? [];
}
if (!owner) {
return null;
@@ -56,8 +56,8 @@ export const createHandler = async ({ ctx, input }: CreateOptions) => {
...rest,
owner: teamId ? undefined : { connect: { id: userId } },
metadata: (metadata as Prisma.InputJsonObject) ?? undefined,
// Only connecting the current user for non-managed event type
users: isManagedEventType ? undefined : { connect: { id: userId } },
// Only connecting the current user for non-managed event types and non team event types
users: isManagedEventType || schedulingType ? undefined : { connect: { id: userId } },
locations,
};