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

หน้าแจ้งสถานะ

StatusPage

A page for an outcome instead of the content: the page wasn't found, the person may not open it, the server failed, or the system is closed for maintenance. Each kind has its own icon, code and default wording. Pass the way forward as actions. With fill, the default, it's the whole page, with the logo and the demo strip. With fill false, it sits in AppShell's content area. Never show a stack trace or technical detail: give the Correlation ID instead.

ใช้แทนเนื้อหาของหน้าเมื่อแสดงหน้านั้นไม่ได้ ได้แก่ ไม่พบหน้า (404) ไม่มีสิทธิ์ (403) ระบบขัดข้อง (5xx) และปิดปรับปรุงระบบ แต่ละ kind มีไอคอน รหัส และข้อความเริ่มต้นของตัวเอง ส่งปุ่มทางไปต่อใน actions เมื่อแสดงเต็มหน้าจอ ใช้ fill ค่าเริ่มต้น เมื่ออยู่ใน AppShell ส่ง fill={false} สำหรับรายการในตารางที่โหลดไม่ได้ ใช้ TableState แทน ดูวิธีใช้ทั้งหน้าในกลุ่มหน้าตัวอย่าง

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

ตัวอย่าง

ไม่พบหน้า ในโครงแอป

fill={false} วางไว้ในพื้นที่เนื้อหาของ AppShell หัวข้อและคำอธิบายเริ่มต้นตาม kind และเปลี่ยนตามภาษาของหน้าจอ รหัส 404 มาจาก kind

รหัสข้อผิดพลาด 404

ไม่พบหน้าที่ต้องการ

ลิงก์อาจไม่ถูกต้อง หรือหน้านี้ถูกย้ายไปแล้ว ตรวจที่อยู่อีกครั้ง หรือกลับไปหน้าแรก

<StatusPage
  kind="notFound"
  fill={false}
  actions={<Button tone="primary" icon={House} label="กลับหน้าแรก" href="#" />}
/>

ระบบขัดข้อง พร้อมรหัสอ้างอิง

reference แสดง Correlation ID พร้อมปุ่มคัดลอก ผู้ใช้ส่งให้ผู้ดูแลระบบเพื่อตามหาปัญหาได้ ห้ามแสดงรายละเอียดทางเทคนิคอื่น

รหัสข้อผิดพลาด 500

ระบบขัดข้องชั่วคราว

ลองอีกครั้งในอีกสักครู่ ถ้ายังไม่สำเร็จ แจ้งผู้ดูแลระบบพร้อมรหัสอ้างอิงด้านล่าง

กลับหน้าแรก
รหัสอ้างอิง0193a5e2-7c4d-7b21-9f00-3c5a1d2e4b6f
<StatusPage
  kind="serverError"
  fill={false}
  reference={{
    label: "รหัสอ้างอิง",
    value: "0193a5e2-7c4d-7b21-9f00-3c5a1d2e4b6f",
  }}
  actions={<>
    <Button tone="primary" icon={RotateCw} label="ลองอีกครั้ง" />
    <Button icon={House} label="กลับหน้าแรก" href="#" />
  </>}
/>

ไม่มีสิทธิ์ ด้วยข้อความของหน้าจอ

title และ description แทนข้อความเริ่มต้น บอกว่าต้องมีสิทธิ์อะไร และติดต่อใคร

รหัสข้อผิดพลาด 403

คุณไม่มีสิทธิ์เปิดรายงานงบประมาณ

รายงานนี้เปิดได้เฉพาะเจ้าหน้าที่งบประมาณ ถ้าต้องใช้งาน ติดต่อผู้ดูแลระบบของหน่วยงาน

<StatusPage
  kind="forbidden"
  title="คุณไม่มีสิทธิ์เปิดรายงานงบประมาณ"
  description="รายงานนี้เปิดได้เฉพาะเจ้าหน้าที่งบประมาณ ถ้าต้องใช้งาน ติดต่อผู้ดูแลระบบของหน่วยงาน"
  fill={false}
  actions={<Button tone="primary" icon={House} label="กลับหน้าแรก" href="#" />}
/>

ปิดปรับปรุงระบบ เต็มหน้าจอ

fill เป็นค่าเริ่มต้น หน้าเต็มจอมีตราและชื่อระบบจาก brand และแถบระบบจำลองจาก notice expectedBack บอกเวลาที่คาดว่าจะกลับมาใช้งานได้ code แสดง 503 แทนค่าเริ่มต้นที่ไม่มีรหัส

ระบบจำลอง ใช้ข้อมูลทดสอบเท่านั้น

BSRU ERPมหาวิทยาลัยราชภัฏบ้านสมเด็จเจ้าพระยา

รหัสข้อผิดพลาด 503

ปิดปรับปรุงระบบชั่วคราว

ระบบจะกลับมาให้บริการเมื่อปรับปรุงเสร็จ ข้อมูลที่บันทึกไว้แล้วไม่สูญหาย

คาดว่าจะกลับมาใช้งานได้ 23 พ.ย. 2569 เวลา 18:00 น.

<StatusPage
  kind="maintenance"
  code="503"
  brand={{
    name: "BSRU ERP",
    caption: "มหาวิทยาลัยราชภัฏบ้านสมเด็จเจ้าพระยา",
    logo: "/bsru-logo.png",
    alt: "ตรามหาวิทยาลัยราชภัฏบ้านสมเด็จเจ้าพระยา",
  }}
  notice="ระบบจำลอง ใช้ข้อมูลทดสอบเท่านั้น"
  expectedBack="23 พ.ย. 2569 เวลา 18:00 น."
  actions={<Button
    tone="primary"
    icon={LogIn}
    label="ลองเข้าสู่ระบบอีกครั้ง"
    href="#"
  />}
/>

props ทั้งหมด

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

StatusPage props
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
kind* จำเป็นStatusKind
ค่าที่ใช้ได้:"notFound""forbidden""serverError""maintenance"
—notFound for 404, forbidden for 403, serverError for 500 and the other 5xx, maintenance for a planned closure.
codestring | null—The code shown above the title. Defaults to 404, 403 or 500 for the kind, and none for maintenance. Pass 503, say, to change it, or null to hide it.
titlestring—What happened, the page's level 1 heading. Defaults to a title for the kind in the screen language.
descriptionstring—What to do next, in a sentence or two. Defaults to a sentence for the kind in the screen language.
actionsReactNode—The ways forward, as Button components, with the primary one first, such as Back to the home page.
referenceStatusReference—For a server error: the Correlation ID, with a button that copies it, so support can trace the problem.
expectedBackstring—For maintenance: when the system is expected back, as text, such as 23 พ.ย. 2569 เวลา 18:00 น.
brandPageBrand—The logo and system name at the top of a whole page. Leave it out inside AppShell, which shows its own.
noticestring—The gold strip across the top of a whole page, for demo and test systems, such as ระบบจำลอง.
fillbooleantruetrue fills the screen as a page of its own, with its own main landmark. false sits in AppShell's content area, in the app's main.

ชนิดข้อมูล

StatusKind

Which outcome a StatusPage shows. Each has its own icon and default code.

type StatusKind = "notFound" | "forbidden" | "serverError" | "maintenance";

StatusReference

A value support needs to trace a problem, such as the Correlation ID, shown with a copy button.

StatusReference fields
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
labelstring—What the value is, such as รหัสอ้างอิง. Defaults to รหัสอ้างอิง in the screen language.
value* จำเป็นstring—The value, such as the request's Correlation ID.

PageBrand

The system's logo and name, at the top of a page that has no app frame, such as the sign-in page.

PageBrand fields
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
name* จำเป็นstring—The system's name, such as BSRU ERP or BSRU ERP คอนโซลผู้ดูแลระบบ.
captionstring—A small line under the name, such as the university's name.
alt* จำเป็นstring—The logo's alternative text, such as ตรามหาวิทยาลัยราชภัฏบ้านสมเด็จเจ้าพระยา.
hrefstring—Makes the logo and name a link, such as to the home page. Leave it out on the sign-in page.

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

  • หัวข้อเป็น h1 หนึ่งเดียวของหน้า ใน AppShell อย่าใส่ PageHeader ซ้ำ
  • รหัสข้อผิดพลาดอ่านออกเสียงว่า รหัสข้อผิดพลาด 404 ส่วนไอคอนเป็นเพียงการตกแต่ง สีบอกชนิดพร้อมข้อความเสมอ
  • ปุ่มหลักมีได้หนึ่งปุ่ม วางไว้ก่อน บนโทรศัพท์ปุ่มเรียงกันเต็มความกว้าง
  • ห้ามแสดง stack trace ข้อความ error ของระบบ ชื่อเซิร์ฟเวอร์ หรือ SQL แสดงเฉพาะรหัสอ้างอิง

ซอร์สโค้ด: ui/src/pages.tsx