PageSourceSearch

https://xterns.ai/assets/SuperAdminUsers-Cf9xJPXT.js

js xterns.ai collected 2026-10-05 13:23:37 UTC 31,977 bytes, 5 lines download raw bytes

1import{r as j,j as e,I as O,B as S,M as B,N as V,O as q,Q as M,V as $,W as de,Y as Pe,h as k,i as D,k as E,m as U,J as N,s as A,f as ke,Z as Ue,_ as W,D as Ae,U as De,X as Ee,g as F}from"./index-DLd_kDlx.js";import{u as Z}from"./useMutation-CotV56Sa.js";import{T as Te,a as Fe,b as R,c as C,d as Ie,e as w}from"./table-BOJIo-OD.js";import{S as K,a as Q,b as H,c as G,d as P}from"./select-RSrodAEw.js";import{S as me}from"./SuperAdminLayout-BsUvQU2j.js";import{L as T}from"./label-D4-ENrYn.js";import{T as he}from"./textarea-C6X-I43k.js";import{A as xe,a as ue}from"./alert-CyfKy7ls.js";import{D as Le}from"./download-Cr0jatld.js";import{L as Oe}from"./loader-circle-D2miE2xB.js";import{B as Re}from"./book-open-BSYsXyfC.js";import{A as ee}from"./award-MEJfpupD.js";import{T as Be}from"./trending-up-BU4cR3Ys.js";import{I as Ve}from"./InvitationStatusBadge-DHSAISAb.js";import{U as qe}from"./upload-CCEcMTV9.js";import{U as Me}from"./user-plus-CSalqUlO.js";import{S as $e}from"./search-DFH5eAlA.js";import{F as Ke}from"./filter-BMeMiGQo.js";import"./index-BdQq_4o_.js";import"./index-Deh-4PO1.js";import"./chevron-down-DpJJsCer.js";import"./chevron-up-M4SAwIjf.js";import"./NotificationIcon-C1wwYnH5.js";import"./popover-BMD5FOmU.js";import"./scroll-area-BXTuUF24.js";import"./NotificationItem-Dc2WXW-y.js";import"./formatDistanceToNow-57P64IbE.js";import"./en-US-9SRVm7yB.js";import"./differenceInCalendarMonths-BA0TPVs2.js";import"./endOfDay-DkR3ZXc8.js";import"./endOfMonth-CYn6pTOm.js";import"./message-square-CtxeCfRz.js";import"./trophy-DBX-jNOC.js";import"./triangle-alert-Chqk_WK7.js";import"./dropdown-menu-DSd1c3Vk.js";import"./index-lTaZyIGy.js";import"./chevron-right-CD1gvy-q.js";import"./crown-hzm_bRIt.js";import"./user-check-DxoAQXwU.js";import"./star-BH1OFEcs.js";import"./globe-C057RQ73.js";import"./timer-CZhDpZys.js";import"./briefcase-business-CphIeAJd.js";import"./key-round-B79BulHq.js";const Qe=({onSubmit:m,isLoading:u,enterprises:n=[]})=>{const[s,v]=j.useState({email:"",full_name:"",user_type:"xtern",enterprise_id:""}),i=["xtern","tech_lead","enterprise","super_admin","client"],h=a=>{a.preventDefault();const o={email:s.email,full_name:s.full_name||null,user_type:s.user_type,roles:[s.user_type],enterprise_id:s.user_type==="enterprise"&&s.enterprise_id?s.enterprise_id:null};m(o)};return e.jsxs("form",{onSubmit:h,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"email",children:"Email"}),e.jsx(O,{id:"email",type:"email",value:s.email,onChange:a=>v(o=>({...o,email:a.target.value})),placeholder:"[email protected]",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"full_name",children:"Full Name (Optional)"}),e.jsx(O,{id:"full_name",value:s.full_name,onChange:a=>v(o=>({...o,full_name:a.target.value})),placeholder:"John Doe"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"user_type",children:"Role"}),e.jsxs(K,{value:s.user_type,onValueChange:a=>v(o=>({...o,user_type:a,enterprise_id:""})),children:[e.jsx(Q,{children:e.jsx(H,{})}),e.jsx(G,{children:i.map(a=>e.jsx(P,{value:a,children:a.replace("_"," ").replace(/\b\w/g,o=>o.toUpperCase())},a))})]})]}),s.user_type==="enterprise"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"enterprise_id",children:"Enterprise Account"}),e.jsxs(K,{value:s.enterprise_id,onValueChange:a=>v(o=>({...o,enterprise_id:a})),children:[e.jsx(Q,{children:e.jsx(H,{placeholder:"Select an enterprise"})}),e.jsx(G,{children:n.map(a=>e.jsx(P,{value:a.id,children:a.name},a.id))})]}),n.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No enterprise accounts found. Create one first."})]}),e.jsx("div",{className:"flex justify-end space-x-2 pt-4",children:e.jsx(S,{type:"submit",disabled:u||s.user_type==="enterprise"&&!s.enterprise_id,children:u?"Sending Invitation...":"Send Invitation"})})]})},He=({onSubmit:m,isLoading:u})=>{const[n,s]=j.useState({name:"",description:"",max_users:""}),v=i=>{i.preventDefault(),m({name:n.name,description:n.description||null,max_users:n.max_users?parseInt(n.max_users):null})};return e.jsxs("form",{onSubmit:v,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"name",children:"Enterprise Name *"}),e.jsx(O,{id:"name",value:n.name,onChange:i=>s(h=>({...h,name:i.target.value})),placeholder:"Acme Corporation",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"description",children:"Description"}),e.jsx(he,{id:"description",value:n.description,onChange:i=>s(h=>({...h,description:i.target.value})),placeholder:"Brief description of the enterprise...",rows:3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"max_users",children:"Maximum Number of Users (Optional)"}),e.jsx(O,{id:"max_users",type:"number",min:"1",value:n.max_users,onChange:i=>s(h=>({...h,max_users:i.target.value})),placeholder:"e.g. 100"})]}),e.jsx("div",{className:"flex justify-end space-x-2 pt-4",children:e.jsx(S,{type:"submit",disabled:u,children:u?"Creating Enterprise...":"Create Enterprise"})})]})},Ge=({onImport:m,isLoading:u})=>{const[n,s]=j.useState(""),[v,i]=j.useState(""),h=()=>{const f=`email,password,full_name,user_type,additional_roles
2[email protected],password123,John Doe,xtern,
3[email protected],password456,Jane Smith,tech_lead,enterprise
4[email protected],admin789,Admin User,super_admin,`,l=new Blob([f],{type:"text/csv"}),c=window.URL.createObjectURL(l),d=document.createElement("a");
4d.href=c,d.download="user-import-template.csv",d.click(),window.URL.revokeObjectURL(c)},a=f=>{try{const l=f.trim().split(`
5`),c=l[0].split(",").map(p=>p.trim());if(!c.includes("email")||!c.includes("password")||!c.includes("user_type"))throw new Error("CSV must contain email, password, and user_type columns");const d=[];for(let p=1;p<l.length;p++){const y=l[p].split(",").map(x=>x.trim());if(y.length!==c.length)throw new Error(`Row ${p+1}: Incorrect number of columns`);const t={};if(c.forEach((x,b)=>{t[x]=y[b]}),!t.email||!t.password||!t.user_type)throw new Error(`Row ${p+1}: Missing required fields`);if(t.additional_roles){const x=t.additional_roles.split(";").map(b=>b.trim()).filter(b=>b);t.roles=[t.user_type,...x]}else t.roles=[t.user_type];d.push(t)}return d}catch(l){throw new Error(`CSV parsing error: ${l.message}`)}},o=()=>{try{i("");const f=a(n);m(f)}catch(f){i(f.message)}};return e.jsxs("div",{className:"space-y-4",children:[e.jsx(xe,{children:e.jsx(ue,{children:'Upload a CSV file with columns: email, password, full_name, user_type, additional_roles. Additional roles should be separated by semicolons (e.g., "tech_lead;enterprise").'})}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx(T,{htmlFor:"csv-data",children:"CSV Data"}),e.jsxs(S,{type:"button",variant:"outline",size:"sm",onClick:h,children:[e.jsx(Le,{className:"h-4 w-4 mr-2"}),"Download Template"]})]}),e.jsx(he,{id:"csv-data",value:n,onChange:f=>s(f.target.value),placeholder:"Paste your CSV data here or download the template to get started...",rows:10})]}),v&&e.jsx(xe,{variant:"destructive",children:e.jsx(ue,{children:v})}),e.jsx("div",{className:"flex justify-end space-x-2",children:e.jsx(S,{onClick:o,disabled:!n.trim()||u,children:u?"Importing...":"Import Users"})})]})},ze=({userId:m,userEmail:u,onClose:n})=>{var o,f,l,c,d,p,y;const{data:s,isLoading:v,error:i}=B({queryKey:["user-details",m],queryFn:async()=>{const t=new URLSearchParams({action:"user-details",user_id:m}),{data:x,error:b}=await A.functions.invoke(`superadmin-users?${t}`,{method:"GET"});if(b)throw b;return x},enabled:!!m}),h=t=>t?new Date(t).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric",hour:"2-digit",minute:"2-digit"}):"Never",a=t=>{switch(t){case"super_admin":return"bg-purple-100 text-purple-800";case"tech_lead":return"bg-blue-100 text-blue-800";case"corporate":return"bg-green-100 text-green-800";case"xtern":return"bg-gray-100 text-gray-800";default:return"bg-gray-100 text-gray-800"}};return e.jsx(V,{open:!0,onOpenChange:n,children:e.jsxs(q,{className:"max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(M,{children:[e.jsxs($,{className:"flex items-center gap-2",children:[e.jsx(de,{className:"h-5 w-5"}),"User Details: ",u]}),e.jsx(Pe,{children:"View detailed information about this user's profile, assessment scores, and activity."})]}),v?e.jsxs("div",{className:"flex items-center justify-center py-12",children:[e.jsx(Oe,{className:"h-8 w-8 animate-spin"}),e.jsx("span",{className:"ml-2",children:"Loading user details..."})]}):i?e.jsxs("div",{className:"text-center py-12",children:[e.jsx("p",{className:"text-red-600",children:"Failed to load user details"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:i instanceof Error?i.message:"Unknown error"})]}):s?e.jsxs("div",{className:"space-y-6",children:[e.jsxs(k,{children:[e.jsx(D,{children:e.jsxs(E,{className:"flex items-center gap-2",children:[e.jsx(de,{className:"h-4 w-4"}),"Profile Information"]})}),e.jsx(U,{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Full Name"}),e.jsx("p",{className:"text-sm",children:((o=s.profile)==null?void 0:o.full_name)||"Not provided"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Email"}),e.jsx("p",{className:"text-sm",children:((f=s.profile)==null?void 0:f.email)||"Not available"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"User Type"}),e.jsx(N,{className:a(((l=s.profile)==null?void 0:l.user_type)||"unknown"),children:((c=s.profile)==null?void 0:c.user_type)||"Unknown"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Created At"}),e.jsx("p",{className:"text-sm",children:h((d=s.profile)==null?void 0:d.created_at)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Last Sign In"}),e.jsx("p",{className:"text-sm",children:h((p=s.profile)==null?void 0:p.last_sign_in_at)})]})]})})]}),e.jsxs(k,{children:[e.jsx(D,{children:e.jsx(E,{children:"Assigned Roles"})}),e.jsx(U,{children:e.jsx("div",{className:"flex flex-wrap gap-2",children:((y=s.roles)==null?void 0:y.length)>0?s.roles.map(t=>e.jsx(N,{variant:"outline",className:a(t),children:t},t)):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No roles assigned"})})})]}),s.onboarding_assessments&&s.onboarding_assessments.length>0&&e.jsxs(k,{children:[e.jsx(D,{children:e.jsxs(E,{className:"flex items-center gap-2",children:[e.jsx(Re,{className:"h-4 w-4"}),"Onboarding Assessment History"]})}),e.jsx(U,{children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b",children:[e.jsx("th",{className:"text-left py-2 px-2 font-medium text-muted-foreground",children:"Attempt #"}),e.jsx("th",{className:"text-left py-2 px-2 font-medium text-muted-foreground",children:"Score"}),e.jsx("th",{className:"text-left py-2 px-2 font-medium text-muted-foreground",children:"Status"}),e.jsx("th",{className:"text-left py-2 px-2 font-medium text-muted-foreground",children:"Tech Stacks"}),e.jsx("th",{className:"text-left py-2 px-2 font-medium text-muted-foreground",children:"Completed At"})]})}),e.jsx("tbody",{children:s.onboarding_assessments.map(t=>e.jsxs("tr",{className:"border-b last:border-0",children:[e.jsx("td",{className:"py-2 px-2",children:t.attempt_number}),e.jsxs("td",{className:"py-2 px-2",children:[e.jsxs("span",{className:"font-semibold",children:[Math.round(t.score),"%"]}),e.jsxs("span",{className:"text-muted-foreground ml-1",children:["(",t.total_score,"/",t.max_possible_score,")"]})]}),e.jsx("td",{className:"py-2 px-2",children:e.jsx(N,{variant:t.passed?"default":"destructive",children:t.passed?"Passed":"Failed"})}),e.jsx("td",{className:"py-2 px-2",children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[Array.isArray(t.tech_stacks)?t.tech_stacks.slice(0,3).map(x=>e.jsx(N,{variant:"outline",className:"text-xs",children:typeof x=="str
5ing"?x:(x==null?void 0:x.name)||"Unknown"},typeof x=="string"?x:x==null?void 0:x.name)):e.jsx("span",{className:"text-muted-foreground",children:"-"}),Array.isArray(t.tech_stacks)&&t.tech_stacks.length>3&&e.jsxs(N,{variant:"outline",className:"text-xs",children:["+",t.tech_stacks.length-3]})]})}),e.jsx("td",{className:"py-2 px-2 text-muted-foreground",children:h(t.completed_at)})]},t.id))})]})})})]}),s.assessment_score&&e.jsxs(k,{children:[e.jsx(D,{children:e.jsxs(E,{className:"flex items-center gap-2",children:[e.jsx(ee,{className:"h-4 w-4"}),"Assessment Score"]})}),e.jsxs(U,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Score"}),e.jsxs("p",{className:"text-2xl font-bold text-primary",children:[s.assessment_score.score_percentage,"%"]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Points"}),e.jsxs("p",{className:"text-lg font-semibold",children:[s.assessment_score.total_score,"/",s.assessment_score.max_possible_score]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Status"}),e.jsx(N,{variant:s.assessment_score.passed?"default":"destructive",children:s.assessment_score.passed?"Passed":"Failed"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Completed At"}),e.jsx("p",{className:"text-sm",children:h(s.assessment_score.completed_at)})]})]})]}),s.ei_score&&e.jsxs(k,{children:[e.jsx(D,{children:e.jsxs(E,{className:"flex items-center gap-2",children:[e.jsx(Be,{className:"h-4 w-4"}),"Signal Score"]})}),e.jsxs(U,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Overall Score"}),e.jsxs("p",{className:"text-2xl font-bold text-primary",children:[Math.round(s.ei_score.score||0),"/1000"]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Calculated At"}),e.jsx("p",{className:"text-sm",children:h(s.ei_score.calculated_at)})]})]}),s.ei_score.score_breakdown&&e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground mb-2 block",children:"Score Breakdown"}),e.jsxs("div",{className:"grid grid-cols-3 gap-4 text-sm",children:[e.jsxs("div",{className:"text-center p-3 bg-blue-50 dark:bg-blue-950/30 rounded-lg",children:[e.jsx("div",{className:"text-lg font-bold text-blue-600 dark:text-blue-400",children:Math.round(s.ei_score.score_breakdown.technical||0)}),e.jsx("div",{className:"text-muted-foreground text-xs",children:"Technical"})]}),e.jsxs("div",{className:"text-center p-3 bg-green-50 dark:bg-green-950/30 rounded-lg",children:[e.jsx("div",{className:"text-lg font-bold text-green-600 dark:text-green-400",children:Math.round(s.ei_score.score_breakdown.engagement||0)}),e.jsx("div",{className:"text-muted-foreground text-xs",children:"Engagement"})]}),e.jsxs("div",{className:"text-center p-3 bg-purple-50 dark:bg-purple-950/30 rounded-lg",children:[e.jsx("div",{className:"text-lg font-bold text-purple-600 dark:text-purple-400",children:Math.round(s.ei_score.score_breakdown.collaboration||0)}),e.jsx("div",{className:"text-muted-foreground text-xs",children:"Collaboration"})]})]})]})]})]}),s.xtern_profile&&e.jsxs(k,{children:[e.jsx(D,{children:e.jsxs(E,{className:"flex items-center gap-2",children:[e.jsx(ee,{className:"h-4 w-4"}),"Xtern Profile"]})}),e.jsxs(U,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[s.xtern_profile.phone&&e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Phone"}),e.jsx("p",{className:"text-sm",children:s.xtern_profile.phone})]}),s.xtern_profile.country&&e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Country"}),e.jsx("p",{className:"text-sm",children:s.xtern_profile.country})]})]}),s.xtern_profile.skills.length>0&&e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground mb-2 block",children:"Skills"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:s.xtern_profile.skills.map(t=>e.jsx(N,{variant:"outline",className:"text-xs",children:t},t))})]}),s.xtern_profile.preferred_roles.length>0&&e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground mb-2 block",children:"Preferred Roles"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:s.xtern_profile.preferred_roles.map(t=>e.jsx(N,{variant:"outline",className:"text-xs",children:t},t))})]}),e.jsxs("div",{className:"flex gap-4",children:[s.xtern_profile.github_url&&e.jsx("a",{href:s.xtern_profile.github_url,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-blue-600 hover:underline",children:"GitHub Profile"}),s.xtern_profile.linkedin_url&&e.jsx("a",{href:s.xtern_profile.linkedin_url,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-blue-600 hover:underline",children:"LinkedIn Profile"})]})]})]}),s.tech_lead_profile&&e.jsxs(k,{children:[e.jsx(D,{children:e.jsxs(E,{className:"flex items-center gap-2",children:[e.jsx(ee,{className:"h-4 w-4"}),"Tech Lead Profile"]})}),e.jsxs(U,{className:"space-y-4",children:[s.tech_lead_profile.bio&&e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Bio"}),e.jsx("p",{className:"text-sm",children:s.tech_lead_profile.bio})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Years of Experience"}),e.jsx("p",{className:"text-sm",children:s.tech_lead_profile.years_experience})]}),s.tech_lead_profile.location&&e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Location"}),e.jsx("p",{className:"text-sm",children:s.tech_lead_profile.location})]})]}),s.tech_lead_profile.expertise_areas.length>0&&e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground mb-2 block",children:"Expertise Areas"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:s.tech_lead_profile.expertise_areas.map(t=>e.jsx(N,{variant:"outline",className:"text-xs",children:t},t))})]}),s.tech_lead_profile.career_paths&&s.tech_lead_profile.career_paths.length>0&&e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground mb-2 block",children:"Professional Roles"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:s.tech_lead_profile.career_paths.map(t=>e.jsx(N,{variant:"outline",className:"text-xs",children:t},t))})]}),s.tech_lead_profile.phone&&e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Phone"}),e.jsx("p",{className:"text-sm",children:s.tech_lead_profile.phone})]}),s.tech_lead_profile.is_available!==void 0&&e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"Availability"}),e.jsx(N,{variant:s.tech_lead_profile.is_available?"default":"secondary",children:s.tech_lead_profile.is_available?"Available":"Not Available"})]}),e.jsxs("div",{className:"flex gap-4",children:[s.tech_lead_profile.github_url&&e.jsx("a",{href:s.tech_lead_profile.github_url,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-blue-600 hover:underline",children:"GitHub Profile"}),s.tech_lead_profile.linkedin_url&&e.jsx("a",{href:s.tech_lead_profile.linkedin_url,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-blue-600 hover:underline",children:"LinkedIn Profile"}),s.tech_lead_profile.portfolio_url&&e.jsx("a",{href:s.tech_lead_profile.portfolio_url,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-blue-600 hover:underline",children:"Portfolio"})]})]})]})]}):e.jsx("div",{className:"text-center py-12",children:e.jsx("p",{className:"text-muted-foreground",children:"No user details found"})})]})})};function Je(m,u){const[n,s]=j.useState(m);return j.useEffect(()=>{const v=setTimeout(()=>{s(m)},u);return()=>{clearTimeout(v)}},[m,u]),n}const pe=j.createContext({onlineUsers:new Set,isUserOnline:()=>!1,onlineCount:0,lastSyncAt:null}),Xe=()=>j.useContext(pe),Ye=({children:m})=>{const[u,n]=j.useState(new Set),[s,v]=j.useState(null),{user:i}=ke();j.useEffect(()=>{if(!i)return;console.log("PresenceProvider: Setting up presence for user:",i.id),n(l=>new Set([...l,i.id]));const a=A.channel("online-users",{config:{presence:{key:i.id}}}).on("presence",{event:"sync"},()=>{const l=a.presenceState(),c=new Set;console.log("PresenceProvider: Sync event, presence state:",l),v(new Date),Object.entries(l).forEach(([d,p])=>{p&&p.length>
50&&(p.forEach(y=>{y.user_id&&(c.add(y.user_id),console.log("PresenceProvider: User online via user_id:",y.user_id))}),c.add(d),console.log("PresenceProvider: User online via key:",d))}),console.log("PresenceProvider: Final online users:",Array.from(c)),n(c)}).on("presence",{event:"join"},({key:l,newPresences:c})=>{console.log("PresenceProvider: User joined:",l,c),n(d=>new Set([...d,l]))}).on("presence",{event:"leave"},({key:l,leftPresences:c})=>{console.log("PresenceProvider: User left:",l,c),n(d=>{const p=new Set(d);return p.delete(l),p})});a.subscribe(async l=>{if(console.log("PresenceProvider: Channel status:",l),l==="SUBSCRIBED"){const c=await a.track({user_id:i.id,online_at:new Date().toISOString()});console.log("PresenceProvider: Track status for user",i.id,":",c)}});let o=null;const f=()=>{o&&clearTimeout(o),o=setTimeout(async()=>{if(!document.hidden)try{await a.track({user_id:i.id,online_at:new Date().toISOString()}),console.log("PresenceProvider: Tracked presence on tab focus (debounced)")}catch(l){console.warn("PresenceProvider: Visibility track failed:",l)}},1e3)};return document.addEventListener("visibilitychange",f),()=>{console.log("PresenceProvider: Cleaning up for user:",i.id),document.removeEventListener("visibilitychange",f),o&&clearTimeout(o),A.removeChannel(a)}},[i]);const h=a=>u.has(a);return e.jsx(pe.Provider,{value:{onlineUsers:u,isUserOnline:h,onlineCount:u.size,lastSyncAt:s},children:m})},We=()=>{const[m,u]=j.useState(""),[n,s]=j.useState(1),[v,i]=j.useState(!1),[h,a]=j.useState(!1),[o,f]=j.useState(!1),[l,c]=j.useState(null),[d,p]=j.useState("all"),[y,t]=j.useState("desc"),x=25,b=Ue(),{isUserOnline:je,onlineCount:fe,lastSyncAt:se}=Xe(),z=Je(m.trim(),350),L=z.length>2||z.length===0?z:"",{data:ge}=B({queryKey:["enterprises"],queryFn:async()=>{const{data:r,error:g}=await A.from("enterprise_accounts").select("id, name").order("name");if(g)throw g;return r}}),{data:J,isLoading:ve,error:_e}=B({queryKey:["admin-users",L,n,d,y],queryFn:async()=>{const r=new URLSearchParams({action:"list-users",search:L,page:n.toString(),limit:x.toString(),role:d,sort_created:y}),{data:g,error:_}=await A.functions.invoke(`superadmin-users?${r}`,{method:"GET"});if(_)throw _;return g}}),I=J==null?void 0:J.users,{data:X}=B({queryKey:["admin-users-count",L,d],queryFn:async()=>{const r=new URLSearchParams({action:"count-users",search:L,role:d}),{data:g,error:_}=await A.functions.invoke(`superadmin-users?${r}`,{method:"GET"});if(_)throw _;return g}}),re=X==null?void 0:X.count,te=Z({mutationFn:async r=>{var oe;const{data:g,error:_}=await A.from("enterprise_accounts").insert({...r,created_by:(oe=(await A.auth.getUser()).data.user)==null?void 0:oe.id}).select().single();if(_)throw _;return g},onSuccess:()=>{F.success("Enterprise account created successfully"),b.invalidateQueries({queryKey:["enterprises"]}),a(!1)},onError:r=>{F.error(r.message||"Failed to create enterprise account")}}),ae=Z({mutationFn:async r=>{const{data:g,error:_}=await A.functions.invoke("superadmin-users?action=invite-user",{body:r});if(_)throw _;return g},onSuccess:()=>{F.success("Invitation sent successfully"),b.invalidateQueries({queryKey:["admin-users"]}),b.invalidateQueries({queryKey:["admin-users-count"]}),i(!1)},onError:r=>{F.error(r.message||"Failed to send invitation")}}),ne=Z({mutationFn:async r=>{const{data:g,error:_}=await A.functions.invoke("superadmin-users?action=bulk-create",{body:{users:r}});if(_)throw _;return g},onSuccess:r=>{r.errors.length>0?F.error(`Created ${r.results.length} users with ${r.errors.length} errors`):F.success(`Successfully created ${r.results.length} users`),b.invalidateQueries({queryKey:["admin-users"]}),b.invalidateQueries({queryKey:["admin-users-count"]}),f(!1)},onError:r=>{F.error(r.message||"Failed to import users")}}),Y=Math.ceil((re||0)/x),Ne=r=>{r.preventDefault(),s(1)},le=()=>{s(1)},be=()=>{u(""),s(1)},ie=r=>{if(je(r.id))return"Active";if(r.last_sign_in_at){const g=new Date(r.last_sign_in_at),_=new Date(Date.now()-600*1e3);if(g>_)return"Active"}return"Inactive"},ye=r=>ie(r)==="Active"?"bg-green-100 text-green-800":"bg-gray-100 text-gray-800",ce=r=>r?new Date(r).toLocaleDateString():"Never",we=r=>{switch(r){case"super_admin":return"bg-purple-100 text-purple-800";case"tech_lead":return"bg-blue-100 text-blue-800";case"corporate":return"bg-green-100 text-green-800";
5case"enterprise":return"bg-orange-100 text-orange-800";case"xtern":return"bg-gray-100 text-gray-800";default:return"bg-gray-100 text-gray-800"}},Se=r=>{switch(r){case"approved":return"bg-green-100 text-green-800";case"rejected":return"bg-red-100 text-red-800";case"pending_review":return"bg-yellow-100 text-yellow-800";default:return"bg-gray-100 text-gray-500"}},Ce=r=>{switch(r){case"approved":return"Approved";case"rejected":return"Rejected";case"pending_review":return"Pending";default:return"N/A"}};return _e?e.jsx(me,{children:e.jsxs("div",{className:"text-center py-12",children:[e.jsx("h2",{className:"text-xl font-semibold text-red-600",children:"Error Loading Users"}),e.jsx("p",{className:"text-gray-600 mt-2",children:"Failed to load users data"})]})}):e.jsx(me,{children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold text-gray-900",children:"Users Management"}),e.jsxs("p",{className:"text-gray-600 mt-1",children:["Manage platform users and their roles • Online: ",fe," users",se&&` • Last sync: ${se.toLocaleTimeString()}`]})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs(V,{open:h,onOpenChange:a,children:[e.jsx(W,{asChild:!0,children:e.jsxs(S,{variant:"outline",children:[e.jsx(Ae,{className:"h-4 w-4 mr-2"}),"Create Enterprise Account"]})}),e.jsxs(q,{children:[e.jsx(M,{children:e.jsx($,{children:"Create Enterprise Account"})}),e.jsx(He,{onSubmit:r=>te.mutate(r),isLoading:te.isPending})]})]}),e.jsxs(V,{open:o,onOpenChange:f,children:[e.jsx(W,{asChild:!0,children:e.jsxs(S,{variant:"outline",children:[e.jsx(qe,{className:"h-4 w-4 mr-2"}),"Bulk Import"]})}),e.jsxs(q,{className:"max-w-2xl",children:[e.jsx(M,{children:e.jsx($,{children:"Bulk Import Users"})}),e.jsx(Ge,{onImport:r=>ne.mutate(r),isLoading:ne.isPending})]})]}),e.jsxs(V,{open:v,onOpenChange:i,children:[e.jsx(W,{asChild:!0,children:e.jsxs(S,{className:"bg-primary hover:bg-opacity-90",children:[e.jsx(Me,{className:"h-4 w-4 mr-2"}),"Invite User"]})}),e.jsxs(q,{children:[e.jsx(M,{children:e.jsx($,{children:"Invite New User"})}),e.jsx(Qe,{onSubmit:r=>ae.mutate(r),isLoading:ae.isPending,enterprises:ge})]})]})]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-6",children:e.jsxs(k,{children:[e.jsxs(D,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(E,{className:"text-sm font-medium",children:"Total Users"}),e.jsx(De,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(U,{children:e.jsx("div",{className:"text-2xl font-bold",children:re||0})})]})}),e.jsx(k,{children:e.jsx(U,{className:"pt-6",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("form",{onSubmit:Ne,className:"flex gap-4",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx($e,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 h-4 w-4"}),e.jsx(O,{placeholder:"Search by email or name (min 3 characters)...",value:m,onChange:r=>u(r.target.value),className:"pl-10 pr-10"}),m&&e.jsx("button",{type:"button",onClick:be,className:"absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-400 hover:text-gray-600",children:e.jsx(Ee,{className:"h-4 w-4"})})]}),e.jsx(S,{type:"submit",variant:"outline",children:"Search"})]}),e.jsxs("div",{className:"flex gap-4 items-center",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ke,{className:"h-4 w-4 text-gray-500"}),e.jsx("span",{className:"text-sm font-medium",children:"Filters:"})]}),e.jsxs(K,{value:d,onValueChange:r=>{p(r),le()},children:[e.jsx(Q,{className:"w-48",children:e.jsx(H,{placeholder:"Filter by role"})}),e.jsxs(G,{children:[e.jsx(P,{value:"all",children:"All Roles"}),e.jsx(P,{value:"xtern",children:"Xtern"}),e.jsx(P,{value:"tech_lead",children:"Tech Lead"}),e.jsx(P,{value:"corporate",children:"Corporate"}),e.jsx(P,{value:"enterprise",children:"Enterprise"}),e.jsx(P,{value:"super_admin",children:"Super Admin"})]})]}),e.jsxs(K,{value:y,onValueChange:r=>{t(r),le()},children:[e.jsx(Q,{className:"w-48",children:e.jsx(H,{placeholder:"Sort by created date"})}),e.jsxs(G,{children:[e.jsx(P,{value:"desc",children:"Newest First"}),e.jsx(P,{value:"asc",children:"Oldest First"})]})]})]}),m.length>0&&m.length<=2&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Enter at least 3 characters to search"})]})})}),e.jsx(k,{children:e.jsxs(U,{children:[e.jsxs(Te,{children:[e.jsx(Fe,{children:e.jsxs(R,{children:[e.jsx(C,{children:"Email"}),e.jsx(C,{children:"Name"}),e.jsx(C,{children:"Account Status"}),e.jsx(C,{children:"Invitation Status"}),e.jsx(C,{children:"Review Status"}),e.jsx(C,{children:"Primary Role"}),e.jsx(C,{children:"All Roles"}),e.jsx(C,{children:"Created"}),e.jsx(C,{children:"Last Sign In"}),e.jsx(C,{children:"Actions"})]})}),e.jsx(Ie,{children:ve?e.jsx(R,{children:e.jsx(w,{colSpan:10,className:"text-center py-12",children:"Loading users..."})}):(I==null?void 0:I.length)===0?e.jsx(R,{children:e.jsx(w,{colSpan:10,className:"text-center py-12",children:L?"No users found for your search":"No users found"})}):I==null?void 0:I.map(r=>e.jsxs(R,{children:[e.jsx(w,{className:"font-medium",children:r.email}),e.jsx(w,{children:r.full_name}),e.jsx(w,{children:e.jsx(N,{className:ye(r),children:ie(r)})}),e.jsx(w,{children:e.jsx(Ve,{status:r.invitation_status})}),e.jsx(w,{children:e.jsx(N,{className:Se(r.review_status),children:Ce(r.review_status)})}),e.jsx(w,{children:e.jsx(N,{className:we(r.user_type),children:r.user_type})}),e.jsx(w,{children:e.jsx("div",{className:"flex flex-wrap gap-1",children:r.roles.map(g=>e.jsx(N,{variant:"outline",className:"text-xs",children:g},g))})}),e.jsx(w,{children:ce(r.created_at)}),e.jsx(w,{children:ce(r.last_sign_in_at)}),e.jsx(w,{children:e.jsx(S,{variant:"outline",size:"sm",onClick:()=>c(r),children:"View Details"})})]},r.id))})]}),Y>1&&e.jsxs("div",{className:"flex justify-center gap-2 mt-6",children:[e.jsx(S,{variant:"outline",disabled:n===1,onClick:()=>s(n-1),children:"Previous"}),e.jsxs("span",{className:"flex items-center px-4",children:["Page ",n," of ",Y]}),e.jsx(S,{variant:"outline",disabled:n===Y,onClick:()=>s(n+1),children:"Next"})]})]})}),l&&e.jsx(ze,{userId:l.id,userEmail:l.email,onClose:()=>c(null)})]})})},$s=()=>e.jsx(Ye,{children:e.jsx(We,{})});
5export{$s 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.