# Conflicts: # hifi/assets/AccountSettings-3Az7PIEf.js # hifi/assets/AccountSettings-C7P_TaTL.js # hifi/assets/AccountSettings-CfY49TlQ.js # hifi/assets/AdminUsers-C1zi3a_m.js # hifi/assets/Brands-V9s4vz2i.js # hifi/assets/ContactRequests-BcF_HxL3.js # hifi/assets/Dashboard-m6lX2kWI.js # hifi/assets/DatabaseSettings-pQejbEjR.js # hifi/assets/Downloads-DCZm2dP9.js # hifi/assets/EmailSettings-B_RqPmc9.js # hifi/assets/EmailSettings-DixrL0D8.js # hifi/assets/EmailSettings-VadOa5J3.js # hifi/assets/ExportImportSettings-Bkwm__tE.js # hifi/assets/Faqs-CDIDxeRo.js # hifi/assets/GalleryBrands-CeGo7QXi.js # hifi/assets/GalleryPhotos-NPKQDZMi.js # hifi/assets/GalleryProjects-CfB-fA4x.js # hifi/assets/HomeSections-BzNKNMho.js # hifi/assets/ImageUploadField-B8P2oQZ9.js # hifi/assets/ImageUploadField-DyLcJG5-.js # hifi/assets/ImageUploadField-oqjVVSSG.js # hifi/assets/LegalSettings-BnY85Lz7.js # hifi/assets/LegalSettings-CRgpL0dP.js # hifi/assets/LegalSettings-DGN-Kl_a.js # hifi/assets/Login-CFL8bhtC.js # hifi/assets/Login-Dc1nFqtx.js # hifi/assets/Login-pbnF9xt-.js # hifi/assets/MaintenanceSettings-CFGyPBuq.js # hifi/assets/MaintenanceSettings-DhcTJBUJ.js # hifi/assets/MaintenanceSettings-DsGBefLo.js # hifi/assets/Models-CyjYxQOO.js # hifi/assets/Packages-6JjKaOj1.js # hifi/assets/Partners-BRwobp6H.js # hifi/assets/PermissionGroups-CW64DGq9.js # hifi/assets/PermissionGroups-DI5xJ6TD.js # hifi/assets/PermissionGroups-_i9KMBTo.js # hifi/assets/ResetSettings-Bm64tgsK.js # hifi/assets/RichTextEditor-DJwdsoJ6.js # hifi/assets/RichTextEditor-DTscIhNf.js # hifi/assets/RichTextEditor-DcSNZ4jD.js # hifi/assets/Services-BTvu0ymy.js # hifi/assets/SettingsLayout-C5JQlIqD.js # hifi/assets/SetupWizard-BHY_FJd_.js # hifi/assets/SetupWizard-Cu-s4Wuc.js # hifi/assets/SetupWizard-DcHkEIZ7.js # hifi/assets/TextStyleWidget-BZdrb1Dr.js # hifi/assets/TextStyleWidget-CkwixV2h.js # hifi/assets/TextStyleWidget-Czb7ujSZ.js # hifi/assets/UpdateSettings-Ce5oqncR.js # hifi/assets/WebsiteSettings-B7CzBT2R.js # hifi/assets/eye-CZFeBsZS.js # hifi/assets/eye-YlN_9rkm.js # hifi/assets/eye-jJN30JHV.js # hifi/assets/iconRegistry-BJRytynd.js # hifi/assets/iconRegistry-C8CVLtUq.js # hifi/assets/iconRegistry-DUWamfSa.js # hifi/assets/index-QV-Szw5n.js # hifi/assets/trash-2-CQGOvKRj.js # hifi/assets/trash-2-CwY7wd8m.js # hifi/assets/trash-2-fu7u5OTF.js # hifi/index.html
1 line
7.8 KiB
JavaScript
1 line
7.8 KiB
JavaScript
import{h as R,r as n,o as I,p as L,j as e,c}from"./index-Tg8iNBwT.js";const o={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 q(){const{user:a,hasPermission:h}=R(),[g,w]=n.useState([]),[_,S]=n.useState([]),[b,B]=n.useState([]),[r,d]=n.useState(o),[l,j]=n.useState(null),[N,k]=n.useState(!1),[f,u]=n.useState(""),[z,y]=n.useState(o),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(o),y(o)},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(),u("");try{if(l)await c.put(`/admin-users/${l}`,r);else{if(r.password.length<8){u("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){u(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{q as default};
|