Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

feat: Add delete functionality for automation runs & better UX

Khuram Niaz1d60b41b1b9b
diff --git a/src/actions/automation.actions.ts b/src/actions/automation.actions.ts
index 35b604e..a30ee9f 100644
--- a/src/actions/automation.actions.ts
+++ b/src/actions/automation.actions.ts
@@ -765,3 +765,24 @@ export async function getAutomationRuns(
return formatError(error, "Failed to get automation runs");
}
}
+
+export async function deleteAutomationRun(
+ runId: string,
+): Promise<{ success: boolean; message?: string }> {
+ try {
+ const user = await getCurrentUser();
+ if (!user) return { success: false, message: "Not authenticated" };
+
+ // Ownership check via automation -> userId
+ const run = await db.automationRun.findFirst({
+ where: { id: runId, automation: { userId: user.id } },
+ });
+
+ if (!run) return { success: false, message: "Run not found" };
+
+ await db.automationRun.delete({ where: { id: runId } });
+ return { success: true };
+ } catch (error) {
+ return formatError(error, "Failed to delete run");
+ }
+}
diff --git a/src/app/dashboard/automations/[id]/page.tsx b/src/app/dashboard/automations/[id]/page.tsx
index db1bc2a..0f4576b 100644
--- a/src/app/dashboard/automations/[id]/page.tsx
+++ b/src/app/dashboard/automations/[id]/page.tsx
@@ -1,7 +1,7 @@
"use client";
import { useCallback, useEffect, useRef, useState } from "react";
-import { useParams, useRouter } from "next/navigation";
+import { useParams, useRouter, useSearchParams } from "next/navigation";
import Link from "next/link";
import { format } from "date-fns";
import {
@@ -50,7 +50,13 @@ import Loading from "@/components/Loading";
export default function AutomationDetailPage() {
const params = useParams();
const router = useRouter();
+ const searchParams = useSearchParams();
const automationId = params.id as string;
+ const activeTab = searchParams.get("tab") ?? "logs";
+
+ const handleTabChange = (tab: string) => {
+ router.replace(`?tab=${tab}`, { scroll: false });
+ };
const [automation, setAutomation] = useState<AutomationWithResume | null>(
null,
@@ -247,9 +253,13 @@ export default function AutomationDetailPage() {
</Button>
<div className="flex-1">
<h1 className="text-2xl font-bold">{automation.name}</h1>
- <p className="text-muted-foreground">
- {automation.keywords} in {automation.location}
- </p>
+ {(automation.keywords || automation.location) && (
+ <p className="text-muted-foreground">
+ {[automation.keywords, automation.location]
+ .filter(Boolean)
+ .join(" in ")}
+ </p>
+ )}
</div>
<div className="flex gap-2">
<Button variant="outline" size="icon" onClick={loadData}>
@@ -364,7 +374,7 @@ export default function AutomationDetailPage() {
</CardContent>
</Card>
- <Tabs defaultValue="logs">
+ <Tabs value={activeTab} onValueChange={handleTabChange}>
<TabsList>
<TabsTrigger value="logs">Logs</TabsTrigger>
<TabsTrigger value="jobs">
@@ -389,7 +399,7 @@ export default function AutomationDetailPage() {
/>
</TabsContent>
<TabsContent value="history" className="mt-4">
- <RunHistoryList runs={runs} />
+ <RunHistoryList runs={runs} onDelete={loadData} />
</TabsContent>
</Tabs>
diff --git a/src/components/automations/RunHistoryList.tsx b/src/components/automations/RunHistoryList.tsx
index 0f702e5..972c398 100644
--- a/src/components/automations/RunHistoryList.tsx
+++ b/src/components/automations/RunHistoryList.tsx
@@ -1,6 +1,8 @@
"use client";
+import { useState } from "react";
import { format } from "date-fns";
+import { Fragment } from "react";
import {
Card,
CardContent,
@@ -9,6 +11,7 @@ import {
CardTitle,
} from "@/components/ui/card";
import { Badge } from "@/components/ui/badge";
+import { Button } from "@/components/ui/button";
import {
Table,
TableBody,
@@ -32,12 +35,16 @@ import {
Timer,
History,
Square,
+ Trash2,
} from "lucide-react";
-import { Fragment } from "react";
import type { AutomationRun, FunnelStage } from "@/models/automation.model";
+import { DeleteAlertDialog } from "@/components/DeleteAlertDialog";
+import { deleteAutomationRun } from "@/actions/automation.actions";
+import { toast } from "@/components/ui/use-toast";
interface RunHistoryListProps {
runs: AutomationRun[];
+ onDelete?: () => void;
}
function parseFunnel(funnelStats: string | null): FunnelStage[] {
@@ -60,7 +67,21 @@ const STATUS_CONFIG = {
cancelled: { icon: Square, color: "text-muted-foreground", variant: "secondary" as const },
};
-export function RunHistoryList({ runs }: RunHistoryListProps) {
+export function RunHistoryList({ runs, onDelete }: RunHistoryListProps) {
+ const [deleteRunId, setDeleteRunId] = useState<string | null>(null);
+
+ const handleDelete = async () => {
+ if (!deleteRunId) return;
+ const result = await deleteAutomationRun(deleteRunId);
+ setDeleteRunId(null);
+ if (result.success) {
+ toast({ title: "Run deleted" });
+ onDelete?.();
+ } else {
+ toast({ title: "Error", description: result.message, variant: "destructive" });
+ }
+ };
+
if (runs.length === 0) {
return (
<Card>
@@ -76,105 +97,124 @@ export function RunHistoryList({ runs }: RunHistoryListProps) {
}
return (
- <Card>
- <CardHeader>
- <CardTitle>Run History</CardTitle>
- <CardDescription>
- Recent automation runs and their results
- </CardDescription>
- </CardHeader>
- <CardContent>
- <Table>
- <TableHeader>
- <TableRow>
- <TableHead>Status</TableHead>
- <TableHead>Started</TableHead>
- <TableHead>Duration</TableHead>
- <TableHead className="text-center">Searched</TableHead>
- <TableHead className="text-center">New</TableHead>
- <TableHead className="text-center">Processed</TableHead>
- <TableHead className="text-center">Matched</TableHead>
- <TableHead className="text-center">Saved</TableHead>
- <TableHead>Error</TableHead>
- </TableRow>
- </TableHeader>
- <TableBody>
- {runs.map((run) => {
- const config = STATUS_CONFIG[run.status] || STATUS_CONFIG.failed;
- const StatusIcon = config.icon;
- const duration = run.completedAt
- ? Math.round(
- (new Date(run.completedAt).getTime() - new Date(run.startedAt).getTime()) / 1000
- )
- : null;
- const funnel = parseFunnel(run.funnelStats);
+ <>
+ <Card>
+ <CardHeader>
+ <CardTitle>Run History</CardTitle>
+ <CardDescription>
+ Recent automation runs and their results
+ </CardDescription>
+ </CardHeader>
+ <CardContent className="overflow-x-auto">
+ <Table>
+ <TableHeader>
+ <TableRow>
+ <TableHead>Status</TableHead>
+ <TableHead>Started</TableHead>
+ <TableHead>Duration</TableHead>
+ <TableHead className="text-center">Searched</TableHead>
+ <TableHead className="text-center">New</TableHead>
+ <TableHead className="text-center">Processed</TableHead>
+ <TableHead className="text-center">Matched</TableHead>
+ <TableHead className="text-center">Saved</TableHead>
+ <TableHead>Error</TableHead>
+ <TableHead />
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ {runs.map((run) => {
+ const config = STATUS_CONFIG[run.status] || STATUS_CONFIG.failed;
+ const StatusIcon = config.icon;
+ const duration = run.completedAt
+ ? Math.round(
+ (new Date(run.completedAt).getTime() - new Date(run.startedAt).getTime()) / 1000
+ )
+ : null;
+ const funnel = parseFunnel(run.funnelStats);
- return (
- <Fragment key={run.id}>
- <TableRow>
- <TableCell>
- <div className="flex items-center gap-2">
- <StatusIcon className={`h-4 w-4 ${config.color}`} />
- <Badge variant={config.variant}>{run.status.replace("_", " ")}</Badge>
- </div>
- </TableCell>
- <TableCell>
- {format(new Date(run.startedAt), "MMM d, h:mm a")}
- </TableCell>
- <TableCell>
- {duration !== null ? `${duration}s` : "-"}
- </TableCell>
- <TableCell className="text-center">{run.jobsSearched}</TableCell>
- <TableCell className="text-center">{run.jobsDeduplicated}</TableCell>
- <TableCell className="text-center">{run.jobsProcessed}</TableCell>
- <TableCell className="text-center">{run.jobsMatched}</TableCell>
- <TableCell className="text-center">
- <span className="font-medium">{run.jobsSaved}</span>
- </TableCell>
- <TableCell>
- {(run.errorMessage || run.blockedReason) && (
- <TooltipProvider>
- <Tooltip>
- <TooltipTrigger>
- <Badge variant="outline" className="max-w-[150px] truncate">
- {run.blockedReason || run.errorMessage}
- </Badge>
- </TooltipTrigger>
- <TooltipContent>
- <p className="max-w-xs">
- {run.blockedReason || run.errorMessage}
- </p>
- </TooltipContent>
- </Tooltip>
- </TooltipProvider>
+ return (
+ <Fragment key={run.id}>
+ <TableRow>
+ <TableCell>
+ <div className="flex items-center gap-2">
+ <StatusIcon className={`h-4 w-4 ${config.color}`} />
+ <Badge variant={config.variant}>{run.status.replace("_", " ")}</Badge>
+ </div>
+ </TableCell>
+ <TableCell>
+ {format(new Date(run.startedAt), "MMM d, h:mm a")}
+ </TableCell>
+ <TableCell>
+ {duration !== null ? `${duration}s` : "-"}
+ </TableCell>
+ <TableCell className="text-center">{run.jobsSearched}</TableCell>
+ <TableCell className="text-center">{run.jobsDeduplicated}</TableCell>
+ <TableCell className="text-center">{run.jobsProcessed}</TableCell>
+ <TableCell className="text-center">{run.jobsMatched}</TableCell>
+ <TableCell className="text-center">
+ <span className="font-medium">{run.jobsSaved}</span>
+ </TableCell>
+ <TableCell>
+ {(run.errorMessage || run.blockedReason) && (
+ <TooltipProvider>
+ <Tooltip>
+ <TooltipTrigger>
+ <Badge variant="outline" className="max-w-[150px] truncate">
+ {run.blockedReason || run.errorMessage}
+ </Badge>
+ </TooltipTrigger>
+ <TooltipContent>
+ <p className="max-w-xs">
+ {run.blockedReason || run.errorMessage}
+ </p>
+ </TooltipContent>
+ </Tooltip>
+ </TooltipProvider>
+ )}
+ </TableCell>
+ <TableCell>
+ <Button
+ variant="ghost"
+ size="icon"
+ onClick={() => setDeleteRunId(run.id)}
+ >
+ <Trash2 className="h-4 w-4 text-muted-foreground" />
+ </Button>
+ </TableCell>
+ </TableRow>
+ {funnel.length > 0 && (
+ <TableRow className="hover:bg-transparent border-0">
+ <TableCell colSpan={10} className="pt-0 pb-3">
+ <div className="flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground">
+ {funnel.map((stage, i) => (
+ <Fragment key={stage.key}>
+ {i > 0 && <span className="opacity-50">→</span>}
+ <span>
+ {stage.label}{" "}
+ <span className="font-medium text-foreground">
+ {stage.count}
+ </span>
+ </span>
+ </Fragment>
+ ))}
+ </div>
+ </TableCell>
+ </TableRow>
)}
- </TableCell>
- </TableRow>
- {funnel.length > 0 && (
- <TableRow className="hover:bg-transparent border-0">
- <TableCell colSpan={9} className="pt-0 pb-3">
- <div className="flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground">
- {funnel.map((stage, i) => (
- <Fragment key={stage.key}>
- {i > 0 && <span className="opacity-50">→</span>}
- <span>
- {stage.label}{" "}
- <span className="font-medium text-foreground">
- {stage.count}
- </span>
- </span>
- </Fragment>
- ))}
- </div>
- </TableCell>
- </TableRow>
- )}
- </Fragment>
- );
- })}
- </TableBody>
- </Table>
- </CardContent>
- </Card>
+ </Fragment>
+ );
+ })}
+ </TableBody>
+ </Table>
+ </CardContent>
+ </Card>
+
+ <DeleteAlertDialog
+ pageTitle="run"
+ open={!!deleteRunId}
+ onOpenChange={(open) => !open && setDeleteRunId(null)}
+ onDelete={handleDelete}
+ />
+ </>
);
}