Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+36
-11
@@ -1,6 +1,7 @@
|
||||
import { useState } from "react";
|
||||
import { useParams } from "react-router";
|
||||
import { useFetcher, useParams } from "react-router";
|
||||
import { useAppOrAdminData } from "~/utils/data/useAppOrAdminData";
|
||||
import { useRootData } from "~/utils/data/useRootData";
|
||||
import AddFeedbackButton from "./buttons/AddFeedbackButton";
|
||||
import ChatSupportButton from "./buttons/ChatSupportButton";
|
||||
import CurrentSubscriptionButton from "./buttons/CurrentSubscriptionButton";
|
||||
@@ -36,16 +37,40 @@ export default function NavBar({
|
||||
children?: React.ReactNode;
|
||||
}) {
|
||||
const appOrAdminData = useAppOrAdminData();
|
||||
const rootData = useRootData();
|
||||
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 canReadPlatformLeads = appOrAdminData.permissions?.some(
|
||||
(permission) => permission === "admin.leads.read_own" || permission === "admin.leads.read_all"
|
||||
);
|
||||
const isPlatformLeadAdmin = layout === "admin" && canReadPlatformLeads;
|
||||
const notificationsPath = isPlatformLeadAdmin
|
||||
? adminPath("leads", { mode: "host-aware" })
|
||||
: layout === "admin"
|
||||
? adminPath("notifications", { mode: "host-aware" })
|
||||
: params.tenant
|
||||
? appPath({ tenantSlug: params.tenant, path: "notifications", mode: "host-aware" })
|
||||
: "/notifications";
|
||||
const isTenantApp = layout === "app" && Boolean(params.tenant);
|
||||
const streamPath = isTenantApp && params.tenant ? appPath({ tenantSlug: params.tenant, path: "notifications/stream", mode: "host-aware" }) : null;
|
||||
const streamPath = isPlatformLeadAdmin
|
||||
? adminPath("leads/notifications-stream", { mode: "host-aware" })
|
||||
: isTenantApp && params.tenant
|
||||
? appPath({ tenantSlug: params.tenant, path: "notifications/stream", mode: "host-aware" })
|
||||
: null;
|
||||
const notificationsStream = useNotificationsStream(streamPath, []);
|
||||
const notificationReadFetcher = useFetcher();
|
||||
const [notificationsDrawerOpen, setNotificationsDrawerOpen] = useState(false);
|
||||
const hasNotificationDrawer = isTenantApp || isPlatformLeadAdmin;
|
||||
|
||||
function openNotificationsDrawer() {
|
||||
setNotificationsDrawerOpen(true);
|
||||
if (!isPlatformLeadAdmin || !streamPath) return;
|
||||
const unreadIds = notificationsStream.items.filter((item) => !item.isRead).map((item) => item.id);
|
||||
if (unreadIds.length === 0) return;
|
||||
const form = new FormData();
|
||||
if (rootData.csrf) form.set("csrf", rootData.csrf);
|
||||
for (const deliveryId of unreadIds) form.append("deliveryId", deliveryId);
|
||||
void notificationReadFetcher.submit(form, { method: "post", action: streamPath });
|
||||
}
|
||||
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>
|
||||
@@ -53,7 +78,7 @@ export default function NavBar({
|
||||
{/* {layout === "app" && (
|
||||
<CreditsRemaining
|
||||
feature={appOrAdminData.featureSyncs}
|
||||
redirectTo={appOrAdminData.currentTenant ? `/${appOrAdminData.currentTenant.slug}/settings/subscription` : "/settings/subscription"}
|
||||
redirectTo={appOrAdminData.currentTenant ? `/${appOrAdminData.currentTenant.slug}/settings/billing` : "/settings/billing"}
|
||||
/>
|
||||
)} */}
|
||||
{buttons.onboarding && appOrAdminData?.onboardingSession && (
|
||||
@@ -64,11 +89,11 @@ export default function NavBar({
|
||||
{buttons.notifications && appOrAdminData?.user && (
|
||||
<NotificationsButton
|
||||
to={notificationsPath}
|
||||
unseenCount={isTenantApp ? notificationsStream.unreadCount : undefined}
|
||||
onOpen={isTenantApp ? () => setNotificationsDrawerOpen(true) : undefined}
|
||||
unseenCount={hasNotificationDrawer ? notificationsStream.unreadCount : undefined}
|
||||
onOpen={hasNotificationDrawer ? openNotificationsDrawer : undefined}
|
||||
/>
|
||||
)}
|
||||
{isTenantApp && (
|
||||
{hasNotificationDrawer && (
|
||||
<NotificationsDrawer
|
||||
open={notificationsDrawerOpen}
|
||||
items={notificationsStream.items}
|
||||
|
||||
+148
-48
@@ -1,54 +1,76 @@
|
||||
// AK-P21 (AD-28 interim polish) — global feedback widget. The mini form is a
|
||||
// real ~/ui Dialog (size XS 420) with a category select (bug/feature/question,
|
||||
// designer brief P21); the category is prefixed into the message because the
|
||||
// support-ticket contract intentionally has no category column. Shared by the
|
||||
// legacy NavBar trigger (mobile visibility restriction removed) and the shadcn
|
||||
// nav-actions trigger. Submission keeps the established add-feedback intent on
|
||||
// the tenant root route (rate limit 3/24h lives in Feedback.server).
|
||||
//
|
||||
// Instead of the originally sketched screenshot checkbox, the reporter attaches
|
||||
// an image themselves (decision 2026-07-21): the client never captures the page
|
||||
// on its own, so no third-party personal data leaves the workspace without the
|
||||
// reporter consciously picking the file. The upload is fail-closed scanned and
|
||||
// ClamAV-checked server-side.
|
||||
|
||||
import { useFetcher, useLocation, useParams } from "react-router";
|
||||
import { Fragment, useEffect, useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { toast } from "sonner";
|
||||
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";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Dialog } from "~/ui/components/Dialog";
|
||||
import { Select } from "~/ui/components/Select";
|
||||
import { TextArea } from "~/ui/components/TextArea";
|
||||
|
||||
const FEEDBACK_CATEGORIES = ["bug", "feature", "question"] as const;
|
||||
type FeedbackCategory = (typeof FEEDBACK_CATEGORIES)[number];
|
||||
|
||||
/** Mirrors the server-side contract in Feedback.server. */
|
||||
const FEEDBACK_ATTACHMENT_ACCEPT = "image/png,image/jpeg,image/webp,image/gif";
|
||||
const FEEDBACK_ATTACHMENT_MAX_MB = 5;
|
||||
|
||||
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 className="relative inline-flex">
|
||||
<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="dialog"
|
||||
aria-expanded={isOpen}
|
||||
aria-label={t("feedback.title")}
|
||||
>
|
||||
<span className="sr-only">{t("feedback.title")}</span>
|
||||
<StarsIconFilled className="h-5 w-5 p-0.5" />
|
||||
</button>
|
||||
</div>
|
||||
<Modal open={isOpen} setOpen={setIsOpen} size="sm">
|
||||
<FeedbackForm onClose={() => setIsOpen(false)} />
|
||||
</Modal>
|
||||
<FeedbackFormDialog open={isOpen} onClose={() => setIsOpen(false)} />
|
||||
</Fragment>
|
||||
);
|
||||
}
|
||||
|
||||
function FeedbackForm({ onClose }: { onClose: () => void }) {
|
||||
export function FeedbackFormDialog({ open, onClose }: { open: boolean; onClose: () => void }) {
|
||||
const { t } = useTranslation();
|
||||
const params = useParams();
|
||||
const appOrAdminData = useAppOrAdminData();
|
||||
const { csrf } = useRootData();
|
||||
const fetcher = useFetcher<{ success?: string; error?: string }>();
|
||||
const location = useLocation();
|
||||
const [category, setCategory] = useState<FeedbackCategory>("bug");
|
||||
const [attachmentError, setAttachmentError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
setCategory("bug");
|
||||
setAttachmentError(null);
|
||||
}
|
||||
}, [open]);
|
||||
|
||||
useEffect(() => {
|
||||
if (fetcher.data?.success) {
|
||||
@@ -60,31 +82,109 @@ function FeedbackForm({ onClose }: { onClose: () => void }) {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [fetcher.data]);
|
||||
|
||||
const onSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
|
||||
const submitting = fetcher.state !== "idle";
|
||||
|
||||
const onSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
fetcher.submit(e.currentTarget, {
|
||||
if (attachmentError) return;
|
||||
void fetcher.submit(e.currentTarget, {
|
||||
method: "post",
|
||||
action: appPath({ tenantSlug: params.tenant ?? "", mode: "host-aware" }),
|
||||
encType: "multipart/form-data",
|
||||
action: params.tenant ? appPath({ tenantSlug: params.tenant, mode: "host-aware" }) : "",
|
||||
});
|
||||
// onClose();
|
||||
};
|
||||
|
||||
// Reject oversized or non-image picks before the upload is attempted; the
|
||||
// server enforces the same limits again.
|
||||
const onAttachmentChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.currentTarget.files?.[0] ?? null;
|
||||
if (!file) {
|
||||
setAttachmentError(null);
|
||||
return;
|
||||
}
|
||||
if (file.size > FEEDBACK_ATTACHMENT_MAX_MB * 1024 * 1024) {
|
||||
setAttachmentError(t("feedback.attachment.tooLarge", { megabytes: FEEDBACK_ATTACHMENT_MAX_MB }));
|
||||
return;
|
||||
}
|
||||
if (!FEEDBACK_ATTACHMENT_ACCEPT.split(",").includes(file.type)) {
|
||||
setAttachmentError(t("feedback.attachment.unsupportedType"));
|
||||
return;
|
||||
}
|
||||
setAttachmentError(null);
|
||||
};
|
||||
|
||||
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>
|
||||
<Dialog open={open} onOpenChange={(nextOpen: boolean) => (nextOpen ? undefined : onClose())}>
|
||||
<Dialog.Content className="w-[420px] max-w-[90vw] p-4" aria-label={t("feedback.title")} data-ui-id="ui.feedback.dialog">
|
||||
<fetcher.Form onSubmit={onSubmit} method="post" className="flex w-full flex-col items-start">
|
||||
<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 />
|
||||
{/* Radix Select is not a native form control — mirror the picked category. */}
|
||||
<input type="hidden" name="category" value={category} readOnly hidden />
|
||||
<div className="flex w-full flex-col items-start gap-2">
|
||||
<span className="text-heading-0 font-heading-0 text-text-neutral-primary">{t("feedback.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">{t("feedback.description")}</span>
|
||||
</div>
|
||||
<div className="flex w-full flex-col items-start gap-4 pt-4">
|
||||
<Select
|
||||
className="w-full max-w-none"
|
||||
showLabel
|
||||
label={t("feedback.category.label")}
|
||||
value={category}
|
||||
onValueChange={(value: string) => setCategory(FEEDBACK_CATEGORIES.includes(value as FeedbackCategory) ? (value as FeedbackCategory) : "bug")}
|
||||
data-ui-id="ui.feedback.category"
|
||||
>
|
||||
{FEEDBACK_CATEGORIES.map((key) => (
|
||||
<Select.Item key={key} value={key}>
|
||||
{t(`feedback.category.${key}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<TextArea className="w-full max-w-none" label={t("feedback.message")} showLabel>
|
||||
<TextArea.Input name="message" defaultValue="" rows={5} placeholder={t("feedback.placeholder")} required data-ui-id="ui.feedback.message" />
|
||||
</TextArea>
|
||||
<div className="flex w-full flex-col items-start gap-1">
|
||||
<label
|
||||
className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-primary"
|
||||
htmlFor="feedback-attachment"
|
||||
>
|
||||
{t("feedback.attachment.label")}
|
||||
</label>
|
||||
<input
|
||||
id="feedback-attachment"
|
||||
type="file"
|
||||
name="attachment"
|
||||
accept={FEEDBACK_ATTACHMENT_ACCEPT}
|
||||
onChange={onAttachmentChange}
|
||||
data-ui-id="ui.feedback.attachment"
|
||||
className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary w-full"
|
||||
/>
|
||||
{attachmentError ? (
|
||||
<span className="text-body-extra-small-regular-150 font-body-extra-small-regular-150 text-text-feedback-negative" role="alert">
|
||||
{attachmentError}
|
||||
</span>
|
||||
) : (
|
||||
<span className="text-body-extra-small-regular-150 font-body-extra-small-regular-150 text-text-neutral-tertiary">
|
||||
{t("feedback.attachment.hint", { megabytes: FEEDBACK_ATTACHMENT_MAX_MB })}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<span className="text-body-extra-small-regular-150 font-body-extra-small-regular-150 text-text-neutral-tertiary">
|
||||
{t("feedback.rateLimitHint")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex w-full items-center justify-end gap-2 pt-4">
|
||||
<Button type="button" variant="tertiary" disabled={submitting} onClick={onClose}>
|
||||
{t("shared.cancel")}
|
||||
</Button>
|
||||
<Button type="submit" loading={submitting} disabled={Boolean(attachmentError)} data-ui-id="ui.feedback.send">
|
||||
{t("feedback.send")}
|
||||
</Button>
|
||||
</div>
|
||||
</fetcher.Form>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
+1
-1
@@ -19,7 +19,7 @@ export default function ChatSupportButton() {
|
||||
$crisp?.push(["do", "chat:hide"]);
|
||||
setIsOpen(false);
|
||||
}
|
||||
} catch (e) {
|
||||
} catch (_e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ export default function CurrentSubscriptionButton() {
|
||||
<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 ? "" : appPath({ tenantSlug: params.tenant, path: "settings/subscription", mode: "host-aware" })}
|
||||
to={!params.tenant ? "" : appPath({ tenantSlug: params.tenant, path: "settings/billing", 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",
|
||||
hasSubscription() &&
|
||||
|
||||
+1
-1
@@ -75,7 +75,7 @@ describe("layout button UI IDs", () => {
|
||||
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");
|
||||
expect(screen.getByRole("menuitem", { name: "app.navbar.subscription" })).toHaveAttribute("href", "/acme/settings/billing");
|
||||
});
|
||||
|
||||
it("localizes the public admin menu link", () => {
|
||||
|
||||
+7
@@ -12,4 +12,11 @@ describe("ProfileButton route fallbacks", () => {
|
||||
expect(source).toContain('defaultTenantPath("settings/profile") ?? publicHeaderAdminPath("settings/profile")');
|
||||
expect(source).not.toContain('defaultTenantPath("settings/profile") ?? adminShellPath("settings/profile")');
|
||||
});
|
||||
|
||||
it("gives the tenant menu item additional vertical padding", () => {
|
||||
const source = fs.readFileSync(path.resolve(process.cwd(), "apps/web/app/components/layouts/buttons/ProfileButton.tsx"), "utf8");
|
||||
|
||||
expect(source).toContain('className="hover:bg-secondary block px-4 py-3 text-sm transition duration-150 ease-in-out"');
|
||||
expect(source).toContain('data-ui-id="ui.profile.menu.tenant"');
|
||||
});
|
||||
});
|
||||
+16
-13
@@ -48,7 +48,7 @@ export default function ProfileButton({ user, layout, items }: Props) {
|
||||
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",
|
||||
"bg-background text-muted-foreground hover:bg-secondary border-border focus-visible:ring-ring relative inline-flex items-center rounded-full border font-medium shadow-inner focus-visible:z-10 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none",
|
||||
!user?.avatar && "p-2",
|
||||
user?.avatar && "p-1"
|
||||
)}
|
||||
@@ -58,7 +58,9 @@ export default function ProfileButton({ user, layout, items }: Props) {
|
||||
>
|
||||
{(() => {
|
||||
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")} />;
|
||||
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">
|
||||
@@ -81,7 +83,7 @@ export default function ProfileButton({ user, layout, items }: Props) {
|
||||
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="bg-background rounded-sm py-1 shadow-2xs" 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>
|
||||
@@ -106,7 +108,7 @@ export default function ProfileButton({ user, layout, items }: Props) {
|
||||
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")}
|
||||
to={tenantPath("settings/team")}
|
||||
>
|
||||
{t("app.navbar.members")}
|
||||
</Link>
|
||||
@@ -117,7 +119,7 @@ export default function ProfileButton({ user, layout, items }: Props) {
|
||||
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")}
|
||||
to={tenantPath("settings/billing")}
|
||||
>
|
||||
{t("app.navbar.subscription")}
|
||||
</Link>
|
||||
@@ -125,10 +127,11 @@ export default function ProfileButton({ user, layout, items }: Props) {
|
||||
|
||||
{getUserHasPermission(appOrAdminData, "app.settings.account.view") && (
|
||||
<Link
|
||||
className="hover:bg-secondary block px-4 py-2 text-sm transition duration-150 ease-in-out"
|
||||
className="hover:bg-secondary block px-4 py-3 text-sm transition duration-150 ease-in-out"
|
||||
data-ui-id="ui.profile.menu.tenant"
|
||||
role="menuitem"
|
||||
onClick={closeDropdownUser}
|
||||
to={tenantPath("settings/account")}
|
||||
to={tenantPath("settings/workspace")}
|
||||
>
|
||||
{t("app.navbar.tenant")}
|
||||
</Link>
|
||||
@@ -139,7 +142,7 @@ export default function ProfileButton({ user, layout, items }: Props) {
|
||||
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")}
|
||||
to={tenantPath("settings/team/roles")}
|
||||
>
|
||||
{t("models.role.plural")}
|
||||
</Link>
|
||||
@@ -149,7 +152,7 @@ export default function ProfileButton({ user, layout, items }: Props) {
|
||||
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")}
|
||||
to={tenantPath("settings/team/groups")}
|
||||
>
|
||||
{t("models.group.plural")}
|
||||
</Link> */}
|
||||
@@ -159,7 +162,7 @@ export default function ProfileButton({ user, layout, items }: Props) {
|
||||
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")}
|
||||
to={tenantPath("api")}
|
||||
>
|
||||
{t("models.apiKey.plural")}
|
||||
</Link>
|
||||
@@ -170,7 +173,7 @@ export default function ProfileButton({ user, layout, items }: Props) {
|
||||
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")}
|
||||
to={tenantPath("settings/compliance")}
|
||||
>
|
||||
{t("models.log.plural")}
|
||||
</Link>
|
||||
@@ -209,12 +212,12 @@ export default function ProfileButton({ user, layout, items }: Props) {
|
||||
{t("app.navbar.profile")}
|
||||
</Link>
|
||||
)}
|
||||
{defaultTenantPath("settings/subscription") && (
|
||||
{defaultTenantPath("settings/billing") && (
|
||||
<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")!}
|
||||
to={defaultTenantPath("settings/billing")!}
|
||||
>
|
||||
{t("app.navbar.subscription")}
|
||||
</Link>
|
||||
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
import { ReactNode } from "react";
|
||||
import { cn } from "~/lib/utils";
|
||||
import { sanitizeIconSvg } from "~/utils/html-sanitizer";
|
||||
|
||||
interface Props {
|
||||
@@ -13,7 +14,7 @@ export default function SidebarIcon({ className, item }: Props) {
|
||||
let icon = item.icon;
|
||||
let title = item.title;
|
||||
if (typeof icon !== "string") {
|
||||
return icon;
|
||||
return icon ? <span className={cn("inline-flex shrink-0 [&>*]:size-full", className)}>{icon}</span> : null;
|
||||
}
|
||||
return (
|
||||
<>
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
import "@testing-library/jest-dom";
|
||||
import { render } from "@testing-library/react";
|
||||
import { MemoryRouter } from "react-router";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import NewTenantSelector from "./NewTenantSelector";
|
||||
|
||||
let capturedOptions: Array<Record<string, unknown>> = [];
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
|
||||
vi.mock("~/components/ui/input/InputSelector", () => ({
|
||||
default: ({ options }: { options: Array<Record<string, unknown>> }) => {
|
||||
capturedOptions = options;
|
||||
return <div data-testid="tenant-selector" />;
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/data/useAppData", () => ({
|
||||
useAppData: () => ({
|
||||
currentTenant: { id: "tenant_1", slug: "acme", name: "Acme" },
|
||||
myTenants: [
|
||||
{ id: "tenant_1", slug: "acme", name: "Acme", icon: null },
|
||||
{ id: "tenant_2", slug: "beta", name: "Beta", icon: null },
|
||||
],
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/data/useRootData", () => ({
|
||||
useRootData: () => ({ routing: {} }),
|
||||
}));
|
||||
|
||||
describe("NewTenantSelector", () => {
|
||||
beforeEach(() => {
|
||||
capturedOptions = [];
|
||||
});
|
||||
|
||||
it("does not expose placeholder copy as option metadata", () => {
|
||||
render(
|
||||
<MemoryRouter initialEntries={["/acme/dashboard"]}>
|
||||
<NewTenantSelector />
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
const createOption = capturedOptions.find((option) => option.value === "{new}");
|
||||
expect(createOption).toBeDefined();
|
||||
expect(createOption).not.toHaveProperty("title");
|
||||
});
|
||||
});
|
||||
+3
-9
@@ -6,15 +6,14 @@ import InputSelector from "~/components/ui/input/InputSelector";
|
||||
import { useAppData } from "~/utils/data/useAppData";
|
||||
import { useRootData } from "~/utils/data/useRootData";
|
||||
import { absolutePublicAppPath, isAbsoluteHttpUrl } from "~/utils/app/CrossHostUrls";
|
||||
import { translateLabel } from "~/utils/i18n/translateLabel";
|
||||
import { getTenantSwitchPath } from "./tenant-switch-url";
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export default function TenantSelector({ className }: Props) {
|
||||
const { t, i18n } = useTranslation();
|
||||
export default function TenantSelector({ className: _className }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const appData = useAppData();
|
||||
const rootData = useRootData();
|
||||
const location = useLocation();
|
||||
@@ -39,12 +38,8 @@ export default function TenantSelector({ className }: Props) {
|
||||
function getAllTenants() {
|
||||
const items = appData?.myTenants
|
||||
.map((f) => {
|
||||
let group = t("models.tenant.plural");
|
||||
if (f.types.length > 0) {
|
||||
group = translateLabel(t, i18n, f.types[0].titlePlural) || t("models.tenant.plural");
|
||||
}
|
||||
return {
|
||||
group,
|
||||
group: t("models.tenant.plural"),
|
||||
value: f.slug,
|
||||
name: (
|
||||
<div className="flex items-center space-x-2">
|
||||
@@ -66,7 +61,6 @@ export default function TenantSelector({ className }: Props) {
|
||||
return [
|
||||
...unique,
|
||||
{
|
||||
title: "hey",
|
||||
value: "{new}",
|
||||
className: "border-t border-border rounded-none",
|
||||
name: (
|
||||
|
||||
+3
-8
@@ -3,15 +3,14 @@ import { Fragment, useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import InputSelectorDarkMode from "~/components/ui/input/dark/InputSelectorDarkMode";
|
||||
import { useAppData } from "~/utils/data/useAppData";
|
||||
import { translateLabel } from "~/utils/i18n/translateLabel";
|
||||
import { getTenantSwitchPath } from "./tenant-switch-url";
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export default function TenantSelector({ className }: Props) {
|
||||
const { t, i18n } = useTranslation();
|
||||
export default function TenantSelector({ className: _className }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const appData = useAppData();
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
@@ -35,12 +34,8 @@ export default function TenantSelector({ className }: Props) {
|
||||
function getAllTenants() {
|
||||
const items = appData.myTenants
|
||||
.map((f) => {
|
||||
let group = t("models.tenant.plural");
|
||||
if (f.types.length > 0) {
|
||||
group = translateLabel(t, i18n, f.types[0].titlePlural) || t("models.tenant.plural");
|
||||
}
|
||||
return {
|
||||
group,
|
||||
group: t("models.tenant.plural"),
|
||||
value: f.slug,
|
||||
name: f.name,
|
||||
img: f.icon ? (
|
||||
|
||||
-12
@@ -25,18 +25,6 @@ vi.mock("~/utils/data/useAppOrAdminData", () => ({
|
||||
useAppOrAdminData: () => ({ currentTenant: null }),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/data/useRootData", () => ({
|
||||
useRootData: () => ({ userSession: { lightOrDarkMode: "light" } }),
|
||||
}));
|
||||
|
||||
vi.mock("~/stores/themePreviewStore", () => ({
|
||||
useThemePreviewStore: () => ({ isPreviewActive: false, previewConfig: null }),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/theme/ThemeConfig", () => ({
|
||||
parseThemeConfig: () => ({}),
|
||||
}));
|
||||
|
||||
vi.mock("./app-sidebar", () => ({
|
||||
ShadcnAppSidebar: ({ layout }: { layout: string }) => <aside data-ui-id={`ui.surface.${layout}.sidebar`} />,
|
||||
}));
|
||||
|
||||
+2
-49
@@ -8,10 +8,7 @@ import { lazy, Suspense, useRef, useState } from "react";
|
||||
import { NavActions } from "./nav-actions";
|
||||
import { useCommandPalette } from "~/components/ui/commandPalettes/CommandPalette";
|
||||
import { Separator } from "~/components/ui/separator";
|
||||
import { useThemePreviewStore } from "~/stores/themePreviewStore";
|
||||
import { parseThemeConfig } from "~/utils/theme/ThemeConfig";
|
||||
import { useAppOrAdminData } from "~/utils/data/useAppOrAdminData";
|
||||
import { useRootData } from "~/utils/data/useRootData";
|
||||
import { UI_ACTION_IDS, UI_SURFACE_IDS } from "~/application/ui/uiRegistry";
|
||||
|
||||
const OnboardingSession = lazy(() => import("~/modules/onboarding/components/OnboardingSession"));
|
||||
@@ -31,10 +28,7 @@ export default function ShadcnSidebarLayout({
|
||||
const [searchParams] = useSearchParams();
|
||||
const mainElement = useRef<HTMLElement>(null);
|
||||
|
||||
// Get the app data which includes tenant theme config
|
||||
const appOrAdminData = useAppOrAdminData();
|
||||
const { userSession } = useRootData();
|
||||
const { isPreviewActive, previewConfig } = useThemePreviewStore();
|
||||
|
||||
const commandPalette = useCommandPalette();
|
||||
|
||||
@@ -49,55 +43,14 @@ export default function ShadcnSidebarLayout({
|
||||
void location;
|
||||
void hasCalendar;
|
||||
|
||||
let themeConfig = isPreviewActive && previewConfig ? previewConfig : parseThemeConfig(appOrAdminData?.currentTenant?.themeConfig as string | null);
|
||||
|
||||
let sidebarStyle: Record<string, string> = {};
|
||||
|
||||
if (themeConfig?.colors) {
|
||||
let colors = themeConfig.colors;
|
||||
if (userSession?.lightOrDarkMode === "dark" && themeConfig?.darkColors) {
|
||||
colors = themeConfig.darkColors;
|
||||
}
|
||||
if (colors.sidebar) {
|
||||
// Sidebar specific colors
|
||||
sidebarStyle["--sidebar"] = colors.sidebar;
|
||||
}
|
||||
if (colors.sidebarForeground) {
|
||||
sidebarStyle["--sidebar-foreground"] = colors.sidebarForeground;
|
||||
}
|
||||
if (colors.sidebarPrimary) {
|
||||
sidebarStyle["--sidebar-primary"] = colors.sidebarPrimary;
|
||||
}
|
||||
if (colors.sidebarPrimaryForeground) {
|
||||
sidebarStyle["--sidebar-primary-foreground"] = colors.sidebarPrimaryForeground;
|
||||
}
|
||||
if (colors.sidebarAccent) {
|
||||
sidebarStyle["--sidebar-accent"] = colors.sidebarAccent;
|
||||
}
|
||||
if (colors.sidebarAccentForeground) {
|
||||
sidebarStyle["--sidebar-accent-foreground"] = colors.sidebarAccentForeground;
|
||||
}
|
||||
if (colors.sidebarBorder) {
|
||||
sidebarStyle["--sidebar-border"] = colors.sidebarBorder;
|
||||
}
|
||||
if (colors.sidebarRing) {
|
||||
sidebarStyle["--sidebar-ring"] = colors.sidebarRing;
|
||||
}
|
||||
}
|
||||
|
||||
if (!appOrAdminData.currentTenant) {
|
||||
sidebarStyle = {};
|
||||
themeConfig = {};
|
||||
}
|
||||
|
||||
return (
|
||||
<SidebarProvider style={sidebarStyle as React.CSSProperties} data-ui-id={UI_SURFACE_IDS.shell}>
|
||||
<SidebarProvider data-ui-id={UI_SURFACE_IDS.shell}>
|
||||
{appOrAdminData?.onboardingSession ? (
|
||||
<Suspense fallback={null}>
|
||||
<OnboardingSession open={onboardingModalOpen} setOpen={setOnboardingModalOpen} />
|
||||
</Suspense>
|
||||
) : null}
|
||||
<ShadcnAppSidebar layout={layout} items={menuItems} themeConfig={themeConfig} style={sidebarStyle as React.CSSProperties} />
|
||||
<ShadcnAppSidebar layout={layout} items={menuItems} />
|
||||
<SidebarInset className="overflow-hidden" data-ui-id={UI_SURFACE_IDS.shellInset}>
|
||||
<header
|
||||
className="border-border bg-background flex h-16 shrink-0 items-center gap-2 border-b transition-[width,height] ease-linear group-has-data-[collapsible=icon]/sidebar-wrapper:h-12"
|
||||
|
||||
+51
-2
@@ -21,7 +21,7 @@ vi.mock("~/utils/data/useRootData", () => ({
|
||||
}));
|
||||
|
||||
let mockedPermissions = ["app.dashboard.view"];
|
||||
let mockedCurrentTenant: null | { slug: string; logo: string } = null;
|
||||
let mockedCurrentTenant: null | { slug: string; name: string; logo: string } = null;
|
||||
|
||||
vi.mock("~/utils/data/useAppOrAdminData", () => ({
|
||||
useAppOrAdminData: () => ({
|
||||
@@ -38,6 +38,10 @@ vi.mock("./nav-user", () => ({
|
||||
NavUser: ({ layout }: { layout: string }) => <div data-testid="nav-user">User {layout}</div>,
|
||||
}));
|
||||
|
||||
vi.mock("./team-switcher", () => ({
|
||||
TeamSwitcher: () => <div data-testid="team-switcher" />,
|
||||
}));
|
||||
|
||||
const baseItems = [
|
||||
{
|
||||
id: "ui.nav.test.main",
|
||||
@@ -153,8 +157,44 @@ describe("ShadcnAppSidebar UI IDs", () => {
|
||||
expect(screen.getByRole("link", { name: "Settings" })).toHaveAttribute("data-active", "true");
|
||||
});
|
||||
|
||||
it("keeps consolidated workspace entries active on alternate area routes", () => {
|
||||
const workspaceItems: SideBarItem[] = [
|
||||
{
|
||||
id: "ui.nav.test.main",
|
||||
title: "Main",
|
||||
path: "",
|
||||
items: [
|
||||
{
|
||||
id: "ui.nav.test.communication",
|
||||
title: "Communication",
|
||||
path: "/acme/emails",
|
||||
activePaths: ["/acme/emails", "/acme/email-marketing", "/acme/forms"],
|
||||
contextItems: [
|
||||
{ title: "Mailbox", path: "/acme/emails" },
|
||||
{ title: "Campaigns", path: "/acme/email-marketing" },
|
||||
{ title: "Forms", path: "/acme/forms" },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
render(
|
||||
<MemoryRouter initialEntries={["/acme/forms/form_1"]}>
|
||||
<SidebarProvider>
|
||||
<ShadcnAppSidebar layout="app" items={workspaceItems} />
|
||||
</SidebarProvider>
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
expect(screen.getByRole("link", { name: "Communication" })).toHaveAttribute("data-active", "true");
|
||||
expect(screen.queryByRole("link", { name: "Mailbox" })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("link", { name: "Campaigns" })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("link", { name: "Forms" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("does not render tenant logo links inside the admin sidebar", () => {
|
||||
mockedCurrentTenant = { slug: "acme", logo: "/tenant-logo.svg" };
|
||||
mockedCurrentTenant = { slug: "acme", name: "Acme", logo: "/tenant-logo.svg" };
|
||||
|
||||
renderSidebar("admin", "/dashboard");
|
||||
|
||||
@@ -162,6 +202,15 @@ describe("ShadcnAppSidebar UI IDs", () => {
|
||||
expect(screen.queryByRole("link", { name: "Logo" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("uses the tenant name for the tenant logo link", () => {
|
||||
mockedCurrentTenant = { slug: "acme", name: "Acme", logo: "/tenant-logo.svg" };
|
||||
|
||||
renderSidebar("app", "/acme/dashboard");
|
||||
|
||||
expect(screen.getByRole("link", { name: "Acme" })).toHaveAttribute("href", "/acme/dashboard");
|
||||
expect(screen.getByAltText("Acme")).toHaveAttribute("src", "/tenant-logo.svg");
|
||||
});
|
||||
|
||||
it("filters sidebar items by declared permission", () => {
|
||||
const permissionItems: SideBarItem[] = [
|
||||
{
|
||||
|
||||
+17
-5
@@ -207,7 +207,13 @@ export function ShadcnAppSidebar({
|
||||
}
|
||||
|
||||
function isCurrent(menuItem: SideBarItem): boolean {
|
||||
return pathMatchesCurrent(getPath(menuItem), menuItem.exact);
|
||||
if (menuItem.excludePaths?.some((path) => pathMatchesCurrent(UrlUtils.replaceVariables(params, path) ?? path))) {
|
||||
return false;
|
||||
}
|
||||
return (
|
||||
pathMatchesCurrent(getPath(menuItem), menuItem.exact) ||
|
||||
(menuItem.activePaths?.some((path) => pathMatchesCurrent(UrlUtils.replaceVariables(params, path) ?? path)) ?? false)
|
||||
);
|
||||
}
|
||||
|
||||
function currentIsChild(menuItem: SideBarItem): boolean {
|
||||
@@ -240,7 +246,9 @@ export function ShadcnAppSidebar({
|
||||
return !item.tenantUserTypes || (currentRole !== null && item.tenantUserTypes.includes(currentRole));
|
||||
}
|
||||
function checkUserRolePermissions(item: SideBarItem) {
|
||||
return !item.permission || getUserHasPermission(appOrAdminData, item.permission);
|
||||
const hasRequired = !item.permission || getUserHasPermission(appOrAdminData, item.permission);
|
||||
const hasAny = !item.anyPermissions || item.anyPermissions.some((permission) => getUserHasPermission(appOrAdminData, permission));
|
||||
return hasRequired && hasAny;
|
||||
}
|
||||
function getVisibleItem(item: SideBarItem): SideBarItem | null {
|
||||
if (item.hidden === true || !allowCurrentUserType(item) || !allowCurrentTenantUserType(item)) {
|
||||
@@ -248,16 +256,20 @@ export function ShadcnAppSidebar({
|
||||
}
|
||||
|
||||
const items = item.items?.map((child) => getVisibleItem(child)).filter((child): child is SideBarItem => child !== null) ?? [];
|
||||
const contextItems = item.contextItems?.map((child) => getVisibleItem(child)).filter((child): child is SideBarItem => child !== null) ?? [];
|
||||
const hasPermission = checkUserRolePermissions(item);
|
||||
if (!hasPermission && items.length === 0) {
|
||||
if ((!hasPermission && items.length === 0 && contextItems.length === 0) || ((item.contextItems?.length ?? 0) > 0 && contextItems.length === 0)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const ownPathVisible = contextItems.some((child) => child.path === item.path);
|
||||
|
||||
return {
|
||||
...item,
|
||||
path: hasPermission ? item.path : "",
|
||||
path: hasPermission && (contextItems.length === 0 || ownPathVisible) ? item.path : (contextItems[0]?.path ?? ""),
|
||||
redirectTo: hasPermission ? item.redirectTo : undefined,
|
||||
items,
|
||||
contextItems,
|
||||
};
|
||||
}
|
||||
const getMenu = (): SidebarGroupDto[] => {
|
||||
@@ -316,7 +328,7 @@ export function ShadcnAppSidebar({
|
||||
{props.layout === "app" && appData.currentTenant?.logo ? (
|
||||
<a href={appPath({ tenantSlug: appData.currentTenant.slug, path: "dashboard", mode: "host-aware" })} className="flex justify-center">
|
||||
<div className="flex shrink-0 items-center justify-center border-b border-transparent">
|
||||
<img className="mx-auto h-10 w-auto p-1.5" src={appData.currentTenant.logo} alt="Logo" />
|
||||
<img className="mx-auto h-10 w-auto p-1.5" src={appData.currentTenant.logo} alt={appData.currentTenant.name} />
|
||||
</div>
|
||||
</a>
|
||||
) : null}
|
||||
|
||||
+5
-1
@@ -122,7 +122,7 @@ describe("NavActions host-aware links", () => {
|
||||
const subscription = screen.getByRole("link", { name: /app\.navbar\.subscription/i });
|
||||
|
||||
expect(profile).toHaveAttribute("href", "/acme/settings/profile");
|
||||
expect(subscription).toHaveAttribute("href", "/acme/settings/subscription");
|
||||
expect(subscription).toHaveAttribute("href", "/acme/settings/billing");
|
||||
expect(profile.getAttribute("href")).not.toContain("/app/");
|
||||
expect(subscription.getAttribute("href")).not.toContain("/app/");
|
||||
});
|
||||
@@ -147,6 +147,10 @@ describe("NavActions host-aware links", () => {
|
||||
expect(fetcherSubmit).toHaveBeenCalledWith(expect.any(HTMLFormElement), {
|
||||
method: "post",
|
||||
action: "/acme",
|
||||
// AK-P21 — the widget carries an optional image attachment, which only
|
||||
// reaches the action as multipart. Pinned here because a silent fall back
|
||||
// to urlencoded would drop the file without any visible error.
|
||||
encType: "multipart/form-data",
|
||||
});
|
||||
expect(fetcherSubmit.mock.calls[0][1].action).not.toContain("/app/");
|
||||
});
|
||||
|
||||
+7
-63
@@ -10,15 +10,12 @@ 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 { Form, 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 OnboardingButton from "../../buttons/OnboardingButton";
|
||||
import { toast } from "sonner";
|
||||
import ButtonPrimary from "~/components/ui/buttons/ButtonPrimary";
|
||||
import { Textarea } from "~/components/ui/textarea";
|
||||
import { FeedbackFormDialog } from "../../buttons/AddFeedbackButton";
|
||||
import { UI_ACTION_IDS, UI_SURFACE_IDS } from "~/application/ui/uiRegistry";
|
||||
import NotificationsButton from "../../buttons/NotificationsButton";
|
||||
|
||||
@@ -155,7 +152,7 @@ export function NavActions({
|
||||
|
||||
{getUserHasPermission(appOrAdminData, "app.settings.subscription.view") && (
|
||||
<SidebarMenuItem>
|
||||
<a href={tenantPath("settings/subscription")}>
|
||||
<a href={tenantPath("settings/billing")}>
|
||||
<SidebarMenuButton data-ui-id={UI_ACTION_IDS.subscription}>
|
||||
<CreditCard className="mr-2 h-4 w-4" />
|
||||
{t("app.navbar.subscription")}
|
||||
@@ -225,63 +222,10 @@ function AddFeedbackButton() {
|
||||
<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>
|
||||
{/* AK-P21: shared ~/ui Dialog (category select + rate-limit hint), see AddFeedbackButton.tsx. */}
|
||||
<span data-ui-id={UI_SURFACE_IDS.feedbackDialog}>
|
||||
<FeedbackFormDialog open={isOpen} onClose={() => setIsOpen(false)} />
|
||||
</span>
|
||||
</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>
|
||||
);
|
||||
}
|
||||
+15
-2
@@ -2,6 +2,7 @@
|
||||
|
||||
import { type ReactNode } from "react";
|
||||
import { Fragment } from "react/jsx-runtime";
|
||||
import { Link } from "react-router";
|
||||
import { SidebarGroupDto } from "~/application/sidebar/SidebarGroupDto";
|
||||
|
||||
import {
|
||||
@@ -27,9 +28,21 @@ function hasConfiguredChildren(item: SidebarNavItem) {
|
||||
return (item.items?.length ?? 0) > 0;
|
||||
}
|
||||
|
||||
function isInternalNavigationPath(to: string) {
|
||||
return to.startsWith("/") && !to.startsWith("//");
|
||||
}
|
||||
|
||||
function SidebarLink({ to, children, ...props }: { to: string; children: ReactNode } & Record<string, unknown>) {
|
||||
if (isInternalNavigationPath(to)) {
|
||||
return (
|
||||
<Link to={to} data-navigation-kind="client" {...props}>
|
||||
{children}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<a href={to} {...props}>
|
||||
<a href={to} data-navigation-kind="document" {...props}>
|
||||
{children}
|
||||
</a>
|
||||
);
|
||||
@@ -38,7 +51,7 @@ function SidebarLink({ to, children, ...props }: { to: string; children: ReactNo
|
||||
function SidebarItemContent({ item }: { item: SidebarNavItem }) {
|
||||
return (
|
||||
<>
|
||||
{item.icon !== undefined && <SidebarIcon className="size-4" item={item} />}
|
||||
{item.icon !== undefined && <SidebarIcon className="size-5" item={item} />}
|
||||
<span>{item.title}</span>
|
||||
</>
|
||||
);
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ import {
|
||||
import { SidebarGroupDto } from "~/application/sidebar/SidebarGroupDto";
|
||||
import SidebarIcon from "../../icons/SidebarIcon";
|
||||
import { getUiIdAttributes } from "~/application/ui/uiRegistry";
|
||||
import { t as i18nT } from "i18next";
|
||||
import { requestScopedT as i18nT } from "~/locale/request-scoped-t";
|
||||
|
||||
type SidebarNavItem = SidebarGroupDto["items"][number];
|
||||
|
||||
|
||||
+2
-2
@@ -114,7 +114,7 @@ export function NavUser({
|
||||
</DropdownMenuItem>
|
||||
</a>
|
||||
{getUserHasPermission(appOrAdminData, "app.settings.subscription.view") && (
|
||||
<a href={UrlUtils.currentTenantUrl(params, `settings/subscription`)}>
|
||||
<a href={UrlUtils.currentTenantUrl(params, `settings/billing`)}>
|
||||
<DropdownMenuItem>
|
||||
<CreditCard className="mr-2 h-4 w-4" />
|
||||
{t("app.navbar.subscription")}
|
||||
@@ -122,7 +122,7 @@ export function NavUser({
|
||||
</a>
|
||||
)}
|
||||
{getUserHasPermission(appOrAdminData, "app.settings.account.view") && (
|
||||
<a href={UrlUtils.currentTenantUrl(params, `settings/account`)}>
|
||||
<a href={UrlUtils.currentTenantUrl(params, `settings/workspace`)}>
|
||||
<DropdownMenuItem>
|
||||
<BadgeCheck className="mr-2 h-4 w-4" />
|
||||
{t("app.navbar.tenant")}
|
||||
|
||||
-35
@@ -29,11 +29,6 @@ export function TeamSwitcher({ tenants, size = "md" }: { tenants: TenantSimple[]
|
||||
|
||||
const [activeTenant] = React.useState(appData?.currentTenant);
|
||||
|
||||
let activeTenantDescription = getTenantDescription({
|
||||
subscription: appData.mySubscription,
|
||||
types: appData.currentTenant.types,
|
||||
t,
|
||||
});
|
||||
const newAccountPath = absolutePublicAppPath(rootData.routing, "new-account");
|
||||
|
||||
return (
|
||||
@@ -63,7 +58,6 @@ export function TeamSwitcher({ tenants, size = "md" }: { tenants: TenantSimple[]
|
||||
</div>
|
||||
<div className="grid flex-1 text-left text-sm leading-tight">
|
||||
<span className="truncate font-semibold">{activeTenant.name}</span>
|
||||
{size === "md" && <span className="truncate text-xs">{activeTenantDescription}</span>}
|
||||
</div>
|
||||
<ChevronsUpDown className="ml-auto" />
|
||||
</SidebarMenuButton>
|
||||
@@ -95,9 +89,6 @@ export function TeamSwitcher({ tenants, size = "md" }: { tenants: TenantSimple[]
|
||||
</div>
|
||||
<div className="truncate">
|
||||
<div className="text-foreground truncate text-sm">{tenant.name} </div>
|
||||
{/* {tenant.types.length > 0 && (
|
||||
<span className=" truncate text-xs">{getTenantDescription({ subscription: null, types: tenant.types, t })}</span>
|
||||
)} */}
|
||||
</div>
|
||||
</div>
|
||||
{/* <div className="shrink-0">
|
||||
@@ -142,29 +133,3 @@ function CreateAccountMenuItem({ label }: { label: string }) {
|
||||
</DropdownMenuItem>
|
||||
);
|
||||
}
|
||||
|
||||
function getTenantDescription({
|
||||
subscription,
|
||||
types,
|
||||
t,
|
||||
}: {
|
||||
subscription: {
|
||||
products: { subscriptionProduct: { title: string } }[];
|
||||
} | null;
|
||||
types: { title: string }[];
|
||||
t: any;
|
||||
}) {
|
||||
void subscription;
|
||||
void types;
|
||||
void t;
|
||||
return "";
|
||||
// let activeTenantDescription = subscription?.products.length
|
||||
// ? t(subscription.products.find((f) => f)?.subscriptionProduct.title || "")
|
||||
// : t("settings.subscription.noSubscription");
|
||||
// if (!subscription || !subscription.products.length) {
|
||||
// // if (types.length > 0) {
|
||||
// // activeTenantDescription = t(types[0].title);
|
||||
// // }
|
||||
// }
|
||||
// return activeTenantDescription;
|
||||
}
|
||||
Reference in new issue
Block a user