ProfilePage.jsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. "use client";
  2. import React from "react";
  3. import { useAuth } from "@/components/auth/authContext";
  4. import ChangePasswordCard from "@/components/profile/ChangePasswordCard";
  5. import { Alert, AlertTitle, AlertDescription } from "@/components/ui/alert";
  6. import {
  7. Card,
  8. CardHeader,
  9. CardTitle,
  10. CardDescription,
  11. CardContent,
  12. } from "@/components/ui/card";
  13. function formatRole(role) {
  14. if (role === "branch") return "Niederlassung";
  15. if (role === "admin") return "Admin";
  16. if (role === "superadmin") return "Superadmin";
  17. if (role === "dev") return "Entwicklung";
  18. return role ? String(role) : "Unbekannt";
  19. }
  20. export default function ProfilePage() {
  21. const { status, user } = useAuth();
  22. const [passwordChangedSuccess, setPasswordChangedSuccess] = React.useState(false);
  23. const isAuthenticated = status === "authenticated" && user;
  24. const roleLabel = isAuthenticated ? formatRole(user.role) : "—";
  25. const branchLabel = isAuthenticated ? user.branchId || "—" : "—";
  26. const emailLabel = isAuthenticated ? user.email || "—" : "—";
  27. const userIdLabel = isAuthenticated ? user.userId || "—" : "—";
  28. const mustChangePassword = isAuthenticated && user.mustChangePassword === true;
  29. React.useEffect(() => {
  30. if (mustChangePassword) {
  31. setPasswordChangedSuccess(false);
  32. }
  33. }, [mustChangePassword]);
  34. return (
  35. <div className="space-y-4">
  36. <div className="space-y-1">
  37. <h1 className="text-2xl font-semibold tracking-tight">Profil</h1>
  38. <p className="text-sm text-muted-foreground">
  39. Konto- und Zugangseinstellungen.
  40. </p>
  41. </div>
  42. {mustChangePassword ? (
  43. <Alert variant="destructive">
  44. <AlertTitle>Passwortänderung erforderlich</AlertTitle>
  45. <AlertDescription>
  46. Sie müssen Ihr Passwort ändern, bevor Sie fortfahren können.
  47. </AlertDescription>
  48. </Alert>
  49. ) : null}
  50. {!mustChangePassword && passwordChangedSuccess ? (
  51. <Alert className="border-emerald-500/40 bg-emerald-50 text-emerald-900 dark:border-emerald-400/40 dark:bg-emerald-950/40 dark:text-emerald-100">
  52. <AlertTitle>Passwort erfolgreich geändert</AlertTitle>
  53. <AlertDescription className="text-emerald-800 dark:text-emerald-200">
  54. Ihr Passwort wurde erfolgreich aktualisiert. Sie können jetzt normal
  55. weiterarbeiten.
  56. </AlertDescription>
  57. </Alert>
  58. ) : null}
  59. <Card>
  60. <CardHeader>
  61. <CardTitle>Konto</CardTitle>
  62. <CardDescription>Aktuelle Sitzungsinformationen.</CardDescription>
  63. </CardHeader>
  64. <CardContent className="grid gap-3 text-sm">
  65. <div className="flex items-center justify-between gap-4">
  66. <span className="text-muted-foreground">Rolle</span>
  67. <span>{roleLabel}</span>
  68. </div>
  69. <div className="flex items-center justify-between gap-4">
  70. <span className="text-muted-foreground">Niederlassung</span>
  71. <span>{branchLabel}</span>
  72. </div>
  73. <div className="flex items-center justify-between gap-4">
  74. <span className="text-muted-foreground">E-Mail</span>
  75. <span className="truncate">{emailLabel}</span>
  76. </div>
  77. <div className="flex items-center justify-between gap-4">
  78. <span className="text-muted-foreground">User ID</span>
  79. <span className="truncate">{userIdLabel}</span>
  80. </div>
  81. <p className="pt-1 text-xs text-muted-foreground">
  82. Die E-Mail wird zentral verwaltet. Für Änderungen wenden Sie sich an
  83. die IT.
  84. </p>
  85. </CardContent>
  86. </Card>
  87. <ChangePasswordCard
  88. onPasswordChangeSuccess={() => setPasswordChangedSuccess(true)}
  89. />
  90. {!isAuthenticated ? (
  91. <p className="text-xs text-muted-foreground">
  92. Hinweis: Profilfunktionen sind nur verfügbar, wenn Sie angemeldet
  93. sind.
  94. </p>
  95. ) : null}
  96. </div>
  97. );
  98. }