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,313 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import { CreditCard, LogOut, MoreHorizontal, GearIcon, SparklesIcon, SearchIcon, MessageCircleIcon } from "~/components/ui/icons/vendor";
|
||||
|
||||
import { Button } from "~/components/ui/button";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "~/components/ui/popover";
|
||||
import { Sidebar, SidebarContent, SidebarGroup, SidebarGroupContent, SidebarMenu, SidebarMenuButton, SidebarMenuItem } from "~/components/ui/sidebar";
|
||||
import NavBar from "../../NavBar";
|
||||
import { getUserHasPermission } from "~/utils/helpers/PermissionsHelper";
|
||||
import { useAppOrAdminData } from "~/utils/data/useAppOrAdminData";
|
||||
import { useRootData } from "~/utils/data/useRootData";
|
||||
import { Form, useFetcher, useLocation, useParams } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { adminPath, appPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
import Modal from "~/components/ui/modals/Modal";
|
||||
import StarsIconFilled from "~/components/ui/icons/StarsIconFilled";
|
||||
import { useAppData } from "~/utils/data/useAppData";
|
||||
import OnboardingButton from "../../buttons/OnboardingButton";
|
||||
import { toast } from "sonner";
|
||||
import ButtonPrimary from "~/components/ui/buttons/ButtonPrimary";
|
||||
import { Textarea } from "~/components/ui/textarea";
|
||||
import { UI_ACTION_IDS, UI_SURFACE_IDS } from "~/application/ui/uiRegistry";
|
||||
import { subscriptionCheckoutPath } from "~/utils/app/SubscriptionUrlUtils";
|
||||
import NotificationsButton from "../../buttons/NotificationsButton";
|
||||
|
||||
const headerIconButtonClass = "size-10 shrink-0 text-muted-foreground";
|
||||
|
||||
export function NavActions({
|
||||
layout,
|
||||
onOpenCommandPalette,
|
||||
setOnboardingModalOpen,
|
||||
}: {
|
||||
layout: "admin" | "app" | "docs";
|
||||
onOpenCommandPalette: () => void;
|
||||
setOnboardingModalOpen: (value: boolean) => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
// const title = useTitleData() ?? "";
|
||||
|
||||
const appOrAdminData = useAppOrAdminData();
|
||||
const appData = useAppData();
|
||||
const rootData = useRootData();
|
||||
const appConfiguration = rootData.appConfiguration;
|
||||
const params = useParams();
|
||||
|
||||
const tenantPath = (path?: string) => (params.tenant ? appPath({ tenantSlug: params.tenant, path, mode: "host-aware" }) : "");
|
||||
const adminShellPath = (path?: string) => adminPath(path, { mode: "host-aware" });
|
||||
|
||||
const [isOpen, setIsOpen] = React.useState(false);
|
||||
|
||||
function hasSubscription() {
|
||||
const myProducts = appData?.mySubscription?.products.map((f) => t(f.subscriptionProduct.title)) ?? [];
|
||||
return myProducts.length > 0;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-w-0 max-w-full overflow-hidden text-sm">
|
||||
{false && (
|
||||
<NavBar
|
||||
layout={layout}
|
||||
// title={title}
|
||||
buttons={{
|
||||
mySubscription: getUserHasPermission(appOrAdminData, "app.settings.subscription.update"),
|
||||
feedback: rootData.appConfiguration.app.features.tenantFeedback,
|
||||
chatSupport: !!rootData.chatWebsiteId,
|
||||
quickActions: appOrAdminData?.entities?.filter((f) => f.showInSidebar).length > 0,
|
||||
search: true,
|
||||
notifications: appConfiguration.notifications.enabled && (layout === "admin" || layout === "app"),
|
||||
onboarding: appConfiguration.onboarding.enabled,
|
||||
userProfile: false,
|
||||
}}
|
||||
onOpenCommandPalette={onOpenCommandPalette}
|
||||
onOpenOnboardingModal={() => setOnboardingModalOpen(true)}
|
||||
></NavBar>
|
||||
)}
|
||||
|
||||
<div className="flex min-w-0 max-w-[calc(100vw-4rem)] items-center gap-1 overflow-x-auto overscroll-x-contain py-1 [scrollbar-width:none] md:ml-6 md:max-w-none md:gap-2 md:overflow-visible md:py-0 [&::-webkit-scrollbar]:hidden">
|
||||
{appConfiguration.onboarding.enabled && appOrAdminData?.onboardingSession && (
|
||||
<div data-ui-id={UI_ACTION_IDS.onboarding}>
|
||||
<OnboardingButton item={appOrAdminData?.onboardingSession} onClick={() => setOnboardingModalOpen(true)} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* NavBar Button: My Subscription */}
|
||||
{layout === "app" && getUserHasPermission(appOrAdminData, "app.settings.subscription.update") && (
|
||||
<React.Fragment>
|
||||
{!hasSubscription() && (
|
||||
<a href={subscriptionCheckoutPath(params.tenant ?? "")}>
|
||||
<Button variant="outline" size="sm" data-ui-id={UI_ACTION_IDS.subscription}>
|
||||
<span>{t("pricing.subscribe")} </span>
|
||||
<SparklesIcon className="ml-2 h-4 w-4" />
|
||||
</Button>
|
||||
</a>
|
||||
)}
|
||||
</React.Fragment>
|
||||
)}
|
||||
|
||||
{/* NavBar Button: Notifications */}
|
||||
{appConfiguration.notifications.enabled && (layout === "admin" || layout === "app") && appOrAdminData?.user && (
|
||||
<div className="text-foreground/70 px-2 py-0.5">
|
||||
<NotificationsButton to={layout === "admin" ? adminShellPath("notifications") : tenantPath("notifications")} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* NavBar Button: Search */}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={onOpenCommandPalette}
|
||||
className={headerIconButtonClass}
|
||||
aria-label={t("shared.search")}
|
||||
data-ui-id={UI_ACTION_IDS.search}
|
||||
>
|
||||
<SearchIcon className="size-5" aria-hidden="true" />
|
||||
</Button>
|
||||
|
||||
{/* NavBar Button: Feedback */}
|
||||
{appConfiguration.app.features.tenantFeedback && layout === "app" && <AddFeedbackButton />}
|
||||
|
||||
{/* NavBar Button: Chat Support */}
|
||||
{(layout === "app" || layout === "admin") && !!rootData.chatWebsiteId && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className={headerIconButtonClass}
|
||||
aria-label={t("shared.openSupportChat")}
|
||||
data-ui-id={UI_ACTION_IDS.chatSupport}
|
||||
onClick={() => {
|
||||
try {
|
||||
// @ts-ignore
|
||||
$crisp?.push(["do", "chat:open"]);
|
||||
// @ts-ignore
|
||||
$crisp?.push(["do", "chat:show"]);
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}}
|
||||
>
|
||||
<MessageCircleIcon className="size-5" aria-hidden="true" />
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{/* NavBar Button: Profile */}
|
||||
{/* {(layout === "app" || layout === "admin") && <ProfileButton user={appOrAdminData?.user} layout={layout} />} */}
|
||||
|
||||
{/* NavBar Button: Theme Selector */}
|
||||
{/* {rootData.debug && <ThemeSelector variant="secondary" />} */}
|
||||
|
||||
{/* NavBar Button: Quick Actions */}
|
||||
{/* {layout === "app" && <QuickActionsButton entities={appOrAdminData?.entities?.filter((f) => f.showInSidebar)} />} */}
|
||||
|
||||
{/* NavBar Button: More */}
|
||||
<Popover open={isOpen} onOpenChange={setIsOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className={`${headerIconButtonClass} data-[state=open]:bg-accent`}
|
||||
aria-label={t("shared.openMenu")}
|
||||
data-ui-id={UI_ACTION_IDS.more}
|
||||
>
|
||||
<MoreHorizontal className="size-4" aria-hidden="true" />
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-56 overflow-hidden rounded-lg p-0" align="end">
|
||||
<Sidebar collapsible="none" className="bg-transparent">
|
||||
<SidebarContent>
|
||||
{layout === "app" ? (
|
||||
<SidebarGroup className="border-b last:border-none">
|
||||
<SidebarGroupContent className="gap-0">
|
||||
<SidebarMenu>
|
||||
<SidebarMenuItem>
|
||||
<a href={tenantPath("settings/profile")}>
|
||||
<SidebarMenuButton data-ui-id={UI_ACTION_IDS.profile}>
|
||||
<GearIcon className="mr-2 h-4 w-4" />
|
||||
{t("app.navbar.profile")}
|
||||
</SidebarMenuButton>
|
||||
</a>
|
||||
</SidebarMenuItem>
|
||||
|
||||
{getUserHasPermission(appOrAdminData, "app.settings.subscription.view") && (
|
||||
<SidebarMenuItem>
|
||||
<a href={tenantPath("settings/subscription")}>
|
||||
<SidebarMenuButton data-ui-id={UI_ACTION_IDS.subscription}>
|
||||
<CreditCard className="mr-2 h-4 w-4" />
|
||||
{t("app.navbar.subscription")}
|
||||
</SidebarMenuButton>
|
||||
</a>
|
||||
</SidebarMenuItem>
|
||||
)}
|
||||
</SidebarMenu>
|
||||
</SidebarGroupContent>
|
||||
</SidebarGroup>
|
||||
) : layout === "admin" ? (
|
||||
<SidebarGroup className="border-b last:border-none">
|
||||
<SidebarGroupContent className="gap-0">
|
||||
<SidebarMenu>
|
||||
<SidebarMenuItem>
|
||||
<a href={adminShellPath("settings/profile")}>
|
||||
<SidebarMenuButton data-ui-id={UI_ACTION_IDS.profile}>
|
||||
<GearIcon className="mr-2 h-4 w-4" />
|
||||
{t("app.navbar.profile")}
|
||||
</SidebarMenuButton>
|
||||
</a>
|
||||
</SidebarMenuItem>
|
||||
</SidebarMenu>
|
||||
</SidebarGroupContent>
|
||||
</SidebarGroup>
|
||||
) : null}
|
||||
|
||||
<SidebarGroup className="border-b last:border-none">
|
||||
<SidebarGroupContent className="gap-0">
|
||||
<SidebarMenu>
|
||||
<SidebarMenuItem>
|
||||
<Form method="post" action="/logout">
|
||||
{rootData.csrf && <input type="hidden" name="csrf" value={rootData.csrf} />}
|
||||
<SidebarMenuButton data-ui-id={UI_ACTION_IDS.signOut} className="w-full" type="submit">
|
||||
<LogOut className="mr-2 h-4 w-4" />
|
||||
{t("app.navbar.signOut")}
|
||||
</SidebarMenuButton>
|
||||
</Form>
|
||||
</SidebarMenuItem>
|
||||
</SidebarMenu>
|
||||
</SidebarGroupContent>
|
||||
</SidebarGroup>
|
||||
</SidebarContent>
|
||||
</Sidebar>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function AddFeedbackButton() {
|
||||
const [isOpen, setIsOpen] = React.useState(false);
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<React.Fragment>
|
||||
<Button
|
||||
onClick={() => setIsOpen(!isOpen)}
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className={headerIconButtonClass}
|
||||
aria-label={t("feedback.title")}
|
||||
data-ui-id={UI_ACTION_IDS.feedback}
|
||||
>
|
||||
<span className="sr-only">{t("feedback.title")}</span>
|
||||
<span aria-hidden="true">
|
||||
<StarsIconFilled className="size-5 p-0.5" />
|
||||
</span>
|
||||
</Button>
|
||||
<Modal open={isOpen} setOpen={setIsOpen} size="sm" data-ui-id={UI_SURFACE_IDS.feedbackDialog}>
|
||||
<FeedbackForm isOpen={isOpen} onClose={() => setIsOpen(false)} />
|
||||
</Modal>
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
|
||||
function FeedbackForm({ isOpen, onClose }: { isOpen: boolean; onClose: () => void }) {
|
||||
const { t } = useTranslation();
|
||||
const params = useParams();
|
||||
const appOrAdminData = useAppOrAdminData();
|
||||
const fetcher = useFetcher<{ success?: string; error?: string }>();
|
||||
const location = useLocation();
|
||||
|
||||
const mainInput = React.useRef<HTMLTextAreaElement>(null);
|
||||
React.useEffect(() => {
|
||||
if (isOpen) {
|
||||
setTimeout(() => {
|
||||
mainInput.current?.focus();
|
||||
}, 100);
|
||||
}
|
||||
}, [isOpen]);
|
||||
|
||||
React.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: params.tenant ? 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="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 leading-6 font-medium">{t("feedback.title")}</h3>
|
||||
<p className="text-muted-foreground text-sm">{t("feedback.description")}</p>
|
||||
<Textarea ref={mainInput} name="message" 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>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user