PageSourceSearch

https://www.abbeytheatre.co.uk/assets/AdminShowAdmins-CV6U4AIl.js

js abbeytheatre.co.uk collected 2026-09-25 08:04:30 UTC 8,705 bytes, 6 lines download raw bytes

1import{k as xe,l as fe,r as i,s as l,j as s,B as c,A as pe,D as ge,bq as je,w as we,x as ve,y as Ae,z as Se,v as W,I as X,bp as _e,C,c as Z,d as G,n as J,e as y,P as Ne,Z as Ce,q as o}from"./index-tvAeWDDu.js";import{S as b,a as D,b as P,c as k,d as $}from"./select-D_9989fq.js";import{C as ye}from"./checkbox-evR8m3pO.js";import{P as K}from"./plus-D42lu7Dc.js";import{U as be}from"./user-plus-DnmQiIxh.js";import"./index-BdQq_4o_.js";import"./chevron-down-DdqJBhHb.js";import"./chevron-up-eQONr_xY.js";function Te(){const{user:m,isAdmin:h,loading:w}=xe(),v=fe(),[p,Q]=i.useState([]),[I,Y]=i.useState([]),[ee,se]=i.useState([]),[te,ae]=i.useState(!0),[A,u]=i.useState(""),[S,x]=i.useState(""),[U,F]=i.useState([]),[g,q]=i.useState(""),[T,L]=i.useState(""),[z,ie]=i.useState(""),[ne,E]=i.useState(!1),[re,j]=i.useState(!1),[O,f]=i.useState(!1);i.useEffect(()=>{!w&&(!m||!h)&&v("/admin/login")},[m,h,w,v]),i.useEffect(()=>{m&&h&&B()},[m,h]);const B=async()=>{await M(),await Promise.all([oe(),_(),R()]),ae(!1)},M=async()=>{const{data:e}=await l.from("user_roles").select("user_id").eq("role","show_admin");if(e&&e.length>0){const t=e.map(n=>n.user_id),{data:r}=await l.from("user_profiles").select("id, email, first_name, last_name").in("id",t);Q(r||[])}},R=async()=>{const{data:e}=await l.from("user_profiles").select("id, email, first_name, last_name").order("email");if(!e){F([]);return}const t=p.map(n=>n.id),r=e.filter(n=>!t.includes(n.id));F(r||[]),L("")},V=(e,t)=>{if(!t)return!0;const r=e.toLowerCase(),n=t.toLowerCase();let d=0;for(let a=0;a<n.length;a++){const N=n[a];if(d=r.indexOf(N,d),d===-1)return!1;d++}return!0},oe=async()=>{const e=new Date().toISOString().split("T")[0],{data:t}=await l.from("productions").select("id, title, showtimes(date)").order("title");if(t){const r=t.map(n=>{const d=(n.showtimes||[]).filter(a=>a.date>=e).sort((a,N)=>a.date.localeCompare(N.date));return{id:n.id,title:n.title,earliestDate:d[0]?.date||null}});Y(r)}},_=async()=>{const{data:e}=await l.from("production_admins").select(`
2        id,
3        user_id,
4        production_id,
5        created_at
6      `);if(e){const t=[...new Set(e.map(a=>a.production_id))],{data:r}=await l.from("productions").select("id, title").in("id",t),n=new Map(r?.map(a=>[a.id,a.title])),d=e.map(a=>({...a,productions:{title:n.get(a.production_id)||"Unknown"}}));se(d)}},le=async()=>{if(!g){o.error("Please select a user to make a show admin");return}E(!0);const{error:e}=await l.from("user_roles").insert({user_id:g,role:"show_admin"});e?e.code==="23505"?o.error("User is already a show admin"):o.error("Failed to add show admin"):(o.success("Show admin added successfully"),q(""),await M(),await R()),E(!1)},de=async()=>{if(!A||!S){o.error("Please select both a show admin and a production");return}const{error:e}=await l.from("production_admins").insert({user_id:A,production_id:S,created_by:m?.id});e?e.code==="23505"?o.error("This production is already assigned to this show admin"):o.error("Failed to assign production"):(o.success("Production assigned successfully"),u(""),x(""),j(!1),f(!1),_())},ce=async e=>{const{error:t}=await l.from("production_admins").delete().eq("id",e);t?o.error("Failed to remove assignment"):(o.success("Assignment removed"),_())},me=async e=>{if(!confirm("Are you sure? This will remove all production assignments for this show admin."))return;await l.from("production_admins").delete().eq("user_id",e);const{error:t}=await l.from("user_roles").delete().eq("user_id",e).eq("role","show_admin");t?o.error("Failed to remove show admin"):(o.success("Show admin removed"),B())},he=e=>ee.filter(t=>t.user_id===e),ue=e=>{u(e),x(""),f(!1),j(!0)},H=O?I:I.filter(e=>e.earliestDate!==null);return w||!m||!h?null:s.jsxs("div",{className:"min-h-screen bg-background",children:[s.jsx("header",{className:"border-b border-border",children:s.jsx("div",{className:"container mx-auto px-4 py-4",children:s.jsxs(c,{variant:"ghost",onClick:()=>v("/admin"),children:[s.jsx(pe,{className:"mr-2 h-4 w-4"}),"Back to Admin"]})})}),s.jsxs("main",{className:"container mx-auto px-4 py-8",children:[s.jsxs("div",{className:"flex justify-between items-center mb-8",children:[s.jsxs("div",{children:[s.jsx("h1",{className:"text-3xl font-bold text-foreground mb-2",children:"Manage Show Admins"}),s.jsx("p",{className:"text-muted-foreground",children:"Assign show admins to specific productions they can manage"})]}),s.jsxs(ge,{open:re,onOpenChange:e=>{j(e),e||(f(!1),u(""),x(""))},children:[s.jsx(je,{asChild:!0,children:s.jsxs(c,{onClick:()=>{u(""),x(""),f(!1)},children:[s.jsx(K,{className:"mr-2 h-4 w-4"}),"Assign Production"]})}),s.jsxs(we,{children:[s.jsxs(ve,{children:[s.jsx(Ae,{children:"Assign Production to Show Admin"}),s.jsx(Se,{children:"Select a show admin and a production to grant editing permissions"})]}),s.jsxs("div",{className:"space-y-4 py-4",children:[s.jsxs("div",{children:[s.jsx(W,{htmlFor:"admin-select",children:"Show Admin"}),s.jsxs(b,{value:A,onValueChange:u,children:[s.jsx(D,{id:"admin-select",children:s.jsx(P,{placeholder:"Select a show admin"})}),s.jsxs(k,{children:[s.jsx("div",{className:"px-3 py-2",children:s.jsx(X,{placeholder:"Search show admins...",value:z,onChange:e=>ie(e.target.value),autoFocus:!1})}),p.filter(e=>V(`${e.first_name??""} ${e.last_name??""} ${e.email}`,z)).map(e=>s.jsx($,{value:e.id,children:e.first_name&&e.last_name?`${e.first_name} ${e.last_name} (${e.email})`:e.email},e.id))]})]})]}),s.jsxs("div",{children:[s.jsx(W,{htmlFor:"production-select",children:"Production"}),s.jsxs(b,{value:S,onValueChange:x,children:[s.jsx(D,{id:"production-select",children:s.jsx(P,{placeholder:"Select a production"})}),s.jsx(k,{children:H.length===0?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:'No future-dated productions. Check "Show all" below.'}):H.map(e=>s.jsx($,{value:e.id,children:e.title},e.id))})]}),s.jsxs("div",{className:"flex items-center space-x-2 mt-2",children:[s.jsx(ye,{id:"show-all-productions",checked:O,onCheckedChange:e=>f(e===!0)}),s.jsx("label",{htmlFor:"show-all-productions",className:"text-sm text-muted-foreground cursor-pointer",children:"Show all productions (including past)"})]})]})]}),s.jsxs(_e,{children:[s.jsx(c,{variant:"outline",onClick:()=>j(!1),children:"Cancel"}),s.jsx(c,{onClick:de,children:"Assign"})]})]})]})]}),s.jsxs(C,{className:"mb-6",children:[s.jsxs(Z,{children:[s.jsxs(G,{className:"flex items-center gap-2",children:[s.jsx(be,{className:"h-5 w-5"}),"Add New Show Admin"]}),s.jsx(J,{children:"Enter the email address of an existing user to grant them show admin privileges"})]}),s.jsx(y,{children:s.jsxs("div",{className:"flex gap-2",children:[s.jsx("div",{className:"flex-1",children:s.jsxs(b,{value:g,onValueChange:q,children:[s.jsx(D,{id:"new-admin-select",children:s.jsx(P,{placeholder:U.length>0?"Select a user":"No available users"})}),s.jsxs(k,{children:[s.jsx("div",{className:"px-3 py-2",children:s.jsx(X,{placeholder:"Search users...",value:T,onChange:e=>L(e.target.value),autoFocus:!1})}),U.filter(e=>V(`${e.first_name??""} ${e.last_name??""} ${e.email}`,T)).map(e=>s.jsx($,{value:e.id,children:e.first_name&&e.last_name?`${e.first_name} ${e.last_name} (${e.email})`:e.email},e.id))]})]})}),s.jsx(c,{onClick:le,disabled:ne||!g,children:"Add"})]})})]}),te?s.jsx("p",{className:"text-muted-foreground",children:"Loading show admins..."}):p.length===0?s.jsx(C,{children:s.jsx(y,{className:"text-center py-12",children:s.jsx("p",{className:"text-muted-foreground",children:"No show admins yet"})})}):s.jsx("div",{className:"grid gap-4",children:p.map(e=>{const t=he(e.id);return s.jsxs(C,{children:[s.jsx(Z,{children:s.jsxs("div",{className:"flex justify-between items-start",children:[s.jsxs("div",{children:[s.jsx(G,{children:e.first_name&&e.last_name?`${e.first_name} ${e.last_name}`:e.email}),s.jsx(J,{children:e.email})]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsxs(c,{variant:"outline",size:"sm",onClick:()=>ue(e.id),children:[s.jsx(K,{className:"mr-1 h-3 w-3"}),"Assign Production"]}),s.jsx(c,{variant:"outline",size:"sm",onClick:()=>me(e.id),children:"Remove Admin"})]})]})}),s.jsx(y,{children:s.jsxs("div",{className:"space-y-2",children:[s.jsx("h4",{className:"font-semibold text-sm",children:"Assigned Productions:"}),t.length===0?s.jsx("p",{className:"text-sm text-muted-foreground",children:"No productions assigned yet"}):s.jsx("div",{className:"flex flex-wrap gap-2",children:t.map(r=>s.jsxs(Ne,{variant:"secondary",className:"flex items-center gap-1",children:[r.productions.title,s.jsx("button",{onClick:()=>ce(r.id),className:"ml-1 hover:text-destructive",children:s.jsx(Ce,{className:"h-3 w-3"})})]},r.id))})]})})]},e.id)})})]})]})}export{Te as default};

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.