* refactor: import AppRouter from generated types instead of server source This change improves tRPC build performance by having the client-side code import AppRouter from pre-generated type declarations instead of traversing the entire server router tree. Changes: - Create type bridge file at packages/trpc/types/app-router.ts - Update packages/trpc/react/trpc.ts to import from the bridge - Update .gitignore to only ignore types/server (generated files) - Update eslint.config.mjs to only ignore types/server (generated files) The type bridge provides: 1. Faster typechecking - avoids parsing 458 server files 2. Stable import location that's easy to lint against 3. Single place to adjust if generated path changes Build order is already enforced in turbo.json (type-check depends on @calcom/trpc#build). Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * fix: move bridge file to react/ to avoid TS5055 error Move the AppRouter type bridge file from types/app-router.ts to react/app-router.ts to avoid the TS5055 'Cannot write file because it would overwrite input file' error. The issue was that placing the bridge file in types/ caused TypeScript to treat the generated .d.ts files as input files during the tRPC build, then fail when trying to emit to the same location. By placing the bridge in react/ (which is excluded from the tRPC server build), the bridge file is only used by client code and doesn't interfere with the server type generation. Changes: - Move bridge file from types/app-router.ts to react/app-router.ts - Update import in react/trpc.ts to use ./app-router - Revert .gitignore to ignore all of types/ (generated files) - Revert eslint.config.mjs to ignore all of types/** Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * refactor: split tRPC build into server and react phases - Create tsconfig.server.json for server-only type generation - Create tsconfig.react.json for react/client type generation - Update build script to run server build first, then react build - Remove || true so build properly fails on errors - This allows react code to import from generated server types Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * refactor: split @calcom/trpc exports to separate server and react entrypoints - Remove react exports from @calcom/trpc root (index.ts) - Update 89 files to import from @calcom/trpc/react instead of @calcom/trpc - This fixes the boundary leak where server builds were pulling in react code - Server build no longer compiles react/app-router.ts, fixing the chicken-and-egg issue where react code needed generated server types that didn't exist yet This improves TypeScript build performance by preventing the server type generation from traversing the entire react/client type graph. Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * fix: import WorkflowType from lib/types instead of React component This fixes a boundary leak where the server build was pulling in React components through the WorkflowRepository import chain. By importing WorkflowListType from lib/types instead of WorkflowListPage.tsx, the server build no longer traverses React component files. Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * fix: extract server-safe types to prevent boundary leaks in tRPC build - Extract ChildrenEventType to lib/childrenEventType.ts (server-safe) - Extract Slots type to calendars/lib/slots.ts (server-safe) - Create types.server.ts files for eventtypes and bookings - Update server code to import from server-safe type files - Update DatePicker.tsx to use extracted Slots type - Update app-store utils to use BookerEventForAppData type This prevents the server build from pulling in React files through transitive imports from @calcom/features barrel exports. Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * fix: update Segment.test.tsx mock path to @calcom/trpc/react The test was mocking @calcom/trpc but importing from @calcom/trpc/react. After the entrypoint separation, the mock path needs to match the import path. Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * fix: temporarily restore || true to unblock PR merge The pre-existing Prisma type errors (~345 errors) will be addressed in a follow-up PR. This allows the two-phase build architecture changes to be merged first. Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * Run trpc build as part of API v2 build * Removed the bridge file * refactor: extract event type schemas to server-safe file - Create packages/features/eventtypes/lib/schemas.ts with createEventTypeInput and EventTypeDuplicateInput - Update types.ts to re-export schemas from the new server-safe location - Update tRPC schema files to import from schemas.ts instead of types.server.ts - Delete types.server.ts (was duplicating ~200 lines unnecessarily) This keeps the server build graph clean while avoiding code duplication. Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * Removed the optionality of the tRPC builds * Removed the extra command for API v2 * refactor: rename calendars/lib/slots.ts to types.ts Per Keith's feedback, renamed the file to types.ts since it contains type definitions. Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * Added back tRPC build:server for API v2 --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Dhairyashil Shinde <93669429+dhairyashiil@users.noreply.github.com>
272 lines
9.5 KiB
TypeScript
272 lines
9.5 KiB
TypeScript
"use client";
|
|
|
|
import { keepPreviousData } from "@tanstack/react-query";
|
|
import type { ColumnDef } from "@tanstack/react-table";
|
|
import { getCoreRowModel, getFilteredRowModel, useReactTable } from "@tanstack/react-table";
|
|
import { usePathname } from "next/navigation";
|
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
|
|
import dayjs from "@calcom/dayjs";
|
|
import { DataTableProvider } from "@calcom/features/data-table/DataTableProvider";
|
|
import { DataTable, DataTableToolbar } from "@calcom/features/data-table/components";
|
|
import { useDataTable } from "@calcom/features/data-table/hooks";
|
|
import type { DateRange } from "@calcom/features/schedules/lib/date-ranges";
|
|
import { APP_NAME, WEBAPP_URL } from "@calcom/lib/constants";
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import { CURRENT_TIMEZONE } from "@calcom/lib/timezoneConstants";
|
|
import type { MembershipRole } from "@calcom/prisma/enums";
|
|
import { trpc } from "@calcom/trpc/react";
|
|
import type { UserProfile } from "@calcom/types/UserProfile";
|
|
import { UserAvatar } from "@calcom/ui/components/avatar";
|
|
import { Button } from "@calcom/ui/components/button";
|
|
import { ButtonGroup } from "@calcom/ui/components/buttonGroup";
|
|
|
|
import { UpgradeTip } from "../../tips/UpgradeTip";
|
|
import { createTimezoneBuddyStore, TBContext } from "../store";
|
|
import { AvailabilityEditSheet } from "./AvailabilityEditSheet";
|
|
import { CellHighlightContainer } from "./CellHighlightContainer";
|
|
import { TimeDial } from "./TimeDial";
|
|
|
|
export interface SliderUser {
|
|
id: number;
|
|
username: string | null;
|
|
name: string | null;
|
|
organizationId: number;
|
|
avatarUrl: string | null;
|
|
email: string;
|
|
timeZone: string;
|
|
role: MembershipRole;
|
|
defaultScheduleId: number | null;
|
|
dateRanges: DateRange[];
|
|
profile: UserProfile;
|
|
}
|
|
|
|
function UpgradeTeamTip() {
|
|
const { t } = useLocale();
|
|
|
|
return (
|
|
<UpgradeTip
|
|
plan="team"
|
|
title={t("calcom_is_better_with_team", { appName: APP_NAME }) as string}
|
|
description={t("add_your_team_members")}
|
|
background="/tips/teams"
|
|
features={[]}
|
|
buttons={
|
|
<div className="stack-y-2 rtl:space-x-reverse sm:space-x-2">
|
|
<ButtonGroup>
|
|
<Button color="primary" href={`${WEBAPP_URL}/settings/teams/new`}>
|
|
{t("create_team")}
|
|
</Button>
|
|
<Button color="minimal" href="https://go.cal.com/teams-video" target="_blank">
|
|
{t("learn_more")}
|
|
</Button>
|
|
</ButtonGroup>
|
|
</div>
|
|
}>
|
|
<></>
|
|
</UpgradeTip>
|
|
);
|
|
}
|
|
|
|
export function AvailabilitySliderTable(props: { isOrg: boolean }) {
|
|
const pathname = usePathname();
|
|
if (!pathname) return null;
|
|
return (
|
|
<DataTableProvider tableIdentifier={pathname}>
|
|
<AvailabilitySliderTableContent {...props} />
|
|
</DataTableProvider>
|
|
);
|
|
}
|
|
|
|
function AvailabilitySliderTableContent(props: { isOrg: boolean }) {
|
|
const tableContainerRef = useRef<HTMLDivElement>(null);
|
|
const [browsingDate, setBrowsingDate] = useState(dayjs());
|
|
const [editSheetOpen, setEditSheetOpen] = useState(false);
|
|
const [selectedUser, setSelectedUser] = useState<SliderUser | null>(null);
|
|
const { searchTerm } = useDataTable();
|
|
|
|
const { data, isPending, fetchNextPage, isFetching } = trpc.viewer.availability.listTeam.useInfiniteQuery(
|
|
{
|
|
limit: 10,
|
|
loggedInUsersTz: CURRENT_TIMEZONE,
|
|
startDate: browsingDate.startOf("day").toISOString(),
|
|
endDate: browsingDate.endOf("day").toISOString(),
|
|
searchString: searchTerm,
|
|
},
|
|
{
|
|
getNextPageParam: (lastPage) => lastPage.nextCursor,
|
|
placeholderData: keepPreviousData,
|
|
}
|
|
);
|
|
|
|
const memorisedColumns = useMemo(() => {
|
|
const cols: ColumnDef<SliderUser>[] = [
|
|
{
|
|
id: "member",
|
|
accessorFn: (data) => data.username,
|
|
enableHiding: false,
|
|
enableSorting: false,
|
|
header: "Member",
|
|
size: 200,
|
|
cell: ({ row }) => {
|
|
const { username, email, timeZone, name, avatarUrl, profile } = row.original;
|
|
return (
|
|
<div className="max-w-64 flex shrink-0 items-center gap-2 overflow-hidden">
|
|
<UserAvatar
|
|
size="sm"
|
|
user={{
|
|
username,
|
|
name,
|
|
avatarUrl,
|
|
profile,
|
|
}}
|
|
/>
|
|
<div className="">
|
|
<div className="text-emphasis max-w-64 truncate text-sm font-medium" title={email}>
|
|
{username || "No username"}
|
|
</div>
|
|
<div className="text-subtle text-xs leading-none">{timeZone}</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
},
|
|
filterFn: (row, id, value) => {
|
|
return row.original.username?.toLowerCase().includes(value.toLowerCase()) || false;
|
|
},
|
|
},
|
|
{
|
|
id: "timezone",
|
|
accessorFn: (data) => data.timeZone,
|
|
header: "Timezone",
|
|
enableHiding: false,
|
|
enableSorting: false,
|
|
size: 160,
|
|
cell: ({ row }) => {
|
|
const { timeZone } = row.original;
|
|
const timeRaw = dayjs().tz(timeZone);
|
|
const time = timeRaw.format("HH:mm");
|
|
const utcOffsetInMinutes = timeRaw.utcOffset();
|
|
const hours = Math.abs(Math.floor(utcOffsetInMinutes / 60));
|
|
const minutes = Math.abs(utcOffsetInMinutes % 60);
|
|
const offsetFormatted = `${utcOffsetInMinutes < 0 ? "-" : "+"}${hours
|
|
.toString()
|
|
.padStart(2, "0")}:${minutes.toString().padStart(2, "0")}`;
|
|
|
|
return (
|
|
<div className="flex flex-col text-center">
|
|
<span className="text-default text-sm font-medium">{time}</span>
|
|
<span className="text-subtle text-xs leading-none">GMT {offsetFormatted}</span>
|
|
</div>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
id: "slider",
|
|
meta: {
|
|
autoWidth: true,
|
|
},
|
|
enableHiding: false,
|
|
enableSorting: false,
|
|
header: () => {
|
|
return (
|
|
<div className="flex items-center space-x-2">
|
|
<ButtonGroup containerProps={{ className: "space-x-0" }}>
|
|
<Button
|
|
color="minimal"
|
|
variant="icon"
|
|
StartIcon="chevron-left"
|
|
onClick={() => setBrowsingDate(browsingDate.subtract(1, "day"))}
|
|
/>
|
|
<Button
|
|
onClick={() => setBrowsingDate(browsingDate.add(1, "day"))}
|
|
color="minimal"
|
|
StartIcon="chevron-right"
|
|
variant="icon"
|
|
/>
|
|
</ButtonGroup>
|
|
<span>{browsingDate.format("LL")}</span>
|
|
</div>
|
|
);
|
|
},
|
|
cell: ({ row }) => {
|
|
const { timeZone, dateRanges } = row.original;
|
|
// return <pre>{JSON.stringify(dateRanges, null, 2)}</pre>;
|
|
return <TimeDial timezone={timeZone} dateRanges={dateRanges} />;
|
|
},
|
|
},
|
|
];
|
|
|
|
return cols;
|
|
}, [browsingDate]);
|
|
|
|
//we must flatten the array of arrays from the useInfiniteQuery hook
|
|
const flatData = useMemo(() => data?.pages?.flatMap((page) => page.rows) ?? [], [data]) as SliderUser[];
|
|
const totalRowCount = data?.pages?.[0]?.meta?.totalRowCount ?? 0;
|
|
const totalFetched = flatData.length;
|
|
|
|
//called on scroll and possibly on mount to fetch more data as the user scrolls and reaches bottom of table
|
|
const fetchMoreOnBottomReached = useCallback(
|
|
(containerRefElement?: HTMLDivElement | null) => {
|
|
if (containerRefElement) {
|
|
const { scrollHeight, scrollTop, clientHeight } = containerRefElement;
|
|
//once the user has scrolled within 300px of the bottom of the table, fetch more data if there is any
|
|
if (scrollHeight - scrollTop - clientHeight < 300 && !isFetching && totalFetched < totalRowCount) {
|
|
fetchNextPage();
|
|
}
|
|
}
|
|
},
|
|
[fetchNextPage, isFetching, totalFetched, totalRowCount]
|
|
);
|
|
|
|
useEffect(() => {
|
|
fetchMoreOnBottomReached(tableContainerRef.current);
|
|
}, [fetchMoreOnBottomReached]);
|
|
|
|
const table = useReactTable({
|
|
data: flatData,
|
|
columns: memorisedColumns,
|
|
getCoreRowModel: getCoreRowModel(),
|
|
getFilteredRowModel: getFilteredRowModel(),
|
|
});
|
|
|
|
// This means they are not apart of any teams so we show the upgrade tip
|
|
if (!flatData.length && !data?.pages?.[0]?.meta?.isApartOfAnyTeam) return <UpgradeTeamTip />;
|
|
|
|
return (
|
|
<TBContext.Provider
|
|
value={createTimezoneBuddyStore({
|
|
browsingDate: browsingDate.toDate(),
|
|
})}>
|
|
<>
|
|
<CellHighlightContainer>
|
|
<DataTable
|
|
table={table}
|
|
tableContainerRef={tableContainerRef}
|
|
onRowMouseclick={(row) => {
|
|
if (props.isOrg) {
|
|
setEditSheetOpen(true);
|
|
setSelectedUser(row.original);
|
|
}
|
|
}}
|
|
isPending={isPending}
|
|
onScroll={(e) => fetchMoreOnBottomReached(e.target as HTMLDivElement)}>
|
|
<DataTableToolbar.Root>
|
|
<DataTableToolbar.SearchBar />
|
|
</DataTableToolbar.Root>
|
|
</DataTable>
|
|
</CellHighlightContainer>
|
|
{selectedUser && editSheetOpen ? (
|
|
<AvailabilityEditSheet
|
|
open={editSheetOpen}
|
|
onOpenChange={(e) => {
|
|
setEditSheetOpen(e);
|
|
setSelectedUser(null); // We need to clear the user here or else the sheet will not re-render when opening a new user
|
|
}}
|
|
selectedUser={selectedUser}
|
|
/>
|
|
) : null}
|
|
</>
|
|
</TBContext.Provider>
|
|
);
|
|
}
|