Workflow-App/Workflow/components/DeleteDocumentButton.tsx
sjcoetzeesj-coder 11d0178ab1 feat: commit Workflow app source; move CIPC credentials to env
Adds the full Next.js app (app/, components/, lib/, scripts/, assets/,
docs/, Dockerfile, compose, configs) to version control.

Security:
- CIPC BizPortal customer-code logins (Login 1 + Login 3) now read
  CIPC_LOGIN1_CODE / CIPC_LOGIN1_PASSWORD / CIPC_LOGIN3_CODE /
  CIPC_LOGIN3_PASSWORD from .env.local instead of source.
- BizPortal personal login in apply-bizportal route reads
  BIZPORTAL_ID_NO / BIZPORTAL_PASSWORD.
- Added .env.example as the committed template.

.gitignore excludes .env*, node_modules, .next, logs, sqlite, Playwright
storage_state.json (live CIPC cookies), scratch dirs, client PDFs and
debug screenshots.
2026-10-18 15:21:45 +02:00

96 lines
No EOL
2.8 KiB
TypeScript

"use client";
// components/DeleteDocumentButton.tsx
//
// Removes ONE document from the "View documents" page.
//
// This clears a single file slot on a record — it never deletes the resolution,
// the resignation record, or any other document. PocketBase file deletion is
// irreversible, so the operator confirms first and sees the exact filename they
// are discarding.
import { useRouter } from "next/navigation";
import { useState } from "react";
export default function DeleteDocumentButton({
recordId,
collection,
field,
filename,
label,
}: {
recordId: string;
collection: string;
field: string;
filename: string;
label: string;
}) {
const router = useRouter();
const [confirming, setConfirming] = useState(false);
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
async function remove() {
setBusy(true);
setError(null);
try {
const q = new URLSearchParams({ collection, field });
const res = await fetch(
`/api/resolutions/${encodeURIComponent(recordId)}/document?${q.toString()}`,
{ method: "DELETE" }
);
const body = await res.json().catch(() => null);
if (!res.ok) {
setError(body?.error || `HTTP ${res.status}`);
return;
}
setConfirming(false);
router.refresh();
} catch (err) {
setError(err instanceof Error ? err.message : "Could not remove the document");
} finally {
setBusy(false);
}
}
if (confirming) {
return (
<span className="flex flex-wrap items-center gap-2">
<span className="text-xs text-danger font-semibold">Remove this file?</span>
<button
onClick={remove}
disabled={busy}
className="px-2.5 py-1 text-xs font-semibold rounded bg-danger text-white hover:opacity-90 disabled:opacity-50"
title={`Permanently remove ${filename}`}
>
{busy ? "Removing…" : "Yes, remove"}
</button>
<button
onClick={() => {
setConfirming(false);
setError(null);
}}
disabled={busy}
className="px-2.5 py-1 text-xs font-semibold rounded border border-border hover:border-accent disabled:opacity-50"
>
Keep
</button>
{error && <span className="text-xs text-danger">{error}</span>}
</span>
);
}
return (
<button
onClick={() => {
setConfirming(true);
setError(null);
}}
disabled={busy}
className="px-2.5 py-1 text-xs font-semibold rounded border border-border bg-surface text-muted no-underline hover:border-danger hover:text-danger disabled:opacity-50"
title={`Remove “${label}” (${filename}) from this record`}
>
Remove
</button>
);
}