forked from fahrPool/fahrPool
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:
parent
778827fe1c
commit
2135776343
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
import { createClient } from "@/lib/supabase/server";
|
||||
import { loadProfile } from "@/lib/auth/profile";
|
||||
import { istEinsatzrolle } from "@/lib/auth/roles";
|
||||
import { validateSchichtKorrektur } from "@/lib/zeiterfassung/validate-korrektur";
|
||||
import { findeOffeneSchicht, listSchichten } from "@/lib/zeiterfassung/queries";
|
||||
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> {
|
||||
const profileResult = await loadProfile();
|
||||
if (profileResult.status !== "ok" || profileResult.profile.role !== "fahrer") {
|
||||
return { success: false, error: "Nur Fahrer koennen sich einstempeln." };
|
||||
if (profileResult.status !== "ok" || !istEinsatzrolle(profileResult.profile.role)) {
|
||||
return { success: false, error: "Diese Rolle kann sich nicht einstempeln." };
|
||||
}
|
||||
|
||||
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> {
|
||||
const profileResult = await loadProfile();
|
||||
if (profileResult.status !== "ok" || profileResult.profile.role !== "fahrer") {
|
||||
return { success: false, error: "Nur Fahrer koennen sich ausstempeln." };
|
||||
if (profileResult.status !== "ok" || !istEinsatzrolle(profileResult.profile.role)) {
|
||||
return { success: false, error: "Diese Rolle kann sich nicht ausstempeln." };
|
||||
}
|
||||
|
||||
const supabase = await createClient();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { redirect } from "next/navigation";
|
||||
import { loadProfile } from "@/lib/auth/profile";
|
||||
import { kannZeiterfassungNutzen, personBezeichnung } from "@/lib/auth/roles";
|
||||
import { istEinsatzrolle, kannAuftraegeVerwalten, kannZeiterfassungNutzen, personBezeichnung } from "@/lib/auth/roles";
|
||||
import {
|
||||
listSchichten,
|
||||
listOffeneSchichten,
|
||||
|
|
@ -41,11 +41,12 @@ export default async function ZeiterfassungPage({
|
|||
const bisDatum = bis ?? heute.toISOString().slice(0, 10);
|
||||
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([
|
||||
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
|
||||
? listEinsatzPersonen().then((personen) => personen.map((p) => ({ id: p.id, name: personBezeichnung(p) })))
|
||||
: Promise.resolve([]),
|
||||
|
|
@ -76,8 +77,9 @@ export default async function ZeiterfassungPage({
|
|||
</div>
|
||||
)}
|
||||
|
||||
{!istDisponentOderAdmin && (
|
||||
{kannStempeln && (
|
||||
<div className="mb-6">
|
||||
{istDisponentOderAdmin && <h2 className="mb-2 text-lg font-semibold text-asphalt-grey">Meine Schicht</h2>}
|
||||
<KommenGehenButton offeneSchichtId={offeneSchicht?.id ?? null} />
|
||||
</div>
|
||||
)}
|
||||
|
|
@ -90,9 +92,9 @@ export default async function ZeiterfassungPage({
|
|||
<input id="bis" name="bis" type="date" defaultValue={bisDatum} className={FIELD_CLASSES} />
|
||||
</FormField>
|
||||
{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}>
|
||||
<option value="">Alle Fahrer</option>
|
||||
<option value="">Alle Personen</option>
|
||||
{fahrerListe.map((fahrer) => (
|
||||
<option key={fahrer.id} value={fahrer.id}>
|
||||
{fahrer.name}
|
||||
|
|
|
|||
Loading…
Reference in New Issue