2022-07-14 06:45:07 +00:00
|
|
|
import {
|
|
|
|
KBarProvider,
|
|
|
|
KBarPortal,
|
|
|
|
KBarPositioner,
|
|
|
|
KBarAnimator,
|
|
|
|
KBarSearch,
|
|
|
|
KBarResults,
|
|
|
|
useMatches,
|
|
|
|
useKBar,
|
|
|
|
} from "kbar";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
|
|
import { isMac } from "@calcom/lib/isMac";
|
|
|
|
import { Tooltip } from "@calcom/ui";
|
2022-07-27 02:24:00 +00:00
|
|
|
import { Icon } from "@calcom/ui/Icon";
|
2022-07-14 06:45:07 +00:00
|
|
|
|
|
|
|
type shortcutArrayType = {
|
|
|
|
shortcuts?: string[];
|
|
|
|
};
|
|
|
|
|
|
|
|
export const KBarRoot = ({ children }: { children: React.ReactNode }) => {
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
// grab link to events
|
|
|
|
// quick nested actions would be extremely useful
|
|
|
|
const actions = [
|
|
|
|
// {
|
|
|
|
// id: "toggle-idle",
|
|
|
|
// name: "Test Function",
|
|
|
|
// section: "Status",
|
|
|
|
// shortcut: ["t", "f"],
|
|
|
|
// keywords: "set yourself away bookings",
|
|
|
|
// perform: () => alert("Hello World"),
|
|
|
|
// },
|
2022-07-14 11:32:28 +00:00
|
|
|
|
2022-07-14 06:45:07 +00:00
|
|
|
{
|
2022-07-14 11:32:28 +00:00
|
|
|
id: "workflows",
|
|
|
|
name: "Workflows",
|
|
|
|
section: "Workflows",
|
|
|
|
shortcut: ["w", "f"],
|
|
|
|
keywords: "workflows automation",
|
|
|
|
perform: () => router.push("/workflows"),
|
2022-07-14 06:45:07 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "event-types",
|
|
|
|
name: "Event Types",
|
|
|
|
section: "Event Types",
|
|
|
|
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"),
|
|
|
|
},
|
2022-07-14 11:32:28 +00:00
|
|
|
{
|
|
|
|
id: "upcoming-bookings",
|
|
|
|
name: "Upcoming Bookings",
|
|
|
|
section: "Bookings",
|
|
|
|
shortcut: ["u", "b"],
|
|
|
|
keywords: "upcoming bookings",
|
|
|
|
perform: () => router.push("/bookings/upcoming"),
|
|
|
|
},
|
2022-07-14 06:45:07 +00:00
|
|
|
{
|
|
|
|
id: "recurring-bookings",
|
|
|
|
name: "Recurring Bookings",
|
2022-07-14 11:32:28 +00:00
|
|
|
section: "Bookings",
|
2022-07-14 06:45:07 +00:00
|
|
|
shortcut: ["r", "b"],
|
|
|
|
keywords: "recurring bookings",
|
|
|
|
perform: () => router.push("/bookings/recurring"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "past-bookings",
|
|
|
|
name: "Past Bookings",
|
2022-07-14 11:32:28 +00:00
|
|
|
section: "Bookings",
|
2022-07-14 06:45:07 +00:00
|
|
|
shortcut: ["p", "b"],
|
|
|
|
keywords: "past bookings",
|
|
|
|
perform: () => router.push("/bookings/past"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "cancelled-bookings",
|
|
|
|
name: "Cancelled Bookings",
|
2022-07-14 11:32:28 +00:00
|
|
|
section: "Bookings",
|
2022-07-14 06:45:07 +00:00
|
|
|
shortcut: ["c", "b"],
|
|
|
|
keywords: "cancelled bookings",
|
|
|
|
perform: () => router.push("/bookings/cancelled"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "schedule",
|
|
|
|
name: "Schedule",
|
|
|
|
section: "Availability",
|
|
|
|
shortcut: ["s", "a"],
|
|
|
|
keywords: "schedule availability",
|
|
|
|
perform: () => router.push("/availability"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "profile",
|
|
|
|
name: "Profile",
|
|
|
|
section: "Profile Settings",
|
|
|
|
shortcut: ["p", "s"],
|
|
|
|
keywords: "setting profile",
|
2022-07-16 07:45:44 +00:00
|
|
|
perform: () => router.push("/settings/profile"),
|
2022-07-14 06:45:07 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "avatar",
|
|
|
|
name: "Change Avatar",
|
|
|
|
section: "Profile Settings",
|
|
|
|
shortcut: ["c", "a"],
|
|
|
|
keywords: "remove change modify avatar",
|
2022-07-16 07:45:44 +00:00
|
|
|
perform: () => router.push("/settings/profile"),
|
2022-07-14 06:45:07 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "timezone",
|
|
|
|
name: "Change Timezone",
|
|
|
|
section: "Profile Settings",
|
|
|
|
shortcut: ["c", "t"],
|
|
|
|
keywords: "change modify timezone",
|
2022-07-16 07:45:44 +00:00
|
|
|
perform: () => router.push("/settings/profile"),
|
2022-07-14 06:45:07 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "brand-color",
|
|
|
|
name: "Change Brand Color",
|
|
|
|
section: "Profile Settings",
|
|
|
|
shortcut: ["b", "c"],
|
|
|
|
keywords: "change modify brand color",
|
2022-07-16 07:45:44 +00:00
|
|
|
perform: () => router.push("/settings/profile"),
|
2022-07-14 06:45:07 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "teams",
|
|
|
|
name: "Teams",
|
|
|
|
shortcut: ["t", "s"],
|
|
|
|
keywords: "add manage modify team",
|
|
|
|
perform: () => router.push("/settings/teams"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "password",
|
|
|
|
name: "Change Password",
|
|
|
|
section: "Security Settings",
|
|
|
|
shortcut: ["c", "p"],
|
|
|
|
keywords: "change modify password",
|
|
|
|
perform: () => router.push("/settings/security"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "two-factor",
|
|
|
|
name: "Two Factor Authentication",
|
|
|
|
section: "Security Settings",
|
|
|
|
shortcut: ["t", "f", "a"],
|
|
|
|
keywords: "two factor authentication",
|
|
|
|
perform: () => router.push("/settings/security"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "impersonation",
|
|
|
|
name: "User Impersonation",
|
|
|
|
section: "Security Settings",
|
|
|
|
shortcut: ["u", "i"],
|
|
|
|
keywords: "user impersonation",
|
|
|
|
perform: () => router.push("/settings/security"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "webhooks",
|
|
|
|
name: "Webhook",
|
|
|
|
section: "Developer Settings",
|
|
|
|
shortcut: ["w", "h"],
|
|
|
|
keywords: "webhook automation",
|
|
|
|
perform: () => router.push("/settings/developer"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "api-keys",
|
|
|
|
name: "API Keys",
|
|
|
|
section: "Developer Settings",
|
|
|
|
shortcut: ["a", "p", "i"],
|
|
|
|
keywords: "api keys",
|
|
|
|
perform: () => router.push("/settings/developer"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "billing",
|
|
|
|
name: "View and Manage Billing",
|
|
|
|
section: "Billing",
|
|
|
|
shortcut: ["m", "b"],
|
|
|
|
keywords: "billing view manage",
|
|
|
|
perform: () => router.push("/settings/billing"),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
return <KBarProvider actions={actions}>{children}</KBarProvider>;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const KBarContent = () => {
|
2022-07-14 11:32:28 +00:00
|
|
|
const { t } = useLocale();
|
|
|
|
|
2022-07-14 06:45:07 +00:00
|
|
|
return (
|
|
|
|
<KBarPortal>
|
|
|
|
<KBarPositioner>
|
2022-07-14 11:32:28 +00:00
|
|
|
<KBarAnimator className="z-10 w-full max-w-screen-sm overflow-hidden rounded-sm bg-white shadow-lg">
|
|
|
|
<div className="flex items-center justify-center border-b">
|
2022-08-03 16:01:29 +00:00
|
|
|
<Icon.FiSearch className="mx-3 h-4 w-4 text-gray-500" />
|
2022-07-14 11:32:28 +00:00
|
|
|
<KBarSearch className="w-full rounded-sm py-2.5 focus-visible:outline-none" />
|
|
|
|
</div>
|
2022-07-14 06:45:07 +00:00
|
|
|
<RenderResults />
|
2022-07-14 11:32:28 +00:00
|
|
|
<div className="hidden items-center space-x-1 border-t px-2 py-1.5 text-xs text-gray-500 sm:flex">
|
2022-08-03 16:01:29 +00:00
|
|
|
<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" />
|
2022-07-14 11:32:28 +00:00
|
|
|
<span className="pr-2">{t("open")}</span>
|
2022-08-03 16:01:29 +00:00
|
|
|
{isMac ? <Icon.FiCommand className="h-3 w-3" /> : "CTRL"}
|
2022-07-14 11:32:28 +00:00
|
|
|
<span className="pr-1">+ K </span>
|
|
|
|
<span className="pr-2">{t("close")}</span>
|
|
|
|
</div>
|
2022-07-14 06:45:07 +00:00
|
|
|
</KBarAnimator>
|
2022-07-14 11:32:28 +00:00
|
|
|
<div className="z-1 fixed inset-0 bg-gray-600 bg-opacity-75" />
|
2022-07-14 06:45:07 +00:00
|
|
|
</KBarPositioner>
|
|
|
|
</KBarPortal>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const KBarTrigger = () => {
|
|
|
|
const { query } = useKBar();
|
|
|
|
return (
|
2022-07-14 11:32:28 +00:00
|
|
|
<>
|
|
|
|
<Tooltip side="right" content={isMac ? "⌘ + K" : "CTRL + K"}>
|
|
|
|
<button
|
|
|
|
color="minimal"
|
|
|
|
onClick={query.toggle}
|
|
|
|
className="group flex text-sm font-medium text-neutral-500 hover:text-neutral-900">
|
2022-08-03 16:01:29 +00:00
|
|
|
<Icon.FiSearch className="h-4 w-4 flex-shrink-0 text-neutral-400 group-hover:text-neutral-500" />
|
2022-07-14 11:32:28 +00:00
|
|
|
</button>
|
|
|
|
</Tooltip>
|
|
|
|
</>
|
2022-07-14 06:45:07 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const DisplayShortcuts = (item: shortcutArrayType) => {
|
|
|
|
const shortcuts = item.shortcuts;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<span className="space-x-1">
|
|
|
|
{shortcuts?.map((shortcut) => {
|
|
|
|
return (
|
2022-07-14 11:32:28 +00:00
|
|
|
<kbd key={shortcut} className="rounded-sm border bg-white px-2 py-1 text-black hover:bg-gray-100">
|
2022-07-14 06:45:07 +00:00
|
|
|
{shortcut}
|
|
|
|
</kbd>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
function RenderResults() {
|
|
|
|
const { results } = useMatches();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<KBarResults
|
|
|
|
items={results}
|
|
|
|
onRender={({ item, active }) =>
|
|
|
|
typeof item === "string" ? (
|
|
|
|
<div className="bg-white p-4 text-xs uppercase text-gray-500">{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>{item.name}</span>
|
|
|
|
<DisplayShortcuts shortcuts={item.shortcut} />
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|