1
0
Fork 0

feat: Disponent und Admin stempeln sich selbst ein und aus

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jonny 2026-11-02 09:24:25 +01:00
parent 778827fe1c
commit 2135776343
2 changed files with 13 additions and 10 deletions

View File

@ -2,6 +2,7 @@
import { createClient } from "@/lib/supabase/server"; import { createClient } from "@/lib/supabase/server";
import { loadProfile } from "@/lib/auth/profile"; import { loadProfile } from "@/lib/auth/profile";
import { istEinsatzrolle } from "@/lib/auth/roles";
import { validateSchichtKorrektur } from "@/lib/zeiterfassung/validate-korrektur"; import { validateSchichtKorrektur } from "@/lib/zeiterfassung/validate-korrektur";
import { findeOffeneSchicht, listSchichten } from "@/lib/zeiterfassung/queries"; import { findeOffeneSchicht, listSchichten } from "@/lib/zeiterfassung/queries";
import { pauseMinuten, nettoMinuten } from "@/lib/zeiterfassung/zeit-berechnung"; import { pauseMinuten, nettoMinuten } from "@/lib/zeiterfassung/zeit-berechnung";
@ -11,8 +12,8 @@ export type MutationResult = { success: true } | { success: false; error: string
export async function kommen(): Promise<MutationResult> { export async function kommen(): Promise<MutationResult> {
const profileResult = await loadProfile(); const profileResult = await loadProfile();
if (profileResult.status !== "ok" || profileResult.profile.role !== "fahrer") { if (profileResult.status !== "ok" || !istEinsatzrolle(profileResult.profile.role)) {
return { success: false, error: "Nur Fahrer koennen sich einstempeln." }; return { success: false, error: "Diese Rolle kann sich nicht einstempeln." };
} }
const offeneSchicht = await findeOffeneSchicht(profileResult.profile.id); const offeneSchicht = await findeOffeneSchicht(profileResult.profile.id);
@ -34,8 +35,8 @@ export async function kommen(): Promise<MutationResult> {
export async function gehen(schichtId: string): Promise<MutationResult> { export async function gehen(schichtId: string): Promise<MutationResult> {
const profileResult = await loadProfile(); const profileResult = await loadProfile();
if (profileResult.status !== "ok" || profileResult.profile.role !== "fahrer") { if (profileResult.status !== "ok" || !istEinsatzrolle(profileResult.profile.role)) {
return { success: false, error: "Nur Fahrer koennen sich ausstempeln." }; return { success: false, error: "Diese Rolle kann sich nicht ausstempeln." };
} }
const supabase = await createClient(); const supabase = await createClient();

View File

@ -1,6 +1,6 @@
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
import { loadProfile } from "@/lib/auth/profile"; import { loadProfile } from "@/lib/auth/profile";
import { kannZeiterfassungNutzen, personBezeichnung } from "@/lib/auth/roles"; import { istEinsatzrolle, kannAuftraegeVerwalten, kannZeiterfassungNutzen, personBezeichnung } from "@/lib/auth/roles";
import { import {
listSchichten, listSchichten,
listOffeneSchichten, listOffeneSchichten,
@ -41,11 +41,12 @@ export default async function ZeiterfassungPage({
const bisDatum = bis ?? heute.toISOString().slice(0, 10); const bisDatum = bis ?? heute.toISOString().slice(0, 10);
const zeitraum = { von: `${vonDatum}T00:00:00.000Z`, bis: `${bisDatum}T23:59:59.999Z` }; const zeitraum = { von: `${vonDatum}T00:00:00.000Z`, bis: `${bisDatum}T23:59:59.999Z` };
const istDisponentOderAdmin = profileResult.profile.role === "admin" || profileResult.profile.role === "disponent"; const istDisponentOderAdmin = kannAuftraegeVerwalten(profileResult.profile.role);
const kannStempeln = istEinsatzrolle(profileResult.profile.role);
const [schichten, offeneSchicht, fahrerListe, offeneSchichtenAlle] = await Promise.all([ const [schichten, offeneSchicht, fahrerListe, offeneSchichtenAlle] = await Promise.all([
listSchichten(zeitraum, istDisponentOderAdmin ? fahrer_id : profileResult.profile.id), listSchichten(zeitraum, istDisponentOderAdmin ? fahrer_id : profileResult.profile.id),
istDisponentOderAdmin ? Promise.resolve(null) : findeOffeneSchicht(profileResult.profile.id), kannStempeln ? findeOffeneSchicht(profileResult.profile.id) : Promise.resolve(null),
istDisponentOderAdmin istDisponentOderAdmin
? listEinsatzPersonen().then((personen) => personen.map((p) => ({ id: p.id, name: personBezeichnung(p) }))) ? listEinsatzPersonen().then((personen) => personen.map((p) => ({ id: p.id, name: personBezeichnung(p) })))
: Promise.resolve([]), : Promise.resolve([]),
@ -76,8 +77,9 @@ export default async function ZeiterfassungPage({
</div> </div>
)} )}
{!istDisponentOderAdmin && ( {kannStempeln && (
<div className="mb-6"> <div className="mb-6">
{istDisponentOderAdmin && <h2 className="mb-2 text-lg font-semibold text-asphalt-grey">Meine Schicht</h2>}
<KommenGehenButton offeneSchichtId={offeneSchicht?.id ?? null} /> <KommenGehenButton offeneSchichtId={offeneSchicht?.id ?? null} />
</div> </div>
)} )}
@ -90,9 +92,9 @@ export default async function ZeiterfassungPage({
<input id="bis" name="bis" type="date" defaultValue={bisDatum} className={FIELD_CLASSES} /> <input id="bis" name="bis" type="date" defaultValue={bisDatum} className={FIELD_CLASSES} />
</FormField> </FormField>
{istDisponentOderAdmin && ( {istDisponentOderAdmin && (
<FormField label="Fahrer" htmlFor="fahrer_id"> <FormField label="Person" htmlFor="fahrer_id">
<select id="fahrer_id" name="fahrer_id" defaultValue={fahrer_id ?? ""} className={FIELD_CLASSES}> <select id="fahrer_id" name="fahrer_id" defaultValue={fahrer_id ?? ""} className={FIELD_CLASSES}>
<option value="">Alle Fahrer</option> <option value="">Alle Personen</option>
{fahrerListe.map((fahrer) => ( {fahrerListe.map((fahrer) => (
<option key={fahrer.id} value={fahrer.id}> <option key={fahrer.id} value={fahrer.id}>
{fahrer.name} {fahrer.name}