| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- "use client";
- import React from "react";
- import Link from "next/link";
- import { useAuth } from "@/components/auth/authContext";
- import { branchPath, homePath } from "@/lib/frontend/routes";
- import { Alert, AlertTitle, AlertDescription } from "@/components/ui/alert";
- import { Button } from "@/components/ui/button";
- import {
- Card,
- CardHeader,
- CardTitle,
- CardDescription,
- CardContent,
- CardFooter,
- } from "@/components/ui/card";
- /**
- * ForbiddenView (RHL-021)
- *
- * Reusable UI block for "authenticated, but not allowed here".
- *
- * UX rule:
- * - All user-facing text must be German.
- */
- export default function ForbiddenView({ attemptedBranch = null }) {
- const { status, user } = useAuth();
- const isAuthed = status === "authenticated" && user;
- const isBranchUser = isAuthed && user.role === "branch" && user.branchId;
- const overviewHref = homePath();
- const primaryHref = isBranchUser ? branchPath(user.branchId) : overviewHref;
- const primaryLabel = isBranchUser
- ? "Zu meiner Niederlassung"
- : "Zur Übersicht";
- const showSecondaryOverview = isBranchUser;
- return (
- <Card>
- <CardHeader>
- <CardTitle>Zugriff verweigert</CardTitle>
- <CardDescription>
- Sie haben keine Berechtigung, diese Ressource zu öffnen.
- </CardDescription>
- </CardHeader>
- <CardContent className="space-y-4">
- <Alert variant="destructive">
- <AlertTitle>Keine Berechtigung</AlertTitle>
- <AlertDescription>
- {attemptedBranch ? (
- <span>
- Ihr Konto darf die Niederlassung{" "}
- <strong>{attemptedBranch}</strong> nicht öffnen.
- </span>
- ) : (
- <span>Ihr Konto darf diese Seite nicht öffnen.</span>
- )}
- </AlertDescription>
- </Alert>
- <p className="text-sm text-muted-foreground">
- Wenn Sie glauben, dass das ein Fehler ist, wenden Sie sich an Ihren
- Administrator.
- </p>
- </CardContent>
- <CardFooter className="flex flex-col gap-2 sm:flex-row sm:justify-end">
- {showSecondaryOverview ? (
- <Button variant="outline" asChild>
- <Link href={overviewHref}>Zur Übersicht</Link>
- </Button>
- ) : null}
- <Button asChild>
- <Link href={primaryHref}>{primaryLabel}</Link>
- </Button>
- </CardFooter>
- </Card>
- );
- }
|