PageSourceSearch

https://skuuz.com/assets/AdminApprovals-C-EH9HNL.js

js skuuz.com collected 2026-10-02 06:28:05 UTC 14,466 bytes, 1 lines download raw bytes

1import{r as t,j as e}from"./react-vendor-DTEXiHme.js";import{f as ce,s as v,a0 as de,y as S,z as C,H as G,Z as ue,t as me,_ as pe,k as ge,B as b,ab as z,N as _}from"./index-Cas2BA8G.js";import{u as he,D as xe,o as O}from"./operatorFilter-DBWwNsLg.js";import{I as fe}from"./input-COMpcq49.js";import"./popover-CQgjLlkx.js";import{S as je,a as ve,b as Ne,c as be,d as ye}from"./select-Dd8j6Fts.js";import{T as we,a as Se,b as D,c as E}from"./tabs-C_TdZTlp.js";import{L as P}from"./label-CPIAGVc8.js";import{S as Ce}from"./switch-CuPZPfg3.js";import{A as Ae,a as Re,b as qe,c as ze,d as Oe,e as Fe,f as ke,g as Te}from"./alert-dialog-Cc121-Mn.js";import{S as _e,a as De,b as Ee,c as Pe,d as Le,e as Me}from"./sheet-DgWE-ybh.js";import{b as L}from"./eventLogger-CNA3LMaL.js";import{c as N}from"./toast-utils-DbfcVDp6.js";import{C as Ke}from"./circle-check-muHzTCkC.js";import{C as Ue}from"./circle-x-sAOSygch.js";import{P as $e}from"./plus-BnJ7jTMP.js";import{U as Be}from"./user-check-5azMKnxb.js";import{U as He}from"./user-x-DMCuaTHB.js";import{f as Ie}from"./format-CpEgwowc.js";import"./excel-CPlAJqTR.js";import"./radix-C8G44Doi.js";import"./index-DYj0fNDf.js";import"./table-CTm7mt6O.js";import"./arrow-up-CIk-09Z9.js";import"./arrow-down-XUl8eEu7.js";import"./filter-JbNBtMLY.js";import"./chevron-left-C6mkHNrW.js";import"./copy-CFeQEnPt.js";import"./en-US-Ca8fhmg7.js";function Ve(){const[l,h]=t.useState([]),[g,x]=t.useState(!0),{user:u}=ce(),p=t.useCallback(async()=>{if(u){x(!0);try{const{data:a,error:n}=await v.from("signup_requests").select("*").order("created_at",{ascending:!1});if(n)throw n;h((a||[]).map(i=>({...i,status:i.status})))}catch(a){console.error("Error fetching signup requests:",a),N.error("Failed to load signup requests")}finally{x(!1)}}},[u]),y=async(a,n)=>{try{const{data:i,error:o}=await v.functions.invoke("approve-signup",{body:{requestId:a,action:"approve",orgId:n}});if(o)throw o;const c=l.find(F=>F.id===a);return L({userId:u==null?void 0:u.id,orgId:n,eventType:"Signup-Approve",eventCategory:"auth",level:"success",message:`Signup approved for ${(c==null?void 0:c.email)||a}`,details:{email:c==null?void 0:c.email,full_name:c==null?void 0:c.full_name,org_id:n}}),await p(),N.success("User approved and account created"),!0}catch(i){return console.error("Error approving signup:",i),N.error("Failed to approve signup request"),!1}},r=async a=>{try{const{data:n,error:i}=await v.functions.invoke("approve-signup",{body:{requestId:a,action:"reject"}});if(i)throw i;const o=l.find(c=>c.id===a);return L({userId:u==null?void 0:u.id,eventType:"Signup-Reject",eventCategory:"auth",level:"warn",message:`Signup rejected for ${(o==null?void 0:o.email)||a}`,details:{email:o==null?void 0:o.email}}),await p(),N.success("Signup request rejected"),!0}catch(n){return console.error("Error rejecting signup:",n),N.error("Failed to reject signup request"),!1}},w=async a=>{try{const n=l.find(o=>o.id===a),{error:i}=await v.from("signup_requests").delete().eq("id",a);if(i)throw i;return L({userId:u==null?void 0:u.id,eventType:"Signup-Delete",eventCategory:"auth",level:"warn",message:`Signup request deleted for ${(n==null?void 0:n.email)||a}`}),await p(),N.success("Request deleted"),!0}catch(n){return console.error("Error deleting signup request:",n),N.error("Failed to delete request"),!1}};t.useEffect(()=>{p()},[p]);const m=l.filter(a=>a.status==="pending"),A=l.filter(a=>a.status==="approved"),f=l.filter(a=>a.status==="rejected");return{requests:l,pendingRequests:m,approvedRequests:A,rejectedRequests:f,loading:g,fetchRequests:p,approveRequest:y,rejectRequest:r,deleteRequest:w}}const Xe=l=>{switch(l){case"pending":return e.jsx(_,{variant:"outline",className:"bg-yellow-500/10 text-yellow-500 border-yellow-500/30",children:"Pending"});case"approved":return e.jsx(_,{variant:"outline",className:"bg-green-500/10 text-green-500 border-green-500/30",children:"Approved"});case"rejected":return e.jsx(_,{variant:"outline",className:"bg-red-500/10 text-red-500 border-red-500/30",children:"Rejected"});default:return null}};function M({requests:l,showActions:h=!1,onApprove:g,onReject:x}){const u=t.useMemo(()=>{const y=[{id:"email",header:"Email",accessorKey:"email",filterFn:O,cell:({getValue:r})=>e.jsx("span",{className:"font-medium",children:r()})},{id:"full_name",header:"Name",accessorKey:"full_name",filterFn:O,cell:({getValue:r})=>r()||"–"},{id:"company_name",header:"Company",accessorKey:"company_name",filterFn:O,cell:({getValue:r})=>r()||"–"},{id:"phone",header:"Phone",accessorKey:"phone",enableColumnFilter:!1,cell:({getValue:r})=>r()||"–"},{id:"status",header:"Status",accessorKey:"status",filterFn:O,cell:({getValue:r})=>Xe(r())},{id:"created_at",header:"Requested",accessorKey:"created_at",cell:({getValue:r})=>e.jsx("span",{className:"text-muted-foreground",children:Ie(new Date(r()),"MMM d, yyyy h:mm a")})}];return h&&g&&x&&y.push({id:"actions",header:"",enableSorting:!1,enableColumnFilter:!1,cell:({row:r})=>e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(b,{size:"sm",variant:"outline",className:"text-green-500 hover:text-green-600 hover:bg-green-500/10",onClick:()=>g(r.original.id),children:[e.jsx(Be,{className:"h-4 w-4 mr-1"})," Approve"]}),e.jsxs(b,{size:"sm",variant:"outline",className:"text-red-500 hover:text-red-600 hover:bg-red-500/10",onClick:()=>x(r.original.id),children:[e.jsx(He,{className:"h-4 w-4 mr-1"})," Reject"]})]})}),y},[h,g,x]),{table:p}=he({data:l,columns:u,enablePagination:!0,pageSize:25});return e.jsx(xe,{table:p,showPagination:l.length>25,emptyMessage:"No requests found"})}const ws=()=>{const{pendingRequests:l,approvedRequests:h,rejectedRequests:g,loading:x,approveRequest:u,rejectRequest:p,deleteRequest:y}=Ve(),[r,w]=t.useState(null),[m,A]=t.useState(null),[f,a]=t.useState(!1),[n,i]=t.useState(!1),[o,c]=t.useState(""),[F,K]=t.useState([]),[Q,U]=t.useState(!1),[$,B]=t.useState(null),[W,R]=t.useState(!1),[j,k]=t.useState(""),[T,H]=t.useState(!1),[I,V]=t.useState(!0),[Y,X]=t.useState(!1),J=t.useCallback(async()=>{try{const{data:s}=await v.from("platform_settings").select("value").eq("key","free_tier_approval_required").maybeSingle();s&&V(s.value===!0||s.value==="true")}catch(s){console.error("Error fetching approval setting:",s)}},[]);t.useEffect(()=>{J()},[J]);const ee=async s=>{X(!0);try{const{error:d}=await v.from("platform_settings").update({value:s,updated_at:new Date().toISOString()}).eq("key","free_tier_approval_required");if(d)throw d;V(s),z.success(s?"Free-tier approval enabled":"Free-tier approval disabled — new signups will be auto-approved")}catch(d){console.error("Error toggling approval:",d),z.error("Failed to update setting")}finally{X(!1)}};t.useEffect(()=>{n&&se()},[n]);const se=async()=>{U(!0);try{const{data:s,error:d}=await v.from("organizations").select("id, name, slug").order("name");if(d)throw d;K(s||[])}catch(s){console.error("Error fetching organizations:",s)}finally{U(!1)}},ae=s=>{B(s),c(""),R(!1),k("");const d=l.find(q=>q.id===s);d!=null&&d.company_name&&k(d.company_name),i(!0)},re=s=>{w(s),A("reject")},Z=async()=>
1{if(j.trim()){H(!0);try{const s=j.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)/g,""),{data:d,error:q}=await v.from("organizations").insert({name:j.trim(),slug:s}).select("id, name, slug").single();if(q)throw q;K(le=>[...le,d].sort((ie,oe)=>ie.name.localeCompare(oe.name))),c(d.id),R(!1),z.success(`Organization "${d.name}" created`)}catch(s){console.error("Error creating organization:",s),z.error("Failed to create organization: "+(s.message||"Unknown error"))}finally{H(!1)}}},te=async()=>{if(!(!$||!o)){a(!0);try{await u($,o)}finally{a(!1),i(!1),B(null),c("")}}},ne=async()=>{if(!(!r||!m)){a(!0);try{m==="reject"?await p(r):m==="delete"&&await y(r)}finally{a(!1),w(null),A(null)}}};return e.jsxs(e.Fragment,{children:[e.jsxs(de,{children:[e.jsx("title",{children:"Signup Approvals | Admin | SKUuz"}),e.jsx("meta",{name:"description",content:"Manage user signup requests"})]}),e.jsx("div",{className:"h-full overflow-y-auto p-6",children:e.jsxs("div",{className:"max-w-7xl mx-auto space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:"Signup Approvals"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Review and manage user signup requests"})]}),e.jsx(S,{className:"border-border/50 bg-card/50",children:e.jsx(C,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(P,{htmlFor:"approval-toggle",className:"text-sm font-medium",children:"Require Manual Approval for Free Tier"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:I?"New free-tier signups must be manually approved by an admin before accounts are created.":"Free-tier signups are auto-approved — accounts are created immediately without admin review."})]}),e.jsx(Ce,{id:"approval-toggle",checked:I,onCheckedChange:ee,disabled:Y})]})})}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 mb-6",children:[e.jsx(S,{className:"border-border/50 bg-card/50",children:e.jsx(C,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-3 rounded-lg bg-yellow-500/10",children:e.jsx(G,{className:"h-6 w-6 text-yellow-500"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:l.length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Pending"})]})]})})}),e.jsx(S,{className:"border-border/50 bg-card/50",children:e.jsx(C,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-3 rounded-lg bg-green-500/10",children:e.jsx(Ke,{className:"h-6 w-6 text-green-500"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:h.length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Approved"})]})]})})}),e.jsx(S,{className:"border-border/50 bg-card/50",children:e.jsx(C,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-3 rounded-lg bg-red-500/10",children:e.jsx(Ue,{className:"h-6 w-6 text-red-500"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:g.length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Rejected"})]})]})})})]}),e.jsx(S,{className:"border-border/50 bg-card/50",children:e.jsxs(we,{defaultValue:"pending",children:[e.jsx(ue,{children:e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(me,{className:"h-5 w-5 text-primary"}),e.jsx(pe,{children:"Signup Requests"})]}),e.jsxs(Se,{children:[e.jsxs(D,{value:"pending",className:"gap-2",children:[e.jsx(G,{className:"h-4 w-4"})," Pending (",l.length,")"]}),e.jsxs(D,{value:"approved",children:["Approved (",h.length,")"]}),e.jsxs(D,{value:"rejected",children:["Rejected (",g.length,")"]})]})]})}),e.jsx(C,{children:x?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"Loading requests..."}):e.jsxs(e.Fragment,{children:[e.jsx(E,{value:"pending",className:"mt-0",children:e.jsx(M,{requests:l,showActions:!0,onApprove:ae,onReject:re})}),e.jsx(E,{value:"approved",className:"mt-0",children:e.jsx(M,{requests:h})}),e.jsx(E,{value:"rejected",className:"mt-0",children:e.jsx(M,{requests:g})})]})})]})})]})}),e.jsx(_e,{open:n,onOpenChange:i,children:e.jsxs(De,{className:"w-[500px] sm:max-w-[500px] overflow-y-auto sm:",children:[e.jsxs(Ee,{children:[e.jsxs(Pe,{className:"flex items-center gap-2",children:[e.jsx(ge,{className:"h-5 w-5 text-primary"})," Assign to Organization"]}),e.jsx(Le,{children:"Select an existing organization or create a new one for this user."})]}),e.jsx("div",{className:"space-y-4 py-4",children:W?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{htmlFor:"newOrgName",children:"Organization Name"}),e.jsx(fe,{id:"newOrgName",value:j,onChange:s=>k(s.target.value),placeholder:"Enter organization name",autoFocus:!0,onKeyDown:s=>{s.key==="Enter"&&j.trim()&&Z()}}),j.trim()&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Slug: ",j.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)/g,"")]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{variant:"outline",size:"sm",onClick:()=>R(!1),disabled:T,children:"Back"}),e.jsx(b,{size:"sm",onClick:Z,disabled:!j.trim()||T,children:T?"Creating...":"Create Organization"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{htmlFor:"organization",children:"Organization"}),Q?e.jsx("div",{className:"text-sm text-muted-foreground py-2",children:"Loading organizations..."}):e.jsxs(je,{value:o,onValueChange:c,children:[e.jsx(ve,{id:"organization",className:"w-full",children:e.jsx(Ne,{placeholder:"Select an organization"})}),e.jsx(be,{className:"bg-popover border border-border z-50",children:F.map(s=>e.jsxs(ye,{value:s.id,children:[s.name," ",s.slug&&`(${s.slug})`]},s.id))})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("span",{className:"w-full border-t border-border"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-background px-2 text-muted-foreground",children:"or"})})]}),e.jsxs(b,{variant:"outline",className:"w-full",onClick:()=>R(!0),children:[e.jsx($e,{className:"h-4 w-4 mr-2"})," Create New Organization"]})]})}),e.jsxs(Me,{children:[e.jsx(b,{variant:"outline",onClick:()=>i(!1),disabled:f,children:"Cancel"}),e.jsx(b,{onClick:te,disabled:!o||f,className:"bg-green-600 hover:bg-green-700",children:f?"Approving...":"Approve & Assign"})]})]})}),e.jsx(Ae,{open:!!r&&m!=="approve",onOpenChange:()=>w(null),children:e.jsxs(Re,{children:[e.jsxs(qe,{children:[e.jsxs(ze,{children:[m==="reject"&&"Reject Signup Request?",m==="delete"&&"Delete Signup Request?"]}),e.jsxs(Oe,{children:[m==="reject"&&"This will reject the signup request and notify the user via email.",m==="delete"&&"This will permanently delete this signup request."]})]}),e.jsxs(Fe,{children:[e.jsx(ke,{disabled:f,children:"Cancel"}),e.jsx(Te,{onClick:ne,disabled:f,className:m==="reject"?"bg-red-600 hover:bg-red-700":"",children:f?"Processing...":m==="reject"?"Reject":"Delete"})]})]})})]})};export{ws 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.