Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

feat(frontend): add Give feedback to the account menu (hotfix) (#15248)

Krzysztof Czerwinskica259ccc21e1
diff --git a/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/AccountMenuNewLayout.tsx b/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/AccountMenuNewLayout.tsx
index 2ef91339d9..bedf8c8249 100644
--- a/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/AccountMenuNewLayout.tsx
+++ b/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/AccountMenuNewLayout.tsx
@@ -7,6 +7,7 @@ import * as React from "react";
import { MenuItemGroup } from "../../helpers";
import { AccountLogoutOption } from "./components/AccountLogoutOption";
import { AccountMenuActivityRow } from "./components/AccountMenuActivityRow";
+import { AccountMenuFeedbackRow } from "./components/AccountMenuFeedbackRow";
import { AccountMenuHeader } from "./components/AccountMenuHeader";
import { AccountMenuRow } from "./components/AccountMenuRow";
import { InitialAvatar } from "./components/InitialAvatar";
@@ -124,9 +125,14 @@ export function AccountMenuNewLayout({
);
})}
{groupIndex === 0 && (
- <li>
- <AccountMenuActivityRow />
- </li>
+ <>
+ <li>
+ <AccountMenuActivityRow />
+ </li>
+ <li>
+ <AccountMenuFeedbackRow />
+ </li>
+ </>
)}
</ul>
</div>
diff --git a/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/__tests__/AccountMenu.test.tsx b/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/__tests__/AccountMenu.test.tsx
index affa57f6a3..39a6a765cc 100644
--- a/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/__tests__/AccountMenu.test.tsx
+++ b/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/__tests__/AccountMenu.test.tsx
@@ -20,6 +20,14 @@ vi.mock("next/link", () => ({
useLinkStatus: () => ({ pending: false }),
}));
+vi.mock("@/lib/auth/actions", () => ({
+ getCurrentUser: vi.fn().mockResolvedValue({ user: null }),
+}));
+
+vi.mock("@sentry/nextjs", () => ({
+ getReplay: vi.fn(),
+}));
+
vi.mock("@/components/molecules/Popover/Popover", () => {
function Popover({ children }: { children: React.ReactNode }) {
return <div>{children}</div>;
@@ -184,7 +192,42 @@ describe("AccountMenu", () => {
expect(screen.getByText("Activity")).toBeDefined();
});
- test("classic layout does not render org/activity triggers", () => {
+ test("new layout renders Give feedback right after Activity", () => {
+ render(
+ <AccountMenu
+ userName="Ada"
+ userEmail="[email protected]"
+ menuItemGroups={baseGroups}
+ newLayout
+ />,
+ );
+
+ const activity = screen.getByTestId("account-menu-activity-trigger");
+ const feedback = screen.getByRole("button", { name: "Give feedback" });
+
+ expect(feedback.getAttribute("data-tally-open")).toBe("3yx2L0");
+ expect(activity.closest("li")?.nextElementSibling).toBe(
+ feedback.closest("li"),
+ );
+ });
+
+ test("new layout gives feedback without loading another Tally script", () => {
+ render(
+ <AccountMenu
+ userName="Ada"
+ userEmail="[email protected]"
+ menuItemGroups={baseGroups}
+ newLayout
+ />,
+ );
+
+ expect(screen.getByRole("button", { name: "Give feedback" })).toBeDefined();
+ expect(document.querySelectorAll('script[src*="tally.so"]')).toHaveLength(
+ 0,
+ );
+ });
+
+ test("classic layout does not render org, activity or feedback triggers", () => {
render(
<AccountMenu
userName="Ada"
@@ -195,5 +238,6 @@ describe("AccountMenu", () => {
expect(screen.queryByTestId("account-menu-org-trigger")).toBeNull();
expect(screen.queryByTestId("account-menu-activity-trigger")).toBeNull();
+ expect(screen.queryByRole("button", { name: "Give feedback" })).toBeNull();
});
});
diff --git a/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/components/AccountMenuFeedbackRow.tsx b/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/components/AccountMenuFeedbackRow.tsx
new file mode 100644
index 0000000000..62fd28316c
--- /dev/null
+++ b/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/components/AccountMenuFeedbackRow.tsx
@@ -0,0 +1,52 @@
+"use client";
+
+import { Icon } from "@/components/atoms/Icon/Icon";
+import { useTallyPageContext } from "@/components/molecules/TallyPoup/useTallyPopup";
+import { useOptionalSidebar } from "@/components/ui/sidebar";
+import { useAuth } from "@/lib/auth/hooks/useAuth";
+import { HelpCircleIcon } from "@hugeicons/core-free-icons";
+
+const FEEDBACK_TALLY_FORM_ID = "3yx2L0";
+
+const rowClasses =
+ "group relative flex w-full items-center gap-3 rounded-lg py-2 pl-3 pr-2 text-left text-sm font-normal text-neutral-700 outline-none transition-colors duration-200 ease-out hover:bg-neutral-100 focus-visible:bg-neutral-100 focus-visible:outline-none";
+
+export function AccountMenuFeedbackRow() {
+ const tally = useTallyPageContext();
+ const { isLoggedIn, isUserLoading } = useAuth();
+ const sidebar = useOptionalSidebar();
+
+ function handleClick() {
+ if (sidebar?.isMobile) sidebar.setOpenMobile(false);
+ }
+
+ return (
+ <button
+ type="button"
+ className={rowClasses}
+ onClick={handleClick}
+ data-tally-open={FEEDBACK_TALLY_FORM_ID}
+ data-tally-emoji-text="👋"
+ data-tally-emoji-animation="wave"
+ data-sentry-replay-id={tally.sentryReplayId || "not-initialized"}
+ data-sentry-replay-url={tally.replayUrl || "not-initialized"}
+ data-page-url={
+ tally.pageUrl ? tally.pageUrl.split("?")[0] : "not-initialized"
+ }
+ data-is-authenticated={isUserLoading ? "unknown" : String(isLoggedIn)}
+ >
+ <span
+ className="absolute left-0 top-1/2 h-5 w-[3px] -translate-y-1/2 rounded-full bg-neutral-900 opacity-0 transition-opacity duration-200 group-hover:opacity-100 group-focus-visible:opacity-100"
+ aria-hidden="true"
+ />
+ <span className="relative z-10 flex shrink-0 items-center">
+ <Icon
+ icon={HelpCircleIcon}
+ className="h-[18px] w-[18px] shrink-0"
+ aria-hidden="true"
+ />
+ </span>
+ <span className="relative z-10 flex-1 truncate">Give feedback</span>
+ </button>
+ );
+}
diff --git a/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/components/__tests__/AccountMenuFeedbackRow.test.tsx b/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/components/__tests__/AccountMenuFeedbackRow.test.tsx
new file mode 100644
index 0000000000..d0587144c2
--- /dev/null
+++ b/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/components/__tests__/AccountMenuFeedbackRow.test.tsx
@@ -0,0 +1,117 @@
+import {
+ act,
+ fireEvent,
+ render,
+ screen,
+} from "@/tests/integrations/test-utils";
+import { beforeEach, describe, expect, test, vi } from "vitest";
+import { AccountMenuFeedbackRow } from "../AccountMenuFeedbackRow";
+
+const mockSidebar = vi.hoisted(() => ({
+ current: null as null | {
+ isMobile: boolean;
+ setOpenMobile: (open: boolean) => void;
+ },
+}));
+
+vi.mock("@/components/ui/sidebar", () => ({
+ useOptionalSidebar: () => mockSidebar.current,
+}));
+
+const mockAuth = vi.hoisted(() => ({
+ getCurrentUser: vi.fn(),
+}));
+
+const mockSentry = vi.hoisted(() => ({
+ getReplay: vi.fn(),
+}));
+
+const mockUseAuth = vi.hoisted(() => ({
+ current: { isLoggedIn: true, isUserLoading: false },
+}));
+
+vi.mock("@/lib/auth/actions", () => mockAuth);
+vi.mock("@sentry/nextjs", () => mockSentry);
+vi.mock("@/lib/auth/hooks/useAuth", () => ({
+ useAuth: () => mockUseAuth.current,
+}));
+
+async function renderRow() {
+ render(<AccountMenuFeedbackRow />);
+ await act(async () => {});
+ return screen.getByRole("button", { name: "Give feedback" });
+}
+
+describe("AccountMenuFeedbackRow", () => {
+ beforeEach(() => {
+ mockSidebar.current = null;
+ mockUseAuth.current = { isLoggedIn: true, isUserLoading: false };
+ mockAuth.getCurrentUser.mockReset();
+ mockSentry.getReplay.mockReturnValue({ getReplayId: () => "replay-123" });
+ window.history.replaceState({}, "", "/library?sort=updatedAt");
+ });
+
+ test("renders a Give feedback button wired to the Tally feedback form", async () => {
+ const button = await renderRow();
+
+ expect(button.getAttribute("data-tally-open")).toBe("3yx2L0");
+ expect(button.getAttribute("data-tally-emoji-text")).toBe("👋");
+ expect(button.getAttribute("data-tally-emoji-animation")).toBe("wave");
+ expect(button.getAttribute("data-sentry-replay-id")).toBe("replay-123");
+ expect(button.getAttribute("data-sentry-replay-url")).toBe(
+ "https://significant-gravitas.sentry.io/replays/replay-123/",
+ );
+ expect(button.getAttribute("data-page-url")).toBe(
+ `${window.location.origin}/library`,
+ );
+ expect(button.getAttribute("data-is-authenticated")).toBe("true");
+ });
+
+ test("marks values that are not known yet", async () => {
+ mockSentry.getReplay.mockReturnValue(undefined);
+ mockUseAuth.current = { isLoggedIn: false, isUserLoading: true };
+ const button = await renderRow();
+
+ expect(button.getAttribute("data-sentry-replay-id")).toBe(
+ "not-initialized",
+ );
+ expect(button.getAttribute("data-is-authenticated")).toBe("unknown");
+ });
+
+ test("reads auth from the client store, not the getCurrentUser server action", async () => {
+ await renderRow();
+
+ expect(mockAuth.getCurrentUser).not.toHaveBeenCalled();
+ });
+
+ test("hides the decorative icon from assistive tech", async () => {
+ const button = await renderRow();
+
+ expect(button.querySelector("svg")?.getAttribute("aria-hidden")).toBe(
+ "true",
+ );
+ });
+
+ test("closes the mobile sidebar sheet so the Tally popup is usable", async () => {
+ const setOpenMobile = vi.fn();
+ mockSidebar.current = { isMobile: true, setOpenMobile };
+
+ fireEvent.click(await renderRow());
+
+ expect(setOpenMobile).toHaveBeenCalledWith(false);
+ });
+
+ test("leaves the desktop sidebar alone", async () => {
+ const setOpenMobile = vi.fn();
+ mockSidebar.current = { isMobile: false, setOpenMobile };
+
+ fireEvent.click(await renderRow());
+
+ expect(setOpenMobile).not.toHaveBeenCalled();
+ });
+
+ test("works outside a sidebar", async () => {
+ const button = await renderRow();
+ expect(() => fireEvent.click(button)).not.toThrow();
+ });
+});
diff --git a/autogpt_platform/frontend/src/components/molecules/TallyPoup/useTallyPopup.ts b/autogpt_platform/frontend/src/components/molecules/TallyPoup/useTallyPopup.ts
index d5326b029a..b217df653c 100644
--- a/autogpt_platform/frontend/src/components/molecules/TallyPoup/useTallyPopup.ts
+++ b/autogpt_platform/frontend/src/components/molecules/TallyPoup/useTallyPopup.ts
@@ -3,14 +3,11 @@ import { useEffect, useState } from "react";
import * as Sentry from "@sentry/nextjs";
import { getCurrentUser } from "@/lib/auth/actions";
-export function useTallyPopup() {
- const [isFormVisible, setIsFormVisible] = useState(false);
+export function useTallyPageContext() {
const [sentryReplayId, setSentryReplayId] = useState("");
const [replayUrl, setReplayUrl] = useState("");
const [pageUrl, setPageUrl] = useState("");
const [userAgent, setUserAgent] = useState("");
- const [isAuthenticated, setIsAuthenticated] = useState<boolean | null>(null);
- const [userEmail, setUserEmail] = useState<string>("");
const pathname = usePathname();
useEffect(() => {
@@ -33,6 +30,15 @@ export function useTallyPopup() {
}
}, [pathname]);
+ return { sentryReplayId, replayUrl, pageUrl, userAgent };
+}
+
+export function useTallyContext() {
+ const page = useTallyPageContext();
+ const [isAuthenticated, setIsAuthenticated] = useState<boolean | null>(null);
+ const [userEmail, setUserEmail] = useState<string>("");
+ const pathname = usePathname();
+
useEffect(() => {
// Check authentication status using server action (works with httpOnly cookies)
getCurrentUser().then(({ user }) => {
@@ -41,6 +47,13 @@ export function useTallyPopup() {
});
}, [pathname]);
+ return { ...page, isAuthenticated, userEmail };
+}
+
+export function useTallyPopup() {
+ const context = useTallyContext();
+ const [isFormVisible, setIsFormVisible] = useState(false);
+
useEffect(() => {
// Load Tally script
const script = document.createElement("script");
@@ -99,13 +112,8 @@ export function useTallyPopup() {
return {
state: {
- sentryReplayId,
- replayUrl,
- pageUrl,
- userAgent,
- isAuthenticated,
+ ...context,
isFormVisible,
- userEmail,
},
handlers: {},
};