PageSourceSearch

https://app.backstagebaton.com/app/assets/RolesAccessPage-C1Wbrfrt.js

js backstagebaton.com collected 2026-10-07 08:50:36 UTC 14,499 bytes, 1 lines download raw bytes

1import{c as J,a as ie,r as i,t as Q,j as e,B as d,L as le,M as oe,E as N,u as ce,h as de,D as _,ae as me,af as xe}from"./index-_aijvlUq.js";import{m as x}from"./members-I3UAoZ9P.js";import{P as ue}from"./PageHeader-DCofr6qo.js";import{I as se}from"./Input-ysTyZFq5.js";import{a as pe}from"./Skeleton-B3Wj6cNd.js";import{C as he}from"./ConfirmDialog-CODvETNM.js";import{E as X}from"./EmptyState-CPGKooqj.js";import{M as ge}from"./MemberMultiPicker-DdjcDFao.js";import{g as fe}from"./groups-DEn_1gGo.js";import"./downscaleImage-qyGK-a3D.js";const I=g=>[g.firstName,g.lastName].filter(Boolean).join(" ");function ye(){const g=J(s=>s.showSuccess),f=J(s=>s.showError),{canFully:R}=ie(),A=R("groups:manage"),v=R("members:update"),[z,O]=i.useState(null),[H,y]=i.useState(()=>new Set),[u,w]=i.useState(null),[C,$]=i.useState(null),[c,P]=i.useState(()=>new Set),[k,E]=i.useState(!1),[p,L]=i.useState(null),[M,U]=i.useState(!1),l=i.useCallback(()=>x.getTeamAssignments().then(s=>O(Array.isArray(s)?s:[])).catch(()=>{O([]),f(Q("teams"))}),[f]);i.useEffect(()=>{l()},[l]);function D(s){y(n=>{const r=new Set(n);return r.has(s)?r.delete(s):r.add(s),r})}function S(s){P(new Set),w(s),C||x.list({status:"active",limit:500}).then(n=>$(Array.isArray(n)?n:n?.members||n?.data||[])).catch(()=>{$([]),f(Q("members"))})}async function T(){if(!(!u||c.size===0)){E(!0);try{for(const s of c)await x.setTeam(s,u.id,!0);g(`${c.size===1?"1 person":`${c.size} people`} added to ${u.name}.`),w(null)}catch(s){f(s?.message||N)}finally{E(!1),l()}}}async function B(s,n){try{await x.setTeam(n.id,s.id,!1),g(`${I(n)} taken off ${s.name}.`,{action:{label:"Undo",fn:()=>x.setTeam(n.id,s.id,!0).then(l).catch(r=>f(r?.message||N))}}),l()}catch(r){f(r?.message||N)}}async function V(s){try{await x.setDriverDocuments(s.id,!0),g(`${I(s)}: documents on file.`),l()}catch(n){f(n?.message||N)}}async function W(s){s.preventDefault();const n=(p||"").trim();if(n){E(!0);try{const r=await fe.create({name:n,memberIds:[],isTeam:!0,isPaid:M});g(`${n} is a team. Add its people.`),L(null),U(!1),await l(),r?.id&&y(m=>new Set(m).add(r.id))}catch(r){f(r?.message||N)}finally{E(!1)}}}return z===null?null:e.jsxs("section",{className:"mt-8","aria-labelledby":"teams-heading","data-testid":"teams-panel",children:[e.jsxs("div",{className:"flex flex-wrap items-end gap-3 mb-3",children:[e.jsxs("div",{className:"flex-1 min-w-[14rem]",children:[e.jsx("h2",{id:"teams-heading",className:"text-sm font-semibold text-gray-500 uppercase tracking-wide",children:"Teams"}),e.jsx("p",{className:"text-sm text-gray-600 mt-1",children:"Teams say which jobs people can do, like driving. A Help wanted job can ask for just one team. A team gives no access."})]}),A&&p===null&&e.jsx(d,{type:"button",variant:"secondary",size:"md",onClick:()=>L(""),children:"New team"})]}),p!==null&&e.jsxs("form",{onSubmit:W,className:"bg-white rounded-xl border border-gray-200 p-6 mb-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-4",children:"New team"}),e.jsx(se,{label:"Team name",placeholder:"e.g. Transport",value:p,onChange:s=>L(s.target.value),maxLength:80,required:!0,autoFocus:!0}),e.jsxs("label",{className:"flex items-start gap-3 py-1 mt-3",children:[e.jsx("input",{type:"checkbox",className:"mt-0.5 rounded border-gray-300 text-band-600 focus:ring-band-500 h-5 w-5",checked:M,onChange:s=>U(s.target.checked)}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-medium text-gray-800",children:"This team is paid for its jobs"}),e.jsx("span",{className:"block text-xs text-gray-500",children:"For paid work, like driving the trailer. Its Help wanted jobs count no volunteer hours."})]})]}),e.jsxs("div",{className:"flex gap-2 pt-2 mt-2",children:[e.jsx(d,{type:"submit",variant:"primary",isLoading:k,disabled:!p.trim(),children:"Create"}),e.jsx(d,{type:"button",variant:"ghost",onClick:()=>L(null),disabled:k,children:"Cancel"})]})]}),z.length===0&&p===null?e.jsx(X,{card:!0,size:"compact",title:"No teams yet."}):e.jsx("div",{className:"space-y-3",children:z.map(s=>{const n=H.has(s.id),r=s.members.map(I);return e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200","data-testid":`team-${s.id}`,children:[e.jsx("h3",{className:"m-0",children:e.jsx(d,{type:"button",variant:"ghost","aria-expanded":n,onClick:()=>D(s.id),className:"w-full !px-5 !py-4 text-left min-h-[2.75rem] [&>span]:w-full [&>span]:!justify-start",children:e.jsxs("span",{className:"flex flex-wrap items-center gap-x-3 gap-y-0.5 w-full min-w-0",children:[e.jsx("span",{className:"text-sm font-semibold text-gray-900 shrink-0",children:s.name}),s.isPaid&&e.jsx("span",{className:"text-xs font-medium text-gray-700 bg-gray-100 px-1.5 py-0.5 rounded shrink-0",children:"Paid team"}),e.jsx("span",{className:"order-last basis-full sm:order-none sm:basis-0 sm:flex-1 truncate text-sm text-gray-500",children:r.length===0?"N
1o one yet":`${r.length===1?"1 person":`${r.length} people`}: ${r.join(", ")}`}),e.jsx("svg",{"aria-hidden":"true",className:`ml-auto h-4 w-4 shrink-0 text-gray-400 transition-transform ${n?"rotate-180":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 9l-7 7-7-7"})})]})})}),n&&e.jsxs("div",{className:"px-5 pb-5",children:[s.members.length===0?e.jsx(X,{size:"compact",title:"No one on this team yet."}):e.jsx("ul",{className:"divide-y divide-gray-100 border-t border-gray-100",children:s.members.map(m=>e.jsxs("li",{className:"flex flex-wrap items-center gap-2 py-2",children:[e.jsx(le,{to:`/members/${m.id}`,className:"flex-1 min-w-0 text-base text-gray-900 hover:text-brand-primary hover:underline truncate",children:I(m)}),s.isPaid&&!m.driverDocumentsOnFile&&e.jsx("span",{className:"text-sm font-medium text-amber-800 whitespace-nowrap",children:"No documents on file"}),s.isPaid&&!m.driverDocumentsOnFile&&v&&e.jsx(d,{type:"button",variant:"ghost",size:"sm",className:"min-h-[2.75rem]",onClick:()=>V(m),"aria-label":`Mark documents on file for ${I(m)}`,children:"Mark on file"}),v&&e.jsx(d,{type:"button",variant:"ghost",size:"sm",className:"min-h-[2.75rem]",onClick:()=>B(s,m),"aria-label":`Remove ${I(m)} from ${s.name}`,children:"Remove"})]},m.id))}),v&&e.jsx("div",{className:"flex gap-2 pt-3",children:e.jsx(d,{type:"button",variant:"secondary",size:"sm",className:"min-h-[2.75rem]",onClick:()=>S(s),children:"Add people…"})})]})]},s.id)})}),e.jsx(oe,{isOpen:!!u,onClose:()=>w(null),title:u?`Add people to ${u.name}`:"",footer:e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx(d,{type:"button",variant:"ghost",onClick:()=>w(null),disabled:k,children:"Cancel"}),e.jsx(d,{type:"button",variant:"primary",onClick:T,isLoading:k,disabled:c.size===0,children:c.size>1?`Add ${c.size} people`:"Add"})]}),children:u&&e.jsx(ge,{members:C,selected:c,onToggle:s=>P(n=>{const r=new Set(n);return r.has(s)?r.delete(s):r.add(s),r}),excludeIds:u.members.map(s=>s.id)})})]})}const be=["president","music_director","treasurer"];function Ee(){const g=ce(),{currentOrg:f}=de(),{showSuccess:R,showError:A}=J(),[v,z]=i.useState(null),[O,H]=i.useState(!0),[y,u]=i.useState(null),[w,C]=i.useState(""),[$,c]=i.useState([]),[P,k]=i.useState(!1),[E,p]=i.useState(!1),[L,M]=i.useState(()=>new Set);function U(a){M(o=>{const h=new Set(o);return h.has(a)?h.delete(a):h.add(a),h})}const[l,D]=i.useState(null),[S,T]=i.useState(null),[B,V]=i.useState(""),[W,s]=i.useState(!1);i.useEffect(()=>{n()},[]);async function n(){H(!0);try{const a=await x.getRoleAssignments();z(a)}catch{A(Q("role assignments"))}finally{H(!1)}}async function r(a){if(C(a),a.trim().length<2){c([]);return}k(!0);try{const o=await x.list({search:a.trim(),status:"active",limit:10});c(o.members??[])}catch{c([])}finally{k(!1)}}async function m(a){if(y){p(!0);try{const h=(await x.getById(a.id)).orgRoles??[];h.includes(y)||await x.update(a.id,{orgRoles:[...h,y]}),R(`${a.firstName} ${a.lastName} assigned as ${_[y]}`),u(null),C(""),c([]),n()}catch(o){A(o.message||N)}finally{p(!1)}}}async function ae(){if(l){p(!0);try{const o=((await x.getById(l.member.id)).orgRoles??[]).filter(h=>h!==l.role);await x.update(l.member.id,{orgRoles:o}),R(`${l.member.firstName} ${l.member.lastName} removed from ${_[l.role]}`),D(null),n()}catch(a){A(a.message||N)}finally{p(!1)}}}function te(a,o){T({role:a,memberId:o.id}),V(o.aliasEmail||"")}async function Z(){if(S){s(!0);try{await x.setRoleAlias(S.memberId,S.role,B.trim()),R(B.trim()?"Role email saved":"Role email removed"),T(null),n()}catch(a){A(a.message||N)}finally{s(!1)}}}const ne=xe.filter(a=>a!=="member");return e.jsxs("div",{className:"px-4 md:px-0",children:[e.jsx(he,{isOpen:!!l,onClose:()=>D(null),onConfirm:ae,title:"Remove Role",message:l?`Remove ${l.member.firstName} ${l.member.lastName} from ${_[l.role]}?`:"",confirmLabel:"Remove"}),e.jsx(ue,{title:"Roles & Access",breadcrumbs:[{label:"Home",to:"/"},{label:"Settings"},{label:"Roles & Access"}]}),O?e.jsx("div",{className:"space-y-3",children:Array.from({length:6}).map((a,o)=>e.jsx(pe,{lines:2},o))}):e.jsx("div",{className:"space-y-3",children:ne.map(a=>{const o=v?.orgRoles?.[a]??[],h=v?.systemRoles?.[a]??[],q=be.includes(a),K=o.length===0,F=y===a,Y=L.has(a)||F,ee=o.map(t=>`${t.firstName} ${t.lastName}`);return e.jsxs("div",{"data-testid":`role-${a}`,className:`bg-white rounded-xl border ${q&&K?"border-amber-300 bg-amber-50/30":"border-gray-200"}`,children:[e.jsx("h2",{className:"m-0",children:e.jsx(d,{type:"button",variant:"ghost","aria-expanded":Y,onClick:()=>U(a),className:"w-full !px-5 !py-4 text-left min-h-[2.75rem] [&>span]:w-full [&>span]:!justify-start",children:e.jsxs("span",{className:"flex flex-wrap items-center gap-x-3 gap-y-0.5 w-full min-w-0",children:[e.jsx("span",{className:"text-sm font-semibold text-gray-900 shrink-0",children:_[a]}),q&&K&&e.jsx("span",{className:"text-xs font-medium text-amber-600 bg-amber-100 px-1.5 py-0.5 rounded shrink-0",children:"Unassigned"}),e.jsx("span",{className:"order-last basis-full sm:order-none sm:basis-0 sm:flex-1 truncate text-sm text-gray-500",children:ee.length?ee.join(", "):"No one"}),e.jsx("svg",{"aria-hidden":"true",className:`ml-auto h-4 w-4 shrink-0 text-gray-400 transition-transform ${Y?"rotate-180":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 9l-7 7-7-7"})})]})})}),Y&&e.jsxs("div",{className:"px-5 pb-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsx("p",{className:"flex-1 min-w-0 text-xs text-gray-400",children:me[a]}),e.jsx(d,{variant:"secondary",size:"sm",onClick:()=>{M(t=>new Set(t).add(a)),u(F?null:a),C(""),c([])},children:F?"Cancel":"Assign"})]}),o.length>0&&e.jsx("div",{className:"mt-3 space-y-2",children:o.map(t=>{h.some(j=>j.memberId===t.id);const b=Object.entries(v?.systemRoles??{}).find(([,j])=>j.some(re=>re.memberId===t.id))?.[0],G=S?.role===a&&S?.memberId===t.id;return e.jsxs("div",{className:"rounded-lg border border-gray-100 bg-gray-50 px-4 py-2.5",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("button",{type:"button",onClick:()=>g(`/members/${t.id}`),className:"text-sm font-medium text-gray-900 hover:text-band-600 truncate",children:[t.firstName," ",t.lastName]}),b&&e.jsxs("span",{className:"text-[10px] font-medium px-1.5 py-0.5 rounded bg-band-100 text-band-700",children:["Login: ",_[b]??b]}),!b&&e.jsx("span",{className:"text-[10px] font-medium px-1.5 py-0.5 rounded bg-gray-100 text-gray-400",children:"No login"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-0.5 text-xs text-gray-400 mt-0.5",children:[(t.aliasEmail||t.emailAddress)&&e.jsx("span",{title:t.aliasEmail?"Role email":"Personal email",children:t.aliasEmail||t.emailAddress}),t.phone&&e.jsx("span",{children:t.phone})]})]}),e.jsx(d,{variant:"ghost",size:"sm",onClick:()=>D({role:a,member:t}),className:"text-gray-400 hover:text-red-500 !text-xs shrink-0",children:"Remove"})]}),e.jsx("div",{className:"mt-1.5 flex items-center gap-2",children:G?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"email",value:B,onChange:j=>V(j.target.value),placeholder:"Role email (e.g. [email protected])",className:"flex-1 text-xs border border-gray-300 rounded px-2 py-1 focus:outline-none focus:ring-1 focus:ring-brand-primary",autoF
1ocus:!0,onKeyDown:j=>{j.key==="Enter"&&Z(),j.key==="Escape"&&T(null)}}),e.jsx(d,{variant:"primary",size:"sm",onClick:Z,disabled:W,className:"!text-xs !px-2 !py-0.5",isLoading:W,children:"Save"}),e.jsx(d,{variant:"ghost",size:"sm",onClick:()=>T(null),className:"!text-xs !px-2 !py-0.5",children:"Cancel"})]}):e.jsx("button",{type:"button",onClick:()=>te(a,t),className:"text-xs text-gray-400 hover:text-brand-primary transition-colors",children:t.aliasEmail?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("svg",{className:"h-3 w-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})}),t.aliasEmail]}):"+ Add role email"})})]},t.id)})}),K&&!F&&e.jsx("p",{className:"mt-2 text-xs text-gray-300",children:"No one assigned to this role."}),F&&e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsx(se,{placeholder:"Search members by name...",value:w,onChange:t=>r(t.target.value),autoFocus:!0}),P&&e.jsx("p",{className:"text-xs text-gray-400",children:"Searching..."}),$.length>0&&e.jsx("div",{className:"border border-gray-200 rounded-lg divide-y divide-gray-100 max-h-48 overflow-y-auto",children:$.map(t=>{const b=o.some(G=>G.id===t.id);return e.jsxs("button",{type:"button",disabled:b||E,onClick:()=>m(t),className:`w-full text-left px-3 py-2 text-sm flex items-center gap-2 ${b?"bg-gray-50 text-gray-300":"hover:bg-gray-50 text-gray-800"}`,children:[e.jsxs("span",{className:"font-medium",children:[t.firstName," ",t.lastName]}),t.emailAddress&&e.jsx("span",{className:"text-gray-400 text-xs",children:t.emailAddress}),b&&e.jsx("span",{className:"ml-auto text-xs text-gray-300",children:"Already assigned"})]},t.id)})}),w.trim().length>=2&&!P&&$.length===0&&e.jsx(X,{size:"compact",title:"No members found."})]})]})]},a)})}),!O&&e.jsx(ye,{})]})}export{Ee as RolesAccessPage};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.