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.
This commit is contained in:
Jason committed 2026-10-05 09:58:28 +08:00
1 parent 636e161658
commit df08bb15c3
2 files changed
+28 -2

No files matched your search

@@ -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
@@ -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(
<GrokBuildProviderForm
submitLabel="Save"
onSubmit={() => {}}
onCancel={() => {}}
/>,
);
await user.click(screen.getByRole("button", { name: /88API/ }));
const websiteInput = container.querySelector<HTMLInputElement>(
'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();