PageSourceSearch

https://www.myhacks.org/assets/Admin-BB-XLqxC.js

js myhacks.org collected 2026-10-02 02:04:32 UTC 8,133 bytes, 11 lines download raw bytes

1import{c as L,r as t,a as F,m as M,s as h,j as e,B as i,S as q,I as B,n as H,o as Q,p as Y,q as G,t as J,v as K,w as O,x as V,y as W,f as E}from"./index-Ci9QfuMH.js";import{A as X}from"./AdminNav-DNSQTD7G.js";import{A as Z}from"./arrow-left-XqTaIugV.js";import{T as $}from"./trash-2-DxwURj8t.js";import{C as ee}from"./chevron-left-CSgVvNZJ.js";import{C as se}from"./chevron-right-DYdEsh2m.js";import{A as te}from"./arrow-up-down-Bc2RTqZ9.js";import{A as re}from"./arrow-up-hhIjSydM.js";import{A as ae}from"./arrow-down-DTxYRWKp.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const ne=L("ChevronsLeft",[["path",{d:"m11 17-5-5 5-5",key:"13zhaf"}],["path",{d:"m18 17-5-5 5-5",key:"h8a8et"}]]);/**
7 * @license lucide-react v0.462.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const le=L("ChevronsRight",[["path",{d:"m6 17 5-5-5-5",key:"xnjwq"}],["path",{d:"m13 17 5-5-5-5",key:"17xmmf"}]]),je=()=>{const[v,N]=t.useState([]),[u,y]=t.useState(!0),[p,T]=t.useState(""),[r,a]=t.useState(1),[j,w]=t.useState(0),[o,z]=t.useState("email"),[c,A]=t.useState("asc"),[C,f]=t.useState(null),[I,g]=t.useState(""),[_,D]=t.useState(!1),b=20,d=F(),{toast:S}=M();t.useEffect(()=>{P()},[r,o,c,p]);const P=async()=>{try{const{data:{session:s}}=await h.auth.getSession();if(!s){d("/auth");return}const{data:l}=await h.rpc("is_admin");if(!l){S({title:"Access denied",description:"You need admin privileges to access this page.",variant:"destructive"}),d("/dashboard");return}await k()}catch(s){console.error("Error:",s),d("/dashboard")}},k=async()=>{try{y(!0);const s=(r-1)*b,{data:l,error:U}=await h.rpc("get_users_paginated",{p_limit:b,p_offset:s,p_search:p,p_sort_field:o,p_sort_direction:c});if(U)throw U;l&&l.length>0?(N(l),w(l[0].total_count||0)):(N([]),w(0))}catch(s){S({title:"Error loading users",description:s.message,variant:"destructive"})}finally{y(!1)}},m=s=>{o===s?A(c==="asc"?"desc":"asc"):(z(s),A("asc")),a(1)},R=async()=>{if(C){D(!0);try{const{error:s}=await h.rpc("delete_user_account",{_user_id:C});if(s)throw s;E.success("Account deleted successfully"),f(null),g(""),await k()}catch(s){console.error("Error deleting account:",s),E.error("Failed to delete account: "+s.message)}finally{D(!1)}}},n=Math.ceil(j/b),x=s=>o!==s?e.jsx(te,{className:"h-3 w-3 ml-1 opacity-40"}):c==="asc"?e.jsx(re,{className:"h-3 w-3 ml-1"}):e.jsx(ae,{className:"h-3 w-3 ml-1"});return u?e.jsx("div",{className:"min-h-screen flex items-center justify-center",children:e.jsx("div",{className:"text-muted-foreground",children:"Loading..."})}):e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx("header",{className:"border-b border-border",children:e.jsx("div",{className:"container mx-auto px-4 py-4 flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(i,{variant:"ghost",size:"sm",onClick:()=>d("/dashboard"),children:[e.jsx(Z,{className:"h-4 w-4 mr-2"}),"Dashboard"]}),e.jsx(X,{})]})})}),e.jsxs("main",{className:"container mx-auto px-4 py-8",children:[e.jsx("h1",{className:"text-3xl font-light tracking-tight mb-8",children:"User Management"}),e.jsxs("div",{className:"mb-6 flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"relative flex-1 max-w-sm",children:[e.jsx(q,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(B,{placeholder:"Search by email...",value:p,onChange:s=>{T(s.target.value),a(1)},className:"pl-9"})]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:["Total users: ",e.jsx("span",{className:"font-medium text-foreground",children:j})]})]}),e.jsxs("div",{className:"bg-card border border-border rounded-lg overflow-hidden",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{className:"bg-muted/50 border-b border-border",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left px-6 py-4 text-sm font-medium cursor-pointer hover:bg-muted/70 transition-colors",onClick:()=>m("email"),children:e.jsxs("div",{className:"flex items-center",children:["Email",x("email")]})}),e.jsx("th",{className:"text-left px-6 py-4 text-sm font-medium",children:"Roles"}),e.jsx("th",{className:"text-left px-6 py-4 text-sm font-medium cursor-pointer hover:bg-muted/70 transition-colors",onClick:()=>m("project_count"),children:e.jsxs("div",{className:"flex items-center",children:["Projects",x("project_count")]})}),e.jsx("th",{className:"text-left px-6 py-4 text-sm font-medium cursor-pointer hover:bg-muted/70 transition-colors",onClick:()=>m("habit_count"),children:e.jsxs("div",{className:"flex items-center",children:["Habits",x("habit_count")]})}),e.jsx("th",{className:"text-left px-6 py-4 text-sm font-medium cursor-pointer hover:bg-muted/70 transition-colors",onClick:()=>m("created_at"),children:e.jsxs("div",{className:"flex items-center",children:["Created",x("created_at")]})}),e.jsx("th",{className:"text-left px-6 py-4 text-sm font-medium",children:"Actions"})]})}),e.jsx("tbody",{children:u?e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"px-6 py-12 text-center text-muted-foreground",children:"Loading users..."})}):v.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"px-6 py-12 text-center text-muted-foreground",children:"No users found"})}):v.map(s=>e.jsxs("tr",{className:"border-b border-border last:border-0 hover:bg-muted/30 transition-colors",children:[e.jsx("td",{className:"px-6 py-4 text-sm",children:s.email}),e.jsx("td",{className:"px-6 py-4 text-sm",children:e.jsx("span",{className:"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-muted",children:s.roles.join(", ")})}),e.jsx("td",{className:"px-6 py-4 text-sm text-muted-foreground",children:s.project_count}),e.jsx("td",{className:"px-6 py-4 text-sm text-muted-foreground",children:s.habit_count}),e.jsx("td",{className:"px-6 py-4 text-sm text-muted-foreground",children:s.created_at}
11),e.jsx("td",{className:"px-6 py-4 text-sm",children:e.jsxs(H,{children:[e.jsx(Q,{asChild:!0,children:e.jsx(i,{variant:"ghost",size:"sm",onClick:()=>{f(s.id),g(s.email)},className:"h-8 w-8 p-0 text-destructive hover:text-destructive hover:bg-destructive/10",children:e.jsx($,{className:"h-4 w-4"})})}),e.jsxs(Y,{children:[e.jsxs(G,{children:[e.jsx(J,{children:"Delete User Account?"}),e.jsxs(K,{children:["Are you sure you want to delete the account for ",e.jsx("strong",{children:I}),"?",e.jsx("br",{}),e.jsx("br",{}),"This will permanently delete:",e.jsxs("ul",{className:"list-disc pl-6 mt-2 space-y-1",children:[e.jsx("li",{children:"All user data and profile"}),e.jsx("li",{children:"All projects and tasks"}),e.jsx("li",{children:"All habits and logs"}),e.jsx("li",{children:"All goals and notes"})]}),e.jsx("br",{}),e.jsx("strong",{className:"text-destructive",children:"This action cannot be undone."})]})]}),e.jsxs(O,{children:[e.jsx(V,{onClick:()=>{f(null),g("")},children:"Cancel"}),e.jsx(W,{onClick:R,disabled:_,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:_?"Deleting...":"Delete Account"})]})]})]})})]},s.id))})]})}),!u&&n>1&&e.jsxs("div",{className:"border-t border-border px-6 py-4 flex items-center justify-between",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["Page ",r," of ",n," (",j," total users)"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(i,{variant:"outline",size:"sm",onClick:()=>a(1),disabled:r===1,children:e.jsx(ne,{className:"h-4 w-4"})}),e.jsx(i,{variant:"outline",size:"sm",onClick:()=>a(s=>Math.max(1,s-1)),disabled:r===1,children:e.jsx(ee,{className:"h-4 w-4"})}),e.jsx(i,{variant:"outline",size:"sm",onClick:()=>a(s=>Math.min(n,s+1)),disabled:r===n,children:e.jsx(se,{className:"h-4 w-4"})}),e.jsx(i,{variant:"outline",size:"sm",onClick:()=>a(n),disabled:r===n,children:e.jsx(le,{className:"h-4 w-4"})})]})]})]})]})]})};export{je 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.