PageSourceSearch

https://bright-reimagine-spot.lovable.app/assets/SpeakerManagement-DxmHn3qa.js

js bright-reimagine-spot.lovable.app collected 2026-10-03 03:25:15 UTC 10,919 bytes, 1 lines download raw bytes

1import{i as ee,ag as se,r as i,s as g,A as d,j as e,B as x,aq as ae,I as m,af as R,aP as te,bo as F,D as re,b as le,d as oe,e as ne,aT as T,aH as ie,T as U}from"./index-ClJJfLql.js";import{l as P}from"./changeLog-Cr-DaVbP.js";import{u as de}from"./useCanViewSpeakerFinancials-bdecPchC.js";import{P as ce}from"./plus-KzjM6UO2.js";const B={name:"",bio:"",photo_url:"",website:"",support_email:"",support_phone:"",business_address:"",internal_notes:"",revenue_share_pct:""};function ge(){const{user:q,role:j}=ee(),z=se(),[b,N]=i.useState([]),[M,$]=i.useState(!0),[H,_]=i.useState(!1),[u,V]=i.useState(null),[a,l]=i.useState(B),[f,W]=i.useState(""),[v,k]=i.useState(!1),[G,w]=i.useState(!1),y=i.useRef(null);i.useEffect(()=>{I()},[q]);const I=async()=>{$(!0);const{data:s}=await g.from("speakers").select("*").order("is_starred",{ascending:!1}).order("name");N(s||[]),$(!1)},C=j==="admin"||j==="moderator"||j==="management",E=de(),J=()=>{V(null),l(B),_(!0)},L=i.useCallback(async s=>{if(!s.type.startsWith("image/")){d({title:"Please select an image file",variant:"destructive"});return}k(!0);const t=s.name.split(".").pop()||"jpg",r=`${Date.now()}-${Math.random().toString(36).slice(2)}.${t}`,{error:p}=await g.storage.from("speaker-photos").upload(r,s,{upsert:!0});if(p){d({title:"Upload failed",description:p.message,variant:"destructive"}),k(!1);return}const{data:{publicUrl:c}}=g.storage.from("speaker-photos").getPublicUrl(r);l(o=>({...o,photo_url:c})),k(!1),d({title:"Photo uploaded"})},[]),K=s=>{var r;const t=(r=s.target.files)==null?void 0:r[0];t&&L(t)},Q=s=>{var r;s.preventDefault(),w(!1);const t=(r=s.dataTransfer.files)==null?void 0:r[0];t&&L(t)},X=async()=>{var o;if(!a.name.trim()){d({title:"Name is required",variant:"destructive"});return}const s=((o=a.revenue_share_pct)==null?void 0:o.toString().trim())??"";let t=null;if(s!==""){const n=Number(s);if(!Number.isFinite(n)||n<0||n>100){d({title:"Speaker Commission % must be between 0 and 100",variant:"destructive"});return}t=n}const{revenue_share_pct:r,...p}=a,c={...p,...E?{revenue_share_pct:t}:{},photo_url:a.photo_url||null,bio:a.bio||null,website:a.website||null,support_email:a.support_email||null,support_phone:a.support_phone||null,business_address:a.business_address||null,internal_notes:a.internal_notes||null};if(u){const{error:n}=await g.from("speakers").update(c).eq("id",u);if(n){d({title:"Error",description:n.message,variant:"destructive"});return}P({tableName:"speakers",recordId:u,action:"update",summary:`Updated speaker "${a.name}"`})}else{const{data:n,error:O}=await g.from("speakers").insert(c).select("id").single();if(O){d({title:"Error",description:O.message,variant:"destructive"});return}P({tableName:"speakers",recordId:(n==null?void 0:n.id)||"",action:"create",summary:`Created speaker "${a.name}"`})}d({title:u?"Speaker updated":"Speaker created"}),_(!1),I()},S=b.filter(s=>!f||s.name.toLowerCase().includes(f.toLowerCase())||(s.support_email||"").toLowerCase().includes(f.toLowerCase())),h=S.filter(s=>s.is_starred),D=S.filter(s=>!s.is_starred),Y=s=>s.split(" ").map(t=>t[0]).join("").slice(0,2).toUpperCase(),Z=async(s,t)=>{if(t.stopPropagation(),!C)return;const r=!s.is_starred;N(c=>c.map(o=>o.id===s.id?{...o,is_starred:r}:o));const{error:p}=await g.from("speakers").update({is_starred:r}).eq("id",s.id);if(p){d({title:"Could not update",description:p.message,variant:"destructive"}),N(c=>c.map(o=>o.id===s.id?{...o,is_starred:!r}:o));return}P({tableName:"speakers",recordId:s.id,action:"update",summary:`${r?"Starred":"Unstarred"} speaker "${s.name}"`})},A=s=>e.jsxs("div",{className:"group flex flex-col items-center gap-3 cursor-pointer",onClick:()=>z(`/admin/speaker/${s.id}`),children:[e.jsxs("div",{className:"relative",children:[s.photo_url?e.jsx("img",{src:s.photo_url,alt:s.name,className:"h-28 w-28 rounded-full object-cover border-3 border-transparent group-hover:border-primary transition-all duration-300 shadow-md group-hover:shadow-xl"}):e.jsx("div",{className:"h-28 w-28 rounded-full bg-gradient-to-br from-primary/10 to-primary/20 flex items-center justify-center border-3 border-transparent group-hover:border-primary transition-all duration-300 shadow-md",children:e.jsx("span",{className:"text-2xl font-bold text-primary/60",children:Y(s.name)})}),e.jsx("div",{className:"absolute inset-0 rounded-full ring-2 ring-primary/0 group-hover:ring-primary/50 transition-all duration-300"}),C&&e.jsx("button",{type:"button",onClick:t=>Z(s,t),"aria-label":s.is_starred?"Unstar speaker":"Star speaker",className:`absolute -top-1 -right-1 h-8 w-8 rounded-full bg-background border shadow-sm flex items-center justify-center transition-all ${s.is_starred?"opacity-100 border-accent":"opacity-0 group-hover:opacity-100 border-border hover:border-accent"}`,children:e.jsx(F,{className:`h-4 w-4 ${s.is_starred?"fill-accent text-accent":"text-muted-foreground"}`})})]}),e.jsxs("div",{className:"text-center max-w-[140px]",children:[e.jsx("p",{className:"font-medium text-sm leading-tight truncate group-hover:text-primary transition-colors",children:s.name}),s.support_email&&e.jsx("p",{className:"text-xs text-muted-foreground truncate mt-0.5",children:s.support_email})]})]},s.id);return e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:"Talent Directory"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[b.length," speaker",b.length!==1?"s":""," in roster",h.length>0&&` · ${h.length} starred`]})]}),C&&e.jsxs(x,{onClick:J,children:[e.jsx(ce,{className:"mr-2 h-4 w-4"}),"Add Speaker"]}
1)]}),e.jsxs("div",{className:"relative max-w-sm",children:[e.jsx(ae,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(m,{placeholder:"Search speakers…",value:f,onChange:s=>W(s.target.value),className:"pl-9 h-9"})]}),M?e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-6",children:Array.from({length:12}).map((s,t)=>e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx(R,{className:"h-28 w-28 rounded-full"}),e.jsx(R,{className:"h-4 w-24"})]},t))}):S.length===0?e.jsxs("div",{className:"text-center py-16 text-muted-foreground",children:[e.jsx(te,{className:"h-12 w-12 mx-auto mb-3 opacity-30"}),e.jsx("p",{children:"No speakers found."})]}):e.jsxs("div",{className:"space-y-8",children:[h.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs uppercase tracking-wider font-semibold text-muted-foreground",children:[e.jsx(F,{className:"h-3.5 w-3.5 fill-accent text-accent"}),"Currently working with",e.jsxs("span",{className:"text-muted-foreground/70 normal-case font-normal",children:["· ",h.length]})]}),e.jsx("div",{className:"h-px flex-1 bg-border"})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-6",children:h.map(A)})]}),D.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsxs("div",{className:"text-xs uppercase tracking-wider font-semibold text-muted-foreground",children:[h.length>0?"Roster":"All speakers",e.jsxs("span",{className:"text-muted-foreground/70 normal-case font-normal ml-1",children:["· ",D.length]})]}),e.jsx("div",{className:"h-px flex-1 bg-border"})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-6",children:D.map(A)})]})]}),e.jsx(re,{open:H,onOpenChange:_,children:e.jsxs(le,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[e.jsx(oe,{children:e.jsx(ne,{children:u?"Edit Speaker":"Add Speaker"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(m,{placeholder:"Name *",value:a.name,onChange:s=>l({...a,name:s.target.value})}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1.5 block",children:"Speaker Photo"}),e.jsxs("div",{className:`relative border-2 border-dashed rounded-lg p-4 text-center transition-colors ${G?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"}`,onDragOver:s=>{s.preventDefault(),w(!0)},onDragLeave:()=>w(!1),onDrop:Q,children:[a.photo_url?e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("img",{src:a.photo_url,alt:"",className:"h-16 w-16 rounded-full object-cover flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0 text-left",children:[e.jsx("p",{className:"text-sm text-muted-foreground truncate",children:a.photo_url.split("/").pop()}),e.jsxs("div",{className:"flex gap-2 mt-1.5",children:[e.jsxs(x,{type:"button",size:"sm",variant:"outline",disabled:v,onClick:()=>{var s;return(s=y.current)==null?void 0:s.click()},children:[e.jsx(T,{className:"mr-1 h-3 w-3"}),v?"Uploading…":"Change"]}),e.jsx(x,{type:"button",size:"sm",variant:"ghost",onClick:()=>l(s=>({...s,photo_url:""})),children:"Remove"})]})]})]}):e.jsxs("div",{className:"py-2",children:[e.jsx(ie,{className:"h-8 w-8 mx-auto text-muted-foreground/40 mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Drag & drop a photo here, or"}),e.jsxs(x,{type:"button",size:"sm",variant:"outline",disabled:v,onClick:()=>{var s;return(s=y.current)==null?void 0:s.click()},children:[e.jsx(T,{className:"mr-1 h-3 w-3"}),v?"Uploading…":"Browse Files"]})]}),e.jsx("input",{ref:y,type:"file",accept:"image/*",className:"hidden",onChange:K})]}),e.jsx("div",{className:"mt-1.5",children:e.jsx(m,{placeholder:"Or paste image URL",value:a.photo_url,onChange:s=>l({...a,photo_url:s.target.value}),className:"h-8 text-xs"})})]}),e.jsx(U,{placeholder:"Bio",value:a.bio,onChange:s=>l({...a,bio:s.target.value})}),e.jsx(m,{placeholder:"Website",value:a.website,onChange:s=>l({...a,website:s.target.value})}),e.jsx(m,{placeholder:"Support Email",value:a.support_email,onChange:s=>l({...a,support_email:s.target.value})}),e.jsx(m,{placeholder:"Support Phone",value:a.support_phone,onChange:s=>l({...a,support_phone:s.target.value})}),e.jsx(U,{placeholder:"Business Address",value:a.business_address,onChange:s=>l({...a,business_address:s.target.value})}),E&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1.5 block",children:"Speaker Commission %"}),e.jsx(m,{type:"number",min:0,max:100,step:"0.01",placeholder:"—",value:a.revenue_share_pct,onChange:s=>l({...a,revenue_share_pct:s.target.value})}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-1",children:"RSN keeps the remainder. Leave blank to default to product-level setting."})]}),e.jsx(U,{placeholder:"Internal Notes (private)",value:a.internal_notes,onChange:s=>l({...a,internal_notes:s.target.value})}),e.jsxs(x,{className:"w-full",onClick:X,children:[u?"Update":"Create"," Speaker"]}
1)]})]})})]})}export{ge 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.