From df08bb15c33452ead1cf32e83b61c050dca0f4b3 Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 5 Oct 2026 09:43:39 +0800 Subject: [PATCH] fix(grokbuild): use preset apiKeyUrl for the get-API-key link The Grok Build form passed the preset's websiteUrl to the API key link, so sponsor presets opened the plain homepage instead of their referral signup URL. Prefer the selected preset's apiKeyUrl, matching useApiKeyLink, without changing the saved websiteUrl. --- .../providers/forms/GrokBuildProviderForm.tsx | 8 +++++-- .../components/GrokBuildProviderForm.test.tsx | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/components/providers/forms/GrokBuildProviderForm.tsx b/src/components/providers/forms/GrokBuildProviderForm.tsx index 3d4bcccd1..9c2b0a2fa 100644 --- a/src/components/providers/forms/GrokBuildProviderForm.tsx +++ b/src/components/providers/forms/GrokBuildProviderForm.tsx @@ -196,6 +196,10 @@ export function GrokBuildProviderForm({ }); const { isSubmitting } = form.formState; const websiteUrl = form.watch("websiteUrl") ?? ""; + // 「获取 API Key」优先用预设的 apiKeyUrl(带推广参数),与 useApiKeyLink 一致 + const apiKeyLinkUrl = + grokPresetEntries.find((entry) => entry.id === selectedPresetId)?.preset + .apiKeyUrl || websiteUrl; useEffect(() => { onSubmittingChange?.(isSubmitting); @@ -471,8 +475,8 @@ export function GrokBuildProviderForm({ syncStructuredConfig({ apiKey: value }); }} category={category} - shouldShowApiKeyLink={Boolean(websiteUrl)} - websiteUrl={websiteUrl} + shouldShowApiKeyLink={Boolean(apiKeyLinkUrl)} + websiteUrl={apiKeyLinkUrl} isPartner={isPartner} partnerPromotionKey={partnerPromotionKey} shouldShowSpeedTest diff --git a/tests/components/GrokBuildProviderForm.test.tsx b/tests/components/GrokBuildProviderForm.test.tsx index 6ed35e125..73235b7cc 100644 --- a/tests/components/GrokBuildProviderForm.test.tsx +++ b/tests/components/GrokBuildProviderForm.test.tsx @@ -46,6 +46,28 @@ describe("GrokBuildProviderForm", () => { expect(nameInput?.value).toBe("PatewayAI"); }); + it("points the get-API-key link at the preset's apiKeyUrl", async () => { + const user = userEvent.setup(); + const { container } = render( + {}} + onCancel={() => {}} + />, + ); + + await user.click(screen.getByRole("button", { name: /88API/ })); + + const websiteInput = container.querySelector( + 'input[name="websiteUrl"]', + ); + expect(websiteInput?.value).toBe("https://88api.ai"); + expect(screen.getByRole("link", { name: /API Key/ })).toHaveAttribute( + "href", + "https://88api.ai/sign-up?aff=HSGY", + ); + }); + it("submits a complete config.toml payload with Grok defaults", async () => { const user = userEvent.setup(); const onSubmit = vi.fn();