HifiPlanet-Website/hifi/assets/AdminUsers-hThOPEZA.js
Maaxxs c6214637e8 Collapse overlong package card bullets instead of stretching the row
Since all cards in a row share one height, a single card with long
paragraphs in its description (e.g. Limitless) made every card as tall
as that one, leaving a lot of empty space in the others. Collapsed
bullets are now clamped to three lines; normal bullets fit, long
paragraphs end with an ellipsis and the card offers "Mehr anzeigen" to
show the full text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 00:18:09 +02:00

1 line
7.4 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{b as z,r as n,j as e,a as i}from"./index-CZwY_OSZ.js";const k={username:"",password:"",is_super_admin:!1,permissions:[],group_ids:[]};function C(r){return r?new Date(r.replace(" ","T")).toLocaleString("de-DE",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"}):"Noch nie"}function P(){const{user:r,hasPermission:o}=z(),[x,y]=n.useState([]),[f,_]=n.useState([]),[p,w]=n.useState([]),[a,d]=n.useState(k),[l,h]=n.useState(null),[g,b]=n.useState(!1),[j,c]=n.useState(""),m=()=>{i.get("/admin-users").then(y),i.get("/permissions/catalog").then(_),(o("permission_groups.manage")||o("users.manage"))&&i.get("/permission-groups").then(w)};n.useEffect(m,[]);const v=t=>{h(t.id),b(t.is_primary),d({username:t.username,password:"",is_super_admin:t.is_super_admin,permissions:t.permissions,group_ids:t.groups.map(s=>s.id)})},N=()=>{h(null),b(!1),d(k)},S=t=>{d(s=>({...s,permissions:s.permissions.includes(t)?s.permissions.filter(u=>u!==t):[...s.permissions,t]}))},B=t=>{d(s=>({...s,group_ids:s.group_ids.includes(t)?s.group_ids.filter(u=>u!==t):[...s.group_ids,t]}))},E=async t=>{t.preventDefault(),c("");try{if(l)await i.put(`/admin-users/${l}`,a);else{if(a.password.length<8){c("Passwort muss mindestens 8 Zeichen lang sein");return}await i.post("/admin-users",a)}N(),m()}catch(s){c(s.message)}},A=async t=>{if(confirm("Diesen Benutzer wirklich löschen?"))try{await i.delete(`/admin-users/${t}`),m()}catch(s){alert(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-hidden 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:[x.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===(r==null?void 0:r.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:C(t.last_active_at)}),e.jsxs("td",{className:"px-4 py-2 text-right",children:[e.jsx("button",{onClick:()=>v(t),className:"mr-3 text-brand-600 hover:underline",children:"Bearbeiten"}),t.id!==(r==null?void 0:r.id)&&!t.is_primary&&e.jsx("button",{onClick:()=>A(t.id),className:"text-red-600 hover:underline",children:"Löschen"})]})]},t.id)),x.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",{onSubmit:E,className:"h-fit 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:a.username,onChange:t=>d({...a,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:a.password,onChange:t=>d({...a,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"})]}),(r==null?void 0:r.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:a.is_super_admin,disabled:g,onChange:t=>d({...a,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)"]}),g&&e.jsx("p",{className:"mt-1 text-xs text-neutral-400",children:"Der Erst-Administrator behält immer den Super-Admin-Status."})]}),!a.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:f.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:a.permissions.includes(t.key),onChange:()=>S(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:[p.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:a.group_ids.includes(t.id),onChange:()=>B(t.id),className:"h-4 w-4 rounded border-neutral-300 text-brand-600 focus:ring-brand-500"}),t.name]},t.id)),p.length===0&&e.jsx("p",{className:"text-sm text-neutral-400",children:"Noch keine Berechtigungsgruppen angelegt."})]})]})]}),j&&e.jsx("p",{className:"text-sm text-red-600",children:j}),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:N,className:"rounded-md border border-neutral-300 px-4 py-2 text-sm dark:border-neutral-700",children:"Abbrechen"})]})]})]})}export{P as default};