3de06add71
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.
69 lines
2.0 KiB
TypeScript
69 lines
2.0 KiB
TypeScript
"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ş 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>
|
||
);
|
||
}
|