feat(jobs): bulk-accept all pending inbox items

A lab opening its inbox first thing in the morning shouldn't have to
click 'İşleme Al' on every overnight submission. Added a single bulk
action that flips every currently-pending job into in_progress in one
shot.

  - bulkAcceptPendingJobsAction (lab only, owner/admin/member):
    lists every pending job for this lab (limit 200), then for each
    row in parallel writes status=in_progress + currentStep=alt_yapi_prova
    + location=at_lab. History rows and clinic notifications fire as
    fire-and-forget so a single failure doesn't block the rest. Returns
    { accepted } — count actually moved.
  - BulkAcceptButton (client island, /jobs/inbound only) shows when
    the current filtered list has at least one pending row, with a
    confirm dialog. Disabled / spinner while in flight.
  - 'Tümünü okundu işaretle' bulk action on /notifications was already
    in place, so nothing else needed there.

Notifications mark-all was already wired earlier; this commit covers
the inbox half.
This commit is contained in:
kovakmedya
2026-05-22 16:13:59 +03:00
parent 353d93ad56
commit 3de06add71
3 changed files with 140 additions and 5 deletions
@@ -0,0 +1,68 @@
"use client";
import { useState, useTransition } from "react";
import { useRouter } from "next/navigation";
import { CheckCheck, Loader2 } from "lucide-react";
import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { bulkAcceptPendingJobsAction } from "@/lib/appwrite/job-actions";
export function BulkAcceptButton({ count }: { count: number }) {
const router = useRouter();
const [open, setOpen] = useState(false);
const [pending, startTransition] = useTransition();
if (count === 0) return null;
function onConfirm() {
startTransition(async () => {
const res = await bulkAcceptPendingJobsAction();
if (res.ok) {
toast.success(`${res.accepted ?? 0} iş işleme alındı.`);
setOpen(false);
router.refresh();
} else {
toast.error(res.error ?? "İşlem başarısız.");
}
});
}
return (
<Dialog open={open} onOpenChange={setOpen}>
<Button size="sm" onClick={() => setOpen(true)}>
<CheckCheck className="size-4" />
Bekleyen {count} işi al
</Button>
<DialogContent>
<DialogHeader>
<DialogTitle>{count} işleme alınsın mı?</DialogTitle>
<DialogDescription>
Tüm bekleyen işler aynı anda işleme alınır; her birinde alt yapı
üretimine başlanmış sayılır. Klinikler ayrı ayrı bilgilendirilir.
</DialogDescription>
</DialogHeader>
<DialogFooter>
<DialogClose asChild>
<Button type="button" variant="outline">
Vazgeç
</Button>
</DialogClose>
<Button onClick={onConfirm} disabled={pending}>
{pending ? <Loader2 className="size-4 animate-spin" /> : <CheckCheck className="size-4" />}
Hepsini al
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}
+10 -5
View File
@@ -5,6 +5,7 @@ import { listInboundJobs } from "@/lib/appwrite/job-queries";
import { requireTenant } from "@/lib/appwrite/tenant-guard";
import { JobsFilterBar } from "../_components/jobs-filter-bar";
import { JobsTable } from "../_components/jobs-table";
import { BulkAcceptButton } from "./components/bulk-accept-button";
export const metadata = {
title: "DLS — Gelen İşler",
@@ -29,14 +30,18 @@ export default async function InboundJobsPage({
q: sp.q,
};
const rows = ctx.kind === "lab" ? await listInboundJobs(ctx.tenantId, filters) : [];
const pendingCount = rows.filter((j) => j.status === "pending").length;
return (
<div className="flex-1 space-y-6 px-6">
<div className="flex flex-col gap-1">
<h1 className="text-2xl font-bold tracking-tight">Gelen İşler</h1>
<p className="text-muted-foreground text-sm">
Bağlı kliniklerden size yönlendirilmiş protez işleri.
</p>
<div className="flex flex-wrap items-start justify-between gap-3">
<div className="flex flex-col gap-1">
<h1 className="text-2xl font-bold tracking-tight">Gelen İşler</h1>
<p className="text-muted-foreground text-sm">
Bağlı kliniklerden size yönlendirilmiş protez işleri.
</p>
</div>
{ctx.kind === "lab" && <BulkAcceptButton count={pendingCount} />}
</div>
<Card>