Feature/fixed hosts (#6423)
* Save design updates for fixed round robin support * wip - added Host relation * DRY hostsFixed select * Changes to allow isFixed in the Availability page * Allow booking with fixed hosts * Replace users with hosts if hosts is set * Also prefer hosts over users here * Prevent duplicates when hosts is saved * Accidental slot duplication * Attempt at making isFixed optional * Sydney and Shiraz can live in harmony again * No fixed hosts causes every to be true.. * Make hosts undefinable * Small handleNewBooking fixes * Similar fix to the hosts to check for empty-ness * Default to isFixed false instead of true * Fix event type list avatars * Filter availableTimeSlots, collective ts's wont magically re-enable. * (Further) Fixes to getAggregateWorkingHours * Weird userId artifact that preceeds this branch, investigate later * On user delete, remove host, on event type delete, also remove host * Dynamic event types were incorrectly marked as isFixed=false * Fixed notFound error when there are no users (but hosts) * Fixes userIsOwner * Oops, fixed isFixed users being included correctly * Fixed Button styling on secondary darkmode * Create exclusivity in selectable options * fix: Location dropdown is overflowing #6376 (#6415) * add `menuPlacement` react-select's props to `getReactSelectProps` to avoid dropdown overflow on small screen. By default, set to "auto". * CALCOM-6362 - [CAL-728] App Sidebar. Child items aren't sized/spaced properly (#6424) * [CAL-728] App Sidebar. Child items aren't sized/spaced properly * fix: undo logo size Signed-off-by: Udit Takkar <[email protected]> Signed-off-by: Udit Takkar <[email protected]> Co-authored-by: gitstart-calcom <[email protected]> Co-authored-by: Udit Takkar <[email protected]> * Fixing colors (#6429) * Update website * Update console * Update yarn.lock * Uses disable instead of filtering to be more clear * Update EventTeamTab.tsx * Merge conflict cleanup * During test cases the dayjs() utcOffset is local time, this fixes that Signed-off-by: Udit Takkar <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Thomas Brodusch <[email protected]> Co-authored-by: GitStart-Cal.com <[email protected]> Co-authored-by: gitstart-calcom <[email protected]> Co-authored-by: Udit Takkar <[email protected]> Co-authored-by: sean-brydon <[email protected]> Co-authored-by: zomars <[email protected]>
This commit is contained in:
17 files changed
+406
-151
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { MembershipRole, PeriodType, Prisma } from "@prisma/client";
|
||||
import { MembershipRole, PeriodType, Prisma, SchedulingType } from "@prisma/client";
|
||||
import { PrismaClientKnownRequestError } from "@prisma/client/runtime";
|
||||
// REVIEW: From lint error
|
||||
import _ from "lodash";
|
||||
@@ -84,6 +84,14 @@ const EventTypeUpdateInput = _EventTypeModel
|
||||
externalId: true,
|
||||
}),
|
||||
users: z.array(stringOrNumber).optional(),
|
||||
hosts: z
|
||||
.array(
|
||||
z.object({
|
||||
userId: z.number(),
|
||||
isFixed: z.boolean().optional(),
|
||||
})
|
||||
)
|
||||
.optional(),
|
||||
schedule: z.number().optional(),
|
||||
hashedLink: z.string(),
|
||||
})
|
||||
@@ -187,6 +195,13 @@ export const eventTypesRouter = router({
|
||||
users: {
|
||||
select: baseUserSelect,
|
||||
},
|
||||
hosts: {
|
||||
select: {
|
||||
user: {
|
||||
select: baseUserSelect,
|
||||
},
|
||||
},
|
||||
},
|
||||
...baseEventTypeSelect,
|
||||
});
|
||||
|
||||
@@ -255,6 +270,7 @@ export const eventTypesRouter = router({
|
||||
|
||||
const mapEventType = (eventType: typeof user.eventTypes[number]) => ({
|
||||
...eventType,
|
||||
users: !!eventType.hosts?.length ? eventType.hosts.map((host) => host.user) : eventType.users,
|
||||
// @FIXME: cc @hariombalhara This is failing with production data
|
||||
// metadata: EventTypeMetaDataSchema.parse(eventType.metadata),
|
||||
});
|
||||
@@ -483,6 +499,7 @@ export const eventTypesRouter = router({
|
||||
customInputs,
|
||||
recurringEvent,
|
||||
users,
|
||||
hosts,
|
||||
id,
|
||||
hashedLink,
|
||||
// Extract this from the input so it doesn't get saved in the db
|
||||
@@ -557,6 +574,17 @@ export const eventTypesRouter = router({
|
||||
connect: users.map((userId: number) => ({ id: userId })),
|
||||
};
|
||||
}
|
||||
if (hosts) {
|
||||
data.hosts = {
|
||||
deleteMany: {
|
||||
eventTypeId: id,
|
||||
},
|
||||
createMany: {
|
||||
// when schedulingType is COLLECTIVE, remove unFixed hosts.
|
||||
data: hosts.filter((host) => !(data.schedulingType === SchedulingType.COLLECTIVE && !host.isFixed)),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (input?.price || input.metadata?.apps?.stripe?.price) {
|
||||
data.price = input.price || input.metadata?.apps?.stripe?.price;
|
||||
|
||||
@@ -144,6 +144,14 @@ async function getEventType(ctx: { prisma: typeof prisma }, input: z.infer<typeo
|
||||
days: true,
|
||||
},
|
||||
},
|
||||
hosts: {
|
||||
select: {
|
||||
isFixed: true,
|
||||
user: {
|
||||
select: availabilityUserSelect,
|
||||
},
|
||||
},
|
||||
},
|
||||
users: {
|
||||
select: {
|
||||
...availabilityUserSelect,
|
||||
@@ -227,9 +235,17 @@ export async function getSchedule(input: z.infer<typeof getScheduleSchema>, ctx:
|
||||
}
|
||||
let currentSeats: CurrentSeats | undefined = undefined;
|
||||
|
||||
let users = eventType.users.map((user) => ({
|
||||
isFixed: !eventType.schedulingType || eventType.schedulingType === SchedulingType.COLLECTIVE,
|
||||
...user,
|
||||
}));
|
||||
// overwrite if it is a team event & hosts is set, otherwise keep using users.
|
||||
if (eventType.schedulingType && !!eventType.hosts?.length) {
|
||||
users = eventType.hosts.map(({ isFixed, user }) => ({ isFixed, ...user }));
|
||||
}
|
||||
/* We get all users working hours and busy slots */
|
||||
const userAvailability = await Promise.all(
|
||||
eventType.users.map(async (currentUser) => {
|
||||
users.map(async (currentUser) => {
|
||||
const {
|
||||
busy,
|
||||
workingHours,
|
||||
@@ -255,16 +271,15 @@ export async function getSchedule(input: z.infer<typeof getScheduleSchema>, ctx:
|
||||
workingHours,
|
||||
dateOverrides,
|
||||
busy,
|
||||
userId: currentUser.id,
|
||||
user: currentUser,
|
||||
};
|
||||
})
|
||||
);
|
||||
// flattens availability of multiple users
|
||||
const dateOverrides = userAvailability.flatMap((availability) =>
|
||||
availability.dateOverrides.map((override) => ({ userId: availability.userId, ...override }))
|
||||
availability.dateOverrides.map((override) => ({ userId: availability.user.id, ...override }))
|
||||
);
|
||||
const workingHours = getAggregateWorkingHours(userAvailability, eventType.schedulingType);
|
||||
|
||||
const availabilityCheckProps = {
|
||||
eventLength: eventType.length,
|
||||
currentSeats,
|
||||
@@ -304,34 +319,33 @@ export async function getSchedule(input: z.infer<typeof getScheduleSchema>, ctx:
|
||||
);
|
||||
}
|
||||
|
||||
const isCollective = !eventType.schedulingType || eventType.schedulingType === SchedulingType.COLLECTIVE;
|
||||
|
||||
let availableTimeSlots: typeof timeSlots = [];
|
||||
if (isCollective) {
|
||||
availableTimeSlots = timeSlots.filter((slot) =>
|
||||
userAvailability.every((schedule) => {
|
||||
const startCheckForAvailability = performance.now();
|
||||
const isAvailable = checkIfIsAvailable({
|
||||
time: slot.time,
|
||||
...schedule,
|
||||
...availabilityCheckProps,
|
||||
});
|
||||
const endCheckForAvailability = performance.now();
|
||||
checkForAvailabilityCount++;
|
||||
checkForAvailabilityTime += endCheckForAvailability - startCheckForAvailability;
|
||||
return isAvailable;
|
||||
})
|
||||
);
|
||||
} else {
|
||||
availableTimeSlots = timeSlots
|
||||
availableTimeSlots = timeSlots.filter((slot) => {
|
||||
const fixedHosts = userAvailability.filter((availability) => availability.user.isFixed);
|
||||
return fixedHosts.every((schedule) => {
|
||||
const startCheckForAvailability = performance.now();
|
||||
const isAvailable = checkIfIsAvailable({
|
||||
time: slot.time,
|
||||
...schedule,
|
||||
...availabilityCheckProps,
|
||||
});
|
||||
const endCheckForAvailability = performance.now();
|
||||
checkForAvailabilityCount++;
|
||||
checkForAvailabilityTime += endCheckForAvailability - startCheckForAvailability;
|
||||
return isAvailable;
|
||||
});
|
||||
});
|
||||
// what else are you going to call it?
|
||||
const looseHostAvailability = userAvailability.filter(({ user: { isFixed } }) => !isFixed);
|
||||
if (looseHostAvailability.length > 0) {
|
||||
availableTimeSlots = availableTimeSlots
|
||||
.map((slot) => {
|
||||
slot.userIds = slot.userIds?.filter((slotUserId) => {
|
||||
const userSchedule = userAvailability.find(({ userId }) => userId === slotUserId);
|
||||
const userSchedule = looseHostAvailability.find(
|
||||
({ user: { id: userId } }) => userId === slotUserId
|
||||
);
|
||||
if (!userSchedule) {
|
||||
throw new TRPCError({
|
||||
message: "Shouldn't happen that we don't have a matching user schedule here",
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
});
|
||||
return false;
|
||||
}
|
||||
return checkIfIsAvailable({
|
||||
time: slot.time,
|
||||
@@ -341,7 +355,7 @@ export async function getSchedule(input: z.infer<typeof getScheduleSchema>, ctx:
|
||||
});
|
||||
return slot;
|
||||
})
|
||||
.filter((slot) => slot.userIds && slot.userIds.length > 0);
|
||||
.filter((slot) => !!slot.userIds?.length);
|
||||
}
|
||||
|
||||
availableTimeSlots = availableTimeSlots.filter((slot) => isTimeWithinBounds(slot.time));
|
||||
@@ -355,7 +369,9 @@ export async function getSchedule(input: z.infer<typeof getScheduleSchema>, ctx:
|
||||
r[time.format("YYYY-MM-DD")].push({
|
||||
...passThroughProps,
|
||||
time: time.toISOString(),
|
||||
users: eventType.users.map((user) => user.username || ""),
|
||||
users: (eventType.hosts ? eventType.hosts.map((host) => host.user) : eventType.users).map(
|
||||
(user) => user.username || ""
|
||||
),
|
||||
// Conditionally add the attendees and booking id to slots object if there is already a booking during that time
|
||||
...(currentSeats?.some((booking) => booking.startTime.toISOString() === time.toISOString()) && {
|
||||
attendees:
|
||||
|
||||
Reference in new issue
Block a user