Chor/bulk UI migration (#6367)
* Big bulk commit * Switch and settings toggle * Popover Kbar Timezones * Image Uploader * Fix core export * Meta * Swatch * Remove shell * Fix shell imports * Moved ShellSubHeading component to UI, to prevent recursive imports from shell component * Removed shell from ui ts config since shell doesnt have a dependency on shell anymore. Co-authored-by: Jeroen Reumkens <[email protected]> Co-authored-by: Omar López <[email protected]>
This commit is contained in:
62 files changed
+194
-157
No files matched your search
@@ -1,35 +0,0 @@
|
||||
# Whatsup with all these version?
|
||||
|
||||
We're currently in the progress of merging multiple versions of our UI library into one new version.
|
||||
|
||||
## Version 1
|
||||
|
||||
Anything version 1 is in the root, or in the root folders skeleton, form, booker and apps.
|
||||
|
||||
## Version 2
|
||||
|
||||
Anything version 2 is in the v2 folder
|
||||
|
||||
## New version
|
||||
|
||||
We're currently creating all new components following new standards in the components directory. The /styles directory contains the shared tailwind styles.
|
||||
|
||||
### Adding new components
|
||||
|
||||
For adding new components it is important to take a few patterns into account:
|
||||
|
||||
- All components should be added in /components
|
||||
- All components should be in a folder, no tsx files directly in the root
|
||||
- All components should contain stories and MDX documentation (which is why they can't live in the root, since that would result in a lot of duplication)
|
||||
|
||||
### Migration process
|
||||
|
||||
We're currently migrating existing components step by step, this process looks as following:
|
||||
|
||||
- New components only should get added in /components
|
||||
- Any existing components in v2 are reviewed, updated if needed and then moved to the /components directory
|
||||
- After v2 is moved, the old v2 component should be deleted, as well as any v1 version of that component. All places in the monorepo where we use this component, should use the newest version by then.
|
||||
|
||||
### End state
|
||||
|
||||
The envisioned end state is a state where only the /components directory exists. In this directory all components should have documentation and stories.
|
||||
@@ -1,5 +1,5 @@
|
||||
import Meta from "../../v2/core/Meta";
|
||||
import { ShellSubHeading } from "../../v2/core/Shell";
|
||||
import { ShellSubHeading } from "../layout";
|
||||
import Meta from "../meta/Meta";
|
||||
import { SkeletonText } from "../skeleton";
|
||||
|
||||
export function SkeletonLoader({
|
||||
|
||||
@@ -2,9 +2,9 @@ import Link from "next/link";
|
||||
|
||||
import { classNames } from "@calcom/lib";
|
||||
|
||||
import { Icon } from "../../..";
|
||||
import { Badge, BadgeProps } from "../../../components";
|
||||
import { Divider } from "../../../components/divider";
|
||||
import { Badge, BadgeProps } from "..";
|
||||
import { Icon } from "../..";
|
||||
import { Divider } from "../divider";
|
||||
|
||||
type Action = { check: () => boolean; fn: () => void };
|
||||
export default function FormCard({
|
||||
@@ -1,3 +1,4 @@
|
||||
export { default as Card } from "./Card";
|
||||
export type { BaseCardProps } from "./Card";
|
||||
export { StepCard } from "./StepCard";
|
||||
export { default as FormCard } from "./FormCard";
|
||||
+1
-1
@@ -3,7 +3,7 @@ import { HexColorInput, HexColorPicker } from "react-colorful";
|
||||
|
||||
import { fallBackHex, isValidHexCode } from "@calcom/lib/CustomBranding";
|
||||
|
||||
import { Swatch } from "../..";
|
||||
import { Swatch } from "../../..";
|
||||
|
||||
type Handler = (event: MouseEvent | Event) => void;
|
||||
function useEventListener<
|
||||
File renamed without changes.
@@ -0,0 +1,16 @@
|
||||
export {
|
||||
Dropdown,
|
||||
ButtonOrLink,
|
||||
DropdownItem,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuRadioGroup,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenuTriggerItem,
|
||||
} from "./Dropdown";
|
||||
@@ -23,3 +23,23 @@ export type { ITimezone, ITimezoneOption } from "./timezone-select";
|
||||
export { DateRangePickerLazy as DateRangePicker } from "./date-range-picker";
|
||||
export { BooleanToggleGroup, BooleanToggleGroupField, ToggleGroup, ToggleGroupItem } from "./toggleGroup";
|
||||
export { DatePicker } from "./datepicker";
|
||||
export { FormStep, Steps, Stepper } from "./step";
|
||||
export { WizardForm } from "./wizard";
|
||||
export { default as ColorPicker } from "./color-picker/colorpicker";
|
||||
export {
|
||||
Dropdown,
|
||||
ButtonOrLink,
|
||||
DropdownItem,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuRadioGroup,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenuTriggerItem,
|
||||
} from "./dropdown";
|
||||
export { SettingsToggle, Switch } from "./switch";
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,3 @@
|
||||
export { default as FormStep } from "./FormStep";
|
||||
export { Steps } from "./Steps";
|
||||
export { default as Stepper } from "./Stepper";
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
import { useAutoAnimate } from "@formkit/auto-animate/react";
|
||||
import { ReactNode } from "react";
|
||||
|
||||
import { Label } from "../../components/form";
|
||||
import { Label } from "..";
|
||||
import Switch from "./Switch";
|
||||
|
||||
type Props = {
|
||||
File renamed without changes.
@@ -0,0 +1,2 @@
|
||||
export { default as SettingsToggle } from "./SettingsToggle";
|
||||
export { default as Switch } from "./Switch";
|
||||
+1
-1
@@ -3,7 +3,7 @@ import { ComponentProps } from "react";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
|
||||
import { Button, Stepper } from "../..";
|
||||
import { Button, Stepper } from "../../..";
|
||||
|
||||
type DefaultStep = {
|
||||
title: string;
|
||||
@@ -0,0 +1 @@
|
||||
export { default as WizardForm } from "./WizardForm";
|
||||
+1
-1
@@ -4,7 +4,7 @@ import Cropper from "react-easy-crop";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
|
||||
import { Button, Dialog, DialogClose, DialogContent, DialogTrigger } from "../../";
|
||||
import { Button, Dialog, DialogClose, DialogContent, DialogTrigger } from "../..";
|
||||
|
||||
type ReadAsMethod = "readAsText" | "readAsDataURL" | "readAsArrayBuffer" | "readAsBinaryString";
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export { default as ImageUploader } from "./ImageUploader";
|
||||
@@ -35,6 +35,27 @@ export {
|
||||
ToggleGroup,
|
||||
ToggleGroupItem,
|
||||
getReactSelectProps,
|
||||
ColorPicker,
|
||||
FormStep,
|
||||
Dropdown,
|
||||
DropdownItem,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuRadioGroup,
|
||||
ButtonOrLink,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuTriggerItem,
|
||||
Steps,
|
||||
WizardForm,
|
||||
SettingsToggle,
|
||||
Stepper,
|
||||
Switch,
|
||||
} from "./form";
|
||||
export type { ITimezone, ITimezoneOption } from "./form";
|
||||
export {
|
||||
@@ -49,7 +70,7 @@ export {
|
||||
} from "./apps";
|
||||
export { TopBanner } from "./top-banner";
|
||||
export type { TopBannerProps } from "./top-banner";
|
||||
export { AnimatedPopover } from "./popover/index";
|
||||
export { AnimatedPopover, MeetingTimeInTimezones } from "./popover";
|
||||
export { TableActions, DropdownActions } from "./table/TableActions";
|
||||
export type { ActionType } from "./table/TableActions";
|
||||
export { Icon } from "./icon";
|
||||
@@ -63,10 +84,17 @@ export { EmptyScreen } from "./empty-screen";
|
||||
export { List, ListItem, ListItemText, ListItemTitle, ListLinkItem } from "./list";
|
||||
export type { ListItemProps, ListProps } from "./list";
|
||||
export { HeadSeo } from "./head-seo";
|
||||
export { Skeleton, SkeletonAvatar, SkeletonButton, SkeletonContainer, SkeletonText } from "./skeleton";
|
||||
export {
|
||||
Skeleton,
|
||||
SkeletonAvatar,
|
||||
SkeletonButton,
|
||||
SkeletonContainer,
|
||||
SkeletonText,
|
||||
Loader,
|
||||
} from "./skeleton";
|
||||
export { HorizontalTabs, HorizontalTabItem, VerticalTabs, VerticalTabItem } from "./navigation";
|
||||
export type { HorizontalTabItemProps, NavTabProps, VerticalTabItemProps } from "./navigation";
|
||||
export { Card, StepCard } from "./card";
|
||||
export { Card, StepCard, FormCard } from "./card";
|
||||
export type { BaseCardProps } from "./card";
|
||||
export { Tooltip } from "./tooltip";
|
||||
export { Editor, AddVariablesDropdown } from "./editor";
|
||||
@@ -81,3 +109,6 @@ export {
|
||||
} from "./dialog";
|
||||
export type { DialogProps, ConfirmationDialogContentProps } from "./dialog";
|
||||
export { showToast } from "./toast"; // We don't export the toast components as they are only used in local storybook file
|
||||
export { Meta, MetaProvider, useMeta } from "./meta";
|
||||
export { Swatch } from "./swatch";
|
||||
export { ShellSubHeading } from "./layout";
|
||||
@@ -0,0 +1,22 @@
|
||||
import { ReactNode } from "react";
|
||||
|
||||
import { classNames } from "@calcom/lib";
|
||||
|
||||
export function ShellSubHeading(props: {
|
||||
title: ReactNode;
|
||||
subtitle?: ReactNode;
|
||||
actions?: ReactNode;
|
||||
className?: string;
|
||||
}) {
|
||||
return (
|
||||
<header className={classNames("mb-3 block justify-between sm:flex", props.className)}>
|
||||
<div>
|
||||
<h2 className="flex content-center items-center space-x-2 text-base font-bold leading-6 text-gray-900 rtl:space-x-reverse">
|
||||
{props.title}
|
||||
</h2>
|
||||
{props.subtitle && <p className="text-sm text-neutral-500 ltr:mr-4">{props.subtitle}</p>}
|
||||
</div>
|
||||
{props.actions && <div className="mt-2 flex-shrink-0 sm:mt-0">{props.actions}</div>}
|
||||
</header>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { ShellSubHeading } from "./ShellSubHeading";
|
||||
File renamed without changes.
@@ -0,0 +1 @@
|
||||
export { default as Meta, MetaProvider, useMeta } from "./Meta";
|
||||
File renamed without changes.
+1
-1
@@ -7,7 +7,7 @@ import {
|
||||
sortByTimezone,
|
||||
} from "@calcom/lib/date-fns";
|
||||
|
||||
import { Icon } from "../../components/icon";
|
||||
import { Icon } from "../icon";
|
||||
import { Attendee } from ".prisma/client";
|
||||
|
||||
interface MeetingTimeInTimezonesProps {
|
||||
@@ -0,0 +1,2 @@
|
||||
export { AnimatedPopover } from "./AnimatedPopover";
|
||||
export { default as MeetingTimeInTimezones } from "./MeetingTimeInTimezones";
|
||||
File renamed without changes.
@@ -94,3 +94,4 @@ const SkeletonContainer: React.FC<SkeletonContainer> = ({ children, as, classNam
|
||||
};
|
||||
|
||||
export { Skeleton, SkeletonAvatar, SkeletonText, SkeletonButton, SkeletonContainer };
|
||||
export { default as Loader } from "./Loader";
|
||||
File renamed without changes.
@@ -0,0 +1 @@
|
||||
export { default as Swatch } from "./Swatch";
|
||||
+30
-23
@@ -81,7 +81,36 @@ export {
|
||||
ToggleGroup,
|
||||
ToggleGroupItem,
|
||||
showToast,
|
||||
ShellSubHeading,
|
||||
DatePicker as DatePickerField,
|
||||
FormCard,
|
||||
FormStep,
|
||||
ColorPicker,
|
||||
Dropdown,
|
||||
DropdownItem,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuRadioGroup,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuTriggerItem,
|
||||
WizardForm,
|
||||
Stepper,
|
||||
Steps,
|
||||
Switch,
|
||||
SettingsToggle,
|
||||
MeetingTimeInTimezones,
|
||||
Loader,
|
||||
Meta,
|
||||
MetaProvider,
|
||||
useMeta,
|
||||
Swatch,
|
||||
Logo,
|
||||
} from "./components";
|
||||
export type {
|
||||
ActionType,
|
||||
@@ -107,22 +136,7 @@ export { default as CheckboxField } from "./components/form/checkbox/Checkbox";
|
||||
export { default as AddressInput } from "./form/AddressInputLazy";
|
||||
export { default as PhoneInput } from "./form/PhoneInputLazy";
|
||||
export { UnstyledSelect } from "./form/Select";
|
||||
export { default as Loader } from "./v2/core/Loader";
|
||||
|
||||
export { SettingsToggle, Swatch, Switch } from "./v2";
|
||||
export { default as Shell, ShellMain, MobileNavigationMoreItems, ShellSubHeading } from "./v2/core/Shell";
|
||||
|
||||
export { default as ColorPicker } from "./v2/core/colorpicker";
|
||||
export {
|
||||
Dropdown,
|
||||
DropdownItem,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "./v2/core/Dropdown";
|
||||
export {
|
||||
RadioGroup,
|
||||
/* TODO: solve this conflict -> Select, */
|
||||
@@ -131,13 +145,6 @@ export {
|
||||
RadioField,
|
||||
} from "./form/radio-area";
|
||||
|
||||
export {} from "./components/form/date-range-picker";
|
||||
export { default as FormCard } from "./v2/core/form/FormCard";
|
||||
export { default as MultiSelectCheckboxes } from "./components/form/checkbox/MultiSelectCheckboxes";
|
||||
export type { Option as MultiSelectCheckboxesOptionType } from "./components/form/checkbox/MultiSelectCheckboxes";
|
||||
export { default as ImageUploader } from "./v2/core/ImageUploader";
|
||||
export { default as MeetingTimeInTimezones } from "./v2/core/MeetingTimeInTimezones";
|
||||
export { default as Meta, MetaProvider, useMeta } from "./v2/core/Meta";
|
||||
export { default as Stepper } from "./v2/core/Stepper";
|
||||
export { Steps } from "./v2/core/Steps";
|
||||
export { default as WizardForm } from "./v2/core/WizardForm";
|
||||
export { default as ImageUploader } from "./components/image-uploader/ImageUploader";
|
||||
@@ -1,331 +0,0 @@
|
||||
import {
|
||||
KBarAnimator,
|
||||
KBarPortal,
|
||||
KBarPositioner,
|
||||
KBarProvider,
|
||||
KBarResults,
|
||||
KBarSearch,
|
||||
useKBar,
|
||||
useMatches,
|
||||
} from "kbar";
|
||||
import { useRouter } from "next/router";
|
||||
import { useMemo } from "react";
|
||||
|
||||
import { appStoreMetadata } from "@calcom/app-store/apps.metadata.generated";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { isMac } from "@calcom/lib/isMac";
|
||||
import { RouterOutputs, trpc } from "@calcom/trpc/react";
|
||||
|
||||
import { Icon, Tooltip } from "../../";
|
||||
|
||||
type shortcutArrayType = {
|
||||
shortcuts?: string[];
|
||||
};
|
||||
|
||||
type EventTypeGroups = RouterOutputs["viewer"]["eventTypes"]["getByViewer"]["eventTypeGroups"];
|
||||
type EventTypeGroup = EventTypeGroups[number];
|
||||
type EventType = EventTypeGroup["eventTypes"][number];
|
||||
|
||||
type KBarAction = {
|
||||
perform: () => Promise<boolean>;
|
||||
id: string;
|
||||
name: string;
|
||||
section: string;
|
||||
keywords: string;
|
||||
};
|
||||
|
||||
const getApps = Object.values(appStoreMetadata).map(({ name, slug }) => ({
|
||||
id: slug,
|
||||
name,
|
||||
section: "Installable Apps",
|
||||
keywords: `app ${name}`,
|
||||
}));
|
||||
|
||||
export const KBarRoot = ({ children }: { children: React.ReactNode }) => {
|
||||
const router = useRouter();
|
||||
const { data } = trpc.viewer.eventTypes.getByViewer.useQuery();
|
||||
|
||||
// grab link to events
|
||||
// quick nested actions would be extremely useful
|
||||
const appStoreActions = useMemo(
|
||||
() => getApps.map((item) => ({ ...item, perform: () => router.push(`/apps/${item.id}`) })),
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[]
|
||||
);
|
||||
|
||||
if (!data) return null;
|
||||
|
||||
const eventTypes =
|
||||
data?.eventTypeGroups.reduce((acc: EventType[], group: EventTypeGroup): EventType[] => {
|
||||
acc.push(...group.eventTypes);
|
||||
return acc;
|
||||
}, [] as EventType[]) || [];
|
||||
|
||||
const eventTypeActions =
|
||||
eventTypes.map(
|
||||
(item: EventType): KBarAction => ({
|
||||
id: `event-type-${item.id}`,
|
||||
name: item.title,
|
||||
section: "event_types_page_title",
|
||||
keywords: "event types",
|
||||
perform: () => router.push(`/event-types/${item.id}`),
|
||||
})
|
||||
) || [];
|
||||
|
||||
const actions = [
|
||||
// {
|
||||
// id: "toggle-idle",
|
||||
// name: "Test Function",
|
||||
// section: "Status",
|
||||
// shortcut: ["t", "f"],
|
||||
// keywords: "set yourself away bookings",
|
||||
// perform: () => alert("Hello World"),
|
||||
// },
|
||||
|
||||
{
|
||||
id: "workflows",
|
||||
name: "workflows",
|
||||
section: "workflows",
|
||||
shortcut: ["w", "f"],
|
||||
keywords: "workflows automation",
|
||||
perform: () => router.push("/workflows"),
|
||||
},
|
||||
{
|
||||
id: "event-types",
|
||||
name: "event_types_page_title",
|
||||
section: "event_types_page_title",
|
||||
shortcut: ["e", "t"],
|
||||
keywords: "event types",
|
||||
perform: () => router.push("/event-types"),
|
||||
},
|
||||
{
|
||||
id: "app-store",
|
||||
name: "app_store",
|
||||
section: "apps",
|
||||
shortcut: ["a", "s"],
|
||||
keywords: "app store",
|
||||
perform: () => router.push("/apps"),
|
||||
},
|
||||
{
|
||||
id: "upcoming-bookings",
|
||||
name: "upcoming",
|
||||
section: "bookings",
|
||||
shortcut: ["u", "b"],
|
||||
keywords: "upcoming bookings",
|
||||
perform: () => router.push("/bookings/upcoming"),
|
||||
},
|
||||
{
|
||||
id: "recurring-bookings",
|
||||
name: "recurring",
|
||||
section: "bookings",
|
||||
shortcut: ["r", "b"],
|
||||
keywords: "recurring bookings",
|
||||
perform: () => router.push("/bookings/recurring"),
|
||||
},
|
||||
{
|
||||
id: "past-bookings",
|
||||
name: "past",
|
||||
section: "bookings",
|
||||
shortcut: ["p", "b"],
|
||||
keywords: "past bookings",
|
||||
perform: () => router.push("/bookings/past"),
|
||||
},
|
||||
{
|
||||
id: "cancelled-bookings",
|
||||
name: "cancelled",
|
||||
section: "bookings",
|
||||
shortcut: ["c", "b"],
|
||||
keywords: "cancelled bookings",
|
||||
perform: () => router.push("/bookings/cancelled"),
|
||||
},
|
||||
{
|
||||
id: "schedule",
|
||||
name: "availability",
|
||||
section: "availability",
|
||||
shortcut: ["s", "a"],
|
||||
keywords: "schedule availability",
|
||||
perform: () => router.push("/availability"),
|
||||
},
|
||||
{
|
||||
id: "profile",
|
||||
name: "profile",
|
||||
section: "profile",
|
||||
shortcut: ["p", "s"],
|
||||
keywords: "setting profile",
|
||||
perform: () => router.push("/settings/my-account/profile"),
|
||||
},
|
||||
{
|
||||
id: "avatar",
|
||||
name: "change_avatar",
|
||||
section: "profile",
|
||||
shortcut: ["c", "a"],
|
||||
keywords: "remove change modify avatar",
|
||||
perform: () => router.push("/settings/my-account/profile"),
|
||||
},
|
||||
{
|
||||
id: "timezone",
|
||||
name: "timezone",
|
||||
section: "profile",
|
||||
shortcut: ["c", "t"],
|
||||
keywords: "change modify timezone",
|
||||
perform: () => router.push("/settings/my-account/general"),
|
||||
},
|
||||
{
|
||||
id: "brand-color",
|
||||
name: "brand_color",
|
||||
section: "profile",
|
||||
shortcut: ["b", "c"],
|
||||
keywords: "change modify brand color",
|
||||
perform: () => router.push("/settings/my-account/appearance"),
|
||||
},
|
||||
{
|
||||
id: "teams",
|
||||
name: "teams",
|
||||
shortcut: ["t", "s"],
|
||||
keywords: "add manage modify team",
|
||||
perform: () => router.push("/settings/teams"),
|
||||
},
|
||||
{
|
||||
id: "password",
|
||||
name: "change_password",
|
||||
section: "security",
|
||||
shortcut: ["c", "p"],
|
||||
keywords: "change modify password",
|
||||
perform: () => router.push("/settings/security/password"),
|
||||
},
|
||||
{
|
||||
id: "two-factor",
|
||||
name: "two_factor_auth",
|
||||
section: "security",
|
||||
shortcut: ["t", "f", "a"],
|
||||
keywords: "two factor authentication",
|
||||
perform: () => router.push("/settings/security/two-factor-auth"),
|
||||
},
|
||||
{
|
||||
id: "impersonation",
|
||||
name: "user_impersonation_heading",
|
||||
section: "security",
|
||||
shortcut: ["u", "i"],
|
||||
keywords: "user impersonation",
|
||||
perform: () => router.push("/settings/security/impersonation"),
|
||||
},
|
||||
{
|
||||
id: "webhooks",
|
||||
name: "Webhooks",
|
||||
section: "developer",
|
||||
shortcut: ["w", "h"],
|
||||
keywords: "webhook automation",
|
||||
perform: () => router.push("/settings/developer/webhooks"),
|
||||
},
|
||||
{
|
||||
id: "api-keys",
|
||||
name: "api_keys",
|
||||
section: "developer",
|
||||
shortcut: ["a", "p", "i"],
|
||||
keywords: "api keys",
|
||||
perform: () => router.push("/settings/developer/api-keys"),
|
||||
},
|
||||
{
|
||||
id: "billing",
|
||||
name: "manage_billing",
|
||||
section: "billing",
|
||||
shortcut: ["m", "b"],
|
||||
keywords: "billing view manage",
|
||||
perform: () => router.push("/settings/billing"),
|
||||
},
|
||||
...appStoreActions,
|
||||
...eventTypeActions,
|
||||
];
|
||||
|
||||
return <KBarProvider actions={actions}>{children}</KBarProvider>;
|
||||
};
|
||||
|
||||
export const KBarContent = () => {
|
||||
const { t } = useLocale();
|
||||
|
||||
return (
|
||||
<KBarPortal>
|
||||
<KBarPositioner>
|
||||
<KBarAnimator className="z-10 w-full max-w-screen-sm overflow-hidden rounded-md bg-white shadow-lg">
|
||||
<div className="flex items-center justify-center border-b">
|
||||
<Icon.FiSearch className="mx-3 h-4 w-4 text-gray-500" />
|
||||
<KBarSearch
|
||||
defaultPlaceholder={t("kbar_search_placeholder")}
|
||||
className="w-full rounded-sm py-2.5 focus-visible:outline-none"
|
||||
/>
|
||||
</div>
|
||||
<RenderResults />
|
||||
<div className="hidden items-center space-x-1 border-t px-2 py-1.5 text-xs text-gray-500 sm:flex">
|
||||
<Icon.FiArrowUp className="h-4 w-4" />
|
||||
<Icon.FiArrowDown className="h-4 w-4" /> <span className="pr-2">{t("navigate")}</span>
|
||||
<Icon.FiCornerDownLeft className="h-4 w-4" />
|
||||
<span className="pr-2">{t("open")}</span>
|
||||
{isMac ? <Icon.FiCommand className="h-3 w-3" /> : "CTRL"}
|
||||
<span className="pr-1">+ K </span>
|
||||
<span className="pr-2">{t("close")}</span>
|
||||
</div>
|
||||
</KBarAnimator>
|
||||
<div className="z-1 fixed inset-0 bg-gray-600 bg-opacity-75" />
|
||||
</KBarPositioner>
|
||||
</KBarPortal>
|
||||
);
|
||||
};
|
||||
|
||||
export const KBarTrigger = () => {
|
||||
const { query } = useKBar();
|
||||
return query ? (
|
||||
<>
|
||||
<Tooltip side="right" content={isMac ? "⌘ + K" : "CTRL + K"}>
|
||||
<button
|
||||
color="minimal"
|
||||
onClick={query.toggle}
|
||||
className="group flex rounded-md py-2 px-3 text-sm font-medium hover:bg-gray-100 lg:p-1 lg:hover:bg-gray-200 lg:hover:text-neutral-900">
|
||||
<Icon.FiSearch className="h-4 w-4 flex-shrink-0 text-inherit" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
</>
|
||||
) : null;
|
||||
};
|
||||
|
||||
const DisplayShortcuts = (item: shortcutArrayType) => {
|
||||
const shortcuts = item.shortcuts;
|
||||
|
||||
return (
|
||||
<span className="space-x-1">
|
||||
{shortcuts?.map((shortcut) => {
|
||||
return (
|
||||
<kbd key={shortcut} className="rounded-sm border bg-white px-2 py-1 text-black hover:bg-gray-100">
|
||||
{shortcut}
|
||||
</kbd>
|
||||
);
|
||||
})}
|
||||
</span>
|
||||
);
|
||||
};
|
||||
|
||||
function RenderResults() {
|
||||
const { results } = useMatches();
|
||||
const { t } = useLocale();
|
||||
|
||||
return (
|
||||
<KBarResults
|
||||
items={results}
|
||||
onRender={({ item, active }) =>
|
||||
typeof item === "string" ? (
|
||||
<div className="bg-white p-4 text-xs uppercase text-gray-500">{t(item)}</div>
|
||||
) : (
|
||||
<div
|
||||
// For seeing keyboard up & down navigation in action, we need visual feedback based on "active" prop
|
||||
style={{
|
||||
background: active ? "rgb(245,245,245)" : "#fff",
|
||||
borderLeft: active ? "2px solid black" : "2px solid transparent",
|
||||
}}
|
||||
className="flex items-center justify-between px-4 py-2.5 text-sm hover:cursor-pointer">
|
||||
<span>{t(item.name)}</span>
|
||||
<DisplayShortcuts shortcuts={item.shortcut} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -1,895 +0,0 @@
|
||||
import type { User } from "@prisma/client";
|
||||
import { signOut, useSession } from "next-auth/react";
|
||||
import Link from "next/link";
|
||||
import { NextRouter, useRouter } from "next/router";
|
||||
import React, { Dispatch, Fragment, ReactNode, SetStateAction, useEffect, useState } from "react";
|
||||
import { Toaster } from "react-hot-toast";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { useIsEmbed } from "@calcom/embed-core/embed-iframe";
|
||||
import UnconfirmedBookingBadge from "@calcom/features/bookings/UnconfirmedBookingBadge";
|
||||
import LicenseRequired from "@calcom/features/ee/common/components/v2/LicenseRequired";
|
||||
import ImpersonatingBanner from "@calcom/features/ee/impersonation/components/ImpersonatingBanner";
|
||||
import HelpMenuItem from "@calcom/features/ee/support/components/HelpMenuItem";
|
||||
import { TeamsUpgradeBanner } from "@calcom/features/ee/teams/components";
|
||||
import TimezoneChangeDialog from "@calcom/features/settings/TimezoneChangeDialog";
|
||||
import { Tips } from "@calcom/features/tips";
|
||||
import AdminPasswordBanner from "@calcom/features/users/components/AdminPasswordBanner";
|
||||
import CustomBranding from "@calcom/lib/CustomBranding";
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { APP_NAME, DESKTOP_APP_LINK, JOIN_SLACK, ROADMAP, WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import useTheme from "@calcom/lib/hooks/useTheme";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import useMeQuery from "@calcom/trpc/react/hooks/useMeQuery";
|
||||
import { SVGComponent } from "@calcom/types/SVGComponent";
|
||||
|
||||
import {
|
||||
Button,
|
||||
Dropdown,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
showToast,
|
||||
} from "../..";
|
||||
import { Logo, ErrorBoundary } from "../../components";
|
||||
import { Credits } from "../../components/credits";
|
||||
import { HeadSeo } from "../../components/head-seo";
|
||||
import { Icon } from "../../components/icon";
|
||||
import { SkeletonText } from "../../components/skeleton";
|
||||
import { KBarContent, KBarRoot, KBarTrigger } from "./Kbar";
|
||||
|
||||
/* TODO: Migate this */
|
||||
|
||||
export const ONBOARDING_INTRODUCED_AT = dayjs("September 1 2021").toISOString();
|
||||
|
||||
export const ONBOARDING_NEXT_REDIRECT = {
|
||||
redirect: {
|
||||
permanent: false,
|
||||
destination: "/getting-started",
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const shouldShowOnboarding = (user: Pick<User, "createdDate" | "completedOnboarding">) => {
|
||||
return !user.completedOnboarding && dayjs(user.createdDate).isAfter(ONBOARDING_INTRODUCED_AT);
|
||||
};
|
||||
|
||||
function useRedirectToLoginIfUnauthenticated(isPublic = false) {
|
||||
const { data: session, status } = useSession();
|
||||
const loading = status === "loading";
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
if (isPublic) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!loading && !session) {
|
||||
router.replace({
|
||||
pathname: "/auth/login",
|
||||
query: {
|
||||
callbackUrl: `${WEBAPP_URL}${location.pathname}${location.search}`,
|
||||
},
|
||||
});
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [loading, session, isPublic]);
|
||||
|
||||
return {
|
||||
loading: loading && !session,
|
||||
session,
|
||||
};
|
||||
}
|
||||
|
||||
function useRedirectToOnboardingIfNeeded() {
|
||||
const router = useRouter();
|
||||
const query = useMeQuery();
|
||||
const user = query.data;
|
||||
|
||||
const isRedirectingToOnboarding = user && shouldShowOnboarding(user);
|
||||
|
||||
useEffect(() => {
|
||||
if (isRedirectingToOnboarding) {
|
||||
router.replace({
|
||||
pathname: "/getting-started",
|
||||
});
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [isRedirectingToOnboarding]);
|
||||
return {
|
||||
isRedirectingToOnboarding,
|
||||
};
|
||||
}
|
||||
|
||||
export function ShellSubHeading(props: {
|
||||
title: ReactNode;
|
||||
subtitle?: ReactNode;
|
||||
actions?: ReactNode;
|
||||
className?: string;
|
||||
}) {
|
||||
return (
|
||||
<header className={classNames("mb-3 block justify-between sm:flex", props.className)}>
|
||||
<div>
|
||||
<h2 className="flex content-center items-center space-x-2 text-base font-bold leading-6 text-gray-900 rtl:space-x-reverse">
|
||||
{props.title}
|
||||
</h2>
|
||||
{props.subtitle && <p className="text-sm text-neutral-500 ltr:mr-4">{props.subtitle}</p>}
|
||||
</div>
|
||||
{props.actions && <div className="mt-2 flex-shrink-0 sm:mt-0">{props.actions}</div>}
|
||||
</header>
|
||||
);
|
||||
}
|
||||
|
||||
const Layout = (props: LayoutProps) => {
|
||||
const pageTitle = typeof props.heading === "string" && !props.title ? props.heading : props.title;
|
||||
|
||||
return (
|
||||
<>
|
||||
{!props.withoutSeo && (
|
||||
<HeadSeo
|
||||
title={pageTitle ?? APP_NAME}
|
||||
description={props.subtitle ? props.subtitle?.toString() : ""}
|
||||
nextSeoProps={{
|
||||
nofollow: true,
|
||||
noindex: true,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<div>
|
||||
<Toaster position="bottom-right" />
|
||||
</div>
|
||||
|
||||
{/* todo: only run this if timezone is different */}
|
||||
<TimezoneChangeDialog />
|
||||
<div className="flex min-h-screen flex-col">
|
||||
<div className="divide-y divide-black">
|
||||
<TeamsUpgradeBanner />
|
||||
<ImpersonatingBanner />
|
||||
<AdminPasswordBanner />
|
||||
</div>
|
||||
<div className="flex flex-1" data-testid="dashboard-shell">
|
||||
{props.SidebarContainer || <SideBarContainer />}
|
||||
<div className="flex w-0 flex-1 flex-col">
|
||||
<MainContainer {...props} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
type DrawerState = [isOpen: boolean, setDrawerOpen: Dispatch<SetStateAction<boolean>>];
|
||||
|
||||
type LayoutProps = {
|
||||
centered?: boolean;
|
||||
title?: string;
|
||||
heading?: ReactNode;
|
||||
subtitle?: ReactNode;
|
||||
children: ReactNode;
|
||||
CTA?: ReactNode;
|
||||
large?: boolean;
|
||||
MobileNavigationContainer?: ReactNode;
|
||||
SidebarContainer?: ReactNode;
|
||||
TopNavContainer?: ReactNode;
|
||||
drawerState?: DrawerState;
|
||||
HeadingLeftIcon?: ReactNode;
|
||||
backPath?: string | boolean; // renders back button to specified path
|
||||
// use when content needs to expand with flex
|
||||
flexChildrenContainer?: boolean;
|
||||
isPublic?: boolean;
|
||||
withoutMain?: boolean;
|
||||
// Gives you the option to skip HeadSEO and render your own.
|
||||
withoutSeo?: boolean;
|
||||
// Gives the ability to include actions to the right of the heading
|
||||
actions?: JSX.Element;
|
||||
};
|
||||
|
||||
const CustomBrandingContainer = () => {
|
||||
const { data: user } = useMeQuery();
|
||||
return <CustomBranding lightVal={user?.brandColor} darkVal={user?.darkBrandColor} />;
|
||||
};
|
||||
|
||||
export default function Shell(props: LayoutProps) {
|
||||
useRedirectToLoginIfUnauthenticated(props.isPublic);
|
||||
useRedirectToOnboardingIfNeeded();
|
||||
useTheme("light");
|
||||
// don't load KBar when unauthed
|
||||
return props.isPublic ? (
|
||||
<>
|
||||
<CustomBrandingContainer />
|
||||
<Layout {...props} />
|
||||
</>
|
||||
) : (
|
||||
<KBarRoot>
|
||||
<CustomBrandingContainer />
|
||||
<Layout {...props} />
|
||||
<KBarContent />
|
||||
</KBarRoot>
|
||||
);
|
||||
}
|
||||
|
||||
function UserDropdown({ small }: { small?: boolean }) {
|
||||
const { t } = useLocale();
|
||||
const query = useMeQuery();
|
||||
const user = query.data;
|
||||
useEffect(() => {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
//@ts-ignore
|
||||
const Beacon = window.Beacon;
|
||||
// window.Beacon is defined when user actually opens up HelpScout and username is available here. On every re-render update session info, so that it is always latest.
|
||||
Beacon &&
|
||||
Beacon("session-data", {
|
||||
username: user?.username || "Unknown",
|
||||
screenResolution: `${screen.width}x${screen.height}`,
|
||||
});
|
||||
});
|
||||
const mutation = trpc.viewer.away.useMutation({
|
||||
onSettled() {
|
||||
utils.viewer.me.invalidate();
|
||||
},
|
||||
});
|
||||
const utils = trpc.useContext();
|
||||
const [helpOpen, setHelpOpen] = useState(false);
|
||||
const [menuOpen, setMenuOpen] = useState(false);
|
||||
if (!user) {
|
||||
return null;
|
||||
}
|
||||
const onHelpItemSelect = () => {
|
||||
setHelpOpen(false);
|
||||
setMenuOpen(false);
|
||||
};
|
||||
|
||||
// Prevent rendering dropdown if user isn't available.
|
||||
// We don't want to show nameless user.
|
||||
if (!user) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<Dropdown open={menuOpen}>
|
||||
<div className="ltr:sm:-ml-5 rtl:sm:-mr-5">
|
||||
<DropdownMenuTrigger asChild onClick={() => setMenuOpen((menuOpen) => !menuOpen)}>
|
||||
<button className="group mx-0 flex w-full cursor-pointer appearance-none items-center rounded-full p-2 text-left outline-none hover:bg-gray-200 focus:outline-none focus:ring-0 sm:mx-2.5 sm:pl-3 md:rounded-none lg:rounded lg:pl-2">
|
||||
<span
|
||||
className={classNames(
|
||||
small ? "h-6 w-6" : "h-8 w-8 ltr:mr-2 rtl:ml-2",
|
||||
"relative flex-shrink-0 rounded-full bg-gray-300 "
|
||||
)}>
|
||||
{
|
||||
// eslint-disable-next-line @next/next/no-img-element
|
||||
<img
|
||||
className="rounded-full"
|
||||
src={WEBAPP_URL + "/" + user.username + "/avatar.png"}
|
||||
alt={user.username || "Nameless User"}
|
||||
/>
|
||||
}
|
||||
{!user.away && (
|
||||
<div className="absolute bottom-0 right-0 h-3 w-3 rounded-full border-2 border-white bg-green-500" />
|
||||
)}
|
||||
{user.away && (
|
||||
<div className="absolute bottom-0 right-0 h-3 w-3 rounded-full border-2 border-white bg-yellow-500" />
|
||||
)}
|
||||
</span>
|
||||
{!small && (
|
||||
<span className="flex flex-grow items-center truncate">
|
||||
<span className="flex-grow truncate text-sm">
|
||||
<span className="block truncate font-medium text-gray-900">
|
||||
{user.name || "Nameless User"}
|
||||
</span>
|
||||
<span className="block truncate font-normal text-gray-900">
|
||||
{user.username
|
||||
? process.env.NEXT_PUBLIC_WEBSITE_URL === "https://cal.com"
|
||||
? `cal.com/${user.username}`
|
||||
: `/${user.username}`
|
||||
: "No public page"}
|
||||
</span>
|
||||
</span>
|
||||
<Icon.FiMoreVertical
|
||||
className="h-4 w-4 flex-shrink-0 text-gray-400 group-hover:text-gray-500 ltr:mr-2 rtl:ml-2 rtl:mr-4"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
</div>
|
||||
|
||||
<DropdownMenuPortal>
|
||||
<DropdownMenuContent
|
||||
onInteractOutside={() => {
|
||||
setMenuOpen(false);
|
||||
setHelpOpen(false);
|
||||
}}
|
||||
className="overflow-hidden rounded-md">
|
||||
{helpOpen ? (
|
||||
<HelpMenuItem onHelpItemSelect={() => onHelpItemSelect()} />
|
||||
) : (
|
||||
<>
|
||||
<DropdownMenuItem>
|
||||
<button
|
||||
onClick={() => {
|
||||
mutation.mutate({ away: !user?.away });
|
||||
utils.viewer.me.invalidate();
|
||||
}}
|
||||
className="flex w-full min-w-max cursor-pointer items-center px-4 py-2 text-sm ltr:flex-row rtl:flex-row-reverse">
|
||||
<Icon.FiMoon
|
||||
className={classNames(
|
||||
user.away
|
||||
? "text-purple-500 group-hover:text-purple-700"
|
||||
: "text-gray-500 group-hover:text-gray-700",
|
||||
"h-4 w-4 flex-shrink-0 ltr:mr-2 rtl:ml-2"
|
||||
)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
{user.away ? t("set_as_free") : t("set_as_away")}
|
||||
</button>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator className="h-px bg-gray-200" />
|
||||
{user.username && (
|
||||
<>
|
||||
<DropdownMenuItem>
|
||||
<a
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
href={`${process.env.NEXT_PUBLIC_WEBSITE_URL}/${user.username}`}
|
||||
className="flex items-center px-4 py-2 text-sm text-gray-700 ltr:flex-row rtl:flex-row-reverse">
|
||||
<Icon.FiExternalLink className="h-4 w-4 text-gray-500 ltr:mr-2 rtl:ml-2" />{" "}
|
||||
{t("view_public_page")}
|
||||
</a>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem>
|
||||
<a
|
||||
href="#"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
navigator.clipboard.writeText(
|
||||
`${process.env.NEXT_PUBLIC_WEBSITE_URL}/${user.username}`
|
||||
);
|
||||
showToast(t("link_copied"), "success");
|
||||
}}
|
||||
className="flex items-center px-4 py-2 text-sm text-gray-700 ltr:flex-row rtl:flex-row-reverse">
|
||||
<Icon.FiLink className="h-4 w-4 text-gray-500 ltr:mr-2 rtl:ml-2" />{" "}
|
||||
{t("copy_public_page_link")}
|
||||
</a>
|
||||
</DropdownMenuItem>
|
||||
</>
|
||||
)}
|
||||
<DropdownMenuSeparator className="h-px bg-gray-200" />
|
||||
<DropdownMenuItem>
|
||||
<a
|
||||
href={JOIN_SLACK}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="flex items-center px-4 py-2 text-sm text-gray-700 ltr:flex-row rtl:flex-row-reverse">
|
||||
<Icon.FiSlack strokeWidth={1.5} className="h-4 w-4 text-gray-500 ltr:mr-2 rtl:ml-2" />{" "}
|
||||
{t("join_our_slack")}
|
||||
</a>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem>
|
||||
<a
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
href={ROADMAP}
|
||||
className="flex items-center px-4 py-2 text-sm text-gray-700 ltr:flex-row rtl:flex-row-reverse">
|
||||
<Icon.FiMap className="h-4 w-4 text-gray-500 ltr:mr-2 rtl:ml-2" /> {t("visit_roadmap")}
|
||||
</a>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem>
|
||||
<button
|
||||
onClick={() => setHelpOpen(true)}
|
||||
className="flex w-full items-center px-4 py-2 text-sm text-gray-700 ltr:flex-row rtl:flex-row-reverse">
|
||||
<Icon.FiHelpCircle
|
||||
className={classNames(
|
||||
"text-gray-500 group-hover:text-neutral-500",
|
||||
"h-4 w-4 flex-shrink-0 ltr:mr-2 rtl:ml-2"
|
||||
)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
|
||||
{t("help")}
|
||||
</button>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem>
|
||||
<a
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
href={DESKTOP_APP_LINK}
|
||||
className="desktop-hidden hidden items-center px-4 py-2 text-sm text-gray-700 ltr:flex-row rtl:flex-row-reverse lg:flex">
|
||||
<Icon.FiDownload className="h-4 w-4 text-gray-500 ltr:mr-2 rtl:ml-2" />{" "}
|
||||
{t("download_desktop_app")}
|
||||
</a>
|
||||
</DropdownMenuItem>
|
||||
|
||||
<DropdownMenuSeparator className="h-px bg-gray-200" />
|
||||
<DropdownMenuItem>
|
||||
<a
|
||||
onClick={() => signOut({ callbackUrl: "/auth/logout" })}
|
||||
className="flex cursor-pointer items-center px-4 py-2 text-sm hover:bg-gray-100 hover:text-gray-900 ltr:flex-row rtl:flex-row-reverse">
|
||||
<Icon.FiLogOut
|
||||
className={classNames(
|
||||
"text-gray-500 group-hover:text-gray-700",
|
||||
"h-4 w-4 flex-shrink-0 ltr:mr-2 rtl:ml-2"
|
||||
)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
{t("sign_out")}
|
||||
</a>
|
||||
</DropdownMenuItem>
|
||||
</>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenuPortal>
|
||||
</Dropdown>
|
||||
);
|
||||
}
|
||||
|
||||
export type NavigationItemType = {
|
||||
name: string;
|
||||
href: string;
|
||||
badge?: React.ReactNode;
|
||||
icon?: SVGComponent;
|
||||
child?: NavigationItemType[];
|
||||
pro?: true;
|
||||
onlyMobile?: boolean;
|
||||
onlyDesktop?: boolean;
|
||||
isCurrent?: ({
|
||||
item,
|
||||
isChild,
|
||||
router,
|
||||
}: {
|
||||
item: NavigationItemType;
|
||||
isChild?: boolean;
|
||||
router: NextRouter;
|
||||
}) => boolean;
|
||||
};
|
||||
|
||||
const requiredCredentialNavigationItems = ["Routing Forms"];
|
||||
const MORE_SEPARATOR_NAME = "more";
|
||||
|
||||
const navigation: NavigationItemType[] = [
|
||||
{
|
||||
name: "event_types_page_title",
|
||||
href: "/event-types",
|
||||
icon: Icon.FiLink,
|
||||
},
|
||||
{
|
||||
name: "bookings",
|
||||
href: "/bookings/upcoming",
|
||||
icon: Icon.FiCalendar,
|
||||
badge: <UnconfirmedBookingBadge />,
|
||||
isCurrent: ({ router }) => {
|
||||
const path = router.asPath.split("?")[0];
|
||||
return path.startsWith("/bookings");
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "availability",
|
||||
href: "/availability",
|
||||
icon: Icon.FiClock,
|
||||
},
|
||||
{
|
||||
name: "teams",
|
||||
href: "/teams",
|
||||
icon: Icon.FiUsers,
|
||||
onlyDesktop: true,
|
||||
},
|
||||
{
|
||||
name: "apps",
|
||||
href: "/apps",
|
||||
icon: Icon.FiGrid,
|
||||
isCurrent: ({ router, item }) => {
|
||||
const path = router.asPath.split("?")[0];
|
||||
// During Server rendering path is /v2/apps but on client it becomes /apps(weird..)
|
||||
return (
|
||||
(path.startsWith(item.href) || path.startsWith("/v2" + item.href)) && !path.includes("routing-forms/")
|
||||
);
|
||||
},
|
||||
child: [
|
||||
{
|
||||
name: "app_store",
|
||||
href: "/apps",
|
||||
isCurrent: ({ router, item }) => {
|
||||
const path = router.asPath.split("?")[0];
|
||||
// During Server rendering path is /v2/apps but on client it becomes /apps(weird..)
|
||||
return (
|
||||
(path.startsWith(item.href) || path.startsWith("/v2" + item.href)) &&
|
||||
!path.includes("routing-forms/") &&
|
||||
!path.includes("/installed")
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "installed_apps",
|
||||
href: "/apps/installed/calendar",
|
||||
isCurrent: ({ router }) => {
|
||||
const path = router.asPath;
|
||||
return path.startsWith("/apps/installed/") || path.startsWith("/v2/apps/installed/");
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: MORE_SEPARATOR_NAME,
|
||||
href: "/more",
|
||||
icon: Icon.FiMoreHorizontal,
|
||||
},
|
||||
{
|
||||
name: "Routing Forms",
|
||||
href: "/apps/routing-forms/forms",
|
||||
icon: Icon.FiFileText,
|
||||
isCurrent: ({ router }) => {
|
||||
return router.asPath.startsWith("/apps/routing-forms/");
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "workflows",
|
||||
href: "/workflows",
|
||||
icon: Icon.FiZap,
|
||||
},
|
||||
{
|
||||
name: "settings",
|
||||
href: "/settings/my-account/profile",
|
||||
icon: Icon.FiSettings,
|
||||
},
|
||||
];
|
||||
|
||||
const moreSeparatorIndex = navigation.findIndex((item) => item.name === MORE_SEPARATOR_NAME);
|
||||
// We create all needed navigation items for the different use cases
|
||||
const { desktopNavigationItems, mobileNavigationBottomItems, mobileNavigationMoreItems } = navigation.reduce<
|
||||
Record<string, NavigationItemType[]>
|
||||
>(
|
||||
(items, item, index) => {
|
||||
// We filter out the "more" separator in` desktop navigation
|
||||
if (item.name !== MORE_SEPARATOR_NAME) items.desktopNavigationItems.push(item);
|
||||
// Items for mobile bottom navigation
|
||||
if (index < moreSeparatorIndex + 1 && !item.onlyDesktop) items.mobileNavigationBottomItems.push(item);
|
||||
// Items for the "more" menu in mobile navigation
|
||||
else items.mobileNavigationMoreItems.push(item);
|
||||
return items;
|
||||
},
|
||||
{ desktopNavigationItems: [], mobileNavigationBottomItems: [], mobileNavigationMoreItems: [] }
|
||||
);
|
||||
|
||||
const Navigation = () => {
|
||||
return (
|
||||
<nav className="mt-2 flex-1 space-y-0.5 md:px-2 lg:mt-6 lg:px-0">
|
||||
{desktopNavigationItems.map((item) => (
|
||||
<NavigationItem key={item.name} item={item} />
|
||||
))}
|
||||
<div className="text-gray-500 lg:hidden">
|
||||
<KBarTrigger />
|
||||
</div>
|
||||
</nav>
|
||||
);
|
||||
};
|
||||
|
||||
function useShouldDisplayNavigationItem(item: NavigationItemType) {
|
||||
const { status } = useSession();
|
||||
const { data: routingForms } = trpc.viewer.appById.useQuery(
|
||||
{ appId: "routing-forms" },
|
||||
{
|
||||
enabled: status === "authenticated" && requiredCredentialNavigationItems.includes(item.name),
|
||||
trpc: {},
|
||||
}
|
||||
);
|
||||
return !requiredCredentialNavigationItems.includes(item.name) || routingForms?.isInstalled;
|
||||
}
|
||||
|
||||
const defaultIsCurrent: NavigationItemType["isCurrent"] = ({ isChild, item, router }) => {
|
||||
return isChild ? item.href === router.asPath : router.asPath.startsWith(item.href);
|
||||
};
|
||||
|
||||
const NavigationItem: React.FC<{
|
||||
item: NavigationItemType;
|
||||
isChild?: boolean;
|
||||
}> = (props) => {
|
||||
const { item, isChild } = props;
|
||||
const { t, isLocaleReady } = useLocale();
|
||||
const router = useRouter();
|
||||
const isCurrent: NavigationItemType["isCurrent"] = item.isCurrent || defaultIsCurrent;
|
||||
const current = isCurrent({ isChild: !!isChild, item, router });
|
||||
const shouldDisplayNavigationItem = useShouldDisplayNavigationItem(props.item);
|
||||
|
||||
if (!shouldDisplayNavigationItem) return null;
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
<Link
|
||||
href={item.href}
|
||||
aria-label={t(item.name)}
|
||||
className={classNames(
|
||||
"group flex items-center rounded-md py-2 px-3 text-sm font-medium text-gray-600 hover:bg-gray-100 [&[aria-current='page']]:bg-gray-200 [&[aria-current='page']]:hover:text-neutral-900",
|
||||
isChild
|
||||
? "[&[aria-current='page']]:text-brand-900 hidden pl-16 lg:flex lg:pl-11 [&[aria-current='page']]:bg-transparent"
|
||||
: "[&[aria-current='page']]:text-brand-900 "
|
||||
)}
|
||||
aria-current={current ? "page" : undefined}>
|
||||
{item.icon && (
|
||||
<item.icon
|
||||
className="h-4 w-4 flex-shrink-0 text-gray-500 ltr:mr-2 rtl:ml-2 [&[aria-current='page']]:text-inherit"
|
||||
aria-hidden="true"
|
||||
aria-current={current ? "page" : undefined}
|
||||
/>
|
||||
)}
|
||||
{isLocaleReady ? (
|
||||
<span className="hidden w-full justify-between lg:flex">
|
||||
<div className="flex">{t(item.name)}</div>
|
||||
{item.badge && item.badge}
|
||||
</span>
|
||||
) : (
|
||||
<SkeletonText className="h-3 w-32" />
|
||||
)}
|
||||
</Link>
|
||||
{item.child &&
|
||||
isCurrent({ router, isChild, item }) &&
|
||||
item.child.map((item) => <NavigationItem key={item.name} item={item} isChild />)}
|
||||
</Fragment>
|
||||
);
|
||||
};
|
||||
|
||||
function MobileNavigationContainer() {
|
||||
const { status } = useSession();
|
||||
if (status !== "authenticated") return null;
|
||||
return <MobileNavigation />;
|
||||
}
|
||||
|
||||
const MobileNavigation = () => {
|
||||
const isEmbed = useIsEmbed();
|
||||
|
||||
return (
|
||||
<>
|
||||
<nav
|
||||
className={classNames(
|
||||
"bottom-nav fixed bottom-0 z-30 -mx-4 flex w-full border border-t border-gray-200 bg-gray-50 bg-opacity-40 px-1 shadow backdrop-blur-md md:hidden",
|
||||
isEmbed && "hidden"
|
||||
)}>
|
||||
{mobileNavigationBottomItems.map((item) => (
|
||||
<MobileNavigationItem key={item.name} item={item} />
|
||||
))}
|
||||
</nav>
|
||||
{/* add padding to content for mobile navigation*/}
|
||||
<div className="block pt-12 md:hidden" />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const MobileNavigationItem: React.FC<{
|
||||
item: NavigationItemType;
|
||||
isChild?: boolean;
|
||||
}> = (props) => {
|
||||
const { item, isChild } = props;
|
||||
const router = useRouter();
|
||||
const { t, isLocaleReady } = useLocale();
|
||||
const isCurrent: NavigationItemType["isCurrent"] = item.isCurrent || defaultIsCurrent;
|
||||
const current = isCurrent({ isChild: !!isChild, item, router });
|
||||
const shouldDisplayNavigationItem = useShouldDisplayNavigationItem(props.item);
|
||||
|
||||
if (!shouldDisplayNavigationItem) return null;
|
||||
return (
|
||||
<Link
|
||||
key={item.name}
|
||||
href={item.href}
|
||||
className="relative my-2 min-w-0 flex-1 overflow-hidden rounded-md py-2 px-1 text-center text-xs font-medium text-neutral-400 hover:bg-gray-200 hover:text-gray-700 focus:z-10 sm:text-sm [&[aria-current='page']]:text-gray-900"
|
||||
aria-current={current ? "page" : undefined}>
|
||||
{item.badge && <div className="absolute right-1 top-1">{item.badge}</div>}
|
||||
{item.icon && (
|
||||
<item.icon
|
||||
className="mx-auto mb-1 block h-5 w-5 flex-shrink-0 text-center text-inherit [&[aria-current='page']]:text-gray-900"
|
||||
aria-hidden="true"
|
||||
aria-current={current ? "page" : undefined}
|
||||
/>
|
||||
)}
|
||||
{isLocaleReady ? <span className="block truncate">{t(item.name)}</span> : <SkeletonText />}
|
||||
</Link>
|
||||
);
|
||||
};
|
||||
|
||||
const MobileNavigationMoreItem: React.FC<{
|
||||
item: NavigationItemType;
|
||||
isChild?: boolean;
|
||||
}> = (props) => {
|
||||
const { item } = props;
|
||||
const { t, isLocaleReady } = useLocale();
|
||||
const shouldDisplayNavigationItem = useShouldDisplayNavigationItem(props.item);
|
||||
|
||||
if (!shouldDisplayNavigationItem) return null;
|
||||
|
||||
return (
|
||||
<li className="border-b last:border-b-0" key={item.name}>
|
||||
<Link href={item.href} className="flex items-center justify-between p-5 hover:bg-gray-100">
|
||||
<span className="flex items-center font-semibold text-gray-700 ">
|
||||
{item.icon && <item.icon className="h-5 w-5 flex-shrink-0 ltr:mr-3 rtl:ml-3" aria-hidden="true" />}
|
||||
{isLocaleReady ? t(item.name) : <SkeletonText />}
|
||||
</span>
|
||||
<Icon.FiArrowRight className="h-5 w-5 text-gray-500" />
|
||||
</Link>
|
||||
</li>
|
||||
);
|
||||
};
|
||||
|
||||
function SideBarContainer() {
|
||||
const { status } = useSession();
|
||||
const router = useRouter();
|
||||
|
||||
// Make sure that Sidebar is rendered optimistically so that a refresh of pages when logged in have SideBar from the beginning.
|
||||
// This improves the experience of refresh on app store pages(when logged in) which are SSG.
|
||||
// Though when logged out, app store pages would temporarily show SideBar until session status is confirmed.
|
||||
if (status !== "loading" && status !== "authenticated") return null;
|
||||
if (router.route.startsWith("/v2/settings/")) return null;
|
||||
return <SideBar />;
|
||||
}
|
||||
|
||||
function SideBar() {
|
||||
return (
|
||||
<div className="relative">
|
||||
<aside className="desktop-transparent top-0 hidden h-full max-h-screen w-14 flex-col overflow-y-auto border-r border-gray-100 bg-gray-50 md:sticky md:flex lg:w-56 lg:px-4">
|
||||
<div className="flex h-full flex-col justify-between py-3 lg:pt-6 ">
|
||||
<header className="items-center justify-between md:hidden lg:flex">
|
||||
<Link href="/event-types" className="px-2">
|
||||
<Logo small />
|
||||
</Link>
|
||||
<div className="flex space-x-2 rtl:space-x-reverse">
|
||||
<button
|
||||
color="minimal"
|
||||
onClick={() => window.history.back()}
|
||||
className="desktop-only group flex text-sm font-medium text-neutral-500 hover:text-neutral-900">
|
||||
<Icon.FiArrowLeft className="h-4 w-4 flex-shrink-0 text-neutral-500 group-hover:text-neutral-900" />
|
||||
</button>
|
||||
<button
|
||||
color="minimal"
|
||||
onClick={() => window.history.forward()}
|
||||
className="desktop-only group flex text-sm font-medium text-neutral-500 hover:text-neutral-900">
|
||||
<Icon.FiArrowRight className="h-4 w-4 flex-shrink-0 text-neutral-500 group-hover:text-neutral-900" />
|
||||
</button>
|
||||
<KBarTrigger />
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<hr className="desktop-only absolute -left-3 -right-3 mt-4 block w-full border-gray-200" />
|
||||
|
||||
{/* logo icon for tablet */}
|
||||
<Link href="/event-types" className="text-center md:inline lg:hidden">
|
||||
<Logo small icon />
|
||||
</Link>
|
||||
|
||||
<Navigation />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<LicenseRequired toHide>
|
||||
<Tips />
|
||||
</LicenseRequired>
|
||||
<div data-testid="user-dropdown-trigger">
|
||||
<span className="hidden lg:inline">
|
||||
<UserDropdown />
|
||||
</span>
|
||||
<span className="hidden md:inline lg:hidden">
|
||||
<UserDropdown small />
|
||||
</span>
|
||||
</div>
|
||||
<Credits />
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function ShellMain(props: LayoutProps) {
|
||||
const router = useRouter();
|
||||
const { isLocaleReady } = useLocale();
|
||||
return (
|
||||
<>
|
||||
<div className="flex items-baseline sm:mt-0">
|
||||
{!!props.backPath && (
|
||||
<Button
|
||||
size="icon"
|
||||
color="minimal"
|
||||
onClick={() =>
|
||||
typeof props.backPath === "string" ? router.push(props.backPath as string) : router.back()
|
||||
}
|
||||
StartIcon={Icon.FiArrowLeft}
|
||||
aria-label="Go Back"
|
||||
className="ltr:mr-2 rtl:ml-2"
|
||||
/>
|
||||
)}
|
||||
{props.heading && (
|
||||
<header
|
||||
className={classNames(
|
||||
props.large && "py-8",
|
||||
"mb-4 flex w-full max-w-full items-center pt-4 md:p-0 lg:mb-10"
|
||||
)}>
|
||||
{props.HeadingLeftIcon && <div className="ltr:mr-4">{props.HeadingLeftIcon}</div>}
|
||||
<div className="w-full ltr:mr-4 rtl:ml-4 sm:block">
|
||||
{props.heading && (
|
||||
<h1 className="font-cal max-w-28 sm:max-w-72 md:max-w-80 mb-1 hidden truncate text-xl font-bold tracking-wide text-black sm:block xl:max-w-full">
|
||||
{!isLocaleReady ? <SkeletonText invisible /> : props.heading}
|
||||
</h1>
|
||||
)}
|
||||
{props.subtitle && (
|
||||
<p className="hidden text-sm text-neutral-500 sm:block">
|
||||
{!isLocaleReady ? <SkeletonText invisible /> : props.subtitle}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
{props.CTA && (
|
||||
<div
|
||||
className={classNames(
|
||||
props.backPath ? "relative" : " fixed bottom-[88px] z-40 ltr:right-4 rtl:left-4 sm:z-auto",
|
||||
"flex-shrink-0 sm:relative sm:bottom-auto sm:right-auto"
|
||||
)}>
|
||||
{props.CTA}
|
||||
</div>
|
||||
)}
|
||||
{props.actions && props.actions}
|
||||
</header>
|
||||
)}
|
||||
</div>
|
||||
<div className={classNames(props.flexChildrenContainer && "flex flex-1 flex-col")}>
|
||||
{props.children}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function MainContainer({
|
||||
MobileNavigationContainer: MobileNavigationContainerProp = <MobileNavigationContainer />,
|
||||
TopNavContainer: TopNavContainerProp = <TopNavContainer />,
|
||||
...props
|
||||
}: LayoutProps) {
|
||||
return (
|
||||
<main className="relative z-0 flex-1 bg-white focus:outline-none">
|
||||
{/* show top navigation for md and smaller (tablet and phones) */}
|
||||
{TopNavContainerProp}
|
||||
<div className="max-w-full px-4 py-2 lg:py-8 lg:px-12">
|
||||
<ErrorBoundary>
|
||||
{!props.withoutMain ? <ShellMain {...props}>{props.children}</ShellMain> : props.children}
|
||||
</ErrorBoundary>
|
||||
{/* show bottom navigation for md and smaller (tablet and phones) on pages where back button doesn't exist */}
|
||||
{!props.backPath ? MobileNavigationContainerProp : null}
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
function TopNavContainer() {
|
||||
const { status } = useSession();
|
||||
if (status !== "authenticated") return null;
|
||||
return <TopNav />;
|
||||
}
|
||||
|
||||
function TopNav() {
|
||||
const isEmbed = useIsEmbed();
|
||||
const { t } = useLocale();
|
||||
return (
|
||||
<>
|
||||
<nav
|
||||
style={isEmbed ? { display: "none" } : {}}
|
||||
className="sticky top-0 z-40 flex w-full items-center justify-between border-b border-gray-200 bg-gray-50 bg-opacity-50 py-1.5 px-4 backdrop-blur-lg sm:p-4 md:hidden">
|
||||
<Link href="/event-types">
|
||||
<Logo />
|
||||
</Link>
|
||||
<div className="flex items-center gap-2 self-center">
|
||||
<span className="group flex items-center rounded-full text-sm font-medium text-gray-700 hover:bg-gray-50 hover:text-neutral-900 lg:hidden">
|
||||
<KBarTrigger />
|
||||
</span>
|
||||
<button className="rounded-full p-1 text-gray-400 hover:bg-gray-50 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-black focus:ring-offset-2">
|
||||
<span className="sr-only">{t("settings")}</span>
|
||||
<Link href="/settings/profile">
|
||||
<Icon.FiSettings className="h-4 w-4 text-gray-700" aria-hidden="true" />
|
||||
</Link>
|
||||
</button>
|
||||
<UserDropdown small />
|
||||
</div>
|
||||
</nav>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export const MobileNavigationMoreItems = () => (
|
||||
<ul className="mt-2 rounded-md border">
|
||||
{mobileNavigationMoreItems.map((item) => (
|
||||
<MobileNavigationMoreItem key={item.name} item={item} />
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
@@ -1,3 +0,0 @@
|
||||
export { default as Checkbox } from "../../../components/form/checkbox/Checkbox";
|
||||
|
||||
export { default as FormStep } from "./FormStep";
|
||||
@@ -1,26 +0,0 @@
|
||||
export { default as ColorPicker } from "./colorpicker";
|
||||
export {
|
||||
ButtonOrLink,
|
||||
Dropdown,
|
||||
DropdownItem,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuRadioGroup,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenuTriggerItem,
|
||||
} from "./Dropdown";
|
||||
export { FormStep } from "./form";
|
||||
export { default as Loader } from "./Loader";
|
||||
export { default as MeetingTimeInTimezones } from "./MeetingTimeInTimezones";
|
||||
export { default as SettingsToggle } from "./SettingsToggle";
|
||||
export { default as Shell } from "./Shell";
|
||||
export { default as Stepper } from "./Stepper";
|
||||
export { default as Swatch } from "./Swatch";
|
||||
export { default as Switch } from "./Switch";
|
||||
export { default as WizardForm } from "./WizardForm";
|
||||
@@ -1,2 +0,0 @@
|
||||
/* TODO: Make this index explicit */
|
||||
export * from "./core";
|
||||
Reference in new issue
Block a user