Files

199 lines
11 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client";
import { useState } from "react";
import { Check, X, Palmtree, House, Receipt, Clock, RotateCcw, Inbox } from "lucide-react";
import CanvasHint, { useCanvasHint } from "@/components/ui/CanvasHint";
/* ──────────────────────────────────────────────────────────────────────────
* ApprovalInbox — interactive centrepiece for the mitarbeitermanagement page.
* The team's open requests (Urlaub, Homeoffice, Spesen …); approve or reject
* each one — the card gets a status stamp and slides out, the counter ticks
* down, and an empty state lets you replay. Brand-styled.
* ────────────────────────────────────────────────────────────────────────── */
type Status = "pending" | "approved" | "rejected";
type Request = {
id: string;
name: string;
initials: string;
color: string;
typeLabel: string;
detail: string;
Icon: typeof Palmtree;
};
const INITIAL: Request[] = [
{ id: "r1", name: "Lena Krause", initials: "LK", color: "#0D6E6E", typeLabel: "Urlaubsantrag", detail: "12.–19. Juli · 6 Tage", Icon: Palmtree },
{ id: "r2", name: "Tom Berger", initials: "TB", color: "#3B82F6", typeLabel: "Homeoffice", detail: "Freitag, 11. Juli", Icon: House },
{ id: "r3", name: "Sara Möller", initials: "SM", color: "#F97316", typeLabel: "Spesenabrechnung", detail: "€ 84,50 · Tankbeleg", Icon: Receipt },
{ id: "r4", name: "Jonas Weiß", initials: "JW", color: "#8B5CF6", typeLabel: "Überstundenabbau", detail: "3 Std. · Mittwoch", Icon: Clock },
];
type Item = Request & { status: Status };
export default function ApprovalInbox({ hideHeader = false }: { hideHeader?: boolean }) {
const [items, setItems] = useState<Item[]>(() => INITIAL.map((r) => ({ ...r, status: "pending" as Status })));
const hint = useCanvasHint<HTMLDivElement>();
const decide = (id: string, status: Status) => {
hint.dismiss();
setItems((its) => its.map((it) => (it.id === id ? { ...it, status } : it)));
// Let the stamp + slide animation play, then drop the row.
window.setTimeout(() => setItems((its) => its.filter((it) => it.id !== id)), 520);
};
const reset = () => setItems(INITIAL.map((r) => ({ ...r, status: "pending" as Status })));
const openCount = items.filter((it) => it.status === "pending").length;
const allDone = items.length === 0;
return (
<section className="section-full" style={{ background: "var(--surface)", paddingBlock: hideHeader ? 40 : 80 }}>
<div className="mx-auto flex flex-col gap-5" style={{ maxWidth: 620 }}>
{!hideHeader && (
<div className="flex flex-col items-center gap-4 text-center">
<span className="text-[12px] font-semibold tracking-widest chamfer-badge px-2 py-0.5" style={{ background: "var(--accent-yellow-light)", color: "var(--accent-yellow-dark)" }}>
ANTRÄGE
</span>
<h2 className="text-[32px] md:text-[42px] font-bold leading-[1.15]" style={{ color: "var(--text-primary)" }}>Anträge im Griff.</h2>
</div>
)}
{/* Inbox on a dotted "canvas" — same treatment as the workflow editor &
kanban board. The onboarding popup replaces the old caption. */}
<div
ref={hint.ref}
className="relative rounded-2xl"
style={{
background: "#FAFBFD",
border: "1px solid var(--border-light)",
backgroundImage: "radial-gradient(circle, #E5E7EB 1px, transparent 1px)",
backgroundSize: "24px 24px",
padding: 16,
}}
>
<div className="w-full overflow-hidden rounded-2xl" style={{ background: "#FFFFFF", border: "1px solid var(--border-light)", boxShadow: "0 30px 60px -30px rgba(15,23,42,0.3)" }}>
{/* Inbox header */}
<div className="flex items-center gap-3 px-5 py-4" style={{ borderBottom: "1px solid var(--border-light)", background: "var(--container-bg)" }}>
<span className="grid place-items-center rounded-lg shrink-0" style={{ width: 34, height: 34, background: "var(--accent-yellow-light)" }}>
<Inbox size={17} style={{ color: "var(--accent-yellow-dark)" }} />
</span>
<div className="flex flex-col">
<span className="text-[14px] font-bold" style={{ color: "var(--text-primary)" }}>Offene Anträge</span>
<span className="text-[12px]" style={{ color: "var(--text-tertiary)" }}>
{openCount > 0 ? `${openCount} zu bearbeiten` : "alles erledigt"}
</span>
</div>
{items.length < INITIAL.length && (
<button onClick={reset} className="ml-auto inline-flex items-center gap-1.5 text-[12.5px] font-semibold rounded-lg px-2.5 py-1.5 transition-colors hover:bg-[var(--bg-muted)]" style={{ color: "var(--text-secondary)" }}>
<RotateCcw size={13} /> Zurücksetzen
</button>
)}
</div>
{/* Requests */}
<div className="flex flex-col p-4">
{allDone ? (
<div className="flex flex-col items-center gap-3 text-center px-4" style={{ paddingBlock: 44 }}>
<span className="grid place-items-center rounded-full" style={{ width: 52, height: 52, background: "#DCFCE7" }}>
<Check size={26} style={{ color: "#16A34A" }} />
</span>
<span className="text-[15px] font-bold" style={{ color: "var(--text-primary)" }}>Alle Anträge bearbeitet</span>
<button onClick={reset} className="inline-flex items-center gap-1.5 text-[13px] font-semibold rounded-lg px-3 py-2 transition-colors hover:bg-[var(--bg-muted)]" style={{ color: "var(--accent-yellow-dark)" }}>
<RotateCcw size={14} /> Nochmal ansehen
</button>
</div>
) : (
items.map((it) => {
const decided = it.status !== "pending";
const approved = it.status === "approved";
return (
<div
key={it.id}
style={{
maxHeight: decided ? 0 : 220,
opacity: decided ? 0 : 1,
marginBottom: decided ? 0 : 10,
transform: decided ? `translateX(${approved ? 24 : -24}px)` : "none",
overflow: "hidden",
transition: "all 0.45s cubic-bezier(0.22,1,0.36,1)",
}}
>
<div
className="relative flex flex-col sm:flex-row sm:items-center gap-3 sm:gap-3.5 shadow-sm hover:shadow-md transition-shadow"
style={{
padding: "13px 14px 13px 16px",
borderRadius: 10,
border: "1px solid var(--border-light)",
background: approved ? "rgba(34,197,94,0.06)" : it.status === "rejected" ? "rgba(239,68,68,0.05)" : "#FFFFFF",
}}
>
{/* left accent bar — the request's colour (matches the workflow nodes / kanban language) */}
<span className="absolute rounded-r-full" style={{ left: 0, top: 8, bottom: 8, width: 3, background: it.color }} />
{/* Avatar + text — kept together; on mobile they sit above the actions */}
<div className="flex items-center gap-3.5 min-w-0">
<span className="grid place-items-center rounded-full text-[13px] font-bold shrink-0" style={{ width: 40, height: 40, background: `${it.color}1a`, color: it.color }}>
{it.initials}
</span>
<div className="flex flex-col min-w-0 gap-0.5">
<div className="flex items-center gap-2 min-w-0">
<span className="text-[14px] font-semibold truncate" style={{ color: "var(--text-primary)" }}>{it.name}</span>
<span className="inline-flex items-center gap-1 text-[11px] font-semibold rounded-full px-2 py-0.5 shrink-0" style={{ background: `${it.color}14`, color: it.color, border: `1px solid ${it.color}2e` }}>
<it.Icon size={11} /> {it.typeLabel}
</span>
</div>
<span className="text-[12.5px] whitespace-nowrap" style={{ color: "var(--text-tertiary)" }}>{it.detail}</span>
</div>
</div>
{/* Actions / status — right on desktop, full row below on mobile */}
<div className="sm:ml-auto shrink-0 flex justify-end">
{decided ? (
<span
className="inline-flex items-center gap-1.5 text-[13px] font-bold rounded-lg px-3 py-2"
style={{
background: approved ? "rgba(34,197,94,0.12)" : "rgba(239,68,68,0.1)",
color: approved ? "#16A34A" : "#DC2626",
}}
>
{approved ? <Check size={15} /> : <X size={15} />}
{approved ? "Genehmigt" : "Abgelehnt"}
</span>
) : (
<div className="flex items-center gap-2">
<button
onClick={() => decide(it.id, "rejected")}
aria-label="Ablehnen"
className="grid place-items-center rounded-lg transition-colors"
style={{ width: 38, height: 38, border: "1px solid var(--border-light)", color: "var(--text-muted)" }}
onMouseEnter={(e) => { e.currentTarget.style.background = "rgba(239,68,68,0.08)"; e.currentTarget.style.color = "#DC2626"; e.currentTarget.style.borderColor = "#EF4444"; }}
onMouseLeave={(e) => { e.currentTarget.style.background = "transparent"; e.currentTarget.style.color = "var(--text-muted)"; e.currentTarget.style.borderColor = "var(--border-light)"; }}
>
<X size={17} />
</button>
<button
onClick={() => decide(it.id, "approved")}
className="inline-flex items-center gap-1.5 text-[13px] font-bold rounded-lg transition-transform hover:scale-[1.03]"
style={{ padding: "9px 14px", background: "#16A34A", color: "#FFFFFF" }}
>
<Check size={16} /> Genehmigen
</button>
</div>
)}
</div>
</div>
</div>
);
})
)}
</div>
</div>
{/* Centered onboarding hint (dismisses on first decision or via X) */}
<CanvasHint show={hint.show} onDismiss={hint.dismiss} title="Anträge bearbeiten" subtitle="Genehmige oder lehne mit einem Klick ab" />
</div>
</div>
</section>
);
}