PageSourceSearch

https://bondedpath.com/assets/AdminGrantsPage-BMILDqQT.js

js bondedpath.com collected 2026-10-02 00:48:18 UTC 12,211 bytes, 1 lines download raw bytes

1import{r as i,j as e}from"./vendor-react-BoyrKzsG.js";import{A as M}from"./AdminLayout-UtVj2u1H.js";import{R as A}from"./index-CKCEYSTE.js";import{t as $,Y as N,R as D,G as C,m as E,C as F,Q as S}from"./vendor-ui-Cy9YOY35.js";import{C as O}from"./ConfirmationModal-BP8DnJuo.js";/* empty css                   */import"./vendor-firebase-DbFCdLkQ.js";const P=[{label:"1 Month",days:30},{label:"3 Months",days:90},{label:"6 Months",days:180},{label:"12 Months",days:365}],Q=[{label:"Premium",value:"premium"},{label:"Pro",value:"pro"}],_=({isOpen:h,onClose:o,onAward:g,user:n})=>{var z,b;const[l,y]=i.useState("premium"),[d,w]=i.useState(180),[k,u]=i.useState(""),[a,p]=i.useState(!1);if(i.useEffect(()=>{h&&(y("premium"),w(180),u(""))},[h]),!h)return null;const c=async()=>{p(!0);try{await g(l,d,k),o()}finally{p(!1)}},j=new Date(Date.now()+d*24*60*60*1e3);return e.jsx("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.5)",zIndex:1e3,display:"flex",alignItems:"center",justifyContent:"center",padding:16},children:e.jsxs("div",{style:{background:"white",borderRadius:12,padding:28,width:"100%",maxWidth:480,boxShadow:"0 20px 40px rgba(0,0,0,0.15)"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:20},children:[e.jsx("h3",{style:{margin:0,fontSize:"1.1rem",fontWeight:700},children:"Award Free Access"}),e.jsx("button",{onClick:o,style:{background:"none",border:"none",cursor:"pointer",color:"#6b7280"},children:e.jsx(N,{size:20})})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,background:"#f9fafb",borderRadius:8,padding:"10px 14px",marginBottom:20},children:[e.jsx("div",{style:{width:36,height:36,borderRadius:"50%",background:"#e5e7eb",display:"flex",alignItems:"center",justifyContent:"center",fontWeight:700,fontSize:"0.9rem",color:"#4b5563",overflow:"hidden",flexShrink:0},children:n.photoURL?e.jsx("img",{src:n.photoURL,style:{width:"100%",height:"100%",objectFit:"cover"},alt:""}):(b=(z=n.displayName)==null?void 0:z[0])==null?void 0:b.toUpperCase()}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:600,fontSize:"0.9rem"},children:n.displayName}),e.jsx("div",{style:{fontSize:"0.78rem",color:"#6b7280"},children:n.email})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[e.jsxs("div",{children:[e.jsx("label",{style:{fontSize:"0.78rem",fontWeight:600,color:"#6b7280",textTransform:"uppercase",display:"block",marginBottom:6},children:"Tier"}),e.jsx("div",{style:{display:"flex",gap:8},children:Q.map(r=>e.jsx("button",{onClick:()=>y(r.value),style:{flex:1,padding:"8px 0",borderRadius:8,border:`2px solid ${l===r.value?r.value==="pro"?"#d97706":"#4338ca":"#e1e4e8"}`,background:l===r.value?r.value==="pro"?"#fffbeb":"#eef2ff":"white",fontWeight:600,fontSize:"0.9rem",cursor:"pointer",color:l===r.value?r.value==="pro"?"#92400e":"#3730a3":"#4b5563",transition:"all 0.15s"},children:r.label},r.value))})]}),e.jsxs("div",{children:[e.jsx("label",{style:{fontSize:"0.78rem",fontWeight:600,color:"#6b7280",textTransform:"uppercase",display:"block",marginBottom:6},children:"Duration"}),e.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:P.map(r=>e.jsx("button",{onClick:()=>w(r.days),style:{padding:"7px 14px",borderRadius:8,border:`2px solid ${d===r.days?"#8B5A2B":"#e1e4e8"}`,background:d===r.days?"#fdf6f0":"white",fontWeight:600,fontSize:"0.85rem",cursor:"pointer",color:d===r.days?"#8B5A2B":"#4b5563",transition:"all 0.15s"},children:r.label},r.days))}),e.jsxs("div",{style:{fontSize:"0.78rem",color:"#6b7280",marginTop:6},children:["Expires: ",e.jsx("strong",{children:j.toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"})})]})]}),e.jsxs("div",{children:[e.jsx("label",{style:{fontSize:"0.78rem",fontWeight:600,color:"#6b7280",textTransform:"uppercase",display:"block",marginBottom:6},children:"Note (internal)"}),e.jsx("input",{value:k,onChange:r=>u(r.target.value),placeholder:"e.g. Beta tester, community leader…",style:{width:"100%",padding:"8px 12px",borderRadius:8,border:"1px solid #d1d5db",fontSize:"0.9rem",boxSizing:"border-box",outline:"none"}})]})]}),e.jsxs("div",{style:{display:"flex",gap:10,marginTop:24},children:[e.jsx("button",{onClick:o,style:{flex:1,padding:"10px 0",borderRadius:8,border:"1px solid #e1e4e8",background:"white",fontWeight:600,cursor:"pointer",color:"#4b5563"},children:"Cancel"}),e.jsxs("button",{onClick:c,disabled:a,style:{flex:2,padding:"10px 0",borderRadius:8,border:"none",background:"#8B5A2B",color:"white",fontWeight:700,cursor:a?"not-allowed":"pointer",opacity:a?.7:1,display:"flex",alignItems:"center",justifyContent:"center",gap:8},children:[e.jsx(C,{size:16}),a?"Awarding…":"Award Access"]})]})]})})},Z=()=>{var W;const[h,o]=i.useState(""),[g,n]=i.useState([]),[l,y]=i.useState(!1),[d,w]=i.useState([]),[k,u]=i.useState(!0),[a,p]=i.useState(null),[c,j]=i.useState(null),[z,b]=i.useState(!1),r=i.useRef(null),R=async()=>{u(!0);try{const s=await(await A.getAdminRepository()).getManualGrants({limit:50});w(s.data)}catch(t){console.error("[Grants] Failed to load grants:",t),S.error(`Failed to load grants: ${(t==null?void 0:t.message)??t}`)}finally{u(!1)}};i.useEffect(()=>{R()},[]);const I=t=>{if(o(t),r.current&&clearTimeout(r.current),!t.trim()){n([]);return}r.current=setTimeout(async()=>{y(!0);try{const x=await(await A.getAdminRepository()).searchUsersForGrant(t);n(x)}catch(s){console.error("[Grants] Search failed:",s),S.error(`Search failed: ${(s==null?void 0:s.message)??s}`)}finally{y(!1)}},400)},B=async(t,s,x)=>
1{if(!a)return;await(await A.getAdminRepository()).grantAccess(a.id,t,s,x),S.success(`${t.charAt(0).toUpperCase()+t.slice(1)} access granted to ${a.displayName}`),o(""),n([]),await R()},L=async()=>{if(c){b(!0);try{await(await A.getAdminRepository()).revokeAccess(c.id),S.success(`Access revoked for ${c.displayName}`),j(null),await R()}catch{S.error("Failed to revoke access")}finally{b(!1)}}},T=t=>new Date(t).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}),U=t=>t<Date.now(),G=t=>{const s=t-Date.now();return Math.max(0,Math.ceil(s/(24*60*60*1e3)))};return e.jsxs(M,{title:"Grants",children:[e.jsxs("div",{className:"admin-section",style:{marginBottom:24},children:[e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("h3",{style:{margin:"0 0 4px",fontSize:"1rem",fontWeight:700},children:"Award Free Access"}),e.jsx("p",{style:{margin:0,fontSize:"0.85rem",color:"#6b7280"},children:"Search for a user and grant them premium or pro access for a set period at no charge."})]}),e.jsxs("div",{style:{position:"relative",maxWidth:480},children:[e.jsxs("div",{className:"search-bar",style:{maxWidth:"100%"},children:[e.jsx($,{size:16,color:"#9ca3af"}),e.jsx("input",{value:h,onChange:t=>I(t.target.value),placeholder:"Search by name or email…"}),h&&e.jsx("button",{onClick:()=>{o(""),n([])},style:{background:"none",border:"none",cursor:"pointer",color:"#9ca3af",display:"flex",alignItems:"center"},children:e.jsx(N,{size:14})})]}),h.trim()&&(l||g.length>=0)&&e.jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,right:0,background:"white",border:"1px solid #e1e4e8",borderRadius:10,boxShadow:"0 10px 20px rgba(0,0,0,0.1)",zIndex:50,overflow:"hidden"},children:[l&&e.jsxs("div",{style:{padding:"12px 16px",color:"#6b7280",fontSize:"0.85rem",display:"flex",alignItems:"center",gap:8},children:[e.jsx(D,{size:14})," Searching…"]}),!l&&g.length===0&&e.jsx("div",{style:{padding:"12px 16px",color:"#9ca3af",fontSize:"0.85rem"},children:"No users found"}),g.map(t=>{var s,x,m,v;return e.jsxs("button",{onClick:()=>{p(t),o(""),n([])},style:{width:"100%",display:"flex",alignItems:"center",gap:10,padding:"10px 16px",background:"none",border:"none",cursor:"pointer",textAlign:"left",borderBottom:"1px solid #f3f4f6"},onMouseEnter:f=>f.currentTarget.style.background="#f9fafb",onMouseLeave:f=>f.currentTarget.style.background="none",children:[e.jsx("div",{className:"user-avatar-mini",children:t.photoURL?e.jsx("img",{src:t.photoURL,alt:""}):(x=(s=t.displayName)==null?void 0:s[0])==null?void 0:x.toUpperCase()}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:600,fontSize:"0.875rem"},children:t.displayName}),e.jsx("div",{style:{fontSize:"0.75rem",color:"#6b7280"},children:t.email})]}),e.jsx("div",{style:{marginLeft:"auto"},children:e.jsx("span",{className:`badge tier-${((m=t.subscription)==null?void 0:m.tier)||"free"}`,children:((v=t.subscription)==null?void 0:v.tier)||"free"})})]},t.id)})]})]})]}),e.jsxs("div",{className:"admin-section",children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:16},children:[e.jsxs("div",{children:[e.jsx("h3",{style:{margin:"0 0 4px",fontSize:"1rem",fontWeight:700},children:"Active Grants"}),e.jsx("p",{style:{margin:0,fontSize:"0.85rem",color:"#6b7280"},children:"Users currently on manual (non-billed) access."})]}),e.jsxs("button",{onClick:R,className:"filter-btn",style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx(D,{size:14}),"Refresh"]})]}),k?e.jsx("div",{style:{padding:"40px 0",textAlign:"center",color:"#9ca3af"},children:"Loading grants…"}):d.length===0?e.jsxs("div",{style:{padding:"48px 0",textAlign:"center"},children:[e.jsx(C,{size:36,color:"#d1d5db",style:{margin:"0 auto 12px"}}),e.jsx("p",{style:{color:"#9ca3af",margin:0},children:"No active manual grants yet."})]}):e.jsx("div",{className:"admin-table-container",children:e.jsxs("table",{className:"admin-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"User"}),e.jsx("th",{children:"Tier"}),e.jsx("th",{children:"Granted"}),e.jsx("th",{children:"Expires"}),e.jsx("th",{children:"Days Left"}),e.jsx("th",{children:"Note"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:d.map(t=>{var v,f;const s=t.subscription,x=U(s==null?void 0:s.endDate),m=G(s==null?void 0:s.endDate);return e.jsxs("tr",{children:[e.jsx("td",{children:e.jsxs("div",{className:"user-cell",children:[e.jsx("div",{className:"user-avatar-mini",children:t.photoURL?e.jsx("img",{src:t.photoURL,alt:""}):(f=(v=t.displayName)==null?void 0:v[0])==null?void 0:f.toUpperCase()}),e.jsxs("div",{className:"user-info-mini",children:[e.jsx("span",{className:"user-name",children:t.displayName}),e.jsx("span",{className:"user-email",children:t.email})]})]})}),e.jsx("td",{children:e.jsx("span",{className:`badge tier-${s==null?void 0:s.tier}`,children:s==null?void 0:s.tier})}),e.jsx("td",{style:{color:"#6b7280",fontSize:"0.85rem"},children:s!=null&&s.startDate?T(s.startDate):"—"}),e.jsx("td",{style:{color:"#6b7280",fontSize:"0.85rem"},children:s!=null&&s.endDate?T(s.endDate):"—"}),e.jsx("td",{children:x?e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,color:"#ef4444",fontSize:"0.8rem",fontWeight:600},children:[e.jsx(E,{size:13})," Expired"]}):e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,color:m<=14?"#f59e0b":"#10b981",fontSize:"0.85rem",fontWeight:600},children:[e.jsx(F,{size:13})," ",m,"d"]})}),e.jsx("td",{style:{color:"#6b7280",fontSize:"0.82rem",maxWidth:200,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(s==null?void 0:s.grantNote)||"—"}),e.jsx("td",{children:e.jsxs("div",{style:{display:"flex",gap:6},children:[e.jsxs("button",{onClick:()=>p(t),style:{padding:"5px 10px",borderRadius:6,border:"1px solid #e1e4e8",background:"white",fontSize:"0.78rem",fontWeight:600,cursor:"pointer",color:"#4b5563",display:"flex",alignItems:"center",gap:4},children:[e.jsx(C,{size:12})," Modify"]}),e.jsxs("button",{onClick:()=>j(t),style:{padding:"5px 10px",borderRadius:6,border:"1px solid #fecaca",background:"#fff5f5",fontSize:"0.78rem",fontWeight:600,cursor:"pointer",color:"#dc2626",display:"flex",alignItems:"center",gap:4},children:[e.jsx(N,{size:12})," Revoke"]})]})})]},t.id)})})]})})]}),a&&e.jsx(_,{isOpen:!0,user:a,onClose:()=>p(null),onAward:B}),c&&e.jsx(O,{isOpen:!0,title:"Revoke Access",message:`Remove free ${(W=c.subscription)==null?void 0:W.tier} access from ${c.displayName}? They will be downgraded to free immediately.`,confirmText:z?"Revoking…":"Revoke",variant:"danger",onConfirm:L,onClose:()=>j(null)})]})};export{Z 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.