2022-07-14 06:45:07 +00:00
|
|
|
import {
|
2022-11-23 02:55:25 +00:00
|
|
|
KBarAnimator,
|
2022-07-14 06:45:07 +00:00
|
|
|
KBarPortal,
|
|
|
|
KBarPositioner,
|
2022-11-23 02:55:25 +00:00
|
|
|
KBarProvider,
|
2022-07-14 06:45:07 +00:00
|
|
|
KBarResults,
|
2022-11-23 02:55:25 +00:00
|
|
|
KBarSearch,
|
2022-07-14 06:45:07 +00:00
|
|
|
useKBar,
|
2022-11-23 02:55:25 +00:00
|
|
|
useMatches,
|
2023-03-16 09:49:12 +00:00
|
|
|
useRegisterActions,
|
2022-07-14 06:45:07 +00:00
|
|
|
} from "kbar";
|
2023-03-16 09:49:12 +00:00
|
|
|
import type { Action } from "kbar";
|
2023-08-02 09:35:48 +00:00
|
|
|
import { useRouter } from "next/navigation";
|
2022-12-05 12:13:31 +00:00
|
|
|
import { useMemo } from "react";
|
2022-07-14 06:45:07 +00:00
|
|
|
|
2023-01-18 22:30:25 +00:00
|
|
|
import { appStoreMetadata } from "@calcom/app-store/appStoreMetaData";
|
2022-07-14 06:45:07 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
|
|
import { isMac } from "@calcom/lib/isMac";
|
2023-03-16 09:49:12 +00:00
|
|
|
import type { RouterOutputs } from "@calcom/trpc/react";
|
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2023-01-23 23:08:01 +00:00
|
|
|
import { Tooltip } from "@calcom/ui";
|
2023-04-12 15:26:31 +00:00
|
|
|
import { Search, ArrowUp, ArrowDown, CornerDownLeft, Command } from "@calcom/ui/components/icon";
|
2022-07-14 06:45:07 +00:00
|
|
|
|
|
|
|
type shortcutArrayType = {
|
|
|
|
shortcuts?: string[];
|
|
|
|
};
|
|
|
|
|
2023-01-07 17:06:53 +00:00
|
|
|
type EventTypeGroups = RouterOutputs["viewer"]["eventTypes"]["getByViewer"]["eventTypeGroups"];
|
|
|
|
type EventTypeGroup = EventTypeGroups[number];
|
|
|
|
|
2022-12-05 12:13:31 +00:00
|
|
|
const getApps = Object.values(appStoreMetadata).map(({ name, slug }) => ({
|
|
|
|
id: slug,
|
|
|
|
name,
|
|
|
|
section: "Installable Apps",
|
|
|
|
keywords: `app ${name}`,
|
|
|
|
}));
|
|
|
|
|
2023-03-16 09:49:12 +00:00
|
|
|
const useEventTypesAction = () => {
|
2022-07-14 06:45:07 +00:00
|
|
|
const router = useRouter();
|
2023-01-07 17:06:53 +00:00
|
|
|
const { data } = trpc.viewer.eventTypes.getByViewer.useQuery();
|
2023-03-16 09:49:12 +00:00
|
|
|
const eventTypeActions = data?.eventTypeGroups.reduce<Action[]>((acc: Action[], group: EventTypeGroup) => {
|
|
|
|
const item: Action[] = group.eventTypes.map((item) => ({
|
|
|
|
id: `event-type-${item.id}`,
|
|
|
|
name: item.title,
|
|
|
|
section: "event_types_page_title",
|
|
|
|
keywords: "event types",
|
|
|
|
perform: () => router.push(`/event-types/${item.id}`),
|
|
|
|
}));
|
|
|
|
acc.push(...item);
|
|
|
|
return acc;
|
|
|
|
}, []);
|
2022-07-14 06:45:07 +00:00
|
|
|
|
2023-03-16 09:49:12 +00:00
|
|
|
const actions = eventTypeActions?.length ? eventTypeActions : [];
|
|
|
|
|
|
|
|
return useRegisterActions(actions);
|
|
|
|
};
|
2022-12-05 12:13:31 +00:00
|
|
|
|
2023-03-16 09:49:12 +00:00
|
|
|
export const KBarRoot = ({ children }: { children: React.ReactNode }) => {
|
|
|
|
const router = useRouter();
|
2023-01-07 17:06:53 +00:00
|
|
|
|
2023-03-16 09:49:12 +00:00
|
|
|
// grab link to events
|
|
|
|
// quick nested actions would be extremely useful
|
2023-01-07 17:06:53 +00:00
|
|
|
|
2023-03-16 09:49:12 +00:00
|
|
|
const actions = useMemo(() => {
|
|
|
|
const appStoreActions = getApps.map((item) => ({
|
|
|
|
...item,
|
|
|
|
perform: () => router.push(`/apps/${item.id}`),
|
|
|
|
}));
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
id: "workflows",
|
|
|
|
name: "workflows",
|
|
|
|
section: "workflows",
|
|
|
|
shortcut: ["w", "f"],
|
|
|
|
keywords: "workflows automation",
|
|
|
|
perform: () => router.push("/workflows"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "event-types",
|
|
|
|
name: "event_types_page_title",
|
2023-01-07 17:06:53 +00:00
|
|
|
section: "event_types_page_title",
|
2023-03-16 09:49:12 +00:00
|
|
|
shortcut: ["e", "t"],
|
2023-01-07 17:06:53 +00:00
|
|
|
keywords: "event types",
|
2023-03-16 09:49:12 +00:00
|
|
|
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: "license",
|
|
|
|
name: "choose_a_license",
|
|
|
|
section: "admin",
|
|
|
|
shortcut: ["u", "l"],
|
|
|
|
keywords: "license",
|
|
|
|
perform: () => router.push("/auth/setup?step=1"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
];
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, []);
|
2022-07-14 06:45:07 +00:00
|
|
|
|
|
|
|
return <KBarProvider actions={actions}>{children}</KBarProvider>;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const KBarContent = () => {
|
2022-07-14 11:32:28 +00:00
|
|
|
const { t } = useLocale();
|
2023-03-16 09:49:12 +00:00
|
|
|
useEventTypesAction();
|
2022-07-14 06:45:07 +00:00
|
|
|
return (
|
|
|
|
<KBarPortal>
|
|
|
|
<KBarPositioner>
|
2023-04-05 18:14:46 +00:00
|
|
|
<KBarAnimator className="bg-default z-10 w-full max-w-screen-sm overflow-hidden rounded-md shadow-lg">
|
|
|
|
<div className="border-subtle flex items-center justify-center border-b">
|
2023-04-12 15:26:31 +00:00
|
|
|
<Search className="text-default mx-3 h-4 w-4" />
|
2022-11-30 21:52:56 +00:00
|
|
|
<KBarSearch
|
|
|
|
defaultPlaceholder={t("kbar_search_placeholder")}
|
2023-04-05 18:14:46 +00:00
|
|
|
className="bg-default placeholder:text-subtle text-default w-full rounded-sm py-2.5 focus-visible:outline-none"
|
2022-11-30 21:52:56 +00:00
|
|
|
/>
|
2022-07-14 11:32:28 +00:00
|
|
|
</div>
|
2022-07-14 06:45:07 +00:00
|
|
|
<RenderResults />
|
2023-04-05 18:14:46 +00:00
|
|
|
<div className="text-subtle border-subtle hidden items-center space-x-1 border-t px-2 py-1.5 text-xs sm:flex">
|
2023-04-12 15:26:31 +00:00
|
|
|
<ArrowUp className="h-4 w-4" />
|
|
|
|
<ArrowDown className="h-4 w-4" /> <span className="pr-2">{t("navigate")}</span>
|
|
|
|
<CornerDownLeft className="h-4 w-4" />
|
2022-07-14 11:32:28 +00:00
|
|
|
<span className="pr-2">{t("open")}</span>
|
2023-04-12 15:26:31 +00:00
|
|
|
{isMac ? <Command 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>
|
2023-04-05 18:14:46 +00:00
|
|
|
<div className="z-1 fixed inset-0 bg-neutral-800 bg-opacity-70" />
|
2022-07-14 06:45:07 +00:00
|
|
|
</KBarPositioner>
|
|
|
|
</KBarPortal>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const KBarTrigger = () => {
|
|
|
|
const { query } = useKBar();
|
2023-01-07 22:31:15 +00:00
|
|
|
return query ? (
|
2022-07-14 11:32:28 +00:00
|
|
|
<>
|
|
|
|
<Tooltip side="right" content={isMac ? "⌘ + K" : "CTRL + K"}>
|
|
|
|
<button
|
|
|
|
color="minimal"
|
|
|
|
onClick={query.toggle}
|
2023-06-15 10:42:47 +00:00
|
|
|
className="text-default hover:bg-subtle lg:hover:bg-emphasis lg:hover:text-emphasis group flex rounded-md px-3 py-2 text-sm font-medium lg:px-2">
|
2023-04-12 15:26:31 +00:00
|
|
|
<Search className="h-4 w-4 flex-shrink-0 text-inherit" />
|
2022-07-14 11:32:28 +00:00
|
|
|
</button>
|
|
|
|
</Tooltip>
|
|
|
|
</>
|
2023-01-07 22:31:15 +00:00
|
|
|
) : null;
|
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 (
|
2023-04-05 18:14:46 +00:00
|
|
|
<kbd
|
|
|
|
key={shortcut}
|
|
|
|
className="bg-default hover:bg-subtle text-emphasis rounded-sm border px-2 py-1">
|
2022-07-14 06:45:07 +00:00
|
|
|
{shortcut}
|
|
|
|
</kbd>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
function RenderResults() {
|
|
|
|
const { results } = useMatches();
|
2022-12-07 20:53:44 +00:00
|
|
|
const { t } = useLocale();
|
2022-07-14 06:45:07 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<KBarResults
|
|
|
|
items={results}
|
|
|
|
onRender={({ item, active }) =>
|
|
|
|
typeof item === "string" ? (
|
2023-04-05 18:14:46 +00:00
|
|
|
<div className="bg-default text-emphasis p-4 text-xs font-bold uppercase">{t(item)}</div>
|
2022-07-14 06:45:07 +00:00
|
|
|
) : (
|
|
|
|
<div
|
|
|
|
// For seeing keyboard up & down navigation in action, we need visual feedback based on "active" prop
|
|
|
|
style={{
|
2023-04-05 18:14:46 +00:00
|
|
|
background: active ? "var(--cal-bg-subtle)" : `var(--cal-bg-default)`,
|
|
|
|
borderLeft: active ? "2px solid var(--cal-border-default)" : "2px solid transparent",
|
|
|
|
color: "var(--cal-text)",
|
2022-07-14 06:45:07 +00:00
|
|
|
}}
|
|
|
|
className="flex items-center justify-between px-4 py-2.5 text-sm hover:cursor-pointer">
|
2022-12-07 20:53:44 +00:00
|
|
|
<span>{t(item.name)}</span>
|
2022-07-14 06:45:07 +00:00
|
|
|
<DisplayShortcuts shortcuts={item.shortcut} />
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|