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): settings v2 QA pass — dialog padding, billing tab restore, auto-refill defaults (#12984)
Abhimanyu Yadav3f035d9c593e
diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/account/components/TimezoneCard/TimezoneCard.tsx b/autogpt_platform/frontend/src/app/(platform)/settings/account/components/TimezoneCard/TimezoneCard.tsxindex fbaf8bca8a..7ef1b95b18 100644--- a/autogpt_platform/frontend/src/app/(platform)/settings/account/components/TimezoneCard/TimezoneCard.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/settings/account/components/TimezoneCard/TimezoneCard.tsx@@ -1,6 +1,6 @@"use client";-import { ClockIcon, InfoIcon } from "@phosphor-icons/react";+import { InfoIcon } from "@phosphor-icons/react";import { motion, useReducedMotion } from "framer-motion";import { Select } from "@/components/atoms/Select/Select";@@ -11,12 +11,7 @@ import {TooltipTrigger,} from "@/components/atoms/Tooltip/BaseTooltip";-import {- EASE_OUT,- TIMEZONES,- findTimezoneLabel,- formatGmtOffset,-} from "../../helpers";+import { EASE_OUT, TIMEZONES, findTimezoneLabel } from "../../helpers";interface Props {value: string;@@ -26,7 +21,6 @@ interface Props {export function TimezoneCard({ value, onChange, index = 0 }: Props) {const reduceMotion = useReducedMotion();- const offset = formatGmtOffset(value);const options = TIMEZONES.some((t) => t.value === value)? TIMEZONES@@ -69,31 +63,17 @@ export function TimezoneCard({ value, onChange, index = 0 }: Props) {</Tooltip></div>- <div className="flex h-fit items-center gap-2">- <Select- id="timezone"- label="Timezone"- hideLabel- value={value}- onValueChange={onChange}- options={options}- placeholder="Select your timezone"- size="small"- wrapperClassName="!mb-0 w-fit"- />- {offset ? (- <div className="flex h-fit shrink-0 items-center gap-1.5 rounded-full border border-zinc-200 bg-zinc-50 px-3 py-1.5 tabular-nums text-zinc-600">- <ClockIcon size={14} weight="duotone" />- <Text- variant="small-medium"- as="span"- className="text-zinc-600"- >- {offset}- </Text>- </div>- ) : null}- </div>+ <Select+ id="timezone"+ label="Timezone"+ hideLabel+ value={value}+ onValueChange={onChange}+ options={options}+ placeholder="Select your timezone"+ size="small"+ wrapperClassName="!mb-0 w-fit"+ /></div></div></motion.section>diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/account/helpers.ts b/autogpt_platform/frontend/src/app/(platform)/settings/account/helpers.tsindex 8eda005119..ab13e4c90a 100644--- a/autogpt_platform/frontend/src/app/(platform)/settings/account/helpers.ts+++ b/autogpt_platform/frontend/src/app/(platform)/settings/account/helpers.ts@@ -273,17 +273,3 @@ export const TIMEZONES = TIMEZONE_LIST;export function findTimezoneLabel(value: string): string {return TIMEZONES.find((t) => t.value === value)?.label ?? value;}--export function formatGmtOffset(timezone: string): string | null {- try {- const formatter = new Intl.DateTimeFormat("en-US", {- timeZone: timezone,- timeZoneName: "shortOffset",- });- const parts = formatter.formatToParts(new Date());- const offset = parts.find((p) => p.type === "timeZoneName")?.value;- return offset ?? null;- } catch {- return null;- }-}diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/billing/__tests__/billing-hooks.test.tsx b/autogpt_platform/frontend/src/app/(platform)/settings/billing/__tests__/billing-hooks.test.tsxindex 164b309035..4b8fc19d69 100644--- a/autogpt_platform/frontend/src/app/(platform)/settings/billing/__tests__/billing-hooks.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/settings/billing/__tests__/billing-hooks.test.tsx@@ -323,6 +323,85 @@ describe("useAutoRefillCard", () => {// Mutation never started.expect(result.current.isSaving).toBe(false);});++ it("opening the dialog with no saved config pre-fills $5/$5 so the form is valid by default", async () => {+ server.use(+ jsonHandler("get", "/api/credits/auto-top-up", {+ amount: 0,+ threshold: 0,+ }),+ );++ const { result } = renderHook(() => useAutoRefillCard(), {+ wrapper: makeWrapper(),+ });++ await waitFor(() => expect(result.current.isLoading).toBe(false));++ act(() => result.current.setOpen(true));++ // Empty-state copy in the dialog says "min $5"; defaults must match.+ await waitFor(() => {+ expect(result.current.threshold).toBe("5");+ expect(result.current.refillAmount).toBe("5");+ expect(result.current.isValid).toBe(true);+ });+ });++ it("opening the dialog with saved config pre-fills the saved threshold and refill amount", async () => {+ server.use(+ jsonHandler("get", "/api/credits/auto-top-up", {+ amount: 2000,+ threshold: 750,+ }),+ );++ const { result } = renderHook(() => useAutoRefillCard(), {+ wrapper: makeWrapper(),+ });++ await waitFor(() => expect(result.current.isLoading).toBe(false));++ act(() => result.current.setOpen(true));++ await waitFor(() => {+ // 750 cents → $7.50; 2000 cents → $20.+ expect(result.current.threshold).toBe("7.5");+ expect(result.current.refillAmount).toBe("20");+ });+ });++ it("does not clobber in-progress edits if the dialog is re-opened without first closing", async () => {+ server.use(+ jsonHandler("get", "/api/credits/auto-top-up", {+ amount: 0,+ threshold: 0,+ }),+ );++ const { result } = renderHook(() => useAutoRefillCard(), {+ wrapper: makeWrapper(),+ });++ await waitFor(() => expect(result.current.isLoading).toBe(false));++ act(() => result.current.setOpen(true));+ await waitFor(() => expect(result.current.threshold).toBe("5"));++ // User starts editing — increases the threshold beyond the default.+ act(() => {+ result.current.setThreshold("25");+ result.current.setRefillAmount("50");+ });++ // Re-trigger the open=true effect by toggling open again WITHOUT closing+ // (e.g. another effect fires while open). Defaults must NOT overwrite+ // the user's in-progress edits.+ act(() => result.current.setOpen(true));++ expect(result.current.threshold).toBe("25");+ expect(result.current.refillAmount).toBe("50");+ });});describe("usePaymentMethodCard", () => {diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/billing/__tests__/billing-page.test.tsx b/autogpt_platform/frontend/src/app/(platform)/settings/billing/__tests__/billing-page.test.tsxindex a5070bd85a..c3ea71cbee 100644--- a/autogpt_platform/frontend/src/app/(platform)/settings/billing/__tests__/billing-page.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/settings/billing/__tests__/billing-page.test.tsx@@ -160,6 +160,51 @@ describe("Settings billing page (integration)", () => {);});+ it("activates the Automation Credits tab when a Stripe topup redirect lands on the page", async () => {+ useDefaultBillingHandlers();+ server.use(+ http.patch("*/api/credits/fulfill_checkout", () =>+ HttpResponse.json({}, { status: 200 }),+ ),+ );+ // Topup flow originates from the Automation Credits tab; the redirect+ // back from Stripe must NOT bounce the user to Subscription.+ mockSearchParams.current = new URLSearchParams({ topup: "success" });++ render(<SettingsBillingPage />);++ const automationCreditsTab = await screen.findByRole("tab", {+ name: /automation credits/i,+ });+ expect(automationCreditsTab.getAttribute("data-state")).toBe("active");+ });++ it("activates the requested tab when ?tab=automation-credits is present (deep-link)", async () => {+ useDefaultBillingHandlers();+ mockSearchParams.current = new URLSearchParams({+ tab: "automation-credits",+ });++ render(<SettingsBillingPage />);++ const automationCreditsTab = await screen.findByRole("tab", {+ name: /automation credits/i,+ });+ expect(automationCreditsTab.getAttribute("data-state")).toBe("active");+ });++ it("ignores an unknown ?tab= value and falls back to the Subscription default", async () => {+ useDefaultBillingHandlers();+ mockSearchParams.current = new URLSearchParams({ tab: "bogus" });++ render(<SettingsBillingPage />);++ const subscriptionTab = await screen.findByRole("tab", {+ name: "Subscription",+ });+ expect(subscriptionTab.getAttribute("data-state")).toBe("active");+ });+it("AutomationCreditsTab renders the ErrorCard when the balance fetch fails", async () => {server.use(jsonHandler("get", "/api/credits/subscription", SUBSCRIPTION_RESPONSE),diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/AutomationCreditsTab/AutoRefillCard/AutoRefillDialog.tsx b/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/AutomationCreditsTab/AutoRefillCard/AutoRefillDialog.tsxindex 27b2255aea..9a4bde1c2d 100644--- a/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/AutomationCreditsTab/AutoRefillCard/AutoRefillDialog.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/AutomationCreditsTab/AutoRefillCard/AutoRefillDialog.tsx@@ -60,10 +60,12 @@ export function AutoRefillDialog({onChange={setRefillAmount}/>- <div className="flex items-center gap-2 rounded-[12px] bg-amber-50 px-3 py-2">- <WarningIcon size={18} className="shrink-0 text-amber-600" />+ <div className="flex items-start gap-2 rounded-[12px] bg-amber-50 px-3 py-2">+ <WarningIcon size={18} className="mt-0.5 shrink-0 text-amber-600" /><Text variant="small" as="span" className="text-amber-700">- Auto-refill triggers at most once per agent execution.+ A single agent run can only trigger one auto-refill. Set a refill+ amount that covers your typical usage so agents don't pause+ mid-run.</Text></div></div>diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/AutomationCreditsTab/AutoRefillCard/useAutoRefillCard.ts b/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/AutomationCreditsTab/AutoRefillCard/useAutoRefillCard.tsindex 03c4fdb655..211b8d78b1 100644--- a/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/AutomationCreditsTab/AutoRefillCard/useAutoRefillCard.ts+++ b/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/AutomationCreditsTab/AutoRefillCard/useAutoRefillCard.ts@@ -1,6 +1,6 @@"use client";-import { useEffect, useState } from "react";+import { useEffect, useRef, useState } from "react";import {useGetV1GetAutoTopUp,@@ -33,15 +33,26 @@ export function useAutoRefillCard() {const [open, setOpen] = useState(false);const [threshold, setThreshold] = useState("");const [refillAmount, setRefillAmount] = useState("");+ const initializedForOpenRef = useRef(false);useEffect(() => {- if (open) {- setThreshold(- config?.threshold ? (config.threshold / 100).toString() : "",- );- setRefillAmount(config?.amount ? (config.amount / 100).toString() : "");+ if (!open) {+ initializedForOpenRef.current = false;+ return;}- }, [open, config]);+ // Wait for the config fetch to settle before locking in defaults —+ // otherwise opening the dialog mid-load would seed "5/5" and skip+ // re-hydration when saved config arrives moments later.+ if (isLoading) return;+ // Initialize once per open transition so background refetches (e.g. on+ // window focus) don't clobber the user's in-progress edits.+ if (initializedForOpenRef.current) return;+ initializedForOpenRef.current = true;+ // Backend minimum is $5 — pre-fill with the floor so the form is valid+ // by default and matches the "$5 minimum" copy in the empty state.+ setThreshold(config?.threshold ? (config.threshold / 100).toString() : "5");+ setRefillAmount(config?.amount ? (config.amount / 100).toString() : "5");+ }, [open, config, isLoading]);const thresholdValue = Number.parseFloat(threshold);const refillValue = Number.parseFloat(refillAmount);diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/billing/page.tsx b/autogpt_platform/frontend/src/app/(platform)/settings/billing/page.tsxindex e58e58bf33..a82ecafb8b 100644--- a/autogpt_platform/frontend/src/app/(platform)/settings/billing/page.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/settings/billing/page.tsx@@ -1,6 +1,6 @@"use client";-import { useEffect, useRef } from "react";+import { useEffect, useRef, useState } from "react";import { useRouter, useSearchParams } from "next/navigation";import { useQueryClient } from "@tanstack/react-query";@@ -20,6 +20,22 @@ import {import { AutomationCreditsTab } from "./components/AutomationCreditsTab/AutomationCreditsTab";import { SubscriptionTab } from "./components/SubscriptionTab/SubscriptionTab";+type BillingTab = "subscription" | "automation-credits";++function isBillingTab(value: string): value is BillingTab {+ return value === "subscription" || value === "automation-credits";+}++function resolveInitialTab(searchParams: URLSearchParams): BillingTab {+ const tabParam = searchParams.get("tab");+ if (tabParam && isBillingTab(tabParam)) return tabParam;+ // Topup flow only originates from the Automation Credits tab — when Stripe+ // redirects back, return the user to where they started instead of the+ // Subscription default.+ if (searchParams.get("topup")) return "automation-credits";+ return "subscription";+}+export default function SettingsBillingPage() {const router = useRouter();const searchParams = useSearchParams();@@ -29,6 +45,13 @@ export default function SettingsBillingPage() {const { mutateAsync: fulfillCheckout } = usePatchV1FulfillCheckoutSession();const handledTopupRef = useRef<string | null>(null);const handledSubscriptionRef = useRef<string | null>(null);+ const [activeTab, setActiveTab] = useState<BillingTab>(() =>+ resolveInitialTab(searchParams),+ );++ function handleTabChange(value: string) {+ if (isBillingTab(value)) setActiveTab(value);+ }useEffect(function setBillingDocumentTitle() {document.title = "Billing – AutoGPT Platform";@@ -99,7 +122,7 @@ export default function SettingsBillingPage() {Billing</Text>- <TabsLine defaultValue="subscription">+ <TabsLine value={activeTab} onValueChange={handleTabChange}><TabsLineList flush className="ml-4 overflow-x-auto"><TabsLineTrigger value="subscription">Subscription</TabsLineTrigger><TabsLineTrigger value="automation-credits">diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/integrations/components/ConnectServiceDialog/ConnectServiceDialog.tsx b/autogpt_platform/frontend/src/app/(platform)/settings/integrations/components/ConnectServiceDialog/ConnectServiceDialog.tsxindex e178b37174..1e09c7a77d 100644--- a/autogpt_platform/frontend/src/app/(platform)/settings/integrations/components/ConnectServiceDialog/ConnectServiceDialog.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/settings/integrations/components/ConnectServiceDialog/ConnectServiceDialog.tsx@@ -71,7 +71,7 @@ export function ConnectServiceDialog({ open, onOpenChange }: Props) {<Dialog.Content><MotionConfig transition={TRANSITION}><motion.div- className="relative overflow-hidden"+ className="relative overflow-hidden px-2"animate={{ height: contentHeight ?? "auto" }}transition={reduceMotion ? { duration: 0 } : HEIGHT_TRANSITION}>diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/integrations/components/IntegrationsHeader/IntegrationsHeader.tsx b/autogpt_platform/frontend/src/app/(platform)/settings/integrations/components/IntegrationsHeader/IntegrationsHeader.tsxindex 31a556f9e9..a0f291a1a7 100644--- a/autogpt_platform/frontend/src/app/(platform)/settings/integrations/components/IntegrationsHeader/IntegrationsHeader.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/settings/integrations/components/IntegrationsHeader/IntegrationsHeader.tsx@@ -18,7 +18,7 @@ export function IntegrationsHeader({ onConnect }: Props) {<Text variant="body" className="mt-4 max-w-[600px] text-[#505057]">Manage the 3rd party accounts you've connected to AutoGPT. Theseare services that can be used by your agents — like Gmail for sending- emails, GitHub for code, or Figma for designs.+ emails, GitHub for code, or Notion for documents.</Text></div>diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/profile/__tests__/main.test.tsx b/autogpt_platform/frontend/src/app/(platform)/settings/profile/__tests__/main.test.tsxindex d0bab90b74..8668090230 100644--- a/autogpt_platform/frontend/src/app/(platform)/settings/profile/__tests__/main.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/settings/profile/__tests__/main.test.tsx@@ -479,6 +479,71 @@ describe("SettingsProfilePage - save & discard", () => {});});+ test("Discard restores the row in place (no remount → no AnimatePresence flash)", async () => {+ server.use(+ getGetV2GetUserProfileMockHandler200(+ makeProfile({ links: ["https://a.dev", "https://b.dev"] }),+ ),+ );++ render(<SettingsProfilePage />);++ const link1Before = (await screen.findByLabelText(+ /^link 1$/i,+ )) as HTMLInputElement;+ // Capture the input element identity. If Discard re-keys the row,+ // AnimatePresence remounts it and this reference becomes a stale node.+ const link1Node = link1Before;++ // Trigger a background refetch with the same data — this used to+ // regenerate link IDs via makeLinkRow() and cause Discard to remount+ // every row.+ server.use(+ getGetV2GetUserProfileMockHandler200(+ makeProfile({ links: ["https://a.dev", "https://b.dev"] }),+ ),+ );+ fireEvent(window, new Event("focus"));++ fireEvent.change(link1Before, { target: { value: "https://edited.dev" } });+ fireEvent.click(screen.getByRole("button", { name: /discard/i }));++ await waitFor(() => {+ expect(link1Node.value).toBe("https://a.dev");+ });+ // The original input node is still in the document — it was never+ // unmounted/remounted by Discard.+ expect(link1Node.isConnected).toBe(true);+ });++ test("background refetch with unchanged server data does not clobber in-progress link edits", async () => {+ server.use(getGetV2GetUserProfileMockHandler200(makeProfile()));++ render(<SettingsProfilePage />);++ const link = (await screen.findByLabelText(+ /^link 1$/i,+ )) as HTMLInputElement;++ // User edits a link.+ fireEvent.change(link, { target: { value: "https://edited.dev" } });+ expect(link.value).toBe("https://edited.dev");++ // Simulate a background refetch returning the SAME server data — this+ // used to regenerate LinkRow IDs and replace state, wiping the edit+ // and triggering a row exit/enter flash.+ server.use(getGetV2GetUserProfileMockHandler200(makeProfile()));+ fireEvent(window, new Event("focus"));++ // Wait a tick to let any refetch effect run, then assert the edit+ // survived.+ await waitFor(() => {+ expect(+ (screen.getByLabelText(/^link 1$/i) as HTMLInputElement).value,+ ).toBe("https://edited.dev");+ });+ });+test("Save shows a destructive toast on a 422", async () => {server.use(getGetV2GetUserProfileMockHandler200(makeProfile()),diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/profile/useProfilePage.ts b/autogpt_platform/frontend/src/app/(platform)/settings/profile/useProfilePage.tsindex 93cd23504d..4d5619a69e 100644--- a/autogpt_platform/frontend/src/app/(platform)/settings/profile/useProfilePage.ts+++ b/autogpt_platform/frontend/src/app/(platform)/settings/profile/useProfilePage.ts@@ -1,6 +1,6 @@"use client";-import { useEffect, useMemo, useState } from "react";+import { useEffect, useMemo, useRef, useState } from "react";import { useQueryClient } from "@tanstack/react-query";import {@@ -48,27 +48,61 @@ export function useProfilePage() {},});- const initialState: ProfileFormState = useMemo(- () =>- profileQuery.data ? profileToFormState(profileQuery.data) : EMPTY_FORM,- [profileQuery.data],- );-const [formState, setFormState] = useState<ProfileFormState>(EMPTY_FORM);+ // Pristine baseline for dirty detection + Discard. Held as state (not a+ // ref) so dirty re-derives when it changes; pinned to the current+ // formState's link IDs on every sync so Discard never swaps IDs and+ // triggers an AnimatePresence flash.+ const [pristineState, setPristineState] =+ useState<ProfileFormState>(EMPTY_FORM);+ const formStateRef = useRef<ProfileFormState>(EMPTY_FORM);+ const lastSyncedRef = useRef<ProfileFormState>(EMPTY_FORM);+ const hasHydratedRef = useRef(false);++ useEffect(() => {+ formStateRef.current = formState;+ }, [formState]);useEffect(function syncFormStateOnDataLoad() {- if (profileQuery.data) {- setFormState(profileToFormState(profileQuery.data));+ if (!profileQuery.data) return;+ const incoming = profileToFormState(profileQuery.data);+ const prev = formStateRef.current;++ // First load always hydrates — even when the server returns an empty+ // profile, we need the padded link slots in formState to render.+ if (!hasHydratedRef.current) {+ hasHydratedRef.current = true;+ lastSyncedRef.current = incoming;+ setFormState(incoming);+ setPristineState(incoming);+ return;+ }+ // Refetch returned the same content as the local form — keep prev to+ // preserve link IDs (avoids a row exit/enter flash) and refresh the+ // synced snapshot so future dirty checks compare against the latest.+ if (!isFormDirty(incoming, prev)) {+ lastSyncedRef.current = incoming;+ // Pin the pristine baseline to the current formState (with its+ // existing link IDs) so a subsequent Discard restores the same+ // rows — not freshly-keyed copies that would re-trigger animations.+ setPristineState(prev);+ return;}+ // User has edits relative to the last synced snapshot — never clobber.+ if (isFormDirty(lastSyncedRef.current, prev)) return;+ // Form pristine, server data changed — hydrate with the new snapshot.+ lastSyncedRef.current = incoming;+ setFormState(incoming);+ setPristineState(incoming);},[profileQuery.data],);const validation = useMemo(() => validateForm(formState), [formState]);const dirty = useMemo(- () => isFormDirty(initialState, formState),- [initialState, formState],+ () => isFormDirty(pristineState, formState),+ [pristineState, formState],);function patchField<K extends keyof ProfileFormState>(@@ -103,7 +137,7 @@ export function useProfilePage() {}function discardChanges() {- setFormState(initialState);+ setFormState(pristineState);}const uploadMutation = usePostV2UploadSubmissionMedia({@@ -172,7 +206,6 @@ export function useProfilePage() {error: profileQuery.error,refetch: profileQuery.refetch,formState,- initialState,patchField,setLink,addLink,diff --git a/autogpt_platform/frontend/src/components/molecules/Dialog/components/DialogWrap.tsx b/autogpt_platform/frontend/src/components/molecules/Dialog/components/DialogWrap.tsxindex 038a7fce2e..75e007c010 100644--- a/autogpt_platform/frontend/src/components/molecules/Dialog/components/DialogWrap.tsx+++ b/autogpt_platform/frontend/src/components/molecules/Dialog/components/DialogWrap.tsx@@ -102,7 +102,7 @@ export function DialogWrap({}}><div- className={`flex items-center justify-between ${+ className={`flex items-center justify-between px-2 ${title ? "pb-6" : "pb-0"}`}>@@ -134,7 +134,7 @@ export function DialogWrap({<divref={scrollRef}className={cn(- "flex-1 overflow-y-auto overflow-x-hidden",+ "flex-1 overflow-y-auto overflow-x-hidden px-2",scrollbarStyles,)}style={{