Files
biiproject-kit-v2/public/build/assets/Index-Bnf5l0xj.js
T

1 line
7.9 KiB
JavaScript

import{c as e,d as t,i as n,n as r,t as i}from"./app-BJ7g6sa8.js";import{t as a}from"./AuthenticatedLayout-CrB9BCoI.js";import{t as o}from"./Portal-DJbp1s68.js";import{t as s}from"./swal-DZXjpqDE.js";import{t as c}from"./Can-DIOq7dyw.js";var l=t(e(),1),u=i();function d({roles:e,permissions:t}){let i=[...new Set(t.map(e=>e.group))],[d,f]=(0,l.useState)(()=>{let t={};return e.forEach(e=>{t[e.id]=[...e.permissions]}),t}),[p,m]=(0,l.useState)({}),[h,g]=(0,l.useState)({}),[_,v]=(0,l.useState)(!1),[y,b]=(0,l.useState)(``),x=(e,t)=>{f(n=>{let r=n[e]||[],i=r.includes(t)?r.filter(e=>e!==t):[...r,t];return{...n,[e]:i}}),m(t=>({...t,[e]:!0}))},S=async e=>{g(t=>({...t,[e.id]:!0})),n.patch(`/roles/${e.id}/permissions`,{permissions:d[e.id]||[]},{preserveScroll:!0,onSuccess:()=>{m(t=>({...t,[e.id]:!1})),g(t=>({...t,[e.id]:!1})),s.success(`Saved`,`Permissions updated for "${e.name}"`)},onError:()=>{g(t=>({...t,[e.id]:!1})),s.error(`Error`,`Failed to update permissions.`)}})},C=e=>{e.preventDefault(),y.trim()&&n.post(`/roles`,{name:y.trim()},{onSuccess:()=>{v(!1),b(``),s.success(`Created`,`New role created successfully.`)},onError:()=>s.error(`Error`,`Failed to create role.`)})},w=async e=>{(await s.confirmDelete(e.name)).isConfirmed&&n.delete(`/roles/${e.id}`,{onSuccess:()=>s.success(`Deleted`,`Role "${e.name}" has been deleted.`),onError:()=>s.error(`Error`,`Failed to delete role.`)})};return(0,u.jsxs)(a,{children:[(0,u.jsx)(r,{title:`Roles & Permissions`}),(0,u.jsxs)(`div`,{className:`flex items-center justify-between mb-8 anim-down`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`h1`,{className:`text-xl font-bold text-[#3D4E4B] tracking-tight leading-none`,children:`Access Control`}),(0,u.jsx)(`p`,{className:`text-sm font-semibold text-gray-400 tracking-tight mt-2`,children:`Configure hierarchical roles and granular permissions`})]}),(0,u.jsx)(c,{ability:`role.manage`,children:(0,u.jsx)(`button`,{onClick:()=>v(!0),className:`h-10 px-6 rounded-xl bg-[#D4A017] text-white text-sm font-bold tracking-tight hover:bg-[#B88B14] transition-all shadow-lg shadow-[#D4A017]/20`,children:`New Role`})})]}),(0,u.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6 mb-8`,children:e.map((e,n)=>{let r=(d[e.id]||[]).length,i=e.name===`super-admin`;return(0,u.jsxs)(`div`,{className:`bg-white rounded-2xl border border-gray-100 p-6 shadow-sm anim-up`,style:{animationDelay:`${n*.05}s`},children:[(0,u.jsxs)(`div`,{className:`flex items-center justify-between mb-6`,children:[(0,u.jsx)(`span`,{className:`px-3 py-1 text-[10px] font-black uppercase tracking-widest rounded-lg border ${i?`bg-[#3D4E4B] text-white border-[#3D4E4B]`:`bg-white text-gray-500 border-gray-100`}`,children:e.name}),!i&&(0,u.jsx)(c,{ability:`role.manage`,children:(0,u.jsx)(`button`,{onClick:()=>w(e),className:`w-8 h-8 rounded-lg flex items-center justify-center text-gray-300 hover:text-red-500 hover:bg-red-50 transition-all`,children:(0,u.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2.5,children:(0,u.jsx)(`path`,{d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})})})]}),(0,u.jsxs)(`div`,{className:`text-3xl font-black text-[#3D4E4B] tracking-tighter`,children:[r,(0,u.jsxs)(`span`,{className:`text-sm text-gray-200 font-bold ml-1 tracking-normal`,children:[`/ `,t.length,` perms`]})]}),(0,u.jsxs)(`div`,{className:`text-[10px] font-black text-gray-300 uppercase tracking-widest mt-2`,children:[e.users_count,` Total Active Users`]}),(0,u.jsx)(`div`,{className:`mt-6 h-1.5 bg-gray-50 rounded-full overflow-hidden`,children:(0,u.jsx)(`div`,{className:`h-full bg-[#D4A017] transition-all duration-700`,style:{width:`${r/t.length*100}%`}})}),p[e.id]&&(0,u.jsx)(`button`,{onClick:()=>S(e),disabled:h[e.id],className:`mt-6 w-full h-10 bg-[#3D4E4B] text-white text-xs font-black uppercase tracking-widest rounded-xl anim-fade shadow-lg shadow-[#3D4E4B]/20 disabled:opacity-60`,children:h[e.id]?`Saving…`:`Apply Changes`})]},e.id)})}),(0,u.jsxs)(`div`,{className:`bg-white rounded-2xl border border-gray-100 shadow-sm overflow-hidden mb-20 anim-up`,style:{animationDelay:`0.2s`},children:[(0,u.jsx)(`div`,{className:`px-8 py-6 border-b border-gray-50 bg-gray-50/20`,children:(0,u.jsx)(`h3`,{className:`text-sm font-black text-[#3D4E4B] uppercase tracking-widest`,children:`Permissions Matrix`})}),(0,u.jsx)(`div`,{className:`overflow-x-auto custom-scrollbar`,children:(0,u.jsxs)(`table`,{className:`w-full text-left border-collapse`,children:[(0,u.jsx)(`thead`,{children:(0,u.jsxs)(`tr`,{className:`bg-white`,children:[(0,u.jsx)(`th`,{className:`px-8 py-5 text-[10px] font-black text-gray-400 uppercase tracking-widest w-72 sticky left-0 bg-white z-10 border-b border-gray-50`,children:`Functional Permission`}),e.map(e=>(0,u.jsx)(`th`,{className:`px-8 py-5 text-center text-[10px] font-black text-[#3D4E4B] uppercase tracking-widest border-b border-gray-50 bg-gray-50/30`,children:e.name},e.id))]})}),(0,u.jsx)(`tbody`,{className:`divide-y divide-gray-50`,children:i.map(n=>(0,u.jsxs)(l.Fragment,{children:[(0,u.jsx)(`tr`,{className:`bg-gray-50/10`,children:(0,u.jsx)(`td`,{colSpan:e.length+1,className:`px-8 py-3`,children:(0,u.jsxs)(`span`,{className:`text-[10px] font-black text-[#D4A017] uppercase tracking-[0.2em]`,children:[n,` Module`]})})}),t.filter(e=>e.group===n).map(t=>(0,u.jsxs)(`tr`,{className:`hover:bg-gray-50/30 transition-colors`,children:[(0,u.jsxs)(`td`,{className:`px-8 py-4 sticky left-0 bg-white group border-r border-gray-50/50`,children:[(0,u.jsx)(`div`,{className:`text-sm font-bold text-[#3D4E4B] tracking-tight capitalize`,children:t.name.replace(`.`,` `)}),(0,u.jsx)(`div`,{className:`text-[9px] text-gray-300 font-bold uppercase tracking-widest mt-1`,children:t.name})]}),e.map(e=>{let n=(d[e.id]||[]).includes(t.name),r=e.name===`super-admin`;return(0,u.jsx)(`td`,{className:`px-8 py-4 text-center`,children:(0,u.jsx)(`button`,{onClick:()=>!r&&x(e.id,t.name),disabled:r,className:`w-8 h-8 rounded-xl transition-all flex items-center justify-center mx-auto border-2 ${r?`bg-gray-50 text-[#3D4E4B] border-gray-100 opacity-40`:n?`bg-[#3D4E4B] text-white shadow-lg shadow-[#3D4E4B]/20 border-[#3D4E4B]`:`bg-white text-gray-100 hover:text-[#D4A017] border-gray-100 hover:border-[#D4A017]`}`,children:n?(0,u.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:4,children:(0,u.jsx)(`path`,{d:`M5 13l4 4L19 7`})}):(0,u.jsx)(`div`,{className:`w-1.5 h-1.5 rounded-full bg-current`})})},`${e.id}-${t.id}`)})]},t.id))]},n))})]})})]}),_&&(0,u.jsx)(o,{children:(0,u.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center p-4 bg-[#3D4E4B]/60 backdrop-blur-md anim-fade`,children:(0,u.jsxs)(`div`,{className:`relative bg-white rounded-3xl shadow-2xl w-full max-w-sm overflow-hidden anim-zoom border border-gray-100`,children:[(0,u.jsx)(`div`,{className:`px-8 py-6 border-b border-gray-50`,children:(0,u.jsx)(`h3`,{className:`text-base font-black text-[#3D4E4B] tracking-tight`,children:`Provision New Role`})}),(0,u.jsxs)(`form`,{onSubmit:C,className:`p-8 space-y-8`,children:[(0,u.jsxs)(`div`,{className:`space-y-2`,children:[(0,u.jsx)(`label`,{className:`text-xs font-black text-gray-400 uppercase tracking-widest ml-1`,children:`Internal Role Name`}),(0,u.jsx)(`input`,{type:`text`,value:y,onChange:e=>b(e.target.value),placeholder:`e.g. auditor`,className:`input-field`,required:!0,autoFocus:!0})]}),(0,u.jsxs)(`div`,{className:`flex gap-4`,children:[(0,u.jsx)(`button`,{type:`button`,onClick:()=>v(!1),className:`flex-1 h-11 bg-white text-gray-400 text-xs font-black uppercase tracking-widest border border-gray-100 rounded-2xl hover:bg-gray-50 transition-all`,children:`Cancel`}),(0,u.jsx)(`button`,{type:`submit`,className:`flex-1 h-11 bg-[#3D4E4B] text-white text-xs font-black uppercase tracking-widest rounded-2xl hover:bg-[#2D3A38] transition-all shadow-lg shadow-[#3D4E4B]/20`,children:`Provision`})]})]})]})})})]})}export{d as default};