PageSourceSearch

https://app.backstagebaton.com/app/assets/SectionsPage-DdVUI83H.js

js backstagebaton.com collected 2026-10-07 08:50:30 UTC 13,422 bytes, 1 lines download raw bytes

1import{c as U,a as Y,r as a,t as J,j as e,S as X,p as le,B as O,E as oe,h as Z,g as de}from"./index-_aijvlUq.js";import{e as ee}from"./ensembles-WGlB365j.js";import{s as R}from"./sections-BvnWLeCW.js";import{P as ce}from"./PageHeader-DCofr6qo.js";import{a as me}from"./Skeleton-B3Wj6cNd.js";import{I as ue}from"./InstrumentTag-CHdSvMU6.js";import{m as fe}from"./members-I3UAoZ9P.js";import{I as he}from"./Input-ysTyZFq5.js";import{C as be}from"./ConfirmDialog-CODvETNM.js";import{C as pe}from"./ChipToggleGroup-DiMa_Ns9.js";import{p as ge}from"./paletteHash-DBBw93pZ.js";import{M as xe}from"./MobileListSkeleton-BxuyWDCs.js";import{M as ve}from"./MobileFab-CAyx0Bpg.js";import{B as ye}from"./BottomSheet-BiQNSujt.js";import{e as je}from"./ensembleTag-kZVL-M-W.js";import{E as Se}from"./EmptyState-CPGKooqj.js";import"./Badge-DJIi163x.js";import"./downscaleImage-qyGK-a3D.js";import"./ChipToggle-hmCaOMqs.js";const P=["brass","woodwind","percussion","string","keyboard"];function Ne(s){const c={};for(const x of s){const n=x.family??"other";c[n]||(c[n]=[]),c[n].push(x)}return c}function te({section:s=null,ensembles:c=[],ensembleId:x="",onSaved:n,onCancel:p,onDeleted:y,showTopActions:N=!1}){const h=!!s,{showSuccess:S,showError:v}=U(),{canFully:I}=Y(),L=I("section:create"),[j,C]=a.useState(s?.name??""),[l,A]=a.useState(x||c[0]?.id||""),[o,w]=a.useState(s?.leader?.id||s?.leaderId||""),[b,k]=a.useState(()=>new Set((s?.instruments??[]).map(t=>t.id))),[z,$]=a.useState([]),[D,F]=a.useState([]),[H,T]=a.useState(!1),[r,m]=a.useState(!1),[i,g]=a.useState(!1),B=a.useRef(h?{name:s.name,leaderId:s.leader?.id||s.leaderId||"",ids:new Set((s.instruments??[]).map(t=>t.id))}:null);a.useEffect(()=>{if(!l){$([]),F([]);return}let t=!1;return T(!0),fe.list({ensembleId:l,status:"active",limit:500}).then(d=>{t||F(d.members??[])}).catch(()=>{t||F([])}),R.getAvailableInstruments(l,h?s.id:void 0).then(d=>{if(t)return;let u=d;if(h){u=[...d];for(const E of s.instruments??[])u.find(f=>f.id===E.id)||u.push(E);u.sort((E,f)=>{const M=P.indexOf(E.family),W=P.indexOf(f.family);return M!==W?M-W:E.name.localeCompare(f.name)})}$(u)}).catch(()=>{t||v(J("instruments"))}).finally(()=>{t||T(!1)}),()=>{t=!0}},[l]);function V(t){k(d=>{const u=new Set(d);return u.has(t)?u.delete(t):u.add(t),u})}function _(){const t=(f,M)=>(f.lastName||"").localeCompare(M.lastName||"")||(f.firstName||"").localeCompare(M.firstName||""),d=[],u=[];for(const f of D){if(f.memberStatus==="retired")continue;(b.size>0&&f.instruments?.some(W=>b.has(W.instrumentId))?d:u).push(f)}d.sort(t),u.sort(t);const E=[{value:"",label:"No leader"}];for(const f of d)E.push({value:f.id,label:`${f.firstName} ${f.lastName}`});d.length>0&&u.length>0&&E.push({value:"__divider__",label:"────────────────",disabled:!0});for(const f of u)E.push({value:f.id,label:`${f.firstName} ${f.lastName}`});return E}const se=!h||!B.current||(()=>{const t=B.current;if(j!==t.name||o!==(t.leaderId??"")||b.size!==t.ids.size)return!0;for(const d of b)if(!t.ids.has(d))return!0;return!1})(),ae=!!j.trim()&&!!l&&se;async function K(t){if(t?.preventDefault?.(),!(!j.trim()||!l)){m(!0);try{const d={name:j.trim(),instrumentIds:Array.from(b),leaderId:o||null};if(h){const u=await R.update(l,s.id,d);S("Section updated"),n?.(u,l,"edit")}else{const u=await R.create(l,d);
1S("Section created"),n?.(u,l,"create")}}catch(d){v(d.message||oe)}finally{m(!1)}}}async function ne(){try{await R.remove(l,s.id),S("Section deleted"),g(!1),y?.(s.id,l)}catch(t){v(t.message||le)}}const q=Ne(z),re=P.filter(t=>q[t]),ie=Object.keys(q).filter(t=>!P.includes(t)),Q=()=>e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx(O,{type:"button",size:"sm",isLoading:r,disabled:!ae,onClick:K,children:h?"Save changes":"Create"}),e.jsx(O,{type:"button",variant:"secondary",size:"sm",onClick:p,children:"Cancel"}),h&&L&&y&&e.jsx(O,{type:"button",variant:"danger",size:"sm",className:"ml-auto",onClick:()=>g(!0),children:"Delete"})]});return e.jsxs(e.Fragment,{children:[e.jsx(be,{isOpen:i,onClose:()=>g(!1),onConfirm:ne,title:"Delete Section",message:`Delete "${s?.name}"? Its instruments will become available for other sections.`,confirmLabel:"Delete"}),N&&e.jsx("div",{className:"mb-4",children:Q()}),e.jsxs("form",{onSubmit:K,className:"space-y-4",children:[!h&&e.jsx(X,{label:"Ensemble",value:l,onChange:t=>A(t.target.value),options:[{value:"",label:"Select ensemble"},...c.map(t=>({value:t.id,label:t.name}))]}),e.jsx(he,{label:"Name",placeholder:"Brass Section",value:j,onChange:t=>C(t.target.value),required:!0}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-700 mb-2",children:"Instruments"}),H?e.jsx("p",{className:"text-sm text-gray-400",children:"Loading instruments…"}):z.length===0?e.jsx("p",{className:"text-sm text-gray-400",children:"No unassigned instruments available."}):e.jsx(pe,{groups:[...re,...ie].map(t=>({label:t,items:q[t].map(d=>({id:d.id,name:d.name}))})),selectedIds:b,onToggle:V})]}),e.jsx(X,{label:"Section Leader",value:o,onChange:t=>w(t.target.value),options:_()}),Q()]})]})}function we({isOpen:s,onClose:c,section:x=null,ensembleId:n="",ensembles:p=[],onSaved:y,onDeleted:N}){const h=!!x;return e.jsx(ye,{isOpen:s,onClose:c,title:h?"Edit section":"New section",children:e.jsx("div",{style:{padding:"var(--bb-space-4)"},children:!h&&p.length===0?e.jsx("p",{className:"text-sm text-gray-500",children:"Create an ensemble first — sections belong to an ensemble."}):e.jsx(te,{section:x,ensembles:p,ensembleId:n,onCancel:c,onSaved:(S,v,I)=>{y?.(S,v,I),c?.()},onDeleted:(S,v)=>{N?.(S,v),c?.()}})})})}function Ee(){const s=Z(o=>o.currentOrg?.id),{showError:c}=U(),{canFully:x}=Y(),n=x("section:create"),[p,y]=a.useState([]),[N,h]=a.useState({}),[S,v]=a.useState(!0),[I,L]=a.useState(!1),[j,C]=a.useState(null),l=a.useCallback(()=>{s&&(v(!0),ee.list(s).then(async o=>{y(o);const w=await Promise.all(o.map(b=>R.list(b.id).then(k=>[b.id,k]).catch(()=>[b.id,[]])));h(Object.fromEntries(w))}).catch(()=>c(J("sections"))).finally(()=>v(!1)))},[s]);a.useEffect(()=>{l()},[l]);const A=Object.values(N).some(o=>o&&o.length>0);return e.jsxs("div",{"data-testid":"mobile-sections-list",style:{paddingBottom:n?96:void 0},children:[S?e.jsx(xe,{variant:"member",count:4}):A?p.map(o=>{const w=N[o.id]||[];if(w.length===0)return null;const b=je({id:o.id,color:o.color});return e.jsxs("section",{style:{marginTop:"var(--bb-space-4)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"0 var(--bb-space-4) var(--bb-space-2)"},children:[e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",borderRadius:"var(--bb-radius-pill)",background:b.bg,color:b.fg,fontSize:11,fontWeight:600},children:o.name}),e.jsxs("span",{style:{fontSize:12,color:"var(--bb-fg-muted)"},children:[w.length," section",w.length===1?"":"s"]})]}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:0,background:"var(--bb-surface)"},children:w.map(k=>e.jsx(Ie,{section:k,canManage:n,onEdit:()=>C({section:k,ensembleId:o.id})},k.id))})]},o.id)}):e.jsx("div",{style:{margin:"var(--bb-space-4)",padding:"var(--bb-space-6)",background:"var(--bb-surface)",border:"1px solid var(--bb-border-soft)",borderRadius:"var(--bb-radius-lg)",textAlign:"center",color:"var(--bb-fg-muted)"},children:"No sections yet."}),n&&e.jsx(ve,{onClick:()=>L(!0),label:"New section",testId:"mobile-section-fab"}),e.jsx(we,{isOpen:I||!!j,onClose:()=>{L(!1),C(null)},section:j?.section||null,ensembleId:j?.ensembleId||"",ensembles:p,onSaved:l,onDeleted:l})]})}function Ie({section:s,canManage:c,onEdit:x}){const n=s.leader,p=ge(s.id,6),y=s.instruments?.length||0;return e.jsxs("li",{style:{display:"flex",alignItems:"center",gap:"var(--bb-space-3)",minHeight:72,padding:"12px var(--bb-space-4)",borderTop:"1px solid var(--bb-border-soft)"},children:[e.jsx("div",{"aria-hidden":"true",style:{width:44,height:44,borderRadius:"50%",background:`var(--bb-avatar-${p})`,color:`var(--bb-avatar-${p}-ink)`,fontSize:14,fontWeight:700,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:s.name?.[0]||"S"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:16,fontWeight:600,color:"var(--bb-fg)"},children:s.name}),e.jsxs("div",{style:{marginTop:2,fontSize:13,color:"var(--bb-fg-muted)"},children:[n?`Led by ${n.name}`:"No leader assigned",y>0&&` · ${y} instrument${y===1?"":"s"}`]})]}),e.jsxs("div",{style:{display:"flex",gap:6,flexShrink:0},children:[n?.phone&&e.jsx("a",{href:`tel:${n.phone}`,"aria-label":`Call ${n.name}`,style:G,children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.75,"aria-hidden":"true",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3 5a2 2 0 012-2h2.28a1 1 0 01.95.68l1.5 4.5a1 1 0 01-.27 1.05L8.09 10.91a11 11 0 005 5l1.68-1.37a1 1 0 011.05-.27l4.5 1.5a1 1 0 01.68.95V19a2 2 0 01-2 2A16 16 0 013 5z"})})}),n?.emailAddress&&e.jsx("a",{href:`mailto:${n.emailAddress}`,"aria-label":`Email ${n.name}`,style:G,children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.75,"aria-hidden":"true",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"})})}),c&&e.jsx("button",{type:"button",onClick:x,"aria-label":`Edit ${s.name}`,style:{...G,border:"none",cursor:"pointer"},children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.75,"aria-hidden":"true",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M11 4H4a2 2 0 00-2 2v14a2 2 0 002 2h14a2 2 0 002-2v-7M18.5 2.5a2.121 2.121 0 013 3L12 15l-4 1 1-4 9.5-9.5z"})})})]})]})}const G={width:44,height:44,borderRadius:"var(--bb-radius-pill)",background:"var(--bb-primary-soft)",color:"var(--bb-primary)",display:"flex",alignItems:"center",justifyContent:"center",textDecoration:"none"};function Ge(){const{currentOrg:s}=Z(),c=s?.id,{showError:x}=U(),{canFully:n}=Y(),p=n("section:create"),y=de(),N=a.useRef(null),[h,S]=a.useState([]),[v,I]=a.use
1State({}),[L,j]=a.useState(!0),[C,l]=a.useState(!1),[A,o]=a.useState(null),[w,b]=a.useState("");a.useEffect(()=>{c&&k()},[c]);async function k(){j(!0);try{const r=await ee.list(c);S(r);const m=await Promise.all(r.map(i=>R.list(i.id).then(g=>[i.id,g])));I(Object.fromEntries(m))}catch{x(J("sections"))}finally{j(!1)}}function z(r){o(null),b(r||h[0]?.id||""),l(!0),requestAnimationFrame(()=>N.current?.scrollIntoView({behavior:"smooth",block:"start"}))}function $(r,m){o(m),b(r),l(!0),requestAnimationFrame(()=>N.current?.scrollIntoView({behavior:"smooth",block:"start"}))}function D(){l(!1),o(null),b("")}function F(r,m,i){I(g=>{const B=g[m]||[],V=i==="edit"?B.map(_=>_.id===r.id?r:_):[...B,r];return{...g,[m]:V}}),D()}function H(r,m){I(i=>({...i,[m]:(i[m]||[]).filter(g=>g.id!==r)})),D()}const T=Object.values(v).reduce((r,m)=>r+m.length,0);return y?e.jsx(Ee,{}):e.jsxs("div",{children:[e.jsx(ce,{title:"Sections",breadcrumbs:[{label:"Home",to:"/"},{label:"Sections"}],actions:p&&e.jsx(O,{onClick:()=>z(),children:"New section"})}),C&&e.jsxs("div",{ref:N,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:A?"Edit Section":"New Section"}),e.jsx(te,{section:A,ensembles:h,ensembleId:w,showTopActions:!0,onSaved:F,onCancel:D,onDeleted:H})]}),!C&&(L?e.jsx("div",{className:"space-y-2",children:Array.from({length:4}).map((r,m)=>e.jsx(me,{lines:3},m))}):T===0&&h.length===0?e.jsx(Se,{card:!0,title:"No ensembles have been created yet. Create ensembles first, then add sections."}):e.jsx("div",{className:"space-y-6",children:h.map(r=>{const m=v[r.id]||[];return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide",children:r.name}),p&&e.jsx(O,{variant:"ghost",size:"sm",onClick:()=>z(r.id),children:"New section"})]}),m.length===0?e.jsx("div",{className:"bg-white rounded-xl border border-gray-200 px-5 py-4 text-sm text-gray-400",children:"No sections yet."}):e.jsx("div",{className:"space-y-2",children:m.map(i=>e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 px-5 py-4 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-gray-900",children:i.name}),i.leader?e.jsxs("div",{className:"text-sm text-gray-400 mt-0.5",children:[e.jsx("span",{className:"font-medium text-gray-600",children:i.leader.name}),i.leader.emailAddress&&e.jsx("span",{className:"ml-2",children:i.leader.emailAddress}),i.leader.phone&&e.jsx("span",{className:"ml-2",children:i.leader.phone})]}):e.jsx("p",{className:"text-sm text-gray-300 mt-0.5",children:"No leader assigned"})]}),e.jsxs("span",{className:"text-xs text-gray-400 shrink-0 mt-1",children:[i.memberCount??0," ",(i.memberCount??0)===1?"member":"members"]}),p&&e.jsx(O,{variant:"ghost",size:"sm",onClick:()=>$(r.id,i),children:"Edit"})]}),i.instruments?.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:i.instruments.map(g=>e.jsx(ue,{name:g.name,family:g.family},g.id))})]},i.id))})]},r.id)})}))]})}export{Ge as SectionsPage};

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.