PageSourceSearch

https://etaps.ai/assets/OnboardingTrainingDashboard-DZ-ugiSI.js

js etaps.ai collected 2026-10-05 14:21:59 UTC 11,030 bytes, 1 lines download raw bytes

1import{r as o,j as e}from"./react-2yNL-0jO.js";import{P as Z}from"./CommandCenter-COHUW4tT.js";import{L as M}from"./react-router-C95oXNrA.js";import{h as J,s as C,I as K,B as W}from"./index-0I6tP8u4.js";import{C as B}from"./card-Dyz-4WUa.js";import{S as ee,a as te,b as se,c as ae,d as A}from"./select-Y_CU5rpp.js";import{T as ne,C as E}from"./CategoryBreakdown-DdcCZz7m.js";import{O as le,Y as re,a_ as ie,aq as oe,l as ce,f as F,c8 as de,aI as k,d as q,aw as me,V as xe}from"./lucide-YE_Cg0sW.js";import"./admin-vendor-CGWxZvmW.js";import"./ui-vendor-C2kPg7wM.js";import"./date-fns-VUYwK_nv.js";import"./recharts-BX1VkUUO.js";function Se(){const{user:l}=J(),[b,g]=o.useState(!0),[r,j]=o.useState([]),[L,D]=o.useState([]),[N,U]=o.useState([]),[x,P]=o.useState(""),[p,V]=o.useState("all"),[d,$]=o.useState({key:"date",dir:-1});o.useEffect(()=>{(async()=>{if(!(l!=null&&l.companyId))return;g(!0);const t=l.companyId,[s,a,i]=await Promise.all([C.from("onboarding_training_sessions").select("*").eq("company_id",t),C.from("onboarding_clients").select("id, client_name, brand_name").eq("company_id",t),C.from("profiles").select("id, full_name").eq("company_id",t)]);j(s.data||[]),D(a.data||[]),U(i.data||[]),g(!1)})()},[l==null?void 0:l.companyId]);const _=t=>{const s=L.find(a=>a.id===t);return(s==null?void 0:s.brand_name)||(s==null?void 0:s.client_name)||"—"},f=t=>{var s;return t.host_name||((s=N.find(a=>a.id===t.trainer_id))==null?void 0:s.full_name)||"—"},z=t=>t.scheduled_at?new Date(t.scheduled_at).toLocaleString("en-US",{weekday:"short",day:"numeric",month:"short",hour:"numeric",minute:"2-digit",timeZone:t.timezone||void 0}):t.scheduled_date||"No date",c=o.useMemo(()=>{const t=r.filter(n=>n.status!=="cancelled"),s=r.filter(n=>n.status==="scheduled"),a=r.filter(n=>n.status==="completed"),i=a.filter(n=>!n.client_attended),u=r.filter(n=>n.booked_by_client),h=a.filter(n=>n.recording_url),v=a.filter(n=>n.client_rating),H=v.length?v.reduce((n,S)=>n+S.client_rating,0)/v.length:0,y=a.filter(n=>n.trainer_rating),Q=y.length?y.reduce((n,S)=>n+S.trainer_rating,0)/y.length:0,X=t.length?Math.round(a.length/t.length*100):0;return{total:t.length,scheduled:s.length,completed:a.length,completionRate:X,clientBooked:u.length,noShows:i.length,withRecording:h.length,avgClient:H,avgTrainer:Q}},[r]),I=o.useMemo(()=>{const t=new Map;for(const s of r){if(s.status==="cancelled")continue;const a=f(s),i=t.get(a)||{name:a,total:0,completed:0,ratingSum:0,ratingN:0};i.total++,s.status==="completed"&&i.completed++,s.client_rating&&(i.ratingSum+=s.client_rating,i.ratingN++),t.set(a,i)}return[...t.values()].filter(s=>s.name!=="—").sort((s,a)=>a.total-s.total)},[r,N]),O=o.useMemo(()=>Array.from(new Set(r.map(t=>t.status).filter(Boolean))).sort(),[r]),Y=t=>t.scheduled_date||(t.scheduled_at?t.scheduled_at.slice(0,10):"")||(t.completed_at?t.completed_at.slice(0,10):""),w=o.useMemo(()=>{const t=r.filter(a=>(p==="all"||a.status===p)&&(!x||_(a.client_id).toLowerCase().includes(x.toLowerCase())||(a.title||"").toLowerCase().includes(x.toLowerCase())||f(a).toLowerCase().includes(x.toLowerCase()))),s=(a,i)=>{switch(i){case"client":return _(a.client_id).toLowerCase();case"session":return a.session_number||0;case"date":return Y(a);case"trainer":return f(a).toLowerCase();case"status":return a.status||"";case"rating":return a.client_rating||0;default:return""}};return[...t].sort((a,i)=>{const u=s(a,d.key),h=s(i,d.key);return typeof u=="number"&&typeof h=="number"?(u-h)*d.dir:String(u).localeCompare(String(h))*d.dir})},[r,x,p,d,L,N]),R=t=>$(s=>s.key===t?{key:t,dir:s.dir===1?-1:1}:{key:t,dir:1}),T=t=>d.key===t?d.dir===1?" ▲":" ▼":"",G=t=>t==="completed"?"bg-emerald-100 text-emerald-700":t==="scheduled"?"bg-blue-100 text-blue-700":t==="cancelled"?"bg-slate-100 text-slate-600":"bg-muted text-muted-foreground";return b?e.jsx("div",{className:"p-12 flex justify-center",children:e.jsx(le,{className:"h-6 w-6 animate-spin"})}):e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Z,{eyebrow:"CRM — training",title:"Training Dashboard",subtitle:"Every training session across clients — bookings, completion, ratings, and recordings."}),e.jsxs(M,{to:"/admin/settings/onboarding/training",className:"text-sm text-primary underline flex items-center gap-1",children:["Booking settings ",e.jsx(re,{className:"h-3.5 w-3.5"})]})]}),e.jsx(ne,{companyId:l==null?void 0:l.companyId,title:"Training trend",series:[{key:"sched",label:"Scheduled",table:"onboarding_training_sessions",field:"scheduled_date",color:"#6366F1"},{key:"done",label:"Completed",table:"onboarding_training_sessions",field:"completed_at",color:"#22C55E"}]}),e.jsxs("div",{className:"grid md:grid-cols-2 gap-3",children:[e.jsx(E,{companyId:l==null?void 0:l.companyId,title:"Sessions by status",table:"onboarding_training_sessions",field:"status",color:"#6366F1"}),e.jsx(E,{companyId:l==null?void 0:l.companyId,title:"Sessions by trainer",table:"onboarding_training_sessions",field:"host_name",color:"#0EA5E9"})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 lg:grid-cols-7 gap-3",children:[e.jsx(m,{icon:ie,label:"Upcoming",value:c.scheduled,tint:"blue"}),e.jsx(m,{icon:oe,label:"Completed",value:c.completed,tint:"emerald"}),e.jsx(m,{icon:ce,label:"Completion",value:`${c.completionRate}%`,tint:"emerald"}),e.jsx(m,{icon:F,label:"Client-booked",value:c.clientBooked,tint:"violet"}),e.jsx(m,{icon:de,label:"No-shows",value:c.noShows,tint:"rose"}),e.jsx(m,{icon:k,label:"Avg rating",value:c.avgClient?c.avgClient.toFixed(1):"—",tint:"amber"}),e.jsx(m,{icon:q,label:"Recorded",value:c.withRecording,tint:"indigo"})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("div",{className:"relative max-w-xs flex-1 min-w-[200px]",children:[e.jsx(me,{className:"h-4 w-4 absolute left-2 top-2.5 text-muted-foreground"}),e.jsx(K,{className:"pl-8 h-9",placeholder:"Search customer, title, trainer…",value:x,onChange:t=>P(t.target.value)})]}),e.jsxs(ee,{value:p,onValueChange:V,children:[e.jsx(te,{className:"h-9 w-40",children:e.jsx(se,{})}),e.jsxs(ae,{children:[e.jsx(A,{value:"all",children:"All statuses"}),O.map(t=>e.jsx(A,{value:t,className:"capitalize",children:t},t))]})]}),e.jsxs("span",{className:"text-xs text-muted-foreground ml-auto",children:[w.length," sessions · click a column to sort"]})]}),e.jsx(B,{className:"p-0 overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm min-w-[1000px]",children:[e.jsx("thead",{className:"bg-muted/40 text-xs",children:e.jsxs("tr",{children:[[["client","Customer"],["session","Session"],["date","Scheduled"],["trainer","Trainer"],["status","Status"]].map(([t,s])=>e.jsxs("th",{className:"text-left p-2 cursor-pointer select-none whitespace-nowrap hover:text-foreground",onClick:()=>R(t),children:[s,e.jsx("span",{className:"text-primary",children:T(t)})]},t)),e.jsx("th",{className:"text-left p-2",children:"Attended"}),e.jsxs("th",{className:"text-left p-2 cursor-pointer select-none hover:text-foreground",onClick:()=>
1R("rating"),children:["Rating",T("rating")]}),e.jsx("th",{className:"text-left p-2",children:"Links"})]})}),e.jsxs("tbody",{children:[w.map(t=>e.jsxs("tr",{className:"border-t hover:bg-muted/20",children:[e.jsxs("td",{className:"p-2",children:[e.jsx(M,{to:`/admin/onboarding/${t.client_id}`,className:"text-primary hover:underline font-medium",children:_(t.client_id)}),t.title&&e.jsx("div",{className:"text-[11px] text-muted-foreground",children:t.title})]}),e.jsxs("td",{className:"p-2 text-xs",children:["#",t.session_number||"—"]}),e.jsxs("td",{className:"p-2 text-xs whitespace-nowrap",children:[z(t),t.booked_by_client&&e.jsx("span",{className:"text-violet-600",children:" · client"})]}),e.jsx("td",{className:"p-2 text-xs whitespace-nowrap",children:f(t)}),e.jsx("td",{className:"p-2",children:e.jsx(W,{variant:"secondary",className:`text-[10px] capitalize ${G(t.status)}`,children:t.status})}),e.jsx("td",{className:"p-2 text-xs",children:t.status==="completed"?t.client_attended?e.jsx("span",{className:"text-emerald-600",children:"Yes"}):e.jsx("span",{className:"text-rose-600 font-medium",children:"No-show"}):"—"}),e.jsx("td",{className:"p-2 text-xs",children:t.client_rating?e.jsxs("span",{className:"inline-flex items-center gap-0.5 text-amber-600 font-semibold",children:[e.jsx(k,{className:"h-3 w-3 fill-amber-400 text-amber-400"}),t.client_rating]}):"—"}),e.jsx("td",{className:"p-2 text-xs",children:e.jsxs("div",{className:"flex items-center gap-2",children:[t.meet_link&&e.jsx("a",{href:t.meet_link,target:"_blank",rel:"noopener",className:"text-blue-600 inline-flex items-center gap-0.5",title:"Meeting",children:e.jsx(xe,{className:"h-3.5 w-3.5"})}),t.recording_url&&e.jsx("a",{href:t.recording_url,target:"_blank",rel:"noopener",className:"text-emerald-600 inline-flex items-center gap-0.5",title:"Recording",children:e.jsx(q,{className:"h-3.5 w-3.5"})}),!t.meet_link&&!t.recording_url&&"—"]})})]},t.id)),w.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:8,className:"p-8 text-center text-muted-foreground",children:"No sessions match."})})]})]})})}),e.jsxs(B,{className:"p-5",children:[e.jsxs("h2",{className:"font-bold mb-4 flex items-center gap-2",children:[e.jsx(F,{className:"h-4 w-4"})," Trainers"]}),I.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No sessions yet."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"text-xs uppercase text-muted-foreground border-b",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left py-2",children:"Trainer"}),e.jsx("th",{children:"Sessions"}),e.jsx("th",{children:"Done"}),e.jsx("th",{children:"Avg rating"})]})}),e.jsx("tbody",{children:I.map(t=>e.jsxs("tr",{className:"border-b last:border-0",children:[e.jsx("td",{className:"py-2 font-medium",children:t.name}),e.jsx("td",{className:"text-center",children:t.total}),e.jsx("td",{className:"text-center",children:t.completed}),e.jsx("td",{className:"text-center",children:t.ratingN?e.jsxs("span",{className:"inline-flex items-center gap-1 text-amber-600 font-semibold",children:[e.jsx(k,{className:"h-3 w-3 fill-amber-400 text-amber-400"}),(t.ratingSum/t.ratingN).toFixed(1)]}):"—"})]},t.name))})]})})]})]})}function m({icon:l,label:b,value:g,tint:r}){const j={blue:"bg-blue-50 text-blue-700",amber:"bg-amber-50 text-amber-700",emerald:"bg-emerald-50 text-emerald-700",rose:"bg-rose-50 text-rose-700",indigo:"bg-indigo-50 text-indigo-700",violet:"bg-violet-50 text-violet-700"};return e.jsxs("div",{className:"rounded-2xl border bg-card p-5",children:[e.jsx("div",{className:`w-9 h-9 rounded-lg flex items-center justify-center mb-3 ${j[r]}`,children:e.jsx(l,{className:"h-4 w-4"})}),e.jsx("p",{className:"text-3xl font-bold tabular-nums leading-none",children:g}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1.5",children:b})]})}export{Se 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.