Skip to content

Commit b7a5fa0

Browse files
committed
Update alert
1 parent eb38ea8 commit b7a5fa0

File tree

2 files changed

+99
-35
lines changed

2 files changed

+99
-35
lines changed

chat/src/components/ChatInterface.tsx

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import MessageList from "./MessageList";
55
import MessageInput from "./MessageInput";
66
import { useSearchParams } from "next/navigation";
77
import { toast } from "sonner";
8+
import { Button } from "./ui/button";
9+
import { TriangleAlertIcon } from "lucide-react";
10+
import { Alert, AlertTitle, AlertDescription } from "./ui/alert";
811

912
interface Message {
1013
role: string;
@@ -214,50 +217,45 @@ export default function ChatInterface() {
214217

215218
return (
216219
<div className="flex flex-col h-svh">
217-
<header className="p-3 dark:text-white text-sm flex items-center justify-between border-b">
218-
<span className="font-medium">AgentAPI Chat</span>
220+
<header className="p-3 dark:text-white flex items-center justify-between border-b">
221+
<span className="font-bold">AgentAPI Chat</span>
219222

220-
<div className="flex items-center space-x-3">
221-
<div className="flex items-center">
223+
{serverStatus !== "unknown" && (
224+
<div className="flex items-center gap-2 text-sm font-medium">
222225
<span
223-
className={`w-2 h-2 rounded-full mr-2 ${
226+
className={`text-secondary w-2 h-2 rounded-full ${
224227
["offline", "unknown"].includes(serverStatus)
225-
? "bg-red-500"
226-
: "bg-green-500"
228+
? "bg-red-500 ring-2 ring-red-500/35"
229+
: "bg-green-500 ring-2 ring-green-500/35"
227230
}`}
228-
></span>
229-
<span>Status: {serverStatus}</span>
231+
/>
232+
<span className="sr-only">Status:</span>
233+
<span className="first-letter:uppercase">{serverStatus}</span>
230234
</div>
231-
</div>
235+
)}
232236
</header>
233237

234238
<main className="flex flex-1 flex-col w-full overflow-auto">
235-
{(serverStatus === "offline" || serverStatus === "unknown") && (
236-
<div className="bg-yellow-100 border-y border-yellow-400 text-yellow-800 px-4 py-3 flex items-center justify-between font-medium">
237-
<div className="flex items-center">
238-
<svg
239-
className="w-5 h-5 mr-2"
240-
fill="currentColor"
241-
viewBox="0 0 20 20"
242-
xmlns="http://www.w3.org/2000/svg"
239+
{serverStatus === "offline" && (
240+
<div className="p-4 w-full max-w-4xl mx-auto">
241+
<Alert className="flex border-yellow-500">
242+
<TriangleAlertIcon className="h-4 w-4 stroke-yellow-600" />
243+
<div>
244+
<AlertTitle>API server is offline</AlertTitle>
245+
<AlertDescription>
246+
Please start the AgentAPI server. Attempting to connect to:{" "}
247+
{agentAPIUrl || "N/A"}.
248+
</AlertDescription>
249+
</div>
250+
<Button
251+
variant="ghost"
252+
size="sm"
253+
className="ml-auto"
254+
onClick={() => window.location.reload()}
243255
>
244-
<path
245-
fillRule="evenodd"
246-
d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z"
247-
clipRule="evenodd"
248-
/>
249-
</svg>
250-
<span>
251-
API server is offline. Please start the AgentAPI server.
252-
Attempting to connect to: {agentAPIUrl || "N/A"}.
253-
</span>
254-
</div>
255-
<button
256-
onClick={() => window.location.reload()}
257-
className="bg-yellow-200 px-3 py-1 rounded text-xs hover:bg-yellow-300"
258-
>
259-
Retry Connection
260-
</button>
256+
Retry
257+
</Button>
258+
</Alert>
261259
</div>
262260
)}
263261

chat/src/components/ui/alert.tsx

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import * as React from "react"
2+
import { cva, type VariantProps } from "class-variance-authority"
3+
4+
import { cn } from "@/lib/utils"
5+
6+
const alertVariants = cva(
7+
"relative w-full rounded-lg border px-4 py-3 text-sm grid has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] grid-cols-[0_1fr] has-[>svg]:gap-x-3 gap-y-0.5 items-start [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",
8+
{
9+
variants: {
10+
variant: {
11+
default: "bg-card text-card-foreground",
12+
destructive:
13+
"text-destructive bg-card [&>svg]:text-current *:data-[slot=alert-description]:text-destructive/90",
14+
},
15+
},
16+
defaultVariants: {
17+
variant: "default",
18+
},
19+
}
20+
)
21+
22+
function Alert({
23+
className,
24+
variant,
25+
...props
26+
}: React.ComponentProps<"div"> & VariantProps<typeof alertVariants>) {
27+
return (
28+
<div
29+
data-slot="alert"
30+
role="alert"
31+
className={cn(alertVariants({ variant }), className)}
32+
{...props}
33+
/>
34+
)
35+
}
36+
37+
function AlertTitle({ className, ...props }: React.ComponentProps<"div">) {
38+
return (
39+
<div
40+
data-slot="alert-title"
41+
className={cn(
42+
"col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight",
43+
className
44+
)}
45+
{...props}
46+
/>
47+
)
48+
}
49+
50+
function AlertDescription({
51+
className,
52+
...props
53+
}: React.ComponentProps<"div">) {
54+
return (
55+
<div
56+
data-slot="alert-description"
57+
className={cn(
58+
"text-muted-foreground col-start-2 grid justify-items-start gap-1 text-sm [&_p]:leading-relaxed",
59+
className
60+
)}
61+
{...props}
62+
/>
63+
)
64+
}
65+
66+
export { Alert, AlertTitle, AlertDescription }

0 commit comments

Comments
 (0)