fix(ui): reset stale error panels when the new-company name changes

The new-company name is part of both the preview and import payloads, so
editing it also supersedes a failed request. Reset the mutation state on
name changes — without discarding the rendered preview, since name
overrides are typed against it — and cover the behavior in the component
tests.
This commit is contained in:
Devin Foley committed 2026-07-30 13:12:49 -07:00
1 parent 37cc66e9d6
commit 2766dcf17a
2 files changed
+28 -6

No files matched your search

+14
View File
@@ -389,6 +389,20 @@ describe("CompanyImport", () => {
expect(container.textContent).toContain("check the target company before retrying.");
expect(mockPushToast).toHaveBeenCalledWith(expect.objectContaining({ tone: "error" }));
// The new-company name feeds the request payload too: editing it clears
// the stale error panel without discarding the rendered preview.
const nameInput = container.querySelector<HTMLInputElement>('input[placeholder="Imported Company"]');
expect(nameInput).toBeTruthy();
await act(async () => {
const setter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")!.set!;
setter.call(nameInput!, "Renamed Import");
nameInput!.dispatchEvent(new Event("input", { bubbles: true }));
});
await flushReact();
expect(container.textContent).not.toContain("Import failed:");
expect(findButton((text) => text.startsWith("Import 3 file"))).toBeTruthy();
// Changing the package supersedes the failed import: previewing a fresh
// package must not resurface the stale import error panel.
await enterGithubUrl("https://github.com/acme/other-starter/tree/main/company");
+14 -6
View File
@@ -927,15 +927,20 @@ export function CompanyImport() {
},
});
// Any change to the package or import configuration supersedes the last
// preview and any settled mutation state, so the persistent progress/error
// panels never keep describing a request that no longer applies.
function resetImportFlowState() {
setImportPreview(null);
// Any change to the import configuration supersedes the request the last
// progress/error panel describes, so it resets both mutations. The
// new-company name is typed against a rendered preview, so it resets only
// the panels; structural changes also discard the preview itself.
function resetMutationState() {
previewMutation.reset();
importMutation.reset();
}
function resetImportFlowState() {
setImportPreview(null);
resetMutationState();
}
async function handleChooseLocalPackage(e: ChangeEvent<HTMLInputElement>) {
const fileList = e.target.files;
if (!fileList || fileList.length === 0) return;
@@ -1419,7 +1424,10 @@ export function CompanyImport() {
className="w-full rounded-md border border-border bg-transparent px-2.5 py-1.5 text-sm outline-none"
type="text"
value={newCompanyName}
onChange={(e) => setNewCompanyName(e.target.value)}
onChange={(e) => {
setNewCompanyName(e.target.value);
resetMutationState();
}}
placeholder="Imported Company"
/>
</Field>