Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

fix(web): 新建工单被拒时,表单留着、填过的字段也留着(7.46)

lmlihengdf07b72d59be
diff --git a/changelog/unreleased/2026-10-26-ticket-create-refusal.md b/changelog/unreleased/2026-10-26-ticket-create-refusal.md
new file mode 100644
index 00000000..4d692fe2
--- /dev/null
+++ b/changelog/unreleased/2026-10-26-ticket-create-refusal.md
@@ -0,0 +1,37 @@
+# Tickets: a refused create keeps the form and everything typed in it
+
+- **Date:** 2026-10-26
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[中文](2026-10-26-ticket-create-refusal.zh.md)
+
+The board's "new ticket" form asks for ten fields — title, slug, goal, acceptance note, owner,
+parent, who to notify, priority, due date. Its write used to report a refusal through a toast
+alone: a few seconds later the reason was gone, the board underneath was unchanged, and the button
+was live again with nothing saying why, while the form still held everything typed into it.
+
+A refusal now draws the server's words at the top of the form (the app's existing "Refused:"
+lead-in) and leaves every field as typed, so the retry is one press. The form only closes once its
+write landed — a write in flight also ignores the dialog's own `onClose`, so the form cannot be
+dismissed from under the answer it is waiting for. Opening the form again drops the previous
+reason, which belonged to the attempt it named.
+
+## Details
+
+- `features/company/tickets-page.tsx`: `CreateTicketDialog` gains the `refusal` state its
+ neighbours in the ticket dialog already use; the failed write's message is drawn in a
+ `NoticeStrip` above the fields instead of a toast, and is cleared whenever the form is opened.
+ The `Modal`'s `onClose` no longer answers while a write is in flight (the cancel button was
+ already disabled; this is the second door).
+- New browser spec `e2e/ticket-create-refusal.spec.mjs`: with the create refused at `page.route`
+ 500, the form, the title and the goal in their fields, and the organization's ticket list all
+ stay (nothing in the notification region carries the words); cancelling and reopening shows an
+ empty form without a stale reason; the retry really writes — the form closes, the board holds
+ the ticket, and its own dialog opens on it.
+
+## Compatibility
+
+- No interface, wire-format, stored-data or dependency change: only *when* this form closes and
+ *where* the reason is drawn. No new copy beyond the existing `S.common.refused` lead-in.
diff --git a/changelog/unreleased/2026-10-26-ticket-create-refusal.zh.md b/changelog/unreleased/2026-10-26-ticket-create-refusal.zh.md
new file mode 100644
index 00000000..e835c507
--- /dev/null
+++ b/changelog/unreleased/2026-10-26-ticket-create-refusal.zh.md
@@ -0,0 +1,30 @@
+# 工单:新建工单被拒时,表单留着、填过的每个字段也留着
+
+- **Date:** 2026-10-26
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[English](2026-10-26-ticket-create-refusal.md)
+
+看板右上角那张「新建工单」要填十个字段:标题、id 短名、目标、验收标准、负责人、上级工单、通知谁、
+优先级、截止日期。它的写入过去被拒时只落进一条通知:几秒后原因就没了,背后的看板一点没变,按钮又亮着,
+没有任何东西说明为什么 —— 而表单里刚填的那些还在。
+
+现在被拒时服务端原话画在表单顶部(应用既有的「操作被拒绝:」前缀),每个字段原样留着,重试就是再按一次。
+表单只在写入真正落地那条路径上关;写入在途时连对话框自己的 `onClose` 也不再响应,免得它正在等的那个回答
+还没到、表单就被关掉了。重开这张表单会先清掉上一次的原因 —— 那句话属于上次那次尝试。
+
+## 细节
+
+- `features/company/tickets-page.tsx`:`CreateTicketDialog` 加上 `refusal` 状态(工单详情框里那几张
+ 确认框早就在用同一套写法);写入失败的原话由 `NoticeStrip` 画在字段上方,不再只弹通知;每次打开表单
+ 都清掉上一次的那句。`Modal` 的 `onClose` 在写入在途时不再响应(取消按钮本来就置灰,这是第二道)。
+- 新增浏览器用例 `e2e/ticket-create-refusal.spec.mjs`:用 `page.route` 把创建拒成 500 之后,表单、
+ 字段里的标题与目标、以及组织里的工单列表都不变(通知区里没有那句原话);取消后重开是一张干净的空表单、
+ 不带旧原因;在同一张表单上重试才真正写进去 —— 表单关掉,看板上有了这张工单,它自己的详情框随之打开。
+
+## 兼容性
+
+- 没有接口、传输格式、已存数据或依赖变化:只改了这张表单「什么时候关」与「原因画在哪」。除既有的
+ `S.common.refused` 前缀外没有新文案。
diff --git a/packages/web/e2e/ticket-create-refusal.spec.mjs b/packages/web/e2e/ticket-create-refusal.spec.mjs
new file mode 100644
index 00000000..23111ce5
--- /dev/null
+++ b/packages/web/e2e/ticket-create-refusal.spec.mjs
@@ -0,0 +1,150 @@
+/**
+ * Regression: creating a ticket is asked in a form, and a refused create keeps that form — with
+ * the server's words above its fields and everything typed still in them — instead of leaving
+ * only a toast behind.
+ *
+ * `CreateTicketDialog` (`features/company/tickets-page.tsx`) is the ticket box's own form: a
+ * title, a slug, a goal, an acceptance note, an owner, a parent, the people to notify, a
+ * priority and a due date. Its write used to report a refusal through `toastError` alone, so a
+ * few seconds after the attempt the reason was gone while the panel still showed the same
+ * untitled board and the button was live again with nothing saying why. The reason now sits at
+ * the top of the form (`NoticeStrip`, graded with `S.common.refused`), the fields keep what was
+ * typed, and the dialog only closes once its write landed — a write in flight also ignores
+ * `onClose`, so the form cannot be dismissed from under its own answer. Reopening it does not
+ * carry the old reason.
+ *
+ * The organization is made through the API (this spec is about the form's answer, not about
+ * setting the board up); company mode is off on a fresh server, so each test turns the admin
+ * master switch on first (idempotent), and the Project gets the mock as its model — nothing here
+ * needs the model, but a fresh Project without one would hold the onboarding overlay over the
+ * board.
+ */
+import { test, expect, request } from "@playwright/test";
+import { ADMIN_ID, ADMIN_PASSWORD, login, provisionAndLogin } from "./auth.mjs";
+
+const BASE = process.env.BASE_URL;
+const MOCK = process.env.MOCK_URL;
+const P = "password123";
+const ORG = "ticketcreate";
+const TITLE = "把插件市场搬上博客";
+const GOAL = "博客那边也要能搜到插件,第一条链接指向市场首页。";
+
+/** The refusal the form paints; a 500 with its own words proves those words came back. */
+const REFUSAL = { code: "ticket_files_locked", message: "the ticket files are mid-rewrite" };
+
+/** The admin master switch, off by default: turned on server-wide before the flow starts. */
+async function enableCompanyMode() {
+ const adminCtx = await request.newContext();
+ try {
+ await login(adminCtx, ADMIN_ID, ADMIN_PASSWORD);
+ const res = await adminCtx.put(`${BASE}/api/admin/settings`, { data: { companyMode: true } });
+ if (!res.ok()) {
+ throw new Error(`enable company mode failed: ${res.status()} ${await res.text()}`);
+ }
+ } finally {
+ await adminCtx.dispose();
+ }
+}
+
+/** A fresh user with mock-model credentials and an organization with no tickets yet. */
+async function setUp(page, tag) {
+ await enableCompanyMode();
+ const user = `${tag}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 6)}`;
+ await provisionAndLogin(page.request, user, P);
+ const project = (await (await page.request.get(`${BASE}/api/projects`)).json()).projects[0];
+ const projectId = project.projectId;
+ const put = await page.request.put(`${BASE}/api/projects/${projectId}/models`, {
+ data: {
+ defaultModel: { provider: "custom", modelId: "claude-4-8" },
+ models: [
+ {
+ provider: "custom",
+ modelId: "claude-4-8",
+ apiKey: "sk-mock",
+ baseUrl: MOCK,
+ contextWindow: 200000,
+ },
+ ],
+ },
+ });
+ expect(put.ok(), `put models ${projectId}`).toBeTruthy();
+
+ const orgBase = `${BASE}/api/projects/${projectId}/organizations`;
+ const created = await page.request.post(orgBase, {
+ data: { orgId: ORG, mission: "Let the plugin marketplace be found from the blog too." },
+ });
+ expect(created.ok(), "create organization").toBeTruthy();
+
+ const ticketsUrl = `${orgBase}/${ORG}/tickets`;
+ /** The board as the server holds it: how many tickets the organization has, any column. */
+ const count = async () => {
+ const board = await (await page.request.get(ticketsUrl)).json();
+ return Object.values(board.columns).reduce((n, column) => n + column.length, 0);
+ };
+ return { projectId, ticketsUrl, count };
+}
+
+/** The empty board, and the button that raises the create form. */
+async function openBoard(page, projectId) {
+ await page.goto(`/org/${projectId}/${ORG}/tickets`);
+ await expect(page.getByRole("button", { name: "新建工单" }).first()).toBeVisible();
+}
+
+/** Raise the form and type into the two fields this test reads back. */
+async function openForm(page) {
+ await page.getByRole("button", { name: "新建工单" }).first().click();
+ const form = page.getByRole("dialog", { name: "新建工单" });
+ await expect(form).toBeVisible();
+ await form.getByRole("textbox", { name: "标题", exact: true }).fill(TITLE);
+ await form.getByRole("textbox", { name: /^目标/ }).fill(GOAL);
+ return form;
+}
+
+test("a refused create keeps the form, the reason and every typed field", async ({ page }) => {
+ test.setTimeout(120_000);
+ const { projectId, ticketsUrl, count } = await setUp(page, "r132create");
+ await openBoard(page, projectId);
+ const form = await openForm(page);
+
+ // One refusal with the server's own words, counted so the test knows the page wrote once.
+ const writes = [];
+ const pattern = `**${new URL(ticketsUrl).pathname}`;
+ await page.route(pattern, async (route) => {
+ if (route.request().method() !== "POST") return route.fallback();
+ writes.push(route.request().url());
+ await route.fulfill({
+ status: 500,
+ contentType: "application/json",
+ body: JSON.stringify({ error: REFUSAL }),
+ });
+ });
+
+ await form.getByRole("button", { name: "创建", exact: true }).click();
+
+ // The reason is in the form that asked, and it is not a toast: the notification region never
+ // carries the server's words.
+ await expect(form.getByText(REFUSAL.message)).toBeVisible();
+ await expect(page.getByRole("region", { name: "通知" })).not.toContainText(REFUSAL.message);
+ expect(writes).toHaveLength(1);
+ await expect(form).toBeVisible();
+
+ // Nothing was written, and both fields still hold what was typed.
+ expect(await count()).toBe(0);
+ await expect(form.getByRole("textbox", { name: "标题", exact: true })).toHaveValue(TITLE);
+ await expect(form.getByRole("textbox", { name: /^目标/ })).toHaveValue(GOAL);
+
+ // Cancelling decides nothing; reopening starts from a clean form, without the old reason.
+ await form.getByRole("button", { name: "取消" }).click();
+ await expect(form).toHaveCount(0);
+ const again = await openForm(page);
+ await expect(again.getByText(REFUSAL.message)).toHaveCount(0);
+
+ // The retry lands: the form goes, the ticket is written, and its own dialog comes up on it.
+ await page.unroute(pattern);
+ await again.getByRole("button", { name: "创建", exact: true }).click();
+ await expect(again).toHaveCount(0);
+ await expect.poll(count).toBe(1);
+ const detail = page.getByRole("dialog", { name: TITLE });
+ await expect(detail).toBeVisible();
+ await expect(detail.getByText(GOAL)).toBeVisible();
+});
diff --git a/packages/web/src/features/company/tickets-page.tsx b/packages/web/src/features/company/tickets-page.tsx
index 4c9a5251..9b9e7a93 100644
--- a/packages/web/src/features/company/tickets-page.tsx
+++ b/packages/web/src/features/company/tickets-page.tsx
@@ -45,13 +45,13 @@ import {
Input,
Modal,
Notice,
+ NoticeStrip,
SearchInput,
Segmented,
Select,
Skeleton,
Switch,
Textarea,
- toastError,
toastSuccess,
} from "@adelie/ui";
import * as api from "../../api/endpoints";
@@ -600,6 +600,7 @@ function CreateTicketDialog({
const [due, setDue] = useState("");
const [titleError, setTitleError] = useState<string | undefined>(undefined);
const [slugError, setSlugError] = useState<string | undefined>(undefined);
+ const [refusal, setRefusal] = useState<string | null>(null);
const [busy, setBusy] = useState(false);
useEffect(() => {
@@ -615,6 +616,8 @@ function CreateTicketDialog({
setDue("");
setTitleError(undefined);
setSlugError(undefined);
+ // A new ticket, not the refused one: the previous refusal is not its answer.
+ setRefusal(null);
}, [open]);
const submit = async () => {
@@ -642,7 +645,9 @@ function CreateTicketDialog({
toastSuccess(S.company.tickets.created);
onCreated(detail.ticketId);
} catch (e) {
- toastError(apiErrorText(e));
+ // The dialog stays: it is the form that asked, so the reason belongs above its fields
+ // rather than in a toast that dismisses itself while the reader is still typing.
+ setRefusal(apiErrorText(e));
} finally {
setBusy(false);
}
@@ -652,7 +657,9 @@ function CreateTicketDialog({
<Modal
open={open}
title={S.company.tickets.createTitle}
- onClose={onClose}
+ // A write in flight is the dialog's: closing it would take away the form the answer is
+ // about (the cancel button is already disabled; this is the second door).
+ onClose={() => (busy ? undefined : onClose())}
widthClass="sm:max-w-lg"
footer={
<>
@@ -666,6 +673,13 @@ function CreateTicketDialog({
}
>
<div className="space-y-3">
+ {refusal !== null && (
+ // The form's own words: a refusal is about what the reader just typed, so it reads
+ // above the fields that still hold it, not as page-level news.
+ <NoticeStrip tone="danger" role="alert" className="rounded-md border px-2.5 py-2 text-xs">
+ <span data-slot="body">{S.common.refused(refusal)}</span>
+ </NoticeStrip>
+ )}
<Input
size="sm"
label={S.company.tickets.ticketTitle}