ข้ามไปยังเนื้อหา

ยืนยันก่อนบันทึก

ConfirmChange

Asks the person to confirm a change before anything is saved, when AI proposes it on their behalf. It shows each item with its old and new value, and offers confirm and decline. Nothing saves until they confirm: decline, closing the page and running out of time all save nothing. High-risk transactions only ever create a draft or a request.

ใช้เมื่อ AI ขอเปลี่ยนข้อมูลในนามของผู้ใช้ แสดงแต่ละรายการพร้อมค่าเดิมและค่าใหม่ และไม่บันทึกจนกว่าผู้ใช้จะยืนยัน การปฏิเสธ การปิดหน้า และการหมดเวลาไม่บันทึกอะไรเลย ธุรกรรมความเสี่ยงสูงสร้างได้เฉพาะร่างหรือคำขอ

import { ConfirmChange } from "@bsru/ui";

ตัวอย่าง

คำขอลาจาก AI

changes คือแต่ละค่าที่เปลี่ยน before ว่างเมื่อยังไม่มีค่า เช่น คำขอใหม่ busy แสดงตัวหมุนระหว่างบันทึก ลองกดยืนยันหรือปฏิเสธ

ยืนยันคำขอลาพักผ่อน

ส่งจาก AI ในนามของคุณ รหัสอ้างอิง 7F3A-20C1

คำขอลา
ค่าเดิมไม่มีข้อมูล
ค่าใหม่ลาพักผ่อน 8-9 ธ.ค. 2569 (2 วัน)
วันลาคงเหลือหลังอนุมัติ
ค่าเดิม10 วัน
ค่าใหม่8 วัน

ถ้าไม่ยืนยันภายใน 5 นาที ระบบจะยกเลิกคำขอนี้และไม่บันทึกข้อมูล

<ConfirmChange
  title="ยืนยันคำขอลาพักผ่อน"
  source="ส่งจาก AI ในนามของคุณ รหัสอ้างอิง 7F3A-20C1"
  changes={[
    { label: "คำขอลา", after: "ลาพักผ่อน 8-9 ธ.ค. 2569 (2 วัน)" },
    {
      label: "วันลาคงเหลือหลังอนุมัติ",
      before: "10 วัน",
      after: "8 วัน",
    },
  ]}
  busy={saving}
  expires="ถ้าไม่ยืนยันภายใน 5 นาที ระบบจะยกเลิกคำขอนี้และไม่บันทึกข้อมูล"
  onConfirm={save}
  onDecline={discard}
/>

props ทั้งหมด

ตัวอย่างด้านบนใช้ props เพียงบางตัว ตารางนี้แสดงทุกตัวที่คอมโพเนนต์รับ พร้อมค่าเริ่มต้นและค่าที่ใช้ได้

ConfirmChange props
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
title* จำเป็นstring—What will be saved, such as ยืนยันคำขอลาพักผ่อน.
sourcestring—Who asked and the reference, such as ส่งจาก AI ในนามของคุณ รหัสอ้างอิง 7F3A-20C1.
changes* จำเป็นreadonly ProposedChange[]—Each value that changes, with its old and new value.
confirmLabelstring—The confirm button's text. Defaults to ยืนยันและบันทึก.
declineLabelstring—The decline button's text. Defaults to ปฏิเสธ ไม่บันทึก.
onConfirm* จำเป็น() => void—Saves the change. Only this saves anything.
onDecline* จำเป็น() => void—Throws the change away. Nothing is saved.
busybooleanfalseShows a spinner on the confirm button while it saves, and blocks a second press.
expiresstring—When it stops waiting, such as ถ้าไม่ยืนยันภายใน 5 นาที ระบบจะยกเลิกคำขอนี้และไม่บันทึกข้อมูล.
errorstring—Why saving failed, and what to do.

ชนิดข้อมูล

ProposedChange

One value a ConfirmChange shows, before and after.

ProposedChange fields
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
label* จำเป็นstring—What changes, such as วันลาคงเหลือหลังอนุมัติ.
beforestring—The value now, formatted by the screen. Leave it out when there's none yet, such as for a new request.
after* จำเป็นstring—The value after saving.

ข้อควรปฏิบัติ

  • source บอกว่าใครขอและรหัสอ้างอิง เพื่อให้ตรวจสอบย้อนหลังได้
  • มีเพียง onConfirm ที่บันทึกข้อมูล ที่เหลือทิ้งการเปลี่ยนแปลงทั้งหมด

ซอร์สโค้ด: ui/src/record-header.tsx