feat: Availability slider for orgs (#10740)
* Init + get timezone + offset data agh * Add 12/24h mode - style correctly * User users timezone + working hours. Still some stuff to figure out * Multiple working hours * move calc to once per day * Demo with two users and differnt timezones * availabillity control tab via search params * WIP hover overlay * THIS WORKS ISH * fix: multiple duration getSchedule calls [CAL-2336] (#10709) Co-authored-by: Omar López <[email protected]> * New Crowdin translations by Github Action * fix: If the input type "Name" is selected, the label can't be changed from our default label "Your Name" (#10618) Co-authored-by: Carina Wollendorfer <[email protected]> * New Crowdin translations by Github Action * test: Create unit tests for react components in packages/ui/components/form/step (#10442) Co-authored-by: gitstart-calcom <[email protected]> Co-authored-by: Keith Williams <[email protected]> * feat: element call app added (#10585) Co-authored-by: Hariom Balhara <[email protected]> * New Crowdin translations by Github Action * New Crowdin translations by Github Action * fix: e2e test for rescheduling overlapping time (#10721) Co-authored-by: CarinaWolli <[email protected]> * feat: mailhog fixture (#10606) * feat: mailhog fixture * fix: nodemailer to dispatch emails with e2e env * fix: remove space from email subject * feat: fixture getFirstEventAsOwner * feat: assert email subjects * fix: and enable dynamic booking test (#10642) * fix and enable dynamic booking test * remove page pause --------- Co-authored-by: Alex van Andel <[email protected]> * fix: Broken team events if a user with the same name exists (#10724) * fix: Broken team events if a user with the same name exists * Fix tests + fix usernameList optionality * Try to list calendars, if not continue (#10720) Co-authored-by: Omar López <[email protected]> * v3.1.9 * link to org settings (#10718) * feat: app paypal payment (#8797) Co-authored-by: sean-brydon <[email protected]> Co-authored-by: Omar López <[email protected]> * fix: RTL issues on booking pages + email confirmation (#10526) Co-authored-by: Peer Richelsen <[email protected]> * fix: merge conflict * Fixing org slug (#10538) * fix: paypal build fixes * Fix avatar for org in Shell top (#10712) * feat: add range of dates for availability over-ride (#10462) * feat: add range of dates for availability over-ride * chore: changed range select to multiple select --------- Co-authored-by: Alex van Andel <[email protected]> * fix: border issue for time slots (#10577) Co-authored-by: Raghul D <[email protected]> * style: Fix text wrapping issue in button (#10725) Co-authored-by: Omar López <[email protected]> * New Crowdin translations by Github Action * fix: App Install Dropdown Sort Properly [CAL-2285] (#10672) Co-authored-by: Peer Richelsen <[email protected]> * fix: link escaping in booking page (#10360) Co-authored-by: Hariom Balhara <[email protected]> * chore: fix refund i18n message (#10731) * chore: remove tailwind-scrollbar warning (#10523) Co-authored-by: Udit Takkar <[email protected]> * New Crowdin translations by Github Action * chore: Simplified date overrides (#10728) * chore: Simplified date overrides * Fixed a test that had a date override that wasn't at midnight utc * Wrote test that showed a fixed Europe/Brussels * Lint fix * New Crowdin translations by Github Action * Fix offset time + fetching correct dates * Deal with awkward minute offsets * remove store overhead * Format H based on tz * Cleanup store logic * Cleanup * Remove comments * Remove comments * Remove yarn.lock * Dark mode & v-align text fixes * Move ButtonGroup to the left to prevent chevron from jumping * Shift based on timezone (non-hour) and have 15min granularity in hour display background color --------- Co-authored-by: Leo Giovanetti <[email protected]> Co-authored-by: Omar López <[email protected]> Co-authored-by: Crowdin Bot <[email protected]> Co-authored-by: Zain Gulbaz <[email protected]> Co-authored-by: Carina Wollendorfer <[email protected]> Co-authored-by: GitStart-Cal.com <[email protected]> Co-authored-by: gitstart-calcom <[email protected]> Co-authored-by: Keith Williams <[email protected]> Co-authored-by: Suyash Srivastava <[email protected]> Co-authored-by: Hariom Balhara <[email protected]> Co-authored-by: CarinaWolli <[email protected]> Co-authored-by: Shivam Kalra <[email protected]> Co-authored-by: alannnc <[email protected]> Co-authored-by: Alex van Andel <[email protected]> Co-authored-by: Joe Au-Yeung <[email protected]> Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: Anik Dhabal Babu <[email protected]> Co-authored-by: Pradumn Kumar <[email protected]> Co-authored-by: Raghul <[email protected]> Co-authored-by: Raghul D <[email protected]> Co-authored-by: ABDERRAHMANI IDRISSI HAMZA <[email protected]> Co-authored-by: Nafees Nazik <[email protected]> Co-authored-by: Danila <[email protected]> Co-authored-by: Udit Takkar <[email protected]>
This commit is contained in:
+15









sean-brydon
Omar López
Carina Wollendorfer
gitstart-calcom
Keith Williams
Hariom Balhara
CarinaWolli
Alex van Andel
Peer Richelsen
Raghul D
Udit Takkar
Leo Giovanetti
Crowdin Bot
Zain Gulbaz
GitStart-Cal.com
Suyash Srivastava
Shivam Kalra
alannnc
Joe Au-Yeung
Anik Dhabal Babu
Pradumn Kumar
Raghul
ABDERRAHMANI IDRISSI HAMZA
Nafees Nazik
Danila authored and
GitHub committed 2023-08-18 16:32:24 +00:00
1 parent
ea4618a244
commit
67bb2ed798
12 files changed
+791
-6
No files matched your search
@@ -1,11 +1,13 @@
|
||||
import authedProcedure from "../../../procedures/authedProcedure";
|
||||
import { router } from "../../../trpc";
|
||||
import { scheduleRouter } from "./schedule/_router";
|
||||
import { ZListTeamAvailaiblityScheme } from "./team/listTeamAvailability.schema";
|
||||
import { ZUserInputSchema } from "./user.schema";
|
||||
|
||||
type AvailabilityRouterHandlerCache = {
|
||||
list?: typeof import("./list.handler").listHandler;
|
||||
user?: typeof import("./user.handler").userHandler;
|
||||
listTeamAvailability?: typeof import("./team/listTeamAvailability.handler").listTeamAvailabilityHandler;
|
||||
};
|
||||
|
||||
const UNSTABLE_HANDLER_CACHE: AvailabilityRouterHandlerCache = {};
|
||||
@@ -41,6 +43,23 @@ export const availabilityRouter = router({
|
||||
input,
|
||||
});
|
||||
}),
|
||||
listTeam: authedProcedure.input(ZListTeamAvailaiblityScheme).query(async ({ ctx, input }) => {
|
||||
if (!UNSTABLE_HANDLER_CACHE.listTeamAvailability) {
|
||||
UNSTABLE_HANDLER_CACHE.listTeamAvailability = await import("./team/listTeamAvailability.handler").then(
|
||||
(mod) => mod.listTeamAvailabilityHandler
|
||||
);
|
||||
}
|
||||
|
||||
// Unreachable code but required for type safety
|
||||
if (!UNSTABLE_HANDLER_CACHE.listTeamAvailability) {
|
||||
throw new Error("Failed to load handler");
|
||||
}
|
||||
|
||||
return UNSTABLE_HANDLER_CACHE.listTeamAvailability({
|
||||
ctx,
|
||||
input,
|
||||
});
|
||||
}),
|
||||
|
||||
schedule: scheduleRouter,
|
||||
});
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import type { DateRange } from "@calcom/lib/date-ranges";
|
||||
import { buildDateRanges } from "@calcom/lib/date-ranges";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
import type { TrpcSessionUser } from "../../../../trpc";
|
||||
import type { TListTeamAvailaiblityScheme } from "./listTeamAvailability.schema";
|
||||
|
||||
type GetOptions = {
|
||||
ctx: {
|
||||
user: NonNullable<TrpcSessionUser>;
|
||||
};
|
||||
input: TListTeamAvailaiblityScheme;
|
||||
};
|
||||
|
||||
export const listTeamAvailabilityHandler = async ({ ctx, input }: GetOptions) => {
|
||||
const organizationId = ctx.user.organizationId;
|
||||
|
||||
if (!organizationId) {
|
||||
throw new TRPCError({ code: "NOT_FOUND", message: "User is not part of any organization." });
|
||||
}
|
||||
|
||||
const { cursor, limit } = input;
|
||||
|
||||
const getTotalMembers = await prisma.membership.count({
|
||||
where: {
|
||||
teamId: organizationId,
|
||||
},
|
||||
});
|
||||
|
||||
// I couldnt get this query to work direct on membership table
|
||||
const teamMembers = await prisma.membership.findMany({
|
||||
where: {
|
||||
teamId: organizationId,
|
||||
accepted: true,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
role: true,
|
||||
user: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
email: true,
|
||||
timeZone: true,
|
||||
defaultScheduleId: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
cursor: cursor ? { id: cursor } : undefined,
|
||||
take: limit + 1, // We take +1 as itll be used for the next cursor
|
||||
orderBy: {
|
||||
id: "asc",
|
||||
},
|
||||
});
|
||||
|
||||
let nextCursor: typeof cursor | undefined = undefined;
|
||||
if (teamMembers && teamMembers.length > limit) {
|
||||
const nextItem = teamMembers.pop();
|
||||
nextCursor = nextItem!.id;
|
||||
}
|
||||
|
||||
const dateFrom = dayjs(input.startDate).tz(input.loggedInUsersTz).subtract(1, "day");
|
||||
const dateTo = dayjs(input.endDate).tz(input.loggedInUsersTz).add(1, "day");
|
||||
|
||||
const buildMembers = teamMembers?.map(async (member) => {
|
||||
if (!member.user.defaultScheduleId) {
|
||||
return {
|
||||
id: member.user.id,
|
||||
username: member.user.username,
|
||||
email: member.user.email,
|
||||
timeZone: member.user.timeZone,
|
||||
role: member.role,
|
||||
dateRanges: [] as DateRange[],
|
||||
};
|
||||
}
|
||||
|
||||
const schedule = await prisma.schedule.findUnique({
|
||||
where: { id: member.user.defaultScheduleId },
|
||||
select: { availability: true, timeZone: true },
|
||||
});
|
||||
const timeZone = schedule?.timeZone || member.user.timeZone;
|
||||
|
||||
const dateRanges = buildDateRanges({
|
||||
dateFrom,
|
||||
dateTo,
|
||||
timeZone,
|
||||
availability: schedule?.availability ?? [],
|
||||
});
|
||||
|
||||
return {
|
||||
id: member.user.id,
|
||||
username: member.user.username,
|
||||
email: member.user.email,
|
||||
timeZone,
|
||||
role: member.role,
|
||||
dateRanges,
|
||||
};
|
||||
});
|
||||
|
||||
const members = await Promise.all(buildMembers);
|
||||
|
||||
return {
|
||||
rows: members || [],
|
||||
nextCursor,
|
||||
meta: {
|
||||
totalRowCount: getTotalMembers || 0,
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const ZListTeamAvailaiblityScheme = z.object({
|
||||
limit: z.number().min(1).max(100),
|
||||
cursor: z.number().nullish(),
|
||||
startDate: z.string(),
|
||||
endDate: z.string(),
|
||||
loggedInUsersTz: z.string(),
|
||||
});
|
||||
|
||||
export type TListTeamAvailaiblityScheme = z.infer<typeof ZListTeamAvailaiblityScheme>;
|
||||
Reference in new issue
Block a user