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

1 line
16 KiB
JavaScript

import{c as e,d as t,i as n,n as r,o as i,t as a}from"./app-DqWc0bf2.js";import{t as o}from"./AuthenticatedLayout-BmwijjRz.js";import{n as s,t as c}from"./lodash-B3e-Jfxa.js";import{t as l}from"./Portal-DmZ4v-Fi.js";import{t as u}from"./swal-OIXtGkLz.js";import{t as d}from"./Can-3RHznHg6.js";var f=t(e(),1),p=t(c(),1),m=a();function h({user:e,availableRoles:t,onClose:r}){let i=e?.id?(e.roles||[]).map(e=>e.name||e):[],[a,o]=(0,f.useState)({first_name:e?.first_name||``,last_name:e?.last_name||``,email:e?.email||``,password:``,status:e?.status||`active`,roles:i}),[s,c]=(0,f.useState)({}),[d,p]=(0,f.useState)(!1),h=()=>{let t={};return a.first_name.trim()||(t.first_name=`Required`),a.last_name.trim()||(t.last_name=`Required`),a.email.trim()?/\S+@\S+\.\S+/.test(a.email)||(t.email=`Invalid`):t.email=`Required`,!e?.id&&!a.password&&(t.password=`Required`),c(t),Object.keys(t).length===0},g=e=>{o(t=>({...t,roles:t.roles.includes(e)?t.roles.filter(t=>t!==e):[...t.roles,e]}))};return(0,m.jsx)(l,{children:(0,m.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,m.jsx)(`div`,{className:`bg-white w-full max-w-lg rounded-2xl shadow-2xl overflow-hidden anim-zoom border border-gray-100`,children:(0,m.jsxs)(`div`,{className:`p-8`,children:[(0,m.jsxs)(`div`,{className:`flex items-center justify-between mb-6`,children:[(0,m.jsxs)(`div`,{children:[(0,m.jsx)(`h2`,{className:`text-xl font-bold text-[#3D4E4B] tracking-tight`,children:e?.id?`Edit user`:`New user`}),(0,m.jsx)(`p`,{className:`text-sm text-gray-400 font-medium mt-1`,children:`Fill in the user details below.`})]}),(0,m.jsx)(`button`,{onClick:r,className:`p-2 hover:bg-gray-50 rounded-xl transition-colors`,children:(0,m.jsx)(`svg`,{className:`w-5 h-5 text-gray-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2.5,children:(0,m.jsx)(`path`,{d:`M6 18L18 6M6 6l12 12`})})})]}),(0,m.jsxs)(`form`,{onSubmit:t=>{if(t.preventDefault(),!h())return;p(!0);let i={...a};e?.id?n.patch(`/users/${e.id}`,i,{preserveScroll:!0,onSuccess:()=>{r(),u.success(`Updated`,`User updated successfully.`)},onError:e=>{c(e),p(!1)}}):n.post(`/users`,i,{preserveScroll:!0,onSuccess:()=>{r(),u.success(`Created`,`New user created successfully.`)},onError:e=>{c(e),p(!1)}})},className:`space-y-6`,children:[(0,m.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,m.jsxs)(`div`,{className:`space-y-2`,children:[(0,m.jsx)(`label`,{className:`text-xs font-semibold text-gray-500 tracking-tight px-1`,children:`First Name`}),(0,m.jsx)(`input`,{type:`text`,value:a.first_name,onChange:e=>o({...a,first_name:e.target.value}),className:`input-field${s.first_name?` is-error`:``}`,placeholder:`John`,required:!0}),s.first_name&&(0,m.jsx)(`p`,{className:`text-[10px] text-red-500 font-bold ml-1`,children:s.first_name})]}),(0,m.jsxs)(`div`,{className:`space-y-2`,children:[(0,m.jsx)(`label`,{className:`text-xs font-semibold text-gray-500 tracking-tight px-1`,children:`Last Name`}),(0,m.jsx)(`input`,{type:`text`,value:a.last_name,onChange:e=>o({...a,last_name:e.target.value}),className:`input-field${s.last_name?` is-error`:``}`,placeholder:`Doe`,required:!0}),s.last_name&&(0,m.jsx)(`p`,{className:`text-[10px] text-red-500 font-bold ml-1`,children:s.last_name})]})]}),(0,m.jsxs)(`div`,{className:`space-y-2`,children:[(0,m.jsx)(`label`,{className:`text-xs font-semibold text-gray-500 tracking-tight px-1`,children:`Email Address`}),(0,m.jsx)(`input`,{type:`email`,value:a.email,onChange:e=>o({...a,email:e.target.value}),className:`input-field${s.email?` is-error`:``}`,placeholder:`john.doe@example.com`,required:!0}),s.email&&(0,m.jsx)(`p`,{className:`text-[10px] text-red-500 font-bold ml-1`,children:s.email})]}),!e?.id&&(0,m.jsxs)(`div`,{className:`space-y-2`,children:[(0,m.jsx)(`label`,{className:`text-xs font-semibold text-gray-500 tracking-tight px-1`,children:`Initial Password`}),(0,m.jsx)(`input`,{type:`password`,value:a.password,onChange:e=>o({...a,password:e.target.value}),className:`input-field`,placeholder:`••••••••`,required:!0})]}),(0,m.jsxs)(`div`,{className:`space-y-3`,children:[(0,m.jsx)(`label`,{className:`text-xs font-semibold text-gray-500 tracking-tight px-1`,children:`Assigned Roles`}),(0,m.jsx)(`div`,{className:`flex flex-wrap gap-2 p-1`,children:t.map(e=>(0,m.jsx)(`button`,{type:`button`,onClick:()=>g(e),className:`px-4 py-2 rounded-xl text-xs font-bold tracking-tight transition-all border ${a.roles.includes(e)?`bg-[#3D4E4B] text-white border-[#3D4E4B] shadow-md shadow-[#3D4E4B]/20`:`bg-white text-gray-400 border-gray-100 hover:border-gray-200`}`,children:e},e))})]}),(0,m.jsxs)(`div`,{className:`pt-4 flex gap-3`,children:[(0,m.jsx)(`button`,{type:`button`,onClick:r,className:`flex-1 h-9 bg-white border border-gray-200 rounded-xl text-sm font-bold text-gray-400 hover:bg-gray-50 transition-all`,children:`Cancel`}),(0,m.jsx)(`button`,{type:`submit`,disabled:d,className:`flex-1 h-9 bg-[#3D4E4B] text-white rounded-xl text-sm font-bold hover:bg-[#2D3A38] transition-all shadow-lg shadow-[#3D4E4B]/20 flex items-center justify-center gap-2 disabled:opacity-60`,children:d?(0,m.jsx)(`div`,{className:`w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin`}):e?.id?`Save changes`:`Create user`})]})]})]})})})})}function g({users:e,availableRoles:t,filters:a}){let{permissions:c}=i().props.auth,[g,_]=(0,f.useState)(!1),[v,y]=(0,f.useState)(null),[b,x]=(0,f.useState)(!1),[S,C]=(0,f.useState)([]),[w,T]=(0,f.useState)({search:a.search||``,status:a.status||``,role:a.role||``,trashed:a.trashed||``,per_page:a.per_page||15,sort_field:a.sort_field||`created_at`,sort_direction:a.sort_direction||`desc`});f.useEffect(()=>{T({search:a.search||``,status:a.status||``,role:a.role||``,sort_field:a.sort_field||`created_at`,sort_direction:a.sort_direction||`desc`,per_page:a.per_page||15,trashed:a.trashed||``})},[a]);let E=(0,f.useCallback)(p.default.debounce(e=>{x(!0),n.get(`/users`,e,{preserveState:!0,preserveScroll:!0,replace:!0,only:[`users`,`filters`],onFinish:()=>x(!1)})},400),[]),D=(e,t)=>{let n={...w,[e]:t};T(n);let r={...n,page:1};C([]),E(r)},O=e=>{let t={archive:{url:route(`users.bulk-archive`),text:`Archive`},restore:{url:route(`users.bulk-restore`),text:`Restore`},delete:{url:route(`users.bulk-force-delete`),text:`Delete`}}[e];u.confirm(`${t.text} Selected?`,`Are you sure you want to ${e} ${S.length} users?`,t.text).then(r=>{r.isConfirmed&&n.post(t.url,{ids:S},{preserveScroll:!0,onSuccess:()=>{C([]),u.success(`Success`,`${S.length} users ${e}d successfully.`)}})})},k=[{header:`User`,accessorKey:`first_name`,sortable:!0,cell:e=>(0,m.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,m.jsx)(`div`,{className:`w-10 h-10 rounded-xl flex items-center justify-center text-white text-sm font-bold overflow-hidden shrink-0 ${e.deleted_at?`bg-gray-400`:`bg-[#3D4E4B]`}`,children:e.avatar_url?(0,m.jsx)(`img`,{src:e.avatar_url,className:`w-full h-full object-cover`}):`${e.first_name?.charAt(0)}${e.last_name?.charAt(0)}`}),(0,m.jsxs)(`div`,{children:[(0,m.jsxs)(`div`,{className:`text-sm font-bold tracking-tight ${e.deleted_at?`text-gray-400 line-through`:`text-[#3D4E4B]`}`,children:[e.first_name,` `,e.last_name]}),(0,m.jsx)(`div`,{className:`text-xs text-gray-400 font-semibold mt-0.5`,children:e.email})]})]})},{header:`Roles`,accessorKey:`roles`,cell:e=>(0,m.jsx)(`div`,{className:`flex gap-1.5`,children:e.roles?.length?e.roles.map(t=>(0,m.jsx)(`span`,{className:`px-2 py-0.5 text-sm font-bold tracking-tight bg-white border border-gray-100 rounded-md ${e.deleted_at?`text-gray-300`:`text-gray-500`}`,children:t.name||t},t.name||t)):(0,m.jsx)(`span`,{className:`text-sm font-semibold text-gray-300 italic tracking-tight`,children:`Unassigned`})})},{header:`Status`,accessorKey:`status`,sortable:!0,cell:e=>(0,m.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-bold tracking-tight border border-gray-100 ${e.deleted_at?`text-gray-300 bg-gray-50/50`:e.status===`active`?`text-green-600 bg-white border-green-100`:`text-gray-400 bg-white`}`,children:[(0,m.jsx)(`span`,{className:`w-1 h-1 rounded-full ${e.deleted_at?`bg-gray-300`:e.status===`active`?`bg-green-500`:`bg-gray-300`}`}),e.deleted_at?`Archived`:e.status]})},{header:w.trashed===`only`?`Archived at`:`Joined`,accessorKey:w.trashed===`only`?`deleted_at`:`created_at`,sortable:!0,cell:e=>(0,m.jsx)(`span`,{className:`text-sm font-semibold text-gray-400 tracking-tight`,children:new Date(e[e.deleted_at?`deleted_at`:`created_at`]).toLocaleDateString(`en-US`,{day:`2-digit`,month:`short`,year:`numeric`})})}],A=w.trashed===`only`;return(0,m.jsxs)(o,{children:[(0,m.jsx)(r,{title:`Users`}),(0,m.jsxs)(`div`,{className:`flex items-center justify-between mb-8 anim-down`,children:[(0,m.jsxs)(`div`,{children:[(0,m.jsx)(`h1`,{className:`text-xl font-bold text-[#3D4E4B] tracking-tight leading-none`,children:`User Management`}),(0,m.jsx)(`p`,{className:`text-sm font-semibold text-gray-400 tracking-tight mt-2`,children:`Maintain and configure the global user registry`})]}),(0,m.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,m.jsxs)(`div`,{className:`relative w-[240px]`,children:[(0,m.jsx)(`svg`,{className:`absolute left-3.5 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400 pointer-events-none`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2.5,children:(0,m.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z`})}),(0,m.jsx)(`input`,{type:`text`,placeholder:`Search users…`,value:w.search,onChange:e=>D(`search`,e.target.value),className:`w-full h-11 pl-10 pr-4 rounded-2xl border border-gray-100 bg-white text-sm font-semibold text-gray-700 placeholder-gray-400 focus:outline-none focus:border-[#D4A017] focus:ring-4 focus:ring-[#D4A017]/5 transition-all shadow-sm`})]}),!A&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(`select`,{value:w.status,onChange:e=>D(`status`,e.target.value),className:`h-11 px-4 rounded-2xl border border-gray-100 bg-white text-sm font-semibold text-gray-700 focus:outline-none focus:border-[#D4A017] focus:ring-4 focus:ring-[#D4A017]/5 transition-all shadow-sm cursor-pointer min-w-[140px]`,children:[(0,m.jsx)(`option`,{value:``,children:`All Status`}),(0,m.jsx)(`option`,{value:`active`,children:`Active`}),(0,m.jsx)(`option`,{value:`inactive`,children:`Inactive`})]}),(0,m.jsxs)(`select`,{value:w.role,onChange:e=>D(`role`,e.target.value),className:`h-11 px-4 rounded-2xl border border-gray-100 bg-white text-sm font-semibold text-gray-700 focus:outline-none focus:border-[#D4A017] focus:ring-4 focus:ring-[#D4A017]/5 transition-all shadow-sm cursor-pointer min-w-[140px]`,children:[(0,m.jsx)(`option`,{value:``,children:`All Roles`}),t.map(e=>(0,m.jsx)(`option`,{value:e,children:e},e))]})]}),!A&&(0,m.jsx)(`div`,{className:`flex items-center gap-2 border-l border-gray-100 pl-3`,children:(0,m.jsxs)(`a`,{href:route(`users.export`),className:`flex items-center gap-2 h-11 px-4 rounded-2xl bg-white border border-gray-100 text-[#3D4E4B] text-sm font-bold hover:bg-gray-50 transition-all shadow-sm`,children:[(0,m.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2.5,children:(0,m.jsx)(`path`,{d:`M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4`})}),`Export`]})}),!A&&(0,m.jsx)(d,{ability:`user.create`,children:(0,m.jsx)(`button`,{onClick:()=>{y(null),_(!0)},className:`flex items-center gap-2 h-11 px-6 rounded-2xl bg-[#D4A017] text-white text-sm font-bold hover:bg-[#B88B14] transition-all shadow-lg shadow-[#D4A017]/20 hover:-translate-y-0.5 active:translate-y-0 ml-1`,children:`New user`})})]})]}),(0,m.jsx)(`div`,{className:`flex items-center justify-between mb-5 anim-down`,style:{animationDelay:`0.05s`},children:(0,m.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-gray-100 w-full`,children:[(0,m.jsxs)(`button`,{type:`button`,onClick:()=>D(`trashed`,``),className:`relative pb-3 px-1 mr-4 text-sm font-bold tracking-tight transition-colors ${A?`text-gray-400 hover:text-[#3D4E4B]`:`text-[#3D4E4B]`}`,children:[`Active users`,!A&&(0,m.jsx)(`span`,{className:`absolute bottom-0 left-0 w-full h-0.5 bg-[#D4A017] rounded-t-full`})]}),(0,m.jsxs)(`button`,{type:`button`,onClick:()=>D(`trashed`,`only`),className:`relative pb-3 px-1 text-sm font-bold tracking-tight transition-colors ${A?`text-[#3D4E4B]`:`text-gray-400 hover:text-[#3D4E4B]`}`,children:[`Archived`,A&&(0,m.jsx)(`span`,{className:`absolute bottom-0 left-0 w-full h-0.5 bg-red-400 rounded-t-full`})]}),A&&(0,m.jsxs)(`span`,{className:`ml-auto mb-2 flex items-center gap-1.5 text-xs font-semibold text-amber-600 bg-amber-50 border border-amber-100 px-2.5 py-1 rounded-lg`,children:[(0,m.jsx)(`svg`,{className:`w-3 h-3`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2.5,children:(0,m.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12 9v2m0 4h.01M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z`})}),`Archived users cannot log in`]})]})}),(0,m.jsx)(`div`,{className:`anim-up relative`,style:{animationDelay:`0.08s`},children:(0,m.jsx)(s,{data:e.data,columns:k,meta:e.meta,links:e.links,filters:w,onSort:(e,t)=>{D(`sort_field`,e),D(`sort_direction`,t)},isLoading:b,selectedIds:S,onSelectionChange:C,canEdit:!A&&c.includes(`user.edit`),emptyAction:!A&&c.includes(`user.create`)?(0,m.jsx)(`button`,{onClick:()=>{y(null),_(!0)},className:`h-9 px-5 rounded-xl bg-[#D4A017] text-white text-xs font-bold hover:bg-[#B88B14] transition-all shadow-md shadow-[#D4A017]/20`,children:`Add first user`}):void 0,onEdit:e=>{y(e),_(!0)},onDelete:A?void 0:e=>{u.confirm(`Archive user?`,`Move ${e.first_name} ${e.last_name} to the archived list?`,`Archive`).then(t=>{t.isConfirmed&&n.delete(`/users/${e.id}`,{preserveScroll:!0,onSuccess:()=>u.success(`Archived`,`User archived successfully.`)})})},onRestore:A?e=>{u.confirm(`Restore user?`,`Restore ${e.first_name} ${e.last_name} to active status?`,`Restore`).then(t=>{t.isConfirmed&&n.post(`/users/${e.id}/restore`,{},{preserveScroll:!0,onSuccess:()=>u.success(`Restored`,`User restored successfully.`)})})}:void 0,onPermanentDelete:A?e=>{u.confirmDelete(`${e.first_name} ${e.last_name}`).then(t=>{t.isConfirmed&&n.delete(`/users/${e.id}/force-delete`,{preserveScroll:!0,onSuccess:()=>u.success(`Deleted`,`User permanently deleted.`)})})}:void 0})}),g&&(0,m.jsx)(h,{user:v,availableRoles:t,onClose:()=>{_(!1),y(null)}}),(0,m.jsx)(l,{children:(0,m.jsx)(`div`,{className:`fixed bottom-8 left-1/2 -translate-x-1/2 z-40 transition-all duration-500 ${S.length>0?`translate-y-0 opacity-100`:`translate-y-20 opacity-0 pointer-events-none`}`,children:(0,m.jsxs)(`div`,{className:`bg-[#3D4E4B] rounded-2xl shadow-2xl px-6 py-4 flex items-center gap-6 border border-white/10 backdrop-blur-xl`,children:[(0,m.jsxs)(`div`,{className:`flex items-center gap-3 pr-6 border-r border-white/10`,children:[(0,m.jsx)(`span`,{className:`w-8 h-8 rounded-lg bg-white/10 flex items-center justify-center text-white text-xs font-bold`,children:S.length}),(0,m.jsx)(`span`,{className:`text-white text-sm font-bold tracking-tight`,children:`Items selected`})]}),(0,m.jsxs)(`div`,{className:`flex items-center gap-2`,children:[A?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(`button`,{onClick:()=>O(`restore`),className:`h-10 px-5 rounded-xl bg-green-500 text-white text-xs font-bold hover:bg-green-600 transition-all flex items-center gap-2`,children:[(0,m.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2.5,children:(0,m.jsx)(`path`,{d:`M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15`})}),`Bulk Restore`]}),(0,m.jsxs)(`button`,{onClick:()=>O(`delete`),className:`h-10 px-5 rounded-xl bg-red-500 text-white text-xs font-bold hover:bg-red-600 transition-all flex items-center gap-2`,children:[(0,m.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2.5,children:(0,m.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`})}),`Bulk Delete`]})]}):(0,m.jsxs)(`button`,{onClick:()=>O(`archive`),className:`h-10 px-5 rounded-xl bg-white/10 text-white text-xs font-bold hover:bg-white/20 transition-all flex items-center gap-2`,children:[(0,m.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2.5,children:(0,m.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`})}),`Bulk Archive`]}),(0,m.jsx)(`button`,{onClick:()=>C([]),className:`h-10 px-4 text-white/40 text-xs font-bold hover:text-white transition-colors`,children:`Cancel`})]})]})})})]})}export{g as default};