89 lines
4.0 KiB
TypeScript
89 lines
4.0 KiB
TypeScript
import { useState } from "react";
|
|
import { useParams } from "react-router";
|
|
import { useAppOrAdminData } from "~/utils/data/useAppOrAdminData";
|
|
import AddFeedbackButton from "./buttons/AddFeedbackButton";
|
|
import ChatSupportButton from "./buttons/ChatSupportButton";
|
|
import CurrentSubscriptionButton from "./buttons/CurrentSubscriptionButton";
|
|
import OnboardingButton from "./buttons/OnboardingButton";
|
|
import ProfileButton from "./buttons/ProfileButton";
|
|
import SearchButton from "./buttons/SearchButton";
|
|
import NotificationsButton from "./buttons/NotificationsButton";
|
|
import { NotificationsDrawer } from "~/components/screens/notifications/NotificationsDrawer";
|
|
import { useNotificationsStream } from "~/components/notifications/useNotificationsStream";
|
|
import { adminPath, appPath } from "~/utils/app/CanonicalUrlUtils";
|
|
|
|
export default function NavBar({
|
|
layout,
|
|
title,
|
|
buttons,
|
|
onOpenCommandPalette,
|
|
onOpenOnboardingModal,
|
|
children,
|
|
}: {
|
|
layout?: string;
|
|
title?: string;
|
|
buttons: {
|
|
mySubscription: boolean;
|
|
feedback: boolean;
|
|
chatSupport: boolean;
|
|
search: boolean;
|
|
notifications: boolean;
|
|
onboarding: boolean;
|
|
userProfile: boolean;
|
|
};
|
|
onOpenCommandPalette: () => void;
|
|
onOpenOnboardingModal: () => void;
|
|
children?: React.ReactNode;
|
|
}) {
|
|
const appOrAdminData = useAppOrAdminData();
|
|
const params = useParams();
|
|
const notificationsPath =
|
|
layout === "admin" ? adminPath("notifications", { mode: "host-aware" }) : params.tenant ? appPath({ tenantSlug: params.tenant, path: "notifications", mode: "host-aware" }) : "/notifications";
|
|
// AK-P3 (AD-28): tenant-app bell opens the notifications drawer with a live
|
|
// SSE unseen count; the stream route is tenant-scoped, so the admin layout
|
|
// keeps the plain link (documented Dev-Nachzug in the ticket doc).
|
|
const isTenantApp = layout === "app" && Boolean(params.tenant);
|
|
const streamPath = isTenantApp && params.tenant ? appPath({ tenantSlug: params.tenant, path: "notifications/stream", mode: "host-aware" }) : null;
|
|
const notificationsStream = useNotificationsStream(streamPath, []);
|
|
const [notificationsDrawerOpen, setNotificationsDrawerOpen] = useState(false);
|
|
return (
|
|
<div className="flex flex-1 justify-between space-x-2">
|
|
<div className="flex flex-1 items-center">{title && <div className="font-extrabold">{title}</div>}</div>
|
|
<div className="flex items-center space-x-2 md:ml-6">
|
|
{/* {layout === "app" && (
|
|
<CreditsRemaining
|
|
feature={appOrAdminData.featureSyncs}
|
|
redirectTo={appOrAdminData.currentTenant ? `/${appOrAdminData.currentTenant.slug}/settings/subscription` : "/settings/subscription"}
|
|
/>
|
|
)} */}
|
|
{buttons.onboarding && appOrAdminData?.onboardingSession && (
|
|
<OnboardingButton item={appOrAdminData?.onboardingSession} onClick={onOpenOnboardingModal} />
|
|
)}
|
|
{layout === "app" && buttons.mySubscription && <CurrentSubscriptionButton />}
|
|
{/* <LocaleSelector /> */}
|
|
{buttons.notifications && appOrAdminData?.user && (
|
|
<NotificationsButton
|
|
to={notificationsPath}
|
|
unseenCount={isTenantApp ? notificationsStream.unreadCount : undefined}
|
|
onOpen={isTenantApp ? () => setNotificationsDrawerOpen(true) : undefined}
|
|
/>
|
|
)}
|
|
{isTenantApp && (
|
|
<NotificationsDrawer
|
|
open={notificationsDrawerOpen}
|
|
items={notificationsStream.items}
|
|
allHref={notificationsPath}
|
|
onClose={() => setNotificationsDrawerOpen(false)}
|
|
/>
|
|
)}
|
|
{buttons.search && <SearchButton onClick={onOpenCommandPalette} />}
|
|
{layout === "app" && buttons.feedback && <AddFeedbackButton />}
|
|
{layout === "app" && buttons.chatSupport && <ChatSupportButton />}
|
|
{/* {(layout === "app" || layout === "admin") && <ThemeSelector variant="secondary" />} */}
|
|
{(layout === "app" || layout === "admin") && buttons.userProfile && <ProfileButton user={appOrAdminData?.user} layout={layout} />}
|
|
{children}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|