mirror of
https://github.com/hanzoai/calendar.git
synced 2026-10-30 14:46:43 +00:00
* refactor: remove attributes and segments entrypoints * fix: restore segment entrypoints * cleanup
101 lines
2.9 KiB
TypeScript
101 lines
2.9 KiB
TypeScript
"use client";
|
|
|
|
import { ColumnFilterType, type SystemFilterSegment } from "@calcom/features/data-table";
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import classNames from "@calcom/ui/classNames";
|
|
import dynamic from "next/dynamic";
|
|
import { usePathname, useRouter } from "next/navigation";
|
|
import { useCallback, useMemo } from "react";
|
|
import { DataTableProvider } from "~/data-table/DataTableProvider";
|
|
import { useSegments } from "~/data-table/hooks/useSegments";
|
|
import { BookingListContainer } from "../components/BookingListContainer";
|
|
import { useActiveFiltersValidator } from "../hooks/useActiveFiltersValidator";
|
|
import { useBookingsView } from "../hooks/useBookingsView";
|
|
import type { validStatuses } from "../lib/validStatuses";
|
|
|
|
const BookingCalendarContainer = dynamic(() =>
|
|
import("../components/BookingCalendarContainer").then((mod) => ({
|
|
default: mod.BookingCalendarContainer,
|
|
}))
|
|
);
|
|
|
|
type BookingsProps = {
|
|
status: (typeof validStatuses)[number];
|
|
userId?: number;
|
|
permissions: {
|
|
canReadOthersBookings: boolean;
|
|
};
|
|
bookingsV3Enabled: boolean;
|
|
bookingAuditEnabled: boolean;
|
|
};
|
|
|
|
function useSystemSegments(userId?: number) {
|
|
const { t } = useLocale();
|
|
|
|
const systemSegments: SystemFilterSegment[] = useMemo(() => {
|
|
if (!userId) return [];
|
|
|
|
return [
|
|
{
|
|
id: "my_bookings",
|
|
name: t("my_bookings"),
|
|
type: "system",
|
|
activeFilters: [
|
|
{
|
|
f: "userId",
|
|
v: {
|
|
type: ColumnFilterType.MULTI_SELECT,
|
|
data: [userId],
|
|
},
|
|
},
|
|
],
|
|
perPage: 10,
|
|
},
|
|
];
|
|
}, [userId, t]);
|
|
|
|
return systemSegments;
|
|
}
|
|
|
|
export default function Bookings(props: BookingsProps) {
|
|
const pathname = usePathname();
|
|
const systemSegments = useSystemSegments(props.userId);
|
|
const validateActiveFilters = useActiveFiltersValidator({
|
|
canReadOthersBookings: props.permissions.canReadOthersBookings,
|
|
});
|
|
if (!pathname) return null;
|
|
return (
|
|
<DataTableProvider
|
|
tableIdentifier={pathname}
|
|
useSegments={useSegments}
|
|
systemSegments={systemSegments}
|
|
validateActiveFilters={validateActiveFilters}>
|
|
<BookingsContent {...props} />
|
|
</DataTableProvider>
|
|
);
|
|
}
|
|
|
|
function BookingsContent({ status, permissions, bookingsV3Enabled, bookingAuditEnabled }: BookingsProps) {
|
|
const [view] = useBookingsView({ bookingsV3Enabled });
|
|
|
|
return (
|
|
<div className={classNames(view === "calendar" && "-mb-8")}>
|
|
{view === "list" && (
|
|
<BookingListContainer
|
|
status={status}
|
|
permissions={permissions}
|
|
bookingsV3Enabled={bookingsV3Enabled}
|
|
bookingAuditEnabled={bookingAuditEnabled}
|
|
/>
|
|
)}
|
|
{bookingsV3Enabled && view === "calendar" && (
|
|
<BookingCalendarContainer
|
|
status={status}
|
|
permissions={permissions}
|
|
bookingsV3Enabled={bookingsV3Enabled}
|
|
/>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|