Spaces:
Paused
Paused
File size: 6,412 Bytes
bd0c393 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | 'use client'
import { useState } from 'react'
import { Card } from '@/components/ui/card'
import { Button } from '@/components/ui/button'
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from '@/components/ui/collapsible'
import { Database, Server, ChevronDown, ExternalLink } from 'lucide-react'
import { ConnectionError } from '@/lib/types/config'
import { useTranslation } from '@/lib/hooks/use-translation'
interface ConnectionErrorOverlayProps {
error: ConnectionError
onRetry: () => void
}
export function ConnectionErrorOverlay({
error,
onRetry,
}: ConnectionErrorOverlayProps) {
const { t } = useTranslation()
const [showDetails, setShowDetails] = useState(false)
const isApiError = error.type === 'api-unreachable'
return (
<div
className="fixed inset-0 bg-background z-50 flex items-center justify-center p-4"
role="alert"
aria-live="assertive"
aria-atomic="true"
>
<Card className="max-w-2xl w-full p-8 space-y-6">
{/* Error icon and title */}
<div className="flex items-center gap-4">
{isApiError ? (
<Server className="w-12 h-12 text-destructive" aria-hidden="true" />
) : (
<Database className="w-12 h-12 text-destructive" aria-hidden="true" />
)}
<div>
<h1 className="text-2xl font-bold" id="error-title">
{isApiError
? t('connectionErrors.apiTitle')
: t('connectionErrors.dbTitle')}
</h1>
<p className="text-muted-foreground">
{isApiError
? t('connectionErrors.apiDesc')
: t('connectionErrors.dbDesc')}
</p>
</div>
</div>
{/* Troubleshooting instructions */}
<div className="space-y-4 border-l-4 border-primary pl-4">
<h2 className="font-semibold">{t('connectionErrors.troubleshooting')}</h2>
<ul className="list-disc list-inside space-y-2 text-sm">
{isApiError ? (
<>
<li>{t('connectionErrors.apiUnreachable1')}</li>
<li>{t('connectionErrors.apiUnreachable2')}</li>
<li>{t('connectionErrors.apiUnreachable3')}</li>
</>
) : (
<>
<li>{t('connectionErrors.dbFailed1')}</li>
<li>{t('connectionErrors.dbFailed2')}</li>
<li>{t('connectionErrors.dbFailed3')}</li>
</>
)}
</ul>
<h2 className="font-semibold mt-4">{t('connectionErrors.quickFixes')}</h2>
{isApiError ? (
<div className="space-y-2 text-sm bg-muted p-4 rounded">
<p className="font-medium">{t('connectionErrors.setApiUrl')}</p>
<code className="block bg-background p-2 rounded text-xs">
# {t('connectionErrors.dockerLabel')}:
<br />
docker run -e API_URL=http://your-host:5055 ...
<br />
<br />
# {t('connectionErrors.localDevLabel')}:
<br />
API_URL=http://localhost:5055
</code>
</div>
) : (
<div className="space-y-2 text-sm bg-muted p-4 rounded">
<p className="font-medium">{t('connectionErrors.checkSurreal')}</p>
<code className="block bg-background p-2 rounded text-xs">
# {t('connectionErrors.dockerLabel')}:
<br />
docker compose ps | grep surrealdb
<br />
docker compose logs surrealdb
</code>
</div>
)}
</div>
{/* Documentation link */}
<div className="text-sm">
<p>{t('connectionErrors.seeDocumentation')}</p>
<a
href="https://github.com/lfnovo/open-notebook"
target="_blank"
rel="noopener noreferrer"
className="text-primary hover:underline inline-flex items-center gap-1"
>
{t('connectionErrors.docLink')}
<ExternalLink className="w-4 h-4" />
</a>
</div>
{/* Collapsible technical details */}
{error.details && (
<Collapsible open={showDetails} onOpenChange={setShowDetails}>
<CollapsibleTrigger asChild>
<Button variant="ghost" size="sm" className="w-full justify-between">
<span>{t('connectionErrors.showTechnical')}</span>
<ChevronDown
className={`w-4 h-4 transition-transform ${
showDetails ? 'rotate-180' : ''
}`}
/>
</Button>
</CollapsibleTrigger>
<CollapsibleContent className="pt-4">
<div className="space-y-2 text-sm bg-muted p-4 rounded font-mono">
{error.details.attemptedUrl && (
<div>
<strong>{t('connectionErrors.attemptedUrl')}:</strong> {error.details.attemptedUrl}
</div>
)}
{error.details.message && (
<div>
<strong>{t('connectionErrors.message')}:</strong> {error.details.message}
</div>
)}
{error.details.technicalMessage && (
<div>
<strong>{t('connectionErrors.technicalDetails')}:</strong>{' '}
{error.details.technicalMessage}
</div>
)}
{error.details.stack && (
<div>
<strong>{t('connectionErrors.stackTrace')}:</strong>
<pre className="mt-2 overflow-x-auto text-xs">
{error.details.stack}
</pre>
</div>
)}
</div>
</CollapsibleContent>
</Collapsible>
)}
{/* Retry button */}
<div className="pt-4 border-t">
<Button onClick={onRetry} className="w-full" size="lg">
{t('connectionErrors.retryLabel')}
</Button>
<p className="text-xs text-muted-foreground text-center mt-2">
{t('connectionErrors.retryHint')}
</p>
</div>
</Card>
</div>
)
}
|