PageSourceSearch

https://wedorunning.com/assets/AdminMembers-D3AaAkyn.js

js wedorunning.com collected 2026-10-10 02:24:16 UTC 6,274 bytes, 1 lines download raw bytes

1import{j as e}from"./query-vendor-DBbghNzL.js";import{r as o}from"./react-vendor-B4iqnpmg.js";import{B as l,I as p,C as F,E as z,H as L,J as R,K as H,a as g,V as U,s as m,u as r}from"./index-Dddl32Ja.js";import{A as q}from"./AdminLayout-C0zioWlX.js";import{S as I}from"./switch-Dt-rt4Ds.js";import{B as N}from"./badge-BnNldF_Q.js";import{a as J}from"./exportUtils-7uPBqgeX.js";import"./icons-vendor-DfIUqQcN.js";import"./supabase-vendor-DRR_Es6B.js";async function k(t){try{const i=t==null?void 0:t.context;if(i&&typeof i.json=="function"){const c=await i.clone().json().catch(()=>null);if(c!=null&&c.error)return String(c.error)}if(i&&typeof i.text=="function"){const c=await i.clone().text().catch(()=>"");if(c)return c}}catch{}return(t==null?void 0:t.message)||"Unknown error"}function X(){const[t,i]=o.useState([]),[c,w]=o.useState(""),[C,v]=o.useState(!1),[y,j]=o.useState(null),[n,h]=o.useState({}),[b,_]=o.useState(!1),u=async()=>{v(!0);const{data:s,error:a}=await m.rpc("admin_list_members",{_search:c});a?r.error(a.message):i(s||[]),v(!1)};o.useEffect(()=>{u()},[]);const S=async s=>{const a=prompt("Reason for blocking?")||"",{error:x}=await m.rpc("admin_block_member",{_user_id:s,_reason:a});if(x){r.error(x.message);return}try{const{error:d}=await m.functions.invoke("admin-user-mgmt",{body:{action:"block_user",user_id:s}});if(d){const f=await k(d);console.warn("block_user session revoke failed:",f)}}catch(d){console.warn(d)}r.success("Member blocked and signed out"),u()},E=async s=>{const{error:a}=await m.rpc("admin_unblock_member",{_user_id:s});a?r.error(a.message):(r.success("Unblocked"),u())},D=async s=>{if(!confirm("Permanently delete this member and all their data?"))return;const a=t;i(t.filter(A=>A.id!==s));const{data:x,error:d}=await m.functions.invoke("admin-user-mgmt",{body:{action:"delete_user",user_id:s}}),f=d?await k(d):x==null?void 0:x.error;f?(i(a),r.error(`Delete failed: ${f}`)):(r.success("Member deleted"),u())},M=async s=>{j(s);const{data:a}=await m.from("profiles").select("display_name,handle,city,country,grandfathered_at").eq("id",s.id).maybeSingle();h({display_name:(a==null?void 0:a.display_name)||s.display_name||"",handle:(a==null?void 0:a.handle)||s.handle||"",city:(a==null?void 0:a.city)||s.city||"",country:(a==null?void 0:a.country)||s.country||"",grandfathered:!!(a!=null&&a.grandfathered_at)})},B=async()=>{if(!y)return;_(!0);const s={display_name:n.display_name,handle:n.handle,city:n.city,country:n.country,grandfathered_at:n.grandfathered?"true":"false"},{error:a}=await m.rpc("admin_update_member",{_user_id:y.id,_patch:s}
1);if(_(!1),a){r.error(a.message);return}r.success("Member updated"),j(null),u()};return e.jsxs(q,{children:[e.jsxs("div",{className:"flex flex-wrap gap-2 items-center mb-4",children:[e.jsx("h1",{className:"text-3xl font-bold mr-auto",children:"Members"}),e.jsx(l,{variant:"outline",onClick:()=>J("members.csv",t),children:"Export CSV"})]}),e.jsxs("div",{className:"flex gap-2 mb-4",children:[e.jsx(p,{placeholder:"Search name, handle or email",value:c,onChange:s=>w(s.target.value)}),e.jsx(l,{onClick:u,disabled:C,children:"Search"})]}),e.jsx(F,{className:"rounded-2xl overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted",children:e.jsxs("tr",{className:"text-left",children:[e.jsx("th",{className:"p-2",children:"Name"}),e.jsx("th",{className:"p-2",children:"Email"}),e.jsx("th",{className:"p-2",children:"City"}),e.jsx("th",{className:"p-2",children:"Runs"}),e.jsx("th",{className:"p-2",children:"KM"}),e.jsx("th",{className:"p-2",children:"Joined"}),e.jsx("th",{className:"p-2",children:"Status"}),e.jsx("th",{className:"p-2",children:"Actions"})]})}),e.jsx("tbody",{children:t.map(s=>e.jsxs("tr",{className:"border-t",children:[e.jsxs("td",{className:"p-2",children:[e.jsx("div",{className:"font-medium",children:s.display_name}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["@",s.handle]})]}),e.jsx("td",{className:"p-2",children:s.email}),e.jsxs("td",{className:"p-2",children:[s.city||"—",s.country?`, ${s.country}`:""]}),e.jsx("td",{className:"p-2",children:s.runs_count}),e.jsx("td",{className:"p-2",children:s.total_km}),e.jsx("td",{className:"p-2",children:new Date(s.created_at).toLocaleDateString()}),e.jsx("td",{className:"p-2",children:s.blocked_at?e.jsx(N,{variant:"destructive",children:"Blocked"}):e.jsx(N,{variant:"secondary",className:"bg-emerald-500/15 text-emerald-700",children:"Active"})}),e.jsxs("td",{className:"p-2 space-x-1 whitespace-nowrap",children:[e.jsx(l,{size:"sm",variant:"outline",onClick:()=>M(s),children:"Edit"}),s.blocked_at?e.jsx(l,{size:"sm",variant:"outline",onClick:()=>E(s.id),children:"Unblock"}):e.jsx(l,{size:"sm",variant:"outline",onClick:()=>S(s.id),children:"Block"}),e.jsx(l,{size:"sm",variant:"destructive",onClick:()=>D(s.id),children:"Delete"})]})]},s.id))})]})})}),e.jsx(z,{open:!!y,onOpenChange:s=>!s&&j(null),children:e.jsxs(L,{children:[e.jsx(R,{children:e.jsx(H,{children:"Edit member"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Display name"}),e.jsx(p,{value:n.display_name||"",onChange:s=>h({...n,display_name:s.target.value})})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Handle"}),e.jsx(p,{value:n.handle||"",onChange:s=>h({...n,handle:s.target.value})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx(g,{children:"City"}),e.jsx(p,{value:n.city||"",onChange:s=>h({...n,city:s.target.value})})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Country"}),e.jsx(p,{value:n.country||"",onChange:s=>h({...n,country:s.target.value})})]})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-md border p-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:"Grandfathered member"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Free lifetime access"})]}),e.jsx(I,{checked:!!n.grandfathered,onCheckedChange:s=>h({...n,grandfathered:s})})]})]}),e.jsxs(U,{children:[e.jsx(l,{variant:"outline",onClick:()=>j(null),children:"Cancel"}),e.jsx(l,{onClick:B,disabled:b,children:b?"Saving…":"Save changes"})]})]})})]})}export{X 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.