HifiPlanet-Website/hifi/assets/AdminUsers-Fr-eVHu9.js
Claude 2295ebd2b7
Modelle im Admin neu: Marken links, Modell-Liste mit Paket-Status, Bearbeiten im Seitenpanel
- Marken als Liste links (am Handy Auswahlfeld) mit Modellanzahl und Hinweis auf Modelle
  ohne sichtbares Paket; "Alle Marken" zum Durchsuchen; Auswahl in der Adresse (?marke=)
- Modell-Liste: Bild, Paket-Status ("5 Pakete", "Noch keine Pakete"), Knopf "Pakete"
  direkt zum Modell auf der Paket-Seite, Suche, Ziehen zum Sortieren je Marke
- Bearbeiten/Anlegen im Seitenpanel (Marke vorbelegt), Loeschen nennt die Paketanzahl
- Leerzustaende mit "Aus Vorlage laden"

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01R5qHQ6FkdkREoPVmRJ5V77
2026-10-20 17:12:44 +00:00

1 line
7.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import{k as R,r as n,q as I,s as L,j as e,c}from"./index-hptrrCTJ.js";const u={username:"",password:"",is_super_admin:!1,permissions:[],group_ids:[]};function $(a){return a?new Date(a.replace(" ","T")).toLocaleString("de-DE",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"}):"Noch nie"}function J(){const{user:a,hasPermission:h}=R(),[g,w]=n.useState([]),[_,S]=n.useState([]),[b,B]=n.useState([]),[r,d]=n.useState(u),[l,j]=n.useState(null),[N,k]=n.useState(!1),[f,o]=n.useState(""),[z,y]=n.useState(u),v=n.useRef(null),m=I();L(JSON.stringify(r)!==JSON.stringify(z),"admin-users");const x=()=>{c.get("/admin-users").then(w),c.get("/permissions/catalog").then(S),(h("permission_groups.manage")||h("users.manage"))&&c.get("/permission-groups").then(B)};n.useEffect(x,[]);const E=t=>{var i;j(t.id),k(t.is_primary);const s={username:t.username,password:"",is_super_admin:t.is_super_admin,permissions:t.permissions,group_ids:t.groups.map(P=>P.id)};d(s),y(s),(i=v.current)==null||i.scrollIntoView({behavior:"smooth",block:"start"})},p=()=>{j(null),k(!1),d(u),y(u)},A=t=>{d(s=>({...s,permissions:s.permissions.includes(t)?s.permissions.filter(i=>i!==t):[...s.permissions,t]}))},C=t=>{d(s=>({...s,group_ids:s.group_ids.includes(t)?s.group_ids.filter(i=>i!==t):[...s.group_ids,t]}))},D=async t=>{t.preventDefault(),o("");try{if(l)await c.put(`/admin-users/${l}`,r);else{if(r.password.length<8){o("Passwort muss mindestens 8 Zeichen lang sein");return}await c.post("/admin-users",r)}m.success(l?"Benutzer gespeichert.":`Benutzer „${r.username}“ angelegt.`),p(),x()}catch(s){o(s.message)}},F=async t=>{if(confirm("Diesen Benutzer wirklich löschen?"))try{await c.delete(`/admin-users/${t}`),l===t&&p(),m.success("Benutzer gelöscht."),x()}catch(s){m.error(`Löschen fehlgeschlagen: ${s.message}`)}};return e.jsxs("div",{className:"grid gap-6 lg:grid-cols-3",children:[e.jsxs("div",{className:"lg:col-span-2",children:[e.jsx("h1",{className:"mb-1 text-xl font-bold text-neutral-900 dark:text-white",children:"Benutzer"}),e.jsx("p",{className:"mb-4 text-sm text-neutral-500 dark:text-neutral-400",children:"Jeder Mitarbeiter bekommt ein eigenes Konto mit genau den Rechten, die er braucht."}),e.jsx("div",{className:"overflow-x-auto rounded-xl border border-neutral-200 dark:border-neutral-800",children:e.jsxs("table",{className:"w-full text-left text-sm",children:[e.jsx("thead",{className:"bg-neutral-50 text-neutral-500 dark:bg-neutral-900 dark:text-neutral-400",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-2",children:"Benutzername"}),e.jsx("th",{className:"px-4 py-2",children:"Rolle"}),e.jsx("th",{className:"px-4 py-2",children:"Berechtigungsgruppen"}),e.jsx("th",{className:"px-4 py-2",children:"Zuletzt aktiv"}),e.jsx("th",{className:"px-4 py-2 text-right",children:"Aktionen"})]})}),e.jsxs("tbody",{className:"divide-y divide-neutral-100 dark:divide-neutral-800",children:[g.map(t=>e.jsxs("tr",{className:"bg-white dark:bg-neutral-950",children:[e.jsxs("td",{className:"px-4 py-2 font-medium text-neutral-800 dark:text-neutral-100",children:[t.username,t.id===(a==null?void 0:a.id)&&e.jsx("span",{className:"ml-1 text-xs text-neutral-400",children:"(du)"}),t.is_primary&&e.jsx("span",{className:"ml-1 text-xs text-neutral-400",children:"(Erst-Administrator)"})]}),e.jsx("td",{className:"px-4 py-2",children:t.is_super_admin?e.jsx("span",{className:"rounded-full bg-brand-100 px-2 py-0.5 text-xs font-medium text-brand-700 dark:bg-brand-900/40 dark:text-brand-300",children:"Super-Admin"}):e.jsxs("span",{className:"text-neutral-500 dark:text-neutral-400",children:[t.permissions.length," Einzelrechte"]})}),e.jsx("td",{className:"px-4 py-2",children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[t.groups.map(s=>e.jsx("span",{className:"rounded-full bg-neutral-100 px-2 py-0.5 text-xs text-neutral-600 dark:bg-neutral-800 dark:text-neutral-300",children:s.name},s.id)),t.groups.length===0&&"–"]})}),e.jsx("td",{className:"px-4 py-2 text-neutral-500 dark:text-neutral-400",children:$(t.last_active_at)}),e.jsxs("td",{className:"whitespace-nowrap px-4 py-2 text-right",children:[e.jsx("button",{onClick:()=>E(t),className:"mr-3 text-brand-600 hover:underline",children:"Bearbeiten"}),t.id!==(a==null?void 0:a.id)&&!t.is_primary&&e.jsx("button",{onClick:()=>F(t.id),className:"text-red-600 hover:underline",children:"Löschen"})]})]},t.id)),g.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"px-4 py-6 text-center text-neutral-400",children:"Noch keine Benutzer angelegt."})})]})]})})]}),e.jsxs("form",{ref:v,onSubmit:D,className:"h-fit scroll-mt-20 space-y-4 rounded-xl border border-neutral-200 bg-white p-5 dark:border-neutral-800 dark:bg-neutral-900",children:[e.jsx("h2",{className:"font-bold text-neutral-900 dark:text-white",children:l?"Benutzer bearbeiten":"Neuer Benutzer"}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-neutral-700 dark:text-neutral-300",children:"Benutzername *"}),e.jsx("input",{required:!0,value:r.username,onChange:t=>d({...r,username:t.target.value}),className:"w-full rounded-md border border-neutral-300 bg-white px-3 py-2 text-sm dark:border-neutral-700 dark:bg-neutral-900"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"mb-1 block text-sm font-medium text-neutral-700 dark:text-neutral-300",children:["Passwort ",l?"(leer lassen = unverändert)":"*"]}),e.jsx("input",{type:"password",required:!l,value:r.password,onChange:t=>d({...r,password:t.target.value}),className:"w-full rounded-md border border-neutral-300 bg-white px-3 py-2 text-sm dark:border-neutral-700 dark:bg-neutral-900"})]}),(a==null?void 0:a.is_super_admin)&&e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm text-neutral-700 dark:text-neutral-300",children:[e.jsx("input",{type:"checkbox",checked:r.is_super_admin,disabled:N,onChange:t=>d({...r,is_super_admin:t.target.checked}),className:"h-4 w-4 rounded border-neutral-300 text-brand-600 focus:ring-brand-500 disabled:opacity-50"}),"Super-Admin (hat automatisch alle Rechte)"]}),N&&e.jsx("p",{className:"mt-1 text-xs text-neutral-400",children:"Der Erst-Administrator behält immer den Super-Admin-Status."})]}),!r.is_super_admin&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-sm font-medium text-neutral-700 dark:text-neutral-300",children:"Einzelne Berechtigungen"}),e.jsx("div",{className:"space-y-1.5 rounded-md border border-neutral-200 p-3 dark:border-neutral-700",children:_.map(t=>e.jsxs("label",{className:"flex items-center gap-2 text-sm text-neutral-700 dark:text-neutral-300",children:[e.jsx("input",{type:"checkbox",checked:r.permissions.includes(t.key),onChange:()=>A(t.key),className:"h-4 w-4 rounded border-neutral-300 text-brand-600 focus:ring-brand-500"}),t.label]},t.key))})]}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-sm font-medium text-neutral-700 dark:text-neutral-300",children:"Berechtigungsgruppen"}),e.jsxs("div",{className:"space-y-1.5 rounded-md border border-neutral-200 p-3 dark:border-neutral-700",children:[b.map(t=>e.jsxs("label",{className:"flex items-center gap-2 text-sm text-neutral-700 dark:text-neutral-300",children:[e.jsx("input",{type:"checkbox",checked:r.group_ids.includes(t.id),onChange:()=>C(t.id),className:"h-4 w-4 rounded border-neutral-300 text-brand-600 focus:ring-brand-500"}),t.name]},t.id)),b.length===0&&e.jsx("p",{className:"text-sm text-neutral-400",children:"Noch keine Berechtigungsgruppen angelegt."})]})]})]}),f&&e.jsx("p",{className:"text-sm text-red-600",children:f}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"submit",className:"rounded-md bg-brand-500 px-4 py-2 text-sm font-semibold text-white hover:bg-brand-600",children:l?"Speichern":"Anlegen"}),l&&e.jsx("button",{type:"button",onClick:p,className:"rounded-md border border-neutral-300 px-4 py-2 text-sm dark:border-neutral-700",children:"Abbrechen"})]})]})]})}export{J as default};