Feature/booking filters (#6099)
* EventTypeFilter UI working * Tidy + fix avatar + fix overflow * Component store * WIP - switchin to query filtering instead of state * Push working * Checkbox approach - weird conditional toggle for all bookings * WIP * the master query hook :O * useTypedQuery * Working typed query * Typed query hook * Add optional keys * safeParse query params * Add use callback * Fix re-renders * Remove local version of local query and use util branch * Working team filters! * working people filter! * Tidy up * NIT Co-authored-by: zomars <[email protected]>
This commit is contained in:
1 parent
83b60de640
commit
cefcb1eaf8
20 files changed
+556
-51
No files matched your search
@@ -9,48 +9,56 @@ import { Maybe } from "@trpc/server";
|
||||
|
||||
export type AvatarProps = {
|
||||
className?: string;
|
||||
size: "sm" | "md" | "mdLg" | "lg";
|
||||
size: "xs" | "sm" | "md" | "mdLg" | "lg";
|
||||
imageSrc?: Maybe<string>;
|
||||
title?: string;
|
||||
alt: string;
|
||||
gravatarFallbackMd5?: string;
|
||||
fallback?: React.ReactNode;
|
||||
accepted?: boolean;
|
||||
asChild?: boolean; // Added to ignore the outer span on the fallback component - messes up styling
|
||||
};
|
||||
|
||||
const sizesPropsBySize = {
|
||||
sm: "w-6", // 24px
|
||||
md: "w-8", // 32px
|
||||
mdLg: "w-10", //40px
|
||||
lg: "w-16", // 64px
|
||||
xs: "w-4 h-4", // 16px
|
||||
sm: "w-6 h-6", // 24px
|
||||
md: "w-8 h-8", // 32px
|
||||
mdLg: "w-10 h-10", //40px
|
||||
lg: "w-16 h-16", // 64px
|
||||
} as const;
|
||||
|
||||
export function Avatar(props: AvatarProps) {
|
||||
const { imageSrc, gravatarFallbackMd5, size, alt, title } = props;
|
||||
const sizeClassname = sizesPropsBySize[size];
|
||||
const rootClass = classNames("rounded-full aspect-square", sizeClassname, "h-auto");
|
||||
const rootClass = classNames("rounded-full aspect-square ", sizeClassname);
|
||||
const avatar = (
|
||||
<AvatarPrimitive.Root
|
||||
className={classNames(
|
||||
sizeClassname,
|
||||
"dark:bg-darkgray-300 relative inline-block aspect-square overflow-hidden rounded-full"
|
||||
"dark:bg-darkgray-300 item-center relative inline-flex aspect-square justify-center overflow-hidden rounded-full"
|
||||
)}>
|
||||
<AvatarPrimitive.Image src={imageSrc ?? undefined} alt={alt} className={rootClass} />
|
||||
<AvatarPrimitive.Fallback delayMs={600}>
|
||||
{gravatarFallbackMd5 && (
|
||||
<img src={defaultAvatarSrc({ md5: gravatarFallbackMd5 })} alt={alt} className={rootClass} />
|
||||
)}
|
||||
</AvatarPrimitive.Fallback>
|
||||
{props.accepted && (
|
||||
<div
|
||||
className={classNames(
|
||||
"absolute bottom-0 right-0 block rounded-full bg-green-400 text-white ring-2 ring-white",
|
||||
size === "lg" ? "h-5 w-5" : "h-2 w-2"
|
||||
)}>
|
||||
<div className="flex h-full items-center justify-center p-[2px]">
|
||||
{size === "lg" && <Icon.FiCheck className="" />}
|
||||
<>
|
||||
<AvatarPrimitive.Image src={imageSrc ?? undefined} alt={alt} className={rootClass} />
|
||||
<AvatarPrimitive.Fallback delayMs={600} asChild={props.asChild}>
|
||||
<>
|
||||
{props.fallback && !gravatarFallbackMd5 && props.fallback}
|
||||
{gravatarFallbackMd5 && (
|
||||
<img src={defaultAvatarSrc({ md5: gravatarFallbackMd5 })} alt={alt} className={rootClass} />
|
||||
)}
|
||||
</>
|
||||
</AvatarPrimitive.Fallback>
|
||||
{props.accepted && (
|
||||
<div
|
||||
className={classNames(
|
||||
"absolute bottom-0 right-0 block rounded-full bg-green-400 text-white ring-2 ring-white",
|
||||
size === "lg" ? "h-5 w-5" : "h-2 w-2"
|
||||
)}>
|
||||
<div className="flex h-full items-center justify-center p-[2px]">
|
||||
{size === "lg" && <Icon.FiCheck />}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
)}
|
||||
</>
|
||||
</AvatarPrimitive.Root>
|
||||
);
|
||||
|
||||
|
||||
@@ -29,5 +29,6 @@ export {
|
||||
} from "./form";
|
||||
export { TopBanner } from "./top-banner";
|
||||
export type { TopBannerProps } from "./top-banner";
|
||||
export { AnimatedPopover } from "./popover/index";
|
||||
export { TableActions, DropdownActions } from "./table/TableActions";
|
||||
export type { ActionType } from "./table/TableActions";
|
||||
@@ -0,0 +1,72 @@
|
||||
import * as Popover from "@radix-ui/react-popover";
|
||||
import React from "react";
|
||||
|
||||
import { classNames } from "@calcom/lib";
|
||||
import { Icon } from "@calcom/ui";
|
||||
|
||||
export const AnimatedPopover = ({
|
||||
text,
|
||||
count,
|
||||
children,
|
||||
}: {
|
||||
text: string;
|
||||
count?: number;
|
||||
children: React.ReactNode;
|
||||
}) => {
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const ref = React.useRef<HTMLDivElement>(null);
|
||||
// calculate which aligment to open the popover with based on which half of the screen it is on (left or right)
|
||||
const [align, setAlign] = React.useState<"start" | "end">("start");
|
||||
React.useEffect(() => {
|
||||
const handleResize = () => {
|
||||
const halfWidth = window.innerWidth / 2;
|
||||
const { x, y } = ref?.current?.getBoundingClientRect() || {
|
||||
x: 0,
|
||||
y: 0,
|
||||
};
|
||||
if (x > halfWidth) {
|
||||
setAlign("end");
|
||||
} else {
|
||||
setAlign("start");
|
||||
}
|
||||
};
|
||||
handleResize();
|
||||
window.addEventListener("resize", handleResize);
|
||||
return () => {
|
||||
window.removeEventListener("resize", handleResize);
|
||||
};
|
||||
}, [setAlign]);
|
||||
|
||||
return (
|
||||
<Popover.Root onOpenChange={setOpen} modal={true}>
|
||||
<Popover.Trigger asChild>
|
||||
<div
|
||||
ref={ref}
|
||||
className="item-center mb-2 flex h-9 justify-between whitespace-nowrap rounded-md border border-gray-300 py-2 px-3
|
||||
text-sm placeholder:text-gray-400 hover:cursor-pointer hover:border-gray-400
|
||||
focus:border-neutral-300 focus:outline-none focus:ring-2 focus:ring-neutral-800 focus:ring-offset-1">
|
||||
<div className="max-w-36 flex items-center">
|
||||
<div className="truncate">
|
||||
{text}
|
||||
{count && count > 0 && (
|
||||
<div className="flex h-4 w-4 items-center justify-center rounded-full">{count}</div>
|
||||
)}
|
||||
</div>
|
||||
<Icon.FiChevronDown
|
||||
className={classNames("mt-auto ml-2 transition-transform duration-150", open && "rotate-180")}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Popover.Trigger>
|
||||
<Popover.Content side="bottom" align={align} asChild>
|
||||
<div
|
||||
className={classNames(
|
||||
"absolute z-50 mt-2 w-56 rounded-md bg-white shadow-sm ring-1 ring-black ring-opacity-5 focus-within:outline-none",
|
||||
align === "end" && "-translate-x-[228px]"
|
||||
)}>
|
||||
{children}
|
||||
</div>
|
||||
</Popover.Content>
|
||||
</Popover.Root>
|
||||
);
|
||||
};
|
||||
@@ -24,6 +24,7 @@ export {
|
||||
TextAreaField,
|
||||
TextField,
|
||||
TopBanner,
|
||||
AnimatedPopover,
|
||||
Select,
|
||||
SelectField,
|
||||
SelectWithValidation,
|
||||
@@ -100,7 +101,6 @@ export { ToggleGroup } from "./v2/core/form/ToggleGroup";
|
||||
export { default as ImageUploader } from "./v2/core/ImageUploader";
|
||||
export { default as AdminLayout, getLayout as getAdminLayout } from "./v2/core/layouts/AdminLayout";
|
||||
export { default as AppsLayout } from "./v2/core/layouts/AppsLayout";
|
||||
export { default as BookingLayout } from "./v2/core/layouts/BookingLayout";
|
||||
export { default as InstalledAppsLayout } from "./v2/core/layouts/InstalledAppsLayout";
|
||||
export { default as SettingsLayout, getLayout as getSettingsLayout } from "./v2/core/layouts/SettingsLayout";
|
||||
export { default as WizardLayout, getLayout as getWizardLayout } from "./v2/core/layouts/WizardLayout";
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
"@calcom/trpc": "*",
|
||||
"@formkit/auto-animate": "^1.0.0-beta.5",
|
||||
"@radix-ui/react-dialog": "^1.0.0",
|
||||
"@radix-ui/react-popover": "^1.0.2",
|
||||
"@radix-ui/react-portal": "^1.0.0",
|
||||
"@radix-ui/react-select": "^0.1.1",
|
||||
"@tanstack/react-query": "^4.3.9",
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
import React, { ComponentProps } from "react";
|
||||
|
||||
import type { VerticalTabItemProps } from "../";
|
||||
import { HorizontalTabs, VerticalTabs } from "../";
|
||||
import { Icon } from "../../../Icon";
|
||||
import Shell from "../Shell";
|
||||
import type { HorizontalTabItemProps } from "../navigation/tabs/HorizontalTabItem";
|
||||
|
||||
const tabs: (VerticalTabItemProps | HorizontalTabItemProps)[] = [
|
||||
{
|
||||
name: "upcoming",
|
||||
href: "/bookings/upcoming",
|
||||
icon: Icon.FiCalendar,
|
||||
},
|
||||
{
|
||||
name: "unconfirmed",
|
||||
href: "/bookings/unconfirmed",
|
||||
icon: Icon.FiInbox,
|
||||
},
|
||||
{
|
||||
name: "recurring",
|
||||
href: "/bookings/recurring",
|
||||
icon: Icon.FiRotateCcw,
|
||||
},
|
||||
{
|
||||
name: "past",
|
||||
href: "/bookings/past",
|
||||
icon: Icon.FiSunset,
|
||||
},
|
||||
{
|
||||
name: "cancelled",
|
||||
href: "/bookings/cancelled",
|
||||
icon: Icon.FiSlash,
|
||||
},
|
||||
];
|
||||
|
||||
export default function BookingLayout({
|
||||
children,
|
||||
...rest
|
||||
}: { children: React.ReactNode } & ComponentProps<typeof Shell>) {
|
||||
return (
|
||||
<Shell {...rest}>
|
||||
<div className="flex flex-col sm:space-x-2 xl:flex-row">
|
||||
<div className="hidden xl:block">
|
||||
<VerticalTabs tabs={tabs} sticky />
|
||||
</div>
|
||||
<div className="block xl:hidden">
|
||||
<HorizontalTabs tabs={tabs} />
|
||||
</div>
|
||||
<main className="w-full max-w-6xl">{children}</main>
|
||||
</div>
|
||||
</Shell>
|
||||
);
|
||||
}
|
||||
export const getLayout = (page: React.ReactElement) => <BookingLayout>{page}</BookingLayout>;
|
||||
Reference in new issue
Block a user