"use client";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { useToast } from "@/components/Toast";
import { type ApiError, api } from "@/lib/client/api";
export function PublishButton({
runId,
papers,
}: {
runId: string;
papers: Array<{ id: string; publicId: string; title: string }>;
}) {
const router = useRouter();
const toast = useToast();
const [open, setOpen] = useState(false);
const [busy, setBusy] = useState(false);
const [corrects, setCorrects] = useState("");
const [changelog, setChangelog] = useState("");
const go = async () => {
setBusy(true);
try {
const r = await api<{ publicId: string; slug: string }>("/api/admin/publications", {
json: { runId, correctsPaperId: corrects || undefined, changelog: changelog || undefined },
});
toast.push("success", `Published ${r.publicId}.`);
router.refresh();
} catch (e) {
toast.push("error", (e as ApiError).message);
} finally {
setBusy(false);
setOpen(false);
}
};
return open ? (
{corrects && (
)}
) : (
);
}
export function PaperActions({
id,
status,
title,
abstract,
keywords,
}: {
id: string;
status: string;
title: string;
abstract: string;
keywords: string[];
}) {
const router = useRouter();
const toast = useToast();
const [mode, setMode] = useState(null);
const [f, setF] = useState({
reason: "",
notice: "",
title,
abstract,
keywords: keywords.join(", "),
note: "",
});
const send = async (path: string, json: unknown, msg: string) => {
try {
await api(path, { json });
toast.push("success", msg);
setMode(null);
router.refresh();
} catch (e) {
toast.push("error", (e as ApiError).message);
}
};
if (!mode)
return (
{status !== "retracted" && (
)}
);
return (
{mode === "retract" && (
<>
setF({ ...f, reason: e.target.value })}
/>
);
}