Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

refactor: consolidate error state component [skip version]

Juan Denis4959354cfe3b
diff --git a/frontend/src/components/ErrorBoundary.jsx b/frontend/src/components/ErrorBoundary.jsx
index c3d78308..e2405319 100644
--- a/frontend/src/components/ErrorBoundary.jsx
+++ b/frontend/src/components/ErrorBoundary.jsx
@@ -1,7 +1,7 @@
import { Component } from 'react';
-import { AlertTriangle, RefreshCw } from 'lucide-react';
import api from '../services/api';
import { t } from '../i18n/t';
+import ErrorState from './ErrorState';
// Class-based Error Boundary for catching React errors
export class ErrorBoundary extends Component {
@@ -53,21 +53,11 @@ export class ErrorBoundary extends Component {
render() {
if (this.state.hasError) {
return (
- <div className="sk-error-state" role="alert">
- <div className="sk-error-state__icon">
- <AlertTriangle size={32} />
- </div>
- <h3 className="sk-error-state__title">
- {t('common.error.title', 'Something went wrong')}
- </h3>
- <p className="sk-error-state__message">
- {t('common.error.unexpected', 'An unexpected error occurred')}
- </p>
- <button type="button" className="btn btn-primary" onClick={this.handleRetry}>
- <RefreshCw size={14} />
- {t('common.actions.tryAgain', 'Try again')}
- </button>
- </div>
+ <ErrorState
+ title={t('common.error.title', 'Something went wrong')}
+ message={t('common.error.unexpected', 'An unexpected error occurred')}
+ onRetry={this.handleRetry}
+ />
);
}
@@ -75,46 +65,4 @@ export class ErrorBoundary extends Component {
}
}
-// Functional component for displaying API/fetch errors
-export function ErrorState({
- title = t('common.error.failedToLoad', 'Failed to load'),
- message,
- error,
- onRetry,
- compact = false
-}) {
- const errorMessage = message || error?.message
- || t('common.error.loadingData', 'An error occurred while loading data');
-
- if (compact) {
- return (
- <div className="error-state-compact">
- <AlertTriangle size={16} />
- <span>{errorMessage}</span>
- {onRetry && (
- <button type="button" className="btn btn-ghost btn-sm" onClick={onRetry}>
- <RefreshCw size={14} /> {t('common.actions.retry', 'Retry')}
- </button>
- )}
- </div>
- );
- }
-
- return (
- <div className="sk-error-state">
- <div className="sk-error-state__icon">
- <AlertTriangle size={32} />
- </div>
- <h3 className="sk-error-state__title">{title}</h3>
- <p className="sk-error-state__message">{errorMessage}</p>
- {onRetry && (
- <button type="button" className="btn btn-primary" onClick={onRetry}>
- <RefreshCw size={14} />
- {t('common.actions.tryAgain', 'Try again')}
- </button>
- )}
- </div>
- );
-}
-
export default ErrorBoundary;
diff --git a/frontend/src/components/ErrorState.jsx b/frontend/src/components/ErrorState.jsx
index ecc86aff..5e390a4d 100644
--- a/frontend/src/components/ErrorState.jsx
+++ b/frontend/src/components/ErrorState.jsx
@@ -12,14 +12,38 @@ import { t } from '@/i18n/t';
* onRetry={loadData}
* />
*/
-export function ErrorState({ title = 'Something went wrong', message, onRetry, className = '' }) {
+export function ErrorState({
+ title = t('common.error.failedToLoad', 'Failed to load'),
+ message,
+ error,
+ onRetry,
+ compact = false,
+ className = '',
+}) {
+ const errorMessage = message || error?.message
+ || t('common.error.loadingData', 'An error occurred while loading data');
+
+ if (compact) {
+ return (
+ <div className={`error-state-compact ${className}`.trim()} role="alert">
+ <AlertTriangle size={16} />
+ <span>{errorMessage}</span>
+ {onRetry && (
+ <Button variant="ghost" size="sm" onClick={onRetry}>
+ <RefreshCw size={14} /> {t('common.actions.retry', 'Retry')}
+ </Button>
+ )}
+ </div>
+ );
+ }
+
return (
- <div className={`sk-error-state ${className}`.trim()}>
+ <div className={`sk-error-state ${className}`.trim()} role="alert">
<div className="sk-error-state__icon">
<AlertTriangle size={32} />
</div>
<h3 className="sk-error-state__title">{title}</h3>
- {message && <p className="sk-error-state__message">{message}</p>}
+ {errorMessage && <p className="sk-error-state__message">{errorMessage}</p>}
{onRetry && (
<Button variant="outline" size="sm" onClick={onRetry}>
<RefreshCw size={14} /> {t('common.actions.tryAgain', 'Try again')}
diff --git a/frontend/src/plugins/sdk/index.js b/frontend/src/plugins/sdk/index.js
index 94922e0d..1ecd2675 100644
--- a/frontend/src/plugins/sdk/index.js
+++ b/frontend/src/plugins/sdk/index.js
@@ -162,7 +162,8 @@ export {
// used by both the Git and WordPress surfaces; the backups protection
// panel embedded by both the Backups page and WordPress). Exposing them
// here pins their props as SDK contract — change them accordingly.
-export { default as ErrorBoundary, ErrorState } from '../../components/ErrorBoundary';
+export { default as ErrorBoundary } from '../../components/ErrorBoundary';
+export { default as ErrorState } from '../../components/ErrorState';
export { DangerZone } from '../../components/DangerZone';
export { default as ResourceAdvisory } from '../../components/ResourceAdvisory';
export { default as PluginSlot } from '../../components/PluginSlot';