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): Show toast on low credit balance, rename `Credits` page to `Billing` (#9428)
Krzysztof Czerwinski797916cf14e8
diff --git a/autogpt_platform/frontend/src/app/marketplace/(user)/credits/page.tsx b/autogpt_platform/frontend/src/app/marketplace/(user)/credits/page.tsxindex 22052b32af..63bbf9c6a5 100644--- a/autogpt_platform/frontend/src/app/marketplace/(user)/credits/page.tsx+++ b/autogpt_platform/frontend/src/app/marketplace/(user)/credits/page.tsx@@ -81,7 +81,7 @@ export default function CreditsPage() {return (<div className="w-full min-w-[800px] px-4 sm:px-8"><h1 className="mb-6 text-[28px] font-normal text-neutral-900 dark:text-neutral-100 sm:mb-8 sm:text-[35px]">- Credits+ Billing</h1><div className="grid grid-cols-1 gap-8 lg:grid-cols-2">diff --git a/autogpt_platform/frontend/src/app/marketplace/(user)/layout.tsx b/autogpt_platform/frontend/src/app/marketplace/(user)/layout.tsxindex 07b7d3f4b4..ea88d5edc4 100644--- a/autogpt_platform/frontend/src/app/marketplace/(user)/layout.tsx+++ b/autogpt_platform/frontend/src/app/marketplace/(user)/layout.tsx@@ -7,7 +7,7 @@ export default function Layout({ children }: { children: React.ReactNode }) {links: [{ text: "Creator Dashboard", href: "/marketplace/dashboard" },{ text: "Agent dashboard", href: "/marketplace/agent-dashboard" },- { text: "Credits", href: "/marketplace/credits" },+ { text: "Billing", href: "/marketplace/credits" },{ text: "Integrations", href: "/marketplace/integrations" },{ text: "API Keys", href: "/marketplace/api_keys" },{ text: "Profile", href: "/marketplace/profile" },diff --git a/autogpt_platform/frontend/src/components/agptui/Sidebar.tsx b/autogpt_platform/frontend/src/components/agptui/Sidebar.tsxindex 08f56faa1f..637b3202a3 100644--- a/autogpt_platform/frontend/src/components/agptui/Sidebar.tsx+++ b/autogpt_platform/frontend/src/components/agptui/Sidebar.tsx@@ -61,7 +61,7 @@ export const Sidebar: React.FC<SidebarProps> = ({ linkGroups }) => {><IconCoin className="h-6 w-6" /><div className="p-ui-medium text-base font-medium leading-normal">- Credits+ Billing</div></Link>)}@@ -125,7 +125,7 @@ export const Sidebar: React.FC<SidebarProps> = ({ linkGroups }) => {><IconCoin className="h-6 w-6" /><div className="p-ui-medium text-base font-medium leading-normal">- Credits+ Billing</div></Link>)}diff --git a/autogpt_platform/frontend/src/hooks/useAgentGraph.ts b/autogpt_platform/frontend/src/hooks/useAgentGraph.tsxsimilarity index 96%rename from autogpt_platform/frontend/src/hooks/useAgentGraph.tsrename to autogpt_platform/frontend/src/hooks/useAgentGraph.tsxindex 8fd9b4d148..2a1ab5241f 100644--- a/autogpt_platform/frontend/src/hooks/useAgentGraph.ts+++ b/autogpt_platform/frontend/src/hooks/useAgentGraph.tsx@@ -21,6 +21,8 @@ import { useRouter, useSearchParams, usePathname } from "next/navigation";import { useToast } from "@/components/ui/use-toast";import { InputItem } from "@/components/RunnerUIWrapper";import { GraphMeta } from "@/lib/autogpt-server-api";+import useCredits from "./useCredits";+import { default as NextLink } from "next/link";const ajv = new Ajv({ strict: false, allErrors: true });@@ -72,6 +74,7 @@ export default function useAgentGraph(useState(false);const [nodes, setNodes] = useState<CustomNode[]>([]);const [edges, setEdges] = useState<CustomEdge[]>([]);+ const { credits, fetchCredits } = useCredits();const api = useMemo(() => new BackendAPI(process.env.NEXT_PUBLIC_AGPT_SERVER_URL!),@@ -560,6 +563,33 @@ export default function useAgentGraph(if (nodeResult.graph_exec_id != graphExecution.id) {return;}+ if (+ nodeResult.status === "FAILED" &&+ nodeResult.output_data?.error?.[0]+ .toLowerCase()+ .includes("insufficient balance")+ ) {+ // Show no credits toast if user has low credits+ toast({+ variant: "destructive",+ title: "Credits low",+ description: (+ <div>+ Agent execution failed due to insufficient credits.+ <br />+ Go to the{" "}+ <NextLink+ className="text-purple-300"+ href="/marketplace/credits"+ >+ Credits+ </NextLink>{" "}+ page to top up.+ </div>+ ),+ duration: 5000,+ });+ }if (!["COMPLETED", "TERMINATED", "FAILED"].includes(nodeResult.status,