Projeto bot pontos

This commit is contained in:
2026-10-23 22:31:02 -03:00
parent 29614855ff
commit b35e1a7d69
116 changed files with 14523 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
"use client";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { apiFetch, errorMessage } from "@/lib/client-api";
interface Props {
path: string;
label: string;
method?: "POST" | "PUT" | "PATCH" | "DELETE";
body?: unknown;
confirm?: string;
variant?: "primary" | "danger" | "secondary";
onDone?: (result: unknown) => void;
}
/** Botão que executa uma ação na API e recarrega os dados da página. */
export function ActionButton({ path, label, method = "POST", body, confirm, variant = "secondary", onDone }: Props) {
const router = useRouter();
const [busy, setBusy] = useState(false);
const [error, setError] = useState("");
async function run() {
if (confirm && !window.confirm(confirm)) return;
setBusy(true);
setError("");
try {
const result = await apiFetch(path, { method, body });
onDone?.(result);
router.refresh();
} catch (err) {
setError(errorMessage(err));
} finally {
setBusy(false);
}
}
return (
<span className="action">
<button type="button" className={`btn ${variant}`} onClick={run} disabled={busy}>
{busy ? "Aguarde…" : label}
</button>
{error && <span className="error-text">{error}</span>}
</span>
);
}

View File

@@ -0,0 +1,18 @@
"use client";
import { apiFetch } from "@/lib/client-api";
export function LogoutButton() {
async function logout() {
try {
await apiFetch("/auth/logout", { method: "POST" });
} finally {
window.location.href = "/login";
}
}
return (
<button type="button" className="btn link" onClick={logout}>
Sair
</button>
);
}

View File

@@ -0,0 +1,40 @@
"use client";
import type { QueryWindow } from "@/lib/types";
const FIELDS: { key: keyof QueryWindow; label: string; hint: string }[] = [
{ key: "query_window_start", label: "Início da janela", hint: "Primeira consulta do dia" },
{ key: "day_check_deadline", label: "Confirmação sem pontos", hint: "2ª verificação sem pontos" },
{ key: "no_points_recheck_until", label: "Fim das reverificações", hint: "Depois disso, dia sem pontos é encerrado" },
{ key: "query_window_end", label: "Fim da janela", hint: "Última consulta do dia" },
];
/** Os quatro horários da janela de consulta (ARQUITETURA.md 9.12). */
export function WindowFields({
value,
onChange,
disabled,
}: {
value: QueryWindow;
onChange: (w: QueryWindow) => void;
disabled?: boolean;
}) {
return (
<div className="grid-4">
{FIELDS.map((f) => (
<label key={f.key} className="field">
<span>{f.label}</span>
<input
type="time"
step={900}
value={value[f.key]}
disabled={disabled}
onChange={(e) => onChange({ ...value, [f.key]: e.target.value })}
required
/>
<small className="muted">{f.hint}</small>
</label>
))}
</div>
);
}