Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,90 @@
|
||||
import { useFetcher, useLocation, useParams } from "react-router";
|
||||
import { Fragment, useEffect, useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import ButtonPrimary from "~/components/ui/buttons/ButtonPrimary";
|
||||
import StarsIconFilled from "~/components/ui/icons/StarsIconFilled";
|
||||
import InputText from "~/components/ui/input/InputText";
|
||||
import Modal from "~/components/ui/modals/Modal";
|
||||
import { appPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
import { useAppOrAdminData } from "~/utils/data/useAppOrAdminData";
|
||||
import { useRootData } from "~/utils/data/useRootData";
|
||||
|
||||
export default function AddFeedbackButton() {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<Fragment>
|
||||
<div className="relative hidden sm:inline-flex">
|
||||
<div className="relative">
|
||||
<div className="inline-flex divide-x divide-gray-300 rounded-sm shadow-none">
|
||||
<div className="relative z-0 inline-flex rounded-full text-sm shadow-none">
|
||||
<button
|
||||
onClick={() => setIsOpen(!isOpen)}
|
||||
type="button"
|
||||
className="text-muted-foreground bg-secondary hover:bg-secondary/90 border-border relative inline-flex items-center rounded-full border p-2 font-medium shadow-inner focus:z-10 focus:outline-hidden focus:ring-2 focus:ring-offset-2"
|
||||
aria-haspopup="listbox"
|
||||
aria-expanded="true"
|
||||
aria-label={t("feedback.title")}
|
||||
>
|
||||
<span className="sr-only">{t("feedback.title")}</span>
|
||||
|
||||
<StarsIconFilled className="h-5 w-5 p-0.5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Modal open={isOpen} setOpen={setIsOpen} size="sm">
|
||||
<FeedbackForm onClose={() => setIsOpen(false)} />
|
||||
</Modal>
|
||||
</Fragment>
|
||||
);
|
||||
}
|
||||
|
||||
function FeedbackForm({ onClose }: { onClose: () => void }) {
|
||||
const { t } = useTranslation();
|
||||
const params = useParams();
|
||||
const appOrAdminData = useAppOrAdminData();
|
||||
const { csrf } = useRootData();
|
||||
const fetcher = useFetcher<{ success?: string; error?: string }>();
|
||||
const location = useLocation();
|
||||
|
||||
useEffect(() => {
|
||||
if (fetcher.data?.success) {
|
||||
toast.success(fetcher.data.success);
|
||||
onClose();
|
||||
} else if (fetcher.data?.error) {
|
||||
toast.error(fetcher.data.error);
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [fetcher.data]);
|
||||
|
||||
const onSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
fetcher.submit(e.currentTarget, {
|
||||
method: "post",
|
||||
action: appPath({ tenantSlug: params.tenant ?? "", mode: "host-aware" }),
|
||||
});
|
||||
// onClose();
|
||||
};
|
||||
return (
|
||||
<fetcher.Form onSubmit={onSubmit} method="post">
|
||||
<input type="hidden" name="action" value="add-feedback" readOnly hidden />
|
||||
<input type="hidden" name="csrf" value={csrf ?? ""} readOnly hidden />
|
||||
<input type="hidden" name="tenantId" value={appOrAdminData.currentTenant?.id} readOnly hidden />
|
||||
<input type="hidden" name="fromUrl" value={location.pathname} readOnly hidden />
|
||||
<div className="space-y-3">
|
||||
<h3 className="text-lg font-medium leading-6">{t("feedback.title")}</h3>
|
||||
<p className="text-muted-foreground text-sm">{t("feedback.description")}</p>
|
||||
<InputText name="message" title="feedback.message" withLabel={false} defaultValue="" required rows={5} placeholder={t("feedback.placeholder")} />
|
||||
<div className="flex justify-between">
|
||||
<button type="button" onClick={onClose} className="text-muted-foreground text-sm hover:underline">
|
||||
{t("shared.cancel")}
|
||||
</button>
|
||||
<ButtonPrimary type="submit">{t("feedback.send")}</ButtonPrimary>
|
||||
</div>
|
||||
</div>
|
||||
</fetcher.Form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import clsx from "clsx";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useState } from "react";
|
||||
import { MessageCircleIcon } from "~/components/ui/icons/vendor";
|
||||
|
||||
export default function ChatSupportButton() {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const { t } = useTranslation();
|
||||
function onClick() {
|
||||
try {
|
||||
if (!isOpen) {
|
||||
// @ts-ignore
|
||||
$crisp?.push(["do", "chat:open"]);
|
||||
// @ts-ignore
|
||||
$crisp?.push(["do", "chat:show"]);
|
||||
setIsOpen(true);
|
||||
} else {
|
||||
// @ts-ignore
|
||||
$crisp?.push(["do", "chat:hide"]);
|
||||
setIsOpen(false);
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
return (
|
||||
<div className="relative hidden sm:inline-flex">
|
||||
<div className="relative">
|
||||
<div className="inline-flex divide-x divide-gray-300 rounded-sm shadow-none">
|
||||
<div className="relative z-0 inline-flex rounded-full text-sm shadow-none">
|
||||
<button
|
||||
onClick={onClick}
|
||||
type="button"
|
||||
className={clsx(
|
||||
"text-muted-foreground bg-secondary hover:bg-secondary/90 border-border relative inline-flex items-center rounded-full border p-2 font-medium shadow-inner focus:z-10 focus:outline-hidden focus:ring-2 focus:ring-offset-2"
|
||||
)}
|
||||
aria-haspopup="listbox"
|
||||
aria-expanded="true"
|
||||
aria-label={t("shared.openSupportChat")}
|
||||
>
|
||||
<span className="sr-only">{t("shared.openSupportChat")}</span>
|
||||
<MessageCircleIcon className="h-5 w-5" aria-hidden="true" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useAppData } from "~/utils/data/useAppData";
|
||||
import { Link, useParams } from "react-router";
|
||||
import clsx from "~/utils/shared/ClassesUtils";
|
||||
import { subscriptionCheckoutPath } from "~/utils/app/SubscriptionUrlUtils";
|
||||
import { SparklesIcon } from "~/components/ui/icons/vendor";
|
||||
|
||||
export default function CurrentSubscriptionButton() {
|
||||
const params = useParams();
|
||||
const { t } = useTranslation();
|
||||
const appData = useAppData();
|
||||
|
||||
function getSubscriptionProducts() {
|
||||
return appData.mySubscription?.products.map((f) => t(f.subscriptionProduct.title)) ?? [];
|
||||
}
|
||||
function hasSubscription() {
|
||||
return getSubscriptionProducts().length > 0;
|
||||
}
|
||||
return (
|
||||
<>
|
||||
{!hasSubscription() && (
|
||||
<div className="hidden divide-x divide-gray-300 rounded-sm shadow-none lg:inline-flex">
|
||||
<div className="relative z-0 inline-flex rounded-full text-xs shadow-none sm:text-sm">
|
||||
<Link
|
||||
to={!params.tenant ? "" : subscriptionCheckoutPath(params.tenant)}
|
||||
className={clsx(
|
||||
"text-muted-foreground bg-secondary border-border relative inline-flex items-center space-x-1 rounded-md border p-2 font-medium shadow-inner hover:bg-teal-50 hover:text-teal-800 focus:z-10 focus:bg-teal-100 focus:text-teal-900 focus:outline-hidden",
|
||||
hasSubscription() &&
|
||||
"flex space-x-2 px-3 text-teal-900 hover:bg-teal-50 hover:text-teal-800 focus:z-10 focus:bg-teal-100 focus:text-teal-900 focus:outline-hidden",
|
||||
!hasSubscription() &&
|
||||
" border-yellow-200 bg-yellow-50 text-yellow-800 hover:bg-yellow-100 hover:text-yellow-900 focus:z-10 focus:bg-yellow-100 focus:text-yellow-900 focus:outline-hidden"
|
||||
)}
|
||||
aria-haspopup="listbox"
|
||||
aria-expanded="true"
|
||||
aria-labelledby="listbox-label"
|
||||
>
|
||||
{hasSubscription() ? (
|
||||
<div>
|
||||
<span>{getSubscriptionProducts().join(", ")} </span>
|
||||
</div>
|
||||
) : (
|
||||
<div>
|
||||
<span>{t("pricing.subscribe")} </span>
|
||||
</div>
|
||||
)}
|
||||
<SparklesIcon className="h-4 w-4" />
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
import "@testing-library/jest-dom";
|
||||
import { fireEvent, render, screen } from "@testing-library/react";
|
||||
import { MemoryRouter } from "react-router";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { UI_ACTION_IDS } from "~/application/ui/uiRegistry";
|
||||
import NotificationsButton from "./NotificationsButton";
|
||||
import ProfileButton from "./ProfileButton";
|
||||
import SearchButton from "./SearchButton";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({ t: (value: string) => value }),
|
||||
}));
|
||||
|
||||
vi.mock("react-router", async () => {
|
||||
const actual = await vi.importActual<typeof import("react-router")>("react-router");
|
||||
return {
|
||||
...actual,
|
||||
Form: ({ children, ...props }: React.ComponentProps<"form">) => <form {...props}>{children}</form>,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("~/utils/data/useRootData", () => ({
|
||||
useRootData: () => (globalThis as any).__layoutButtonsRootData,
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/data/useAppOrAdminData", () => ({
|
||||
useAppOrAdminData: () => ({ permissions: [] }),
|
||||
}));
|
||||
|
||||
describe("layout button UI IDs", () => {
|
||||
beforeEach(() => {
|
||||
(globalThis as any).__layoutButtonsRootData = { appConfiguration: { app: { features: { tenantApiKeys: false } } } };
|
||||
});
|
||||
|
||||
it("renders SearchButton with a stable action ID", () => {
|
||||
render(<SearchButton onClick={vi.fn()} />);
|
||||
|
||||
expect(document.querySelector(`[data-ui-id="${UI_ACTION_IDS.search}"]`)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders NotificationsButton with a stable action ID", () => {
|
||||
render(
|
||||
<MemoryRouter>
|
||||
<NotificationsButton unseenCount={2} to="/acme/notifications" />
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
expect(screen.getByLabelText("shell.notifications.ariaLabel")).toHaveAttribute("data-ui-id", UI_ACTION_IDS.notifications);
|
||||
expect(screen.getByLabelText("shell.notifications.ariaLabel")).toHaveAttribute("href", "/acme/notifications");
|
||||
});
|
||||
|
||||
it("renders ProfileButton with stable action and menu IDs", () => {
|
||||
render(
|
||||
<MemoryRouter>
|
||||
<ProfileButton user={{ email: "user@example.com", firstName: "Ada", lastName: "Lovelace", avatar: null }} layout="admin" />
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
expect(document.querySelector(`[data-ui-id="${UI_ACTION_IDS.profile}.menu"]`)).toBeInTheDocument();
|
||||
expect(screen.getByLabelText("shell.profile.userMenu")).toHaveAttribute("data-ui-id", UI_ACTION_IDS.profile);
|
||||
});
|
||||
|
||||
it("uses default tenant settings links in the public profile menu when available", () => {
|
||||
(globalThis as any).__layoutButtonsRootData = {
|
||||
...(globalThis as any).__layoutButtonsRootData,
|
||||
currentTenant: { id: "tenant_1", slug: "acme" },
|
||||
};
|
||||
|
||||
render(
|
||||
<MemoryRouter>
|
||||
<ProfileButton user={{ email: "user@example.com", firstName: "Ada", lastName: "Lovelace", avatar: null }} layout="/" />
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
fireEvent.click(screen.getByLabelText("shell.profile.userMenu"));
|
||||
|
||||
expect(screen.getByRole("menuitem", { name: "app.navbar.profile" })).toHaveAttribute("href", "/acme/settings/profile");
|
||||
expect(screen.getByRole("menuitem", { name: "app.navbar.subscription" })).toHaveAttribute("href", "/acme/settings/subscription");
|
||||
});
|
||||
|
||||
it("localizes the public admin menu link", () => {
|
||||
render(
|
||||
<MemoryRouter>
|
||||
<ProfileButton user={{ email: "admin@example.com", firstName: "Ada", lastName: "Lovelace", avatar: null, admin: { userId: "user_1" } }} layout="/" />
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
fireEvent.click(screen.getByLabelText("shell.profile.userMenu"));
|
||||
|
||||
expect(screen.getByRole("menuitem", { name: "shared.admin" })).toHaveAttribute("href", "/dashboard");
|
||||
expect(screen.queryByRole("menuitem", { name: "Admin" })).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,60 @@
|
||||
import clsx from "clsx";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { UI_ACTION_IDS } from "~/application/ui/uiRegistry";
|
||||
import { BellIcon } from "~/components/ui/icons/vendor";
|
||||
|
||||
interface Props {
|
||||
unseenCount?: number;
|
||||
to: string;
|
||||
}
|
||||
export default function NotificationsButton({ unseenCount, to }: Props) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<div className="relative">
|
||||
<div className="inline-flex divide-x divide-gray-300 rounded-sm shadow-none">
|
||||
<a
|
||||
href={to}
|
||||
data-ui-id={UI_ACTION_IDS.notifications}
|
||||
aria-label={t("shell.notifications.ariaLabel")}
|
||||
className={clsx(
|
||||
"text-muted-foreground bg-secondary hover:bg-secondary/90 border-border relative inline-flex items-center rounded-full border p-2 font-medium shadow-inner focus-visible:z-10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
||||
)}
|
||||
>
|
||||
<span className="relative inline-block h-5 w-5 overflow-hidden rounded-full">
|
||||
<BellIcon className="h-5 w-5" />
|
||||
</span>
|
||||
{unseenCount?.toString() !== "0" && (
|
||||
<span className="absolute inset-0 -mr-6 object-right-top">
|
||||
<div className="inline-flex items-center rounded-full border-2 border-white bg-red-500 px-1.5 py-0.5 text-xs font-semibold leading-4 text-white">
|
||||
{unseenCount}
|
||||
</div>
|
||||
</span>
|
||||
)}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
// <div className="w-full flex md:ml-0">
|
||||
// <div className="align-baseline w-full text-slate-200 pl-1">
|
||||
// <div className="w-full">
|
||||
// <label htmlFor="command-palette" className="sr-only">
|
||||
// {t("shared.commandPalette")}
|
||||
// </label>
|
||||
// <div className="relative text-muted-foreground hover:text-muted-foreground truncate">
|
||||
|
||||
// <button
|
||||
// type="button"
|
||||
// onClick={onOpenCommandPalette}
|
||||
// className="flex space-x-2 text-left w-full pl-3 pr-3 py-1.5 text-sm sm:py-2 border border-border rounded-md leading-5 bg-secondary text-muted-foreground focus:outline-hidden hover:ring-0 hover:placeholder-gray-500 hover:text-muted-foreground truncate"
|
||||
// >
|
||||
// <div className="font-medium hidden lg:block">⌘K</div>
|
||||
// <div className="hidden lg:block truncate">{t("shared.commandPalette")}</div>
|
||||
// <div className="lg:hidden">{t("shared.search")}</div>
|
||||
// </button>
|
||||
// </div>
|
||||
// </div>
|
||||
// </div>
|
||||
// </div>
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import clsx from "~/utils/shared/ClassesUtils";
|
||||
import { OnboardingSessionWithDetails } from "~/modules/onboarding/db/onboardingSessions.db.server";
|
||||
import BycicleIcon from "~/components/ui/icons/onboardings/BycicleIcon";
|
||||
|
||||
export default function OnboardingButton({ item, onClick }: { item: OnboardingSessionWithDetails; onClick?: () => void }) {
|
||||
return (
|
||||
<div className="inline-flex divide-x divide-theme-300 rounded-full shadow-none sm:rounded-md">
|
||||
<div className="relative z-0 inline-flex rounded-full text-xs shadow-none sm:text-sm">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClick}
|
||||
className={clsx(
|
||||
"relative inline-flex items-center rounded-full border border-theme-100 bg-theme-50 p-2 font-medium text-theme-500 shadow-inner hover:bg-theme-100 hover:text-theme-800 focus:z-10 focus:bg-theme-100 focus:text-theme-900 focus:outline-hidden sm:rounded-md",
|
||||
"flex px-3 text-theme-900 hover:bg-theme-200 hover:text-theme-800 focus:z-10 focus:bg-theme-100 focus:text-theme-900 focus:outline-hidden"
|
||||
)}
|
||||
aria-haspopup="listbox"
|
||||
aria-expanded="true"
|
||||
aria-label={item.onboarding.title}
|
||||
>
|
||||
<div className="hidden lg:block">{item.onboarding.title}</div>
|
||||
<BycicleIcon className={clsx("h-5 w-5", item.onboarding.title.length > 0 && "lg:ml-2")} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
describe("ProfileButton route fallbacks", () => {
|
||||
it("does not emit root-relative tenant settings fallbacks from the public header menu", () => {
|
||||
const source = fs.readFileSync(path.resolve(process.cwd(), "apps/web/app/components/layouts/buttons/ProfileButton.tsx"), "utf8");
|
||||
|
||||
expect(source).not.toContain('?? "/settings"');
|
||||
expect(source).not.toContain('?? "/settings/subscription"');
|
||||
expect(source).toContain('publicHeaderAdminPath("dashboard")');
|
||||
expect(source).toContain('defaultTenantPath("settings/profile") ?? publicHeaderAdminPath("settings/profile")');
|
||||
expect(source).not.toContain('defaultTenantPath("settings/profile") ?? adminShellPath("settings/profile")');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,259 @@
|
||||
import { Form, Link, useParams } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Transition } from "@headlessui/react";
|
||||
import { Fragment, useState } from "react";
|
||||
import clsx from "~/utils/shared/ClassesUtils";
|
||||
import { useOuterClick } from "~/utils/shared/KeypressUtils";
|
||||
import UserDisplayUtils from "~/utils/app/UserDisplayUtils";
|
||||
import { adminPath, appPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
import { useAppOrAdminData } from "~/utils/data/useAppOrAdminData";
|
||||
import { getUserHasPermission } from "~/utils/helpers/PermissionsHelper";
|
||||
import { useRootData } from "~/utils/data/useRootData";
|
||||
import { UI_ACTION_IDS } from "~/application/ui/uiRegistry";
|
||||
import { absoluteAdminPath } from "~/utils/app/CrossHostUrls";
|
||||
import { UserIcon } from "~/components/ui/icons/vendor";
|
||||
|
||||
interface Props {
|
||||
user: { email: string; firstName: string | null; lastName: string | null; avatar: string | null; admin?: { userId: string } | null } | null | undefined;
|
||||
layout?: "/" | "app" | "admin" | "docs";
|
||||
items?: { title: string; path: string; hidden?: boolean; onClick?: () => void }[];
|
||||
}
|
||||
|
||||
export default function ProfileButton({ user, layout, items }: Props) {
|
||||
const params = useParams();
|
||||
const { t } = useTranslation();
|
||||
const rootData = useRootData();
|
||||
const appOrAdminData = useAppOrAdminData();
|
||||
const tenantPath = (path?: string) => (params.tenant ? appPath({ tenantSlug: params.tenant, path, mode: "host-aware" }) : "");
|
||||
const defaultTenantPath = (path?: string) =>
|
||||
rootData.currentTenant?.slug ? appPath({ tenantSlug: rootData.currentTenant.slug, path, mode: "host-aware" }) : undefined;
|
||||
const adminShellPath = (path?: string) => adminPath(path, { mode: "host-aware" });
|
||||
const publicHeaderAdminPath = (path?: string) => absoluteAdminPath(rootData.routing, path);
|
||||
|
||||
const [opened, setOpened] = useState(false);
|
||||
|
||||
function closeDropdownUser() {
|
||||
setOpened(false);
|
||||
}
|
||||
// function signOut() {
|
||||
// submit(null, { method: "post", action: "/logout" });
|
||||
// }
|
||||
|
||||
const clickOutside = useOuterClick(() => setOpened(false));
|
||||
|
||||
return (
|
||||
<div ref={clickOutside} className="relative" data-ui-id={`${UI_ACTION_IDS.profile}.menu`}>
|
||||
<div className="inline-flex divide-x divide-gray-300 rounded-sm shadow-none">
|
||||
<button
|
||||
onClick={() => setOpened(!opened)}
|
||||
data-ui-id={UI_ACTION_IDS.profile}
|
||||
className={clsx(
|
||||
"bg-background text-muted-foreground hover:bg-secondary border-border relative inline-flex items-center rounded-full border font-medium shadow-inner focus-visible:z-10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
|
||||
!user?.avatar && "p-2",
|
||||
user?.avatar && "p-1"
|
||||
)}
|
||||
id="user-menu"
|
||||
aria-label={t("shell.profile.userMenu")}
|
||||
aria-haspopup="true"
|
||||
>
|
||||
{(() => {
|
||||
if (user?.avatar) {
|
||||
return <img className="inline-flex h-8 w-8 items-center justify-center rounded-full bg-slate-800" src={user.avatar} alt={t("models.user.avatarAlt")} />;
|
||||
} else {
|
||||
return (
|
||||
<span className="inline-block h-5 w-5 overflow-hidden rounded-full">
|
||||
<UserIcon className="h-full w-full" />
|
||||
</span>
|
||||
);
|
||||
}
|
||||
})()}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<Transition
|
||||
as={Fragment}
|
||||
show={opened}
|
||||
enter="transition ease-out duration-100"
|
||||
enterFrom="transform opacity-0 scale-95"
|
||||
enterTo="transform opacity-100 scale-100"
|
||||
leave="transition ease-in duration-75"
|
||||
leaveFrom="transform opacity-100 scale-100"
|
||||
leaveTo="transform opacity-0 scale-95"
|
||||
>
|
||||
<div className="divide-border border-border absolute right-0 z-40 mt-2 w-64 origin-top-right divide-y overflow-hidden rounded-sm border shadow-lg focus:outline-hidden">
|
||||
<div className="shadow-2xs bg-background rounded-sm py-1" role="menu" aria-orientation="vertical" aria-labelledby="user-menu">
|
||||
<div className="text-muted-foreground group flex items-center truncate px-4 py-2 text-sm transition duration-150 ease-in-out" role="menuitem">
|
||||
<div className="flex flex-col space-y-1 truncate">
|
||||
<div className="font-medium">{UserDisplayUtils.profileName(user)}</div>
|
||||
<div className="truncate font-bold">{user?.email}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="border-border border-t"></div>
|
||||
|
||||
{layout === "app" ? (
|
||||
<>
|
||||
<Link
|
||||
className="hover:bg-secondary block px-4 py-2 text-sm transition duration-150 ease-in-out"
|
||||
role="menuitem"
|
||||
onClick={closeDropdownUser}
|
||||
to={tenantPath("settings/profile")}
|
||||
>
|
||||
{t("app.navbar.profile")}
|
||||
</Link>
|
||||
|
||||
{getUserHasPermission(appOrAdminData, "app.settings.members.view") && (
|
||||
<Link
|
||||
className="hover:bg-secondary block px-4 py-2 text-sm transition duration-150 ease-in-out"
|
||||
role="menuitem"
|
||||
onClick={closeDropdownUser}
|
||||
to={tenantPath("settings/members")}
|
||||
>
|
||||
{t("app.navbar.members")}
|
||||
</Link>
|
||||
)}
|
||||
|
||||
{getUserHasPermission(appOrAdminData, "app.settings.subscription.view") && (
|
||||
<Link
|
||||
className="hover:bg-secondary block px-4 py-2 text-sm transition duration-150 ease-in-out"
|
||||
role="menuitem"
|
||||
onClick={closeDropdownUser}
|
||||
to={tenantPath("settings/subscription")}
|
||||
>
|
||||
{t("app.navbar.subscription")}
|
||||
</Link>
|
||||
)}
|
||||
|
||||
{getUserHasPermission(appOrAdminData, "app.settings.account.view") && (
|
||||
<Link
|
||||
className="hover:bg-secondary block px-4 py-2 text-sm transition duration-150 ease-in-out"
|
||||
role="menuitem"
|
||||
onClick={closeDropdownUser}
|
||||
to={tenantPath("settings/account")}
|
||||
>
|
||||
{t("app.navbar.tenant")}
|
||||
</Link>
|
||||
)}
|
||||
|
||||
{/* {getUserHasPermission(appOrAdminData, "app.settings.roles.view") && (
|
||||
<Link
|
||||
className="block px-4 py-2 text-sm transition duration-150 ease-in-out hover:bg-secondary"
|
||||
role="menuitem"
|
||||
onClick={closeDropdownUser}
|
||||
to={tenantPath("settings/roles-and-permissions")}
|
||||
>
|
||||
{t("models.role.plural")}
|
||||
</Link>
|
||||
)} */}
|
||||
|
||||
{/* <Link
|
||||
className="block px-4 py-2 text-sm transition duration-150 ease-in-out hover:bg-secondary"
|
||||
role="menuitem"
|
||||
onClick={closeDropdownUser}
|
||||
to={tenantPath("settings/groups")}
|
||||
>
|
||||
{t("models.group.plural")}
|
||||
</Link> */}
|
||||
|
||||
{rootData.appConfiguration.app.features.tenantApiKeys && getUserHasPermission(appOrAdminData, "app.settings.apiKeys.view") && (
|
||||
<Link
|
||||
className="hover:bg-secondary block px-4 py-2 text-sm transition duration-150 ease-in-out"
|
||||
role="menuitem"
|
||||
onClick={closeDropdownUser}
|
||||
to={tenantPath("settings/api")}
|
||||
>
|
||||
{t("models.apiKey.plural")}
|
||||
</Link>
|
||||
)}
|
||||
|
||||
{getUserHasPermission(appOrAdminData, "app.settings.auditTrails.view") && (
|
||||
<Link
|
||||
className="hover:bg-secondary block px-4 py-2 text-sm transition duration-150 ease-in-out"
|
||||
role="menuitem"
|
||||
onClick={closeDropdownUser}
|
||||
to={tenantPath("settings/logs")}
|
||||
>
|
||||
{t("models.log.plural")}
|
||||
</Link>
|
||||
)}
|
||||
|
||||
<div className="border-border mt-1 border-t"></div>
|
||||
</>
|
||||
) : layout === "admin" ? (
|
||||
<Link
|
||||
className="hover:bg-secondary block px-4 py-2 text-sm transition duration-150 ease-in-out"
|
||||
role="menuitem"
|
||||
onClick={closeDropdownUser}
|
||||
to={!user ? "" : adminShellPath("settings/profile")}
|
||||
>
|
||||
{t("app.navbar.profile")}
|
||||
</Link>
|
||||
) : layout === "/" ? (
|
||||
<Fragment>
|
||||
{user?.admin && (
|
||||
<Link
|
||||
className="hover:bg-secondary block px-4 py-2 text-sm transition duration-150 ease-in-out"
|
||||
role="menuitem"
|
||||
onClick={closeDropdownUser}
|
||||
to={publicHeaderAdminPath("dashboard")}
|
||||
>
|
||||
{t("shared.admin")}
|
||||
</Link>
|
||||
)}
|
||||
{(defaultTenantPath("settings/profile") || user?.admin) && (
|
||||
<Link
|
||||
className="hover:bg-secondary block px-4 py-2 text-sm transition duration-150 ease-in-out"
|
||||
role="menuitem"
|
||||
onClick={closeDropdownUser}
|
||||
to={defaultTenantPath("settings/profile") ?? publicHeaderAdminPath("settings/profile")}
|
||||
>
|
||||
{t("app.navbar.profile")}
|
||||
</Link>
|
||||
)}
|
||||
{defaultTenantPath("settings/subscription") && (
|
||||
<Link
|
||||
className="hover:bg-secondary block px-4 py-2 text-sm transition duration-150 ease-in-out"
|
||||
role="menuitem"
|
||||
onClick={closeDropdownUser}
|
||||
to={defaultTenantPath("settings/subscription")!}
|
||||
>
|
||||
{t("app.navbar.subscription")}
|
||||
</Link>
|
||||
)}
|
||||
</Fragment>
|
||||
) : items ? (
|
||||
items.map((item) => (
|
||||
<Link
|
||||
key={item.path}
|
||||
className="hover:bg-secondary block px-4 py-2 text-sm transition duration-150 ease-in-out"
|
||||
role="menuitem"
|
||||
onClick={() => {
|
||||
if (item.onClick) {
|
||||
item.onClick();
|
||||
}
|
||||
closeDropdownUser();
|
||||
}}
|
||||
to={item.path}
|
||||
>
|
||||
{item.title}
|
||||
</Link>
|
||||
))
|
||||
) : null}
|
||||
|
||||
{!items && (
|
||||
<Form method="post" action="/logout">
|
||||
{rootData.csrf && <input type="hidden" name="csrf" value={rootData.csrf} />}
|
||||
<button
|
||||
type="submit"
|
||||
className="hover:bg-secondary block w-full px-4 py-2 text-left text-sm transition duration-150 ease-in-out focus:outline-hidden"
|
||||
role="menuitem"
|
||||
>
|
||||
{t("app.navbar.signOut")}
|
||||
</button>
|
||||
</Form>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { quickActionEntityPath } from "./QuickActionsButton";
|
||||
|
||||
describe("quickActionEntityPath", () => {
|
||||
it("keeps create links inside the active group route", () => {
|
||||
expect(quickActionEntityPath({ tenant: "acme", group: "sales" }, "contacts")).toBe("/acme/g/sales/contacts/new");
|
||||
});
|
||||
|
||||
it("uses the tenant entity route outside groups", () => {
|
||||
expect(quickActionEntityPath({ tenant: "acme" }, "contacts")).toBe("/acme/contacts/new");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,90 @@
|
||||
import { Link, useParams } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Transition } from "@headlessui/react";
|
||||
import { Fragment, useState } from "react";
|
||||
import { useOuterClick } from "~/utils/shared/KeypressUtils";
|
||||
import { useAppData } from "~/utils/data/useAppData";
|
||||
import UrlUtils from "~/utils/app/UrlUtils";
|
||||
import { EntitySimple } from "~/utils/db/entities/entities.db.server";
|
||||
import { getEntityPermission, getUserHasPermission } from "~/utils/helpers/PermissionsHelper";
|
||||
import { PlusIcon } from "~/components/ui/icons/vendor";
|
||||
|
||||
interface Props {
|
||||
entities: EntitySimple[];
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function quickActionEntityPath(params: { tenant?: string; group?: string }, entitySlug: string) {
|
||||
const path = params.group ? `g/${params.group}/${entitySlug}/new` : `${entitySlug}/new`;
|
||||
return UrlUtils.currentTenantUrl(params, path);
|
||||
}
|
||||
|
||||
export default function QuickActionsButton({ entities, className }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const params = useParams();
|
||||
const appData = useAppData();
|
||||
|
||||
const [opened, setOpened] = useState(false);
|
||||
const creatableEntities = entities.filter((entity) => getUserHasPermission(appData, getEntityPermission(entity, "create")));
|
||||
const hasQuickActions = creatableEntities.length > 0;
|
||||
|
||||
const clickOutside = useOuterClick(() => setOpened(false));
|
||||
return (
|
||||
<span className={className} ref={clickOutside}>
|
||||
{hasQuickActions && (
|
||||
<div className="relative">
|
||||
<div className="inline-flex divide-x divide-gray-300 rounded-sm shadow-none">
|
||||
<div className="relative z-0 inline-flex rounded-full text-sm shadow-none">
|
||||
<button
|
||||
onClick={() => setOpened(!opened)}
|
||||
type="button"
|
||||
className="text-muted-foreground bg-secondary hover:bg-secondary/90 border-border relative inline-flex items-center rounded-full border p-2 font-medium shadow-inner focus:z-10 focus:outline-hidden focus:ring-2 focus:ring-offset-2"
|
||||
aria-haspopup="listbox"
|
||||
aria-expanded="true"
|
||||
aria-label={t("shared.new")}
|
||||
>
|
||||
<span className="sr-only">{t("shared.new")}</span>
|
||||
<PlusIcon className="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Transition
|
||||
as={Fragment}
|
||||
show={opened}
|
||||
enter="transition ease-out duration-100"
|
||||
enterFrom="transform opacity-0 scale-95"
|
||||
enterTo="transform opacity-100 scale-100"
|
||||
leave="transition ease-in duration-75"
|
||||
leaveFrom="transform opacity-100 scale-100"
|
||||
leaveTo="transform opacity-0 scale-95"
|
||||
>
|
||||
<ul
|
||||
className="divide-border bg-background absolute right-0 z-40 mt-2 w-72 origin-top-right divide-y overflow-hidden rounded-sm shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-hidden"
|
||||
tabIndex={-1}
|
||||
aria-labelledby="listbox-label"
|
||||
>
|
||||
{creatableEntities.map((entity) => {
|
||||
return (
|
||||
<li key={entity.name} className="text-foreground relative cursor-default select-none text-sm" id="listbox-option-0">
|
||||
<Link
|
||||
to={quickActionEntityPath(params, entity.slug)}
|
||||
onClick={() => setOpened(false)}
|
||||
className="hover:bg-secondary flex flex-col p-4"
|
||||
>
|
||||
<div className="flex justify-between">
|
||||
<p className="font-semibold">
|
||||
{t("shared.new")} {t(entity.title)}
|
||||
</p>
|
||||
</div>
|
||||
</Link>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
</Transition>
|
||||
</div>
|
||||
)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import clsx from "clsx";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { UI_ACTION_IDS } from "~/application/ui/uiRegistry";
|
||||
import { SearchIcon } from "~/components/ui/icons/vendor";
|
||||
|
||||
interface Props {
|
||||
onClick: () => void;
|
||||
}
|
||||
export default function SearchButton({ onClick }: Props) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div className="relative">
|
||||
<div className="inline-flex divide-x divide-gray-300 rounded-sm shadow-none">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClick}
|
||||
data-ui-id={UI_ACTION_IDS.search}
|
||||
aria-label={t("shared.search")}
|
||||
className={clsx(
|
||||
"text-muted-foreground bg-secondary hover:bg-secondary/90 border-border relative inline-flex items-center rounded-full border p-2 font-medium shadow-inner focus-visible:z-10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
||||
)}
|
||||
>
|
||||
<span className="inline-block h-5 w-5 overflow-hidden rounded-full">
|
||||
<SearchIcon className="h-5 w-5" aria-hidden="true" />
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
// <div className="w-full flex md:ml-0">
|
||||
// <div className="align-baseline w-full text-slate-200 pl-1">
|
||||
// <div className="w-full">
|
||||
// <label htmlFor="command-palette" className="sr-only">
|
||||
// {t("shared.commandPalette")}
|
||||
// </label>
|
||||
// <div className="relative text-muted-foreground hover:text-muted-foreground truncate">
|
||||
|
||||
// <button
|
||||
// type="button"
|
||||
// onClick={onOpenCommandPalette}
|
||||
// className="flex space-x-2 text-left w-full pl-3 pr-3 py-1.5 text-sm sm:py-2 border border-border rounded-md leading-5 bg-secondary text-muted-foreground focus:outline-hidden hover:ring-0 hover:placeholder-gray-500 hover:text-muted-foreground truncate"
|
||||
// >
|
||||
// <div className="font-medium hidden lg:block">⌘K</div>
|
||||
// <div className="hidden lg:block truncate">{t("shared.commandPalette")}</div>
|
||||
// <div className="lg:hidden">{t("shared.search")}</div>
|
||||
// </button>
|
||||
// </div>
|
||||
// </div>
|
||||
// </div>
|
||||
// </div>
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { Link } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import clsx from "~/utils/shared/ClassesUtils";
|
||||
import { adminPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
import { SparklesIcon } from "~/components/ui/icons/vendor";
|
||||
|
||||
export default function UpdateAvailableButton({ hasUpdate }: { hasUpdate: boolean }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<>
|
||||
{hasUpdate && (
|
||||
<div className="hidden divide-x divide-gray-300 rounded-sm shadow-none lg:inline-flex">
|
||||
<div className="relative z-0 inline-flex rounded-full text-xs shadow-none sm:text-sm">
|
||||
<Link
|
||||
to={adminPath("settings", { mode: "host-aware" })}
|
||||
className={clsx(
|
||||
"text-muted-foreground bg-secondary border-border relative inline-flex items-center space-x-1 rounded-md border p-2 font-medium shadow-inner hover:bg-teal-50 hover:text-teal-800 focus:z-10 focus:bg-teal-100 focus:text-teal-900 focus:outline-hidden",
|
||||
" border-green-200 bg-green-50 text-green-800 hover:bg-green-100 hover:text-green-900 focus:z-10 focus:bg-green-100 focus:text-green-900 focus:outline-hidden"
|
||||
)}
|
||||
aria-haspopup="listbox"
|
||||
aria-expanded="true"
|
||||
aria-labelledby="listbox-label"
|
||||
>
|
||||
<div>
|
||||
<span>{t("shell.updateAvailable")}</span>
|
||||
</div>
|
||||
<SparklesIcon className="h-4 w-4" />
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user