PageSourceSearch

https://starfinancial.ai/assets/unassigned-leads-CXp_NITO.js

js starfinancial.ai collected 2026-10-05 13:48:49 UTC 12,281 bytes, 1 lines download raw bytes

1import{aH as K,aR as L,r as o,ap as k,j as e,bG as p,B as I,U as de,aT as le,aU as ce,aV as ue,aW as me,aX as xe,bE as X,y as ge,cW as fe,bq as he}from"./index-DpejfmNx.js";import{D as pe}from"./DashboardShell-HzznB_4W.js";import{u as be,i as je,R as ye}from"./useBusinessIdentity-BdPHJcI5.js";import{a as we,p as Ne,c as ke,d as ve,s as Se,n as Le,o as J,t as Re,r as Ae,u as Ce,T as Te,z as Me,A as E,B as x,C as De,D as u,f as Ie,G as Ee}from"./company-leads.functions-CQy27OOW.js";import{A as Q}from"./activity-BPhkjCmQ.js";import"./NotificationBell-CXOPXQFl.js";import"./sheet-C_IsnVA1.js";import"./layout-dashboard-CkbBB7YI.js";import"./clipboard-list-qE1i4RvM.js";import"./settings-CbVgSh30.js";import"./git-branch-zm94bXsv.js";import"./megaphone-SG6omtcP.js";import"./bell-2MJPEDjN.js";import"./log-out-BedyD7BK.js";const Oe=[["path",{d:"m18 14 4 4-4 4",key:"10pe0f"}],["path",{d:"m18 2 4 4-4 4",key:"pucp1d"}],["path",{d:"M2 18h1.973a4 4 0 0 0 3.3-1.7l5.454-8.6a4 4 0 0 1 3.3-1.7H22",key:"1ailkh"}],["path",{d:"M2 6h1.972a4 4 0 0 1 3.6 2.2",key:"km57vx"}],["path",{d:"M22 18h-6.041a4 4 0 0 1-3.3-1.8l-.359-.45",key:"os18l9"}]],$e=K("shuffle",Oe);const Ue=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]],_e=K("user-plus",Ue),We=[{key:"all",label:"All"},{key:"unassigned",label:"Unassigned"},{key:"waiting",label:"Assigned – Waiting for Acceptance"},{key:"accepted",label:"Accepted"},{key:"today",label:"Today's Leads"},{key:"week",label:"This Week's Leads"}],$=t=>!t.assignedLoId||t.status==="New",U=t=>!!t.assignedLoId&&t.status==="Assigned",R=t=>t.status==="Accepted",Be=t=>$(t)||U(t)||R(t);function He(){const t=new Date;return t.setHours(0,0,0,0),t.getTime()}function qe(){const t=new Date,a=t.getDay();return t.setDate(t.getDate()-a),t.setHours(0,0,0,0),t.getTime()}const ze=6e4;function Y(t){return Math.max(0,Math.round((Date.now()-new Date(t.receivedAt).getTime())/ze))}function Ve(t){if(t<1)return"just now";if(t<60)return`${t}m`;const a=Math.floor(t/60),d=t%60;if(a<24)return d?`${a}h ${d}m`:`${a}h`;const g=Math.floor(a/24),m=a%24;return m?`${g}d ${m}h`:`${g}d`}function Fe(t){if(R(t))return"done";const a=Y(t);return a<5?"fresh":a<15?"ok":a<60?"warn":"bad"}const Pe={fresh:"border-l-4 border-l-emerald-500",ok:"border-l-4 border-l-amber-400",warn:"border-l-4 border-l-orange-500",bad:"border-l-4 border-l-red-500",done:"border-l-4 border-l-sky-400"},Ge={fresh:"text-emerald-600",ok:"text-amber-600",warn:"text-orange-600",bad:"text-red-600",done:"text-sky-600"};function Xe(t){if(!t.assignedLoId)return"—";const a=[...t.timeline].reverse().find(d=>d.kind==="assigned"||d.kind==="reassigned");return a?a.by?.includes("Round Robin")?"Round Robin":a.by?.toLowerCase().includes("manual")?"Manual":a.by||"Manual":"Manual"}function Je({isAdmin:t,filter:a,onFilterChange:d}){const g=L(we),m=L(Ne),b=L(ke),_=L(ve),[Z,ee]=o.useState([]),[W,B]=o.useState([]),[H,q]=o.useState({entries:[],queueOrder:[]}),[se,z]=o.useState(!0),[h,v]=o.useState(new Set),[A,V]=o.useState(""),[y,C]=o.useState(!1),[,te]=o.useState(0),S=o.useRef(!0),w=o.useCallback(async()=>{z(!0);try{const s=await g();if(!S.current)return;Se(s.officers),ee(s.officers),B(s.leads),q(s.roster)}catch(s){console.error("Failed to load unassigned leads",s),k.error("Could not load leads.")}finally{S.current&&z(!1)}},[g]);o.useEffect(()=>{S.current=!0,w();const s=setInterval(()=>te(r=>r+1),3e4);return()=>{S.current=!1,clearInterval(s)}},[w]);const j=o.useMemo(()=>W.filter(Be),[W]),T=o.useMemo(()=>({unassigned:j.filter($).length,waiting:j.filter(U).length,accepted:j.filter(R).length}),[j]),f=o.useMemo(()=>{const s=He(),r=qe();return j.filter(i=>{const n=new Date(i.receivedAt).getTime();switch(a){case"unassigned":return $(i);case"waiting":return U(i);case"accepted":return R(i);case"today":return n>=s;case"week":return n>=r;default:return!0}}).sort((i,n)=>new Date(n.receivedAt).getTime()-new Date(i.receivedAt).getTime())},[j,a]);o.useEffect(()=>
1{v(s=>{const r=new Set(f.map(n=>n.id)),i=new Set;return s.forEach(n=>r.has(n)&&i.add(n)),i})},[f]);const F=f.length>0&&f.every(s=>h.has(s.id)),ae=()=>v(F?new Set:new Set(f.map(s=>s.id))),ne=s=>v(r=>{const i=new Set(r);return i.has(s)?i.delete(s):i.add(s),i}),M=o.useMemo(()=>f.filter(s=>h.has(s.id)),[f,h]),P=o.useCallback(async s=>{if(!M.length){k.error("Select at least one lead first.");return}C(!0);let r=H;const i=new Date().toISOString(),n=[],G=[];for(const l of M){let c,N=!1;if(s==="auto"){const oe=Le(r,[]);c=J(oe),N=!0}else c=J(s);if(!c)continue;const ie=l.assignedLoName,D=!!l.assignedLoId;n.push({...l,assignedLoId:c.id,assignedLoName:c.name,assignedAt:i,status:"Assigned",firstContactAt:null,lastContactAt:null,timeline:[...l.timeline,Re(D?"reassigned":"assigned",`${D?"Reassigned":"Assigned"} to ${c.name}`,N?"Round Robin":"Star Financial (manual)",N?"Routed by Round Robin":void 0)]}),r={...r,queueOrder:Ae(r.queueOrder,c.id)},G.push({id:Ce("aud"),at:i,leadId:l.id,borrowerName:l.borrowerName,fromOfficerName:ie,toOfficerName:c.name,action:N?"auto_round_robin":D?"manual_reassign":"manual_assign",reason:N?"Routed by Round Robin":"Manual admin assignment"})}if(!n.length){k.error(s==="auto"?"No eligible loan officer available in the Round Robin queue.":"Could not assign the selected leads."),C(!1);return}const re=new Map(n.map(l=>[l.id,l]));B(l=>l.map(c=>re.get(c.id)??c)),q(r),v(new Set);try{await Promise.all([m({data:{leads:n}}),b({data:{roster:r}}),_({data:{entries:G}})]),k.success(s==="auto"?`Round Robin assigned ${n.length} lead${n.length>1?"s":""}.`:`Assigned ${n.length} lead${n.length>1?"s":""}.`),V("")}catch(l){console.error("Assignment persistence failed",l),k.error("Saved locally but could not persist. Refreshing…"),w()}finally{C(!1)}},[M,H,m,b,_,w]);return se?e.jsxs("div",{className:"flex items-center justify-center rounded-2xl border border-border bg-card py-16 text-muted-foreground",children:[e.jsx(Q,{className:"mr-2 h-5 w-5 animate-pulse"})," Loading leads…"]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-3",children:[e.jsx(O,{label:"Unassigned Leads",value:T.unassigned,tone:"bad",active:a==="unassigned",onClick:()=>d("unassigned")}),e.jsx(O,{label:"Waiting for Acceptance",value:T.waiting,tone:"warn",active:a==="waiting",onClick:()=>d("waiting")}),e.jsx(O,{label:"Accepted",value:T.accepted,tone:"ok",active:a==="accepted",onClick:()=>d("accepted")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[We.map(s=>e.jsx("button",{type:"button",onClick:()=>d(s.key),className:p("rounded-full border px-3 py-1.5 text-xs font-medium transition",a===s.key?"border-primary bg-primary text-primary-foreground":"border-border bg-card text-muted-foreground hover:bg-muted"),children:s.label},s.key)),e.jsxs(I,{variant:"ghost",size:"sm",className:"ml-auto",onClick:w,disabled:y,children:[e.jsx(de,{className:p("h-4 w-4",y&&"animate-spin")})," Refresh"]})]}),t&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-xl border border-border bg-muted/40 p-3",children:[e.jsxs("span",{className:"text-sm font-medium text-foreground",children:[h.size," selected"]}),e.jsxs("div",{className:"ml-auto flex flex-wrap items-center gap-2",children:[e.jsxs(le,{value:A,onValueChange:V,disabled:y,children:[e.jsx(ce,{className:"h-9 w-[220px] text-xs",children:e.jsx(ue,{placeholder:"Assign to loan officer…"})}),e.jsx(me,{children:Z.map(s=>e.jsx(xe,{value:s.id,children:s.name},s.id))})]}),e.jsxs(I,{size:"sm",disabled:y||!A||h.size===0,onClick:()=>P(A),children:[e.jsx(_e,{className:"h-4 w-4"})," Assign"]}),e.jsxs(I,{size:"sm",variant:"secondary",disabled:y||h.size===0,onClick:()=>P("auto"),children:[e.jsx($e,{className:"h-4 w-4"})," Round Robin"]})]})]}),e.jsx("div",{className:"overflow-x-auto rounded-2xl border border-border bg-card",children:e.jsxs(Te,{children:[e.jsx(Me,{children:e.jsxs(E,{children:[t&&e.jsx(x,{className:"w-10",children:e.jsx(X,{checked:F,onCheckedChange:ae,"aria-label":"Select all"})}),e.jsx(x,{children:"Borrower Name"}),e.jsx(x,{children:"Phone"}),e.jsx(x,{children:"Email"}),e.jsx(x,{children:"Lead Source"}),e.jsx(x,{children:"Date Received"}),e.jsx(x,{children:"Time Waiting"}),e.jsx(x,{children:"Status"}),e.jsx(x,{children:"Assigned Loan Officer"}),e.jsx(x,{children:"Assignment Method"})]})}),e.jsx(De,{children:f.length===0?e.jsx(E,{children:e.jsx(u,{colSpan:t?10:9,className:"py-10 text-center text-sm text-muted-foreground",children:"No leads match this view."})}):f.map(s=>{const r=Fe(s);return e.jsxs(E,{className:p(Pe[r],h.has(s.id)&&"bg-muted/40"),children:[t&&e.jsx(u,{children:e.jsx(X,{checked:h.has(s.id),onCheckedChange:()=>ne(s.id),"aria-label":`Select ${s.borrowerName}`})}),e.jsx(u,{className:"font-medium text-foreground",children:s.borrowerName}),e.jsx(u,{className:"text-muted-foreground",children:s.phone||"—"}),e.jsx(u,{className:"text-muted-foreground",children:s.email||"—"}),e.jsx(u,{className:"text-muted-foreground",children:s.source}),e.jsx(u,{className:"whitespace-nowrap text-muted-foreground",children:Ie(s.receivedAt)}),e.jsx(u,{className:p("whitespace-nowrap font-medium",Ge[r]),children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(ge,{className:"h-3.5 w-3.5"}),Ve(Y(s))]})}),e.jsx(u,{children:e.jsx("span",{className:p("inline-flex rounded-full px-2 py-0.5 text-xs font-medium",Ee(s.status)),children:s.status})}),e.jsx(u,{className:"text-muted-foreground",children:s.assignedLoName||"—"}),e.jsx(u,{className:"text-muted-foreground",children:Xe(s)})]},s.id)})})]})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-4 text-[11px] text-muted-foreground",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-full bg-emerald-500"})," < 5 min"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-full bg-amber-400"})," 5–15 min"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-full bg-orange-500"})," 15–60 min"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-full bg-red-500"})," > 60 min"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-full bg-sky-4
100"})," Accepted"]})]})]})}function O({label:t,value:a,tone:d,active:g,onClick:m}){const b={bad:"text-red-600",warn:"text-orange-600",ok:"text-emerald-600"};return e.jsxs("button",{type:"button",onClick:m,className:p("rounded-2xl border bg-card p-4 text-left transition hover:shadow-sm",g?"border-primary ring-1 ring-primary":"border-border"),children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:t}),e.jsx("p",{className:p("mt-1 text-3xl font-bold tabular-nums",b[d]),children:a})]})}function cs(){const{identity:t,authChecked:a}=be(),{filter:d}=fe.useSearch(),g=he();if(!a||!t)return e.jsxs("div",{className:"flex min-h-screen items-center justify-center bg-muted/30 text-muted-foreground",children:[e.jsx(Q,{className:"mr-2 h-5 w-5 animate-pulse"})," Loading Unassigned Leads…"]});const m=je(t.role);return e.jsx(pe,{title:"Unassigned Leads",subtitle:`${ye[t.role]}${t.nmls?` · NMLS ${t.nmls}`:""}`,sidebarVariant:m?"admin":"lo",sidebarSlug:t.slug,children:e.jsxs("main",{className:"mx-auto w-full max-w-7xl px-4 py-6 sm:px-6",children:[e.jsxs("div",{className:"mb-5",children:[e.jsx("h1",{className:"text-2xl font-bold tracking-tight text-foreground sm:text-3xl",children:"Unassigned Leads"}),e.jsx("p",{className:"mt-0.5 text-sm text-muted-foreground",children:"Company leads not yet assigned or awaiting acceptance. Color-coded by how long they've been waiting."})]}),e.jsx(Je,{isAdmin:m,filter:d,onFilterChange:b=>g({to:"/unassigned-leads",search:{filter:b},replace:!0})}),e.jsx("p",{className:"mt-8 text-center text-[11px] text-muted-foreground",children:"St Fin Corp dba Star Financial · NMLS 1429 · Equal Housing Opportunity · This is not a commitment to lend."})]})})}export{cs as component};

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.