|
|
/**
|
|
|
* Bind instruction unit.segmentText into MailBusinessSummary form builders.
|
|
|
* ASCII-only edits to avoid Chinese corruption.
|
|
|
*/
|
|
|
import fs from "fs";
|
|
|
|
|
|
const p = "src/components/MailBusinessSummary.tsx";
|
|
|
let t = fs.readFileSync(p, "utf8");
|
|
|
|
|
|
if (!t.includes("segmentText")) {
|
|
|
// work_order block: use unit segment for form
|
|
|
const woOld = `} else if (unit.uiKind === "work_order") {
|
|
|
body = (
|
|
|
<CcWorkOrderForm
|
|
|
mode={canConfirmOps ? "edit" : "readonly"}
|
|
|
value={workOrderValue}
|
|
|
onChange={(p) => setWorkOrderValue((v) => ({ ...v, ...p }))}
|
|
|
/>
|
|
|
);`;
|
|
|
|
|
|
const woNew = `} else if (unit.uiKind === "work_order") {
|
|
|
const woForUnit = buildCcWorkOrderFormValue({
|
|
|
subject: unit.segmentSubject || mail.subject,
|
|
|
body: unit.segmentText || bodyText,
|
|
|
filenames,
|
|
|
containerNo,
|
|
|
actions: record?.work_order_actions,
|
|
|
});
|
|
|
body = (
|
|
|
<CcWorkOrderForm
|
|
|
mode={canConfirmOps ? "edit" : "readonly"}
|
|
|
value={{
|
|
|
...woForUnit,
|
|
|
// keep edits on shared state when confirming primary WO
|
|
|
...(mail.mail_type === "WORK_ORDER" && unit.isCurrent
|
|
|
? workOrderValue
|
|
|
: {}),
|
|
|
}}
|
|
|
onChange={(p) => setWorkOrderValue((v) => ({ ...v, ...p }))}
|
|
|
/>
|
|
|
);`;
|
|
|
|
|
|
if (!t.includes(woOld)) {
|
|
|
console.error("work_order block not found");
|
|
|
process.exit(1);
|
|
|
}
|
|
|
t = t.replace(woOld, woNew);
|
|
|
|
|
|
const doOld = `} else if (unit.uiKind === "do_upload") {
|
|
|
body = (
|
|
|
<CcDoUploadPanel
|
|
|
mode={canConfirmOps ? "edit" : "readonly"}
|
|
|
value={doValue}
|
|
|
onChange={(p) => setDoValue((v) => ({ ...v, ...p }))}
|
|
|
/>
|
|
|
);`;
|
|
|
|
|
|
const doNew = `} else if (unit.uiKind === "do_upload") {
|
|
|
const doForUnit = buildCcDoUploadFormValue({
|
|
|
subject: unit.segmentSubject || mail.subject,
|
|
|
body: unit.segmentText || bodyText,
|
|
|
containerNo,
|
|
|
filenames:
|
|
|
unit.source === "attachment"
|
|
|
? [unit.segmentText]
|
|
|
: filenames,
|
|
|
});
|
|
|
body = (
|
|
|
<CcDoUploadPanel
|
|
|
mode={canConfirmOps ? "edit" : "readonly"}
|
|
|
value={
|
|
|
mail.mail_type === "DO_UPLOAD" && unit.isCurrent
|
|
|
? doValue
|
|
|
: doForUnit
|
|
|
}
|
|
|
onChange={(p) => setDoValue((v) => ({ ...v, ...p }))}
|
|
|
/>
|
|
|
);`;
|
|
|
|
|
|
if (!t.includes(doOld)) {
|
|
|
console.error("do_upload block not found");
|
|
|
process.exit(1);
|
|
|
}
|
|
|
t = t.replace(doOld, doNew);
|
|
|
|
|
|
fs.writeFileSync(p, t, "utf8");
|
|
|
}
|
|
|
|
|
|
const check = fs.readFileSync(p, "utf8");
|
|
|
console.log(
|
|
|
JSON.stringify(
|
|
|
{
|
|
|
hasSegmentBind: check.includes("woForUnit") && check.includes("doForUnit"),
|
|
|
titleOk: check.includes("\u8fd9\u5c01\u90ae\u4ef6\u5728\u5e72\u4ec0\u4e48"),
|
|
|
},
|
|
|
null,
|
|
|
2,
|
|
|
),
|
|
|
);
|
|
|
if (!check.includes("\u8fd9\u5c01\u90ae\u4ef6\u5728\u5e72\u4ec0\u4e48")) {
|
|
|
console.error("Chinese title corrupted <20>?restore with fix-mail-business-summary-zh.ts");
|
|
|
process.exit(1);
|
|
|
}
|