Phase 5: Positions und Bereiche page with create/staff position modals
This commit is contained in:
136
components/positions/CreatePositionModal.tsx
Normal file
136
components/positions/CreatePositionModal.tsx
Normal file
@@ -0,0 +1,136 @@
|
||||
"use client";
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { createPosition, searchSuperiors, type SuperiorSearchResult } from "@/actions/positions";
|
||||
import { Lookup } from "@/components/ui/Lookup";
|
||||
import { Modal } from "@/components/ui/Modal";
|
||||
import { useToast } from "@/components/ui/Toast";
|
||||
import type { Database } from "@/lib/supabase/types";
|
||||
|
||||
type Team = Database["public"]["Tables"]["teams"]["Row"];
|
||||
|
||||
export function CreatePositionModal({ open, onClose, teams }: { open: boolean; onClose: () => void; teams: Team[] }) {
|
||||
const { showToast } = useToast();
|
||||
const router = useRouter();
|
||||
const [title, setTitle] = useState("");
|
||||
const [isLead, setIsLead] = useState(false);
|
||||
const [superior, setSuperior] = useState<SuperiorSearchResult | null>(null);
|
||||
const [teamId, setTeamId] = useState("");
|
||||
const [pending, setPending] = useState(false);
|
||||
|
||||
function reset() {
|
||||
setTitle("");
|
||||
setIsLead(false);
|
||||
setSuperior(null);
|
||||
setTeamId("");
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!title || !superior || (isLead && !teamId)) {
|
||||
showToast("Bitte alle Pflichtfelder ausfüllen.", "error");
|
||||
return;
|
||||
}
|
||||
setPending(true);
|
||||
const result = await createPosition({
|
||||
title,
|
||||
superior_employee_id: superior.id,
|
||||
is_lead: isLead,
|
||||
team_id: isLead ? teamId : undefined,
|
||||
});
|
||||
setPending(false);
|
||||
if (result.success) {
|
||||
showToast("Position ausgeschrieben.");
|
||||
router.refresh();
|
||||
onClose();
|
||||
reset();
|
||||
} else {
|
||||
showToast(result.error ?? "Fehler beim Anlegen.", "error");
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
open={open}
|
||||
onClose={onClose}
|
||||
title="Position ausschreiben"
|
||||
footer={
|
||||
<>
|
||||
<button onClick={onClose} className="rounded px-4 py-2 text-sm font-semibold text-ink-body hover:bg-surface">
|
||||
Abbrechen
|
||||
</button>
|
||||
<button
|
||||
onClick={handleSubmit}
|
||||
disabled={pending}
|
||||
className="rounded bg-brand-500 px-4 py-2 text-sm font-semibold text-white disabled:opacity-50"
|
||||
>
|
||||
Ausschreiben
|
||||
</button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<div className="flex flex-col gap-4">
|
||||
<div>
|
||||
<label className="mb-1 block text-sm font-semibold text-ink">Titel*</label>
|
||||
<input value={title} onChange={(e) => setTitle(e.target.value)} className="w-full rounded border border-border px-3 py-2 text-sm" />
|
||||
</div>
|
||||
<label className="flex items-center gap-2 text-sm text-ink-body">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={isLead}
|
||||
onChange={(e) => {
|
||||
setIsLead(e.target.checked);
|
||||
setSuperior(null);
|
||||
}}
|
||||
/>
|
||||
Führungsposition (Teamleitung)
|
||||
</label>
|
||||
<div>
|
||||
<label className="mb-1 block text-sm font-semibold text-ink">
|
||||
{isLead ? "Übergeordnete Bereichsleitung*" : "Übergeordnete Teamleitung*"}
|
||||
</label>
|
||||
{!superior ? (
|
||||
<Lookup<SuperiorSearchResult>
|
||||
placeholder="Name oder Titel…"
|
||||
onSearch={(q) => searchSuperiors(q, isLead)}
|
||||
onSelect={setSuperior}
|
||||
renderResult={(p) => (
|
||||
<div>
|
||||
<div className="font-semibold text-ink">
|
||||
{p.first_name} {p.last_name}
|
||||
</div>
|
||||
<div className="text-xs text-ink-muted">{p.job_title}</div>
|
||||
</div>
|
||||
)}
|
||||
/>
|
||||
) : (
|
||||
<div className="flex items-center justify-between rounded border border-border bg-surface p-3">
|
||||
<div>
|
||||
<div className="text-sm font-semibold text-ink">
|
||||
{superior.first_name} {superior.last_name}
|
||||
</div>
|
||||
<div className="text-xs text-ink-muted">{superior.job_title}</div>
|
||||
</div>
|
||||
<button type="button" onClick={() => setSuperior(null)} className="text-xs text-ink-muted hover:text-ink">
|
||||
Ändern
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{isLead && (
|
||||
<div>
|
||||
<label className="mb-1 block text-sm font-semibold text-ink">Zu leitendes Team*</label>
|
||||
<select value={teamId} onChange={(e) => setTeamId(e.target.value)} className="w-full rounded border border-border px-3 py-2 text-sm">
|
||||
<option value="">Bitte wählen…</option>
|
||||
{teams.map((t) => (
|
||||
<option key={t.id} value={t.id}>
|
||||
{t.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
162
components/positions/PositionsPageClient.tsx
Normal file
162
components/positions/PositionsPageClient.tsx
Normal file
@@ -0,0 +1,162 @@
|
||||
"use client";
|
||||
|
||||
import { Plus } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { useState } from "react";
|
||||
import { useHireWizard } from "@/components/hire/HireWizardContext";
|
||||
import type { OpenPositionResolved } from "@/lib/positions";
|
||||
import { CreatePositionModal } from "./CreatePositionModal";
|
||||
import { StaffInternallyModal } from "./StaffInternallyModal";
|
||||
|
||||
type Team = {
|
||||
id: string;
|
||||
org_number: string;
|
||||
name: string;
|
||||
lead: { id: string; name: string } | null;
|
||||
headcount: number;
|
||||
fte: number;
|
||||
openCount: number;
|
||||
};
|
||||
type Department = { id: string; org_number: string; name: string; teams: Team[] };
|
||||
type DivisionCard = {
|
||||
id: string;
|
||||
org_number: string;
|
||||
name: string;
|
||||
head: { id: string; name: string } | null;
|
||||
headcount: number;
|
||||
departments: Department[];
|
||||
};
|
||||
type OpenPositionWithDays = OpenPositionResolved & { daysOpen: number };
|
||||
|
||||
type PositionsPageClientProps = {
|
||||
openPositions: OpenPositionWithDays[];
|
||||
divisionCards: DivisionCard[];
|
||||
teams: { id: string; org_number: string; name: string; department_id: string }[];
|
||||
};
|
||||
|
||||
export function PositionsPageClient({ openPositions, divisionCards, teams }: PositionsPageClientProps) {
|
||||
const { openWizard } = useHireWizard();
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [staffTarget, setStaffTarget] = useState<{ id: string; title: string; is_lead: boolean } | null>(null);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-6">
|
||||
<div className="rounded border border-border bg-white p-4">
|
||||
<div className="mb-3 flex items-center justify-between">
|
||||
<h2 className="text-sm font-bold text-ink">Offene Positionen ({openPositions.length})</h2>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setCreateOpen(true)}
|
||||
className="flex items-center gap-1.5 rounded bg-brand-500 px-3 py-1.5 text-sm font-semibold text-white hover:bg-brand-600"
|
||||
>
|
||||
<Plus className="h-4 w-4" />
|
||||
Position ausschreiben
|
||||
</button>
|
||||
</div>
|
||||
{openPositions.length === 0 ? (
|
||||
<p className="text-sm text-ink-muted">Derzeit keine offenen Positionen.</p>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{openPositions.map((p) => (
|
||||
<div key={p.id} className="rounded border border-border p-3">
|
||||
<div className="text-sm font-semibold text-ink">{p.title}</div>
|
||||
<div className="text-xs text-ink-muted">
|
||||
{p.position_number} · {p.orgLabel}
|
||||
</div>
|
||||
<div className="mt-1 text-xs text-ink-muted">seit {p.daysOpen} Tagen offen</div>
|
||||
<div className="mt-3 flex gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setStaffTarget({ id: p.id, title: p.title, is_lead: p.is_lead })}
|
||||
className="flex-1 rounded bg-brand-500 px-3 py-1.5 text-xs font-semibold text-white hover:bg-brand-600"
|
||||
>
|
||||
Intern
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => openWizard({ positionId: p.id })}
|
||||
className="flex-1 rounded border border-border px-3 py-1.5 text-xs font-semibold text-ink-body hover:bg-surface"
|
||||
>
|
||||
Extern
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{divisionCards.map((div) => (
|
||||
<div key={div.id} className="rounded border border-border bg-white p-4">
|
||||
<div className="mb-3 flex flex-wrap items-center justify-between gap-2 border-b border-border pb-3">
|
||||
<div>
|
||||
<div className="text-xs text-ink-muted">{div.org_number}</div>
|
||||
<div className="text-sm font-bold text-ink">{div.name}</div>
|
||||
{div.head && (
|
||||
<Link href={`/employees/${div.head.id}`} className="text-xs text-brand-700 hover:underline">
|
||||
{div.head.name}
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
<div className="text-sm font-semibold text-ink">{div.headcount} Mitarbeiter:innen</div>
|
||||
</div>
|
||||
<div className="flex flex-col gap-4">
|
||||
{div.departments.map((dept) => (
|
||||
<div key={dept.id}>
|
||||
<div className="mb-2 text-xs font-semibold uppercase tracking-wide text-ink-muted">
|
||||
{dept.org_number} · {dept.name}
|
||||
</div>
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full min-w-[600px] text-sm">
|
||||
<thead>
|
||||
<tr className="text-left text-xs text-ink-muted">
|
||||
<th className="py-1 pr-3">Team</th>
|
||||
<th className="py-1 pr-3">Teamleitung</th>
|
||||
<th className="py-1 pr-3">Headcount</th>
|
||||
<th className="py-1 pr-3">FTE</th>
|
||||
<th className="py-1 pr-3">Offen</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{dept.teams.map((team) => (
|
||||
<tr key={team.id} className="border-t border-border">
|
||||
<td className="py-1.5 pr-3">
|
||||
<div className="text-ink">{team.name}</div>
|
||||
<div className="text-xs text-ink-muted">{team.org_number}</div>
|
||||
</td>
|
||||
<td className="py-1.5 pr-3 text-ink-body">
|
||||
{team.lead ? (
|
||||
<Link href={`/employees/${team.lead.id}`} className="hover:text-brand-700 hover:underline">
|
||||
{team.lead.name}
|
||||
</Link>
|
||||
) : (
|
||||
"–"
|
||||
)}
|
||||
</td>
|
||||
<td className="py-1.5 pr-3 text-ink-body">{team.headcount}</td>
|
||||
<td className="py-1.5 pr-3 text-ink-body">{team.fte.toFixed(1)}</td>
|
||||
<td className="py-1.5 pr-3 font-semibold text-brand-700">{team.openCount || "–"}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
||||
<CreatePositionModal open={createOpen} onClose={() => setCreateOpen(false)} teams={teams} />
|
||||
{staffTarget && (
|
||||
<StaffInternallyModal
|
||||
open={Boolean(staffTarget)}
|
||||
onClose={() => setStaffTarget(null)}
|
||||
positionId={staffTarget.id}
|
||||
positionTitle={staffTarget.title}
|
||||
isLead={staffTarget.is_lead}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
102
components/positions/StaffInternallyModal.tsx
Normal file
102
components/positions/StaffInternallyModal.tsx
Normal file
@@ -0,0 +1,102 @@
|
||||
"use client";
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { searchActiveEmployees, type EmployeeSearchResult } from "@/actions/employees";
|
||||
import { staffPositionInternally } from "@/actions/positions";
|
||||
import { Lookup } from "@/components/ui/Lookup";
|
||||
import { Modal } from "@/components/ui/Modal";
|
||||
import { useToast } from "@/components/ui/Toast";
|
||||
|
||||
type StaffInternallyModalProps = {
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
positionId: string;
|
||||
positionTitle: string;
|
||||
isLead: boolean;
|
||||
};
|
||||
|
||||
export function StaffInternallyModal({ open, onClose, positionId, positionTitle, isLead }: StaffInternallyModalProps) {
|
||||
const { showToast } = useToast();
|
||||
const router = useRouter();
|
||||
const [employee, setEmployee] = useState<EmployeeSearchResult | null>(null);
|
||||
const [pending, setPending] = useState(false);
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!employee) return;
|
||||
setPending(true);
|
||||
const result = await staffPositionInternally({ position_id: positionId, employee_id: employee.id });
|
||||
setPending(false);
|
||||
if (result.success) {
|
||||
showToast(`${employee.first_name} ${employee.last_name} wurde intern besetzt.`);
|
||||
router.refresh();
|
||||
onClose();
|
||||
setEmployee(null);
|
||||
} else {
|
||||
showToast(result.error ?? "Fehler beim Besetzen.", "error");
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
open={open}
|
||||
onClose={onClose}
|
||||
title="Intern besetzen"
|
||||
footer={
|
||||
<>
|
||||
<button onClick={onClose} className="rounded px-4 py-2 text-sm font-semibold text-ink-body hover:bg-surface">
|
||||
Abbrechen
|
||||
</button>
|
||||
<button
|
||||
onClick={handleSubmit}
|
||||
disabled={pending || !employee}
|
||||
className="rounded bg-brand-500 px-4 py-2 text-sm font-semibold text-white disabled:opacity-50"
|
||||
>
|
||||
Besetzen
|
||||
</button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<div className="flex flex-col gap-4">
|
||||
<p className="text-sm text-ink-body">
|
||||
Position: <span className="font-semibold">{positionTitle}</span>
|
||||
</p>
|
||||
{isLead && (
|
||||
<div className="rounded bg-warning-bg px-3 py-2 text-sm text-warning-text">
|
||||
Dies ist eine Führungsposition: Das gesamte Team wird der ausgewählten Person unterstellt.
|
||||
</div>
|
||||
)}
|
||||
<div>
|
||||
<label className="mb-1 block text-sm font-semibold text-ink">Mitarbeiter:in*</label>
|
||||
{!employee ? (
|
||||
<Lookup<EmployeeSearchResult>
|
||||
placeholder="Name oder Titel…"
|
||||
onSearch={searchActiveEmployees}
|
||||
onSelect={setEmployee}
|
||||
renderResult={(e) => (
|
||||
<div>
|
||||
<div className="font-semibold text-ink">
|
||||
{e.first_name} {e.last_name}
|
||||
</div>
|
||||
<div className="text-xs text-ink-muted">{e.job_title}</div>
|
||||
</div>
|
||||
)}
|
||||
/>
|
||||
) : (
|
||||
<div className="flex items-center justify-between rounded border border-border bg-surface p-3">
|
||||
<div>
|
||||
<div className="text-sm font-semibold text-ink">
|
||||
{employee.first_name} {employee.last_name}
|
||||
</div>
|
||||
<div className="text-xs text-ink-muted">{employee.job_title}</div>
|
||||
</div>
|
||||
<button type="button" onClick={() => setEmployee(null)} className="text-xs text-ink-muted hover:text-ink">
|
||||
Ändern
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user