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.

fix(frontend): render Ayrshare connect button on all credential surfaces (#14014)

AutoGPT4836d573e7ce
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/__tests__/CustomNode.test.tsx b/autogpt_platform/frontend/src/app/(platform)/build/__tests__/CustomNode.test.tsx
index a27d885176..ce0eb1b72a 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/__tests__/CustomNode.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/__tests__/CustomNode.test.tsx
@@ -91,13 +91,6 @@ vi.mock(
}),
);
-vi.mock(
- "@/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/AyrshareConnectButton",
- () => ({
- AyrshareConnectButton: () => <div data-testid="ayrshare-connect-button" />,
- }),
-);
-
vi.mock(
"@/app/(platform)/build/components/FlowEditor/nodes/FormCreator",
() => ({
@@ -331,16 +324,27 @@ describe("CustomNode", () => {
});
describe("AYRSHARE type rendering", () => {
- it("renders AyrshareConnectButton for AYRSHARE type", () => {
+ // The connect button now lives in CredentialsFlatView, which every Ayrshare
+ // block reaches through its `credentials` field. Rendering it from the node
+ // shell as well would show the user two identical buttons.
+ it("does not render its own AyrshareConnectButton for AYRSHARE type", () => {
renderCustomNode({ uiType: BlockUIType.AYRSHARE });
- expect(screen.getByTestId("ayrshare-connect-button")).toBeDefined();
+ expect(
+ screen.queryByRole("button", {
+ name: /Connect Social Media Accounts/i,
+ }),
+ ).toBeNull();
});
it("does not render AyrshareConnectButton for non-AYRSHARE types", () => {
renderCustomNode({ uiType: BlockUIType.STANDARD });
- expect(screen.queryByTestId("ayrshare-connect-button")).toBeNull();
+ expect(
+ screen.queryByRole("button", {
+ name: /Connect Social Media Accounts/i,
+ }),
+ ).toBeNull();
});
});
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/CustomNode.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/CustomNode.tsx
index 3dd4645288..67123b30a9 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/CustomNode.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/CustomNode.tsx
@@ -11,7 +11,6 @@ import React from "react";
import { BlockUIType } from "../../../types";
import { FormCreator } from "../FormCreator";
import { OutputHandler } from "../OutputHandler";
-import { AyrshareConnectButton } from "./components/AyrshareConnectButton";
import { NodeAdvancedToggle } from "./components/NodeAdvancedToggle";
import { NodeContainer } from "./components/NodeContainer";
import { NodeExecutionBadge } from "./components/NodeExecutionBadge";
@@ -76,8 +75,6 @@ export const CustomNode: React.FC<NodeProps<CustomNode>> = React.memo(
BlockUIType.WEBHOOK_MANUAL,
].includes(data.uiType);
- const isAyrshare = data.uiType === BlockUIType.AYRSHARE;
-
const hasConfigErrors =
data.errors &&
Object.values(data.errors).some(
@@ -106,7 +103,6 @@ export const CustomNode: React.FC<NodeProps<CustomNode>> = React.memo(
<NodeHeader data={data} nodeId={nodeId} />
{isAgent && <SubAgentUpdateFeature nodeID={nodeId} nodeData={data} />}
{isWebhook && <WebhookDisclaimer nodeId={nodeId} />}
- {isAyrshare && <AyrshareConnectButton />}
<FormCreator
jsonSchema={preprocessInputSchema(inputSchema)}
nodeId={nodeId}
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/AyrshareConnectButton.tsx b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/AyrshareConnectButton/AyrshareConnectButton.tsx
similarity index 69%
rename from autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/AyrshareConnectButton.tsx
rename to autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/AyrshareConnectButton/AyrshareConnectButton.tsx
index d50167488c..a22f55050a 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/AyrshareConnectButton.tsx
+++ b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/AyrshareConnectButton/AyrshareConnectButton.tsx
@@ -1,20 +1,26 @@
"use client";
-import React, { useContext, useState } from "react";
+import { useContext, useState } from "react";
-import { Key } from "lucide-react";
+import { Key01Icon } from "@hugeicons/core-free-icons";
import { getV1GetAyrshareSsoUrl } from "@/app/api/__generated__/endpoints/integrations/integrations";
import { useToast } from "@/components/molecules/Toast/use-toast";
import { Button } from "@/components/atoms/Button/Button";
+import { Icon } from "@/components/atoms/Icon/Icon";
import { CredentialsActionsContext } from "@/providers/agent-credentials/credentials-provider";
+import { cn } from "@/lib/utils";
+
+interface Props {
+ className?: string;
+}
// This SSO button is not a part of inputSchema - that's why we are not rendering it using Input renderer
-export const AyrshareConnectButton = () => {
+export function AyrshareConnectButton({ className }: Props) {
const [isLoading, setIsLoading] = useState(false);
const { toast } = useToast();
const credentialsActions = useContext(CredentialsActionsContext);
- const handleSSOLogin = async () => {
+ async function handleSSOLogin() {
setIsLoading(true);
try {
const { data, status } = await getV1GetAyrshareSsoUrl();
@@ -44,21 +50,19 @@ export const AyrshareConnectButton = () => {
} finally {
setIsLoading(false);
}
- };
+ }
+ // TODO :Need better UI to show user which social media accounts are connected
return (
- // TODO :Need better UI to show user which social media accounts are connected
- <div className="mt-4 flex flex-col gap-2 px-4">
- <Button
- type="button"
- onClick={handleSSOLogin}
- disabled={isLoading}
- className="h-fit w-full py-2"
- loading={isLoading}
- leftIcon={<Key className="mr-2 h-4 w-4" />}
- >
- Connect Social Media Accounts
- </Button>
- </div>
+ <Button
+ type="button"
+ onClick={handleSSOLogin}
+ disabled={isLoading}
+ className={cn("h-fit w-full py-2", className)}
+ loading={isLoading}
+ leftIcon={<Icon icon={Key01Icon} size={16} />}
+ >
+ Connect Social Media Accounts
+ </Button>
);
-};
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/__tests__/AyrshareConnectButton.test.tsx b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/AyrshareConnectButton/__tests__/AyrshareConnectButton.test.tsx
similarity index 100%
rename from autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/__tests__/AyrshareConnectButton.test.tsx
rename to autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/AyrshareConnectButton/__tests__/AyrshareConnectButton.test.tsx
diff --git a/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/CredentialsFlatView/CredentialsFlatView.tsx b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/CredentialsFlatView/CredentialsFlatView.tsx
index db521ca1d8..23dbfecb5c 100644
--- a/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/CredentialsFlatView/CredentialsFlatView.tsx
+++ b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/CredentialsFlatView/CredentialsFlatView.tsx
@@ -6,6 +6,7 @@ import {
CredentialsMetaInput,
} from "@/lib/autogpt-server-api/types";
import { ExclamationTriangleIcon } from "@radix-ui/react-icons";
+import { AyrshareConnectButton } from "../AyrshareConnectButton/AyrshareConnectButton";
import { CredentialRow } from "../CredentialRow/CredentialRow";
import { CredentialsSelect } from "../CredentialsSelect/CredentialsSelect";
@@ -53,12 +54,12 @@ export function CredentialsFlatView({
}: Props) {
const hasCredentials = credentials.length > 0;
// Ayrshare has no user-settable credential — provisioning runs on the
- // server after the user clicks the explicit Connect Social Media
- // Accounts button rendered alongside the block. Exposing "Add API
- // key" / "Use a new API key" here just confuses users into entering a
- // random key.
+ // server after the user clicks the Connect Social Media Accounts
+ // button rendered below. Exposing "Add API key" / "Use a new API key"
+ // here just confuses users into entering a random key.
const isManagedOnlyProvider = provider === "ayrshare";
const showAddAction = !readOnly && !isManagedOnlyProvider;
+ const showAyrshareConnect = isManagedOnlyProvider && !readOnly;
return (
<>
@@ -134,6 +135,7 @@ export function CredentialsFlatView({
{actionButtonText}
</Button>
)}
+ {showAyrshareConnect && <AyrshareConnectButton className="mt-2" />}
</>
) : showAddAction ? (
<Button
@@ -145,15 +147,9 @@ export function CredentialsFlatView({
>
{actionButtonText}
</Button>
- ) : (
- isManagedOnlyProvider &&
- !readOnly && (
- <Text variant="body" className="text-zinc-500">
- Click <strong>Connect Social Media Accounts</strong> above to set up
- your managed {displayName} profile.
- </Text>
- )
- )}
+ ) : showAyrshareConnect ? (
+ <AyrshareConnectButton className="mt-2" />
+ ) : null}
</>
);
}
diff --git a/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/CredentialsFlatView/__tests__/CredentialsFlatView.test.tsx b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/CredentialsFlatView/__tests__/CredentialsFlatView.test.tsx
index 45c2c8d35e..630f9b372c 100644
--- a/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/CredentialsFlatView/__tests__/CredentialsFlatView.test.tsx
+++ b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/CredentialsFlatView/__tests__/CredentialsFlatView.test.tsx
@@ -3,6 +3,16 @@ import { afterEach, describe, expect, it, vi } from "vitest";
import { CredentialsFlatView } from "../CredentialsFlatView";
import { BlockIOCredentialsSubSchema } from "@/lib/autogpt-server-api/types";
+vi.mock("@/app/api/__generated__/endpoints/integrations/integrations", () => ({
+ getV1GetAyrshareSsoUrl: vi.fn(),
+}));
+
+vi.mock("@/components/molecules/Toast/use-toast", () => ({
+ useToast: () => ({ toast: vi.fn() }),
+}));
+
+const connectButton = { name: /Connect Social Media Accounts/i };
+
afterEach(() => {
cleanup();
});
@@ -87,4 +97,58 @@ describe("CredentialsFlatView", () => {
const rowContainer = screen.getByText("My API key").closest("div");
expect(rowContainer).toBeTruthy();
});
+
+ it("offers the Ayrshare connect button when the user has no credential yet", () => {
+ render(<CredentialsFlatView {...makeProps({ credentials: [] })} />);
+
+ expect(screen.getByRole("button", connectButton)).toBeTruthy();
+ // "Add API key" must stay hidden — Ayrshare keys are provisioned server-side.
+ expect(screen.queryByRole("button", { name: /Add API key/i })).toBeNull();
+ });
+
+ it("keeps offering the connect button once a managed credential exists", () => {
+ render(
+ <CredentialsFlatView
+ {...makeProps({
+ credentials: [
+ {
+ id: "managed-1",
+ title: "Ayrshare (managed by AutoGPT)",
+ type: "api_key",
+ provider: "ayrshare",
+ is_managed: true,
+ },
+ ],
+ })}
+ />,
+ );
+
+ // Linking additional social networks reuses the same SSO flow.
+ expect(screen.getByRole("button", connectButton)).toBeTruthy();
+ });
+
+ it("hides the connect button when read-only", () => {
+ render(
+ <CredentialsFlatView
+ {...makeProps({ credentials: [], readOnly: true })}
+ />,
+ );
+
+ expect(screen.queryByRole("button", connectButton)).toBeNull();
+ });
+
+ it("does not offer the connect button for other providers", () => {
+ render(
+ <CredentialsFlatView
+ {...makeProps({
+ provider: "github",
+ displayName: "GitHub",
+ credentials: [],
+ })}
+ />,
+ );
+
+ expect(screen.queryByRole("button", connectButton)).toBeNull();
+ expect(screen.getByRole("button", { name: /Add API key/i })).toBeTruthy();
+ });
});