feat: Add remove account button to health page UI
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { CheckCircle2, XCircle, AlertTriangle } from "lucide-react";
|
import { CheckCircle2, XCircle, AlertTriangle, Trash2 } from "lucide-react";
|
||||||
import { Card, CardContent } from "@/components/ui/card";
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
import { Badge } from "@/components/ui/badge";
|
import { Badge } from "@/components/ui/badge";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
|
||||||
function formatResetTime(isoDate: string): string {
|
function formatResetTime(isoDate: string): string {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
@@ -92,7 +93,13 @@ export type AccountData = {
|
|||||||
activeAgentCount: number;
|
activeAgentCount: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function AccountCard({ account }: { account: AccountData }) {
|
export function AccountCard({
|
||||||
|
account,
|
||||||
|
onDelete,
|
||||||
|
}: {
|
||||||
|
account: AccountData;
|
||||||
|
onDelete?: (e: React.MouseEvent) => void;
|
||||||
|
}) {
|
||||||
const hasWarning = account.credentialsValid && !account.isExhausted && account.error;
|
const hasWarning = account.credentialsValid && !account.isExhausted && account.error;
|
||||||
|
|
||||||
const statusIcon = !account.credentialsValid ? (
|
const statusIcon = !account.credentialsValid ? (
|
||||||
@@ -140,6 +147,16 @@ export function AccountCard({ account }: { account: AccountData }) {
|
|||||||
<span>{statusText}</span>
|
<span>{statusText}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{onDelete && (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="shrink-0 text-muted-foreground hover:text-destructive"
|
||||||
|
onClick={onDelete}
|
||||||
|
>
|
||||||
|
<Trash2 className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Usage bars */}
|
{/* Usage bars */}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
RefreshCw,
|
RefreshCw,
|
||||||
Server,
|
Server,
|
||||||
} from 'lucide-react'
|
} from 'lucide-react'
|
||||||
|
import { toast } from 'sonner'
|
||||||
import { trpc } from '@/lib/trpc'
|
import { trpc } from '@/lib/trpc'
|
||||||
import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/card'
|
import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/card'
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
@@ -30,9 +31,19 @@ function formatUptime(seconds: number): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function HealthCheckPage() {
|
function HealthCheckPage() {
|
||||||
|
const utils = trpc.useUtils()
|
||||||
const healthQuery = trpc.systemHealthCheck.useQuery(undefined, {
|
const healthQuery = trpc.systemHealthCheck.useQuery(undefined, {
|
||||||
refetchInterval: 30_000,
|
refetchInterval: 30_000,
|
||||||
})
|
})
|
||||||
|
const removeAccount = trpc.removeAccount.useMutation({
|
||||||
|
onSuccess: () => {
|
||||||
|
void utils.systemHealthCheck.invalidate()
|
||||||
|
toast.success('Account removed')
|
||||||
|
},
|
||||||
|
onError: (err) => {
|
||||||
|
toast.error(`Failed to remove account: ${err.message}`)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
const { data, isLoading, isError, error, refetch } = healthQuery
|
const { data, isLoading, isError, error, refetch } = healthQuery
|
||||||
|
|
||||||
@@ -128,7 +139,15 @@ function HealthCheckPage() {
|
|||||||
</Card>
|
</Card>
|
||||||
) : (
|
) : (
|
||||||
accounts.map((account) => (
|
accounts.map((account) => (
|
||||||
<AccountCard key={account.id} account={account} />
|
<AccountCard
|
||||||
|
key={account.id}
|
||||||
|
account={account}
|
||||||
|
onDelete={(e) => {
|
||||||
|
if (e.shiftKey || window.confirm(`Remove account "${account.email}"?`)) {
|
||||||
|
removeAccount.mutate({ id: account.id })
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
))
|
))
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user