Files
lcbp3/frontend/components/common/workflow-error-boundary.tsx

42 lines
1.3 KiB
TypeScript

'use client';
// ADR-021 T042: Error Boundary สำหรับ WorkflowLifecycle และ FilePreviewModal
// ป้องกัน crash ทั้งหน้าเมื่อเกิด unexpected error ใน Workflow components
// ต้องใช้ class component เพราะ React Error Boundary ยังไม่รองรับ hooks
import { Component, type ReactNode } from 'react';
interface Props {
children: ReactNode;
/** Custom fallback — ถ้าไม่ระบุจะแสดง default message */
fallback?: ReactNode;
}
interface State {
hasError: boolean;
}
export class WorkflowErrorBoundary extends Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = { hasError: false };
}
static getDerivedStateFromError(): State {
return { hasError: true };
}
render() {
if (this.state.hasError) {
return (
this.props.fallback ?? (
<div className="rounded-md bg-muted/50 p-4 text-center text-sm text-muted-foreground">
Workflow
</div>
)
);
}
return this.props.children;
}
}