PageSourceSearch

https://www.premier-insurance.co.uk/assets/StaffPartnerPreview-CSJ1GBEt.js

js premier-insurance.co.uk collected 2026-10-10 01:23:43 UTC 7,059 bytes, 1 lines download raw bytes

1import{b7 as Z,r as l,K as e,cr as G,ap as J,aV as W,a7 as X}from"./vendor-DFiwhBVU.js";import{C as E}from"./card-DQ6Kozk9.js";import{B as Y}from"./badge-BWBaE3uL.js";import{a as ee,I as se,B as M,s as te}from"./index-BAPYoh1K.js";import{S as A,a as I,b as P,c as B,d as c}from"./select-CC1D6Zwp.js";import{m as O,d as ae}from"./partner-stages-B38T8hD0.js";import"./supabase-D-Qt6SjD.js";const x=te,re=i=>{switch(i){case"active":return"bg-emerald-50 text-emerald-700 border-emerald-200";case"suspended":return"bg-rose-50 text-rose-700 border-rose-200";case"approved":return"bg-sky-50 text-sky-700 border-sky-200";default:return"bg-slate-100 text-slate-600 border-slate-200"}};function ue(){const{user:i,isOwnerOrAdmin:g}=ee(),V=Z(),[w,D]=l.useState([]),[b,z]=l.useState([]),[S,U]=l.useState([]),[y,q]=l.useState([]),[F,H]=l.useState({}),[C,L]=l.useState(!0),[j,R]=l.useState(""),[u,T]=l.useState("all"),[p,$]=l.useState("referrals"),[v,K]=l.useState(!1);l.useEffect(()=>{(async()=>{L(!0);const[{data:s},{data:r},{data:o},{data:t},{data:n}]=await Promise.all([x.from("introducers").select("id,name,company,contact_name,email,status,referral_code,account_manager_id,created_at").order("created_at",{ascending:!1}),x.from("introducer_users").select("id,introducer_id,status,last_seen_at"),x.from("quote_leads").select("id,introducer_id,created_at").not("introducer_id","is",null).is("deleted_at",null),x.from("commission_entries").select("introducer_id,amount_pence,status"),x.from("profiles").select("id,full_name,email").order("full_name",{nullsFirst:!1})]);D(s!=null?s:[]),z(r!=null?r:[]),U(o!=null?o:[]),q(t!=null?t:[]);const d={};for(const m of n!=null?n:[])d[m.id]=m.full_name||m.email||"—";H(d),L(!1)})()},[]);const k=l.useMemo(()=>{const s=new Date;s.setDate(1),s.setHours(0,0,0,0);let r=w.map(t=>{const n=b.filter(a=>a.introducer_id===t.id),d=S.filter(a=>a.introducer_id===t.id),m=y.filter(a=>a.introducer_id===t.id&&a.status!=="clawed_back"),_=d.map(a=>a.created_at).sort(),Q=_.length?_[_.length-1]:void 0;return{firm:t,logins:n.filter(a=>a.status==="active").length,everSignedIn:n.some(a=>a.last_seen_at),total:d.length,thisMonth:d.filter(a=>new Date(a.created_at)>=s).length,earned:m.reduce((a,N)=>{var f;return a+((f=N.amount_pence)!=null?f:0)},0),unpaid:m.filter(a=>a.status!=="paid").reduce((a,N)=>{var f;return a+((f=N.amount_pence)!=null?f:0)},0),lastLead:Q}});const o=j.trim().toLowerCase();return o&&(r=r.filter(t=>[t.firm.company,t.firm.name,t.firm.contact_name,t.firm.email,t.firm.referral_code].filter(Boolean).some(n=>String(n).toLowerCase().includes(o)))),u!=="all"&&(r=u==="no_logins"?r.filter(t=>t.logins===0):r.filter(t=>t.firm.status===u)),v&&(r=r.filter(t=>t.firm.account_manager_id===(i==null?void 0:i.id))),r.sort((t,n)=>p==="name"?(t.firm.company||t.firm.name||"").localeCompare(n.firm.company||n.firm.name||""):p==="newest"?n.firm.created_at.localeCompare(t.firm.created_at):n.total-t.total),r},[w,b,S,y,j,u,p,v,i==null?void 0:i.id]);return g?e.jsxs("div",{className:"max-w-6xl space-y-4",children:[e.jsxs("div",{className:"rounded-2xl border border-teal-200 bg-teal-50/70 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4 text-teal-700"}),e.jsx("h1",{className:"text-lg font-semibold text-teal-900",children:"Partner portal preview"})]}),e.jsx("p",{className:"mt-1 text-sm text-teal-800",children:"Pick a partner to see a read-only copy of everything they see when they sign in. Nothing can be changed from here, and partners are never shown premiums, insurer names, internal notes or who is handling the lead."})]}),e.jsxs(E,{className:"flex flex-wrap items-center gap-3 p-3",children:[e.jsxs("div",{className:"relative min-w-[220px] flex-1",children:[e.jsx(J,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(se,{value:j,onChange:s=>R(s.target.value),placeholder:"Search partners",className:"pl-9"})]}),e.jsxs(A,{value:u,onValueChange:T,children:[e.jsx(I,{className:"w-[190px]",children:e.jsx(P,{})}),e.jsxs(B,{className:"bg-background z-50",children:[e.jsx(c,{value:"all",children:"All statuses"}),e.jsx(c,{value:"active",children:"Active"}),e.jsx(c,{value:"approved",children:"Approved"}),e.jsx(c,{value:"suspended",children:"Suspended"}),e.jsx(c,{value:"no_logins",children:"No logins yet"})]})]}),e.jsxs(A,{value:p,onValueChange:$,children:[e.jsx(I,{className:"w-[180px]",children:e.jsx(P,{})}),e.jsxs(B,{className:"bg-background z-50",children:[e.jsx(c,{value:"referrals",children:"Most referrals"}),e.jsx(c,{value:"newest",children:"Newest first"}),e.jsx(c,{value:"name",children:"Name A–Z"})]})]}),e.jsx(M,{variant:v?"default":"outline",size:"sm",onClick:()=>K(s=>!s),children:"My partners"})]}),C&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(W,{className:"h-4 w-4 animate-spin"})," Loading partners…"]}),e.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:k.map(s=>{var r,o;return e.jsxs(E,{className:"p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold",children:s.firm.company||s.firm.name||"Unnamed partner"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s.firm.contact_name||"No named contact",s.firm.email?" · ".concat(s.firm.email):""]})]}),e.jsx(Y,{variant:"outline",className:re(s.firm.status),children:(r=s.firm.status)!=null?r:"—"})]}),e.jsxs("div",{className:"mt-3 grid grid-cols-2 gap-2 text-xs sm:grid-cols-4",children:[e.jsx(h,{label:"Referrals",value:String(s.total)}),e.jsx(h,{label:"This month",value:String(s.thisMonth)}),e.jsx(h,{label:"Earned",value:O(s.earned)}),e.jsx(h,{label:"Unpaid",value:O(s.unpaid)})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2 text-[11px] text-muted-foreground",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(X,{className:"h-3 w-3"})," ",s.logins," login",s.logins===1?"":"s"]}),e.jsx("span",{className:s.everSignedIn?"":"text-amber-600",children:s.everSignedIn?"Has signed in":"Never signed in"}),e.jsxs("span",{children:["Last referral ",s.lastLead?ae(s.lastLead):"—"]}),e.jsxs("span",{children:["Exec: ",s.firm.account_manager_id?(o=F[s.firm.account_manager_id])!=null?o:"—":"Not assigned"]})]}),e.jsx(M,{className:"mt-3 h-9 w-full bg-teal-600 text-white hover:bg-teal-700",onClick:()=>V("/staff/partner-preview/".concat(s.firm.id)),children:"View their portal"})]},s.firm.id)})}),!C&&k.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No partners match those filters."})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Only owners and admins can preview a partner's portal."})}function h({label:i,value:g}){return e.jsxs("div",{className:"rounded-lg border bg-muted/40 px-2 py-1.5",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:i}),e.jsx("p",{className:"text-sm font-semibold",children:g})]})}
1export{ue 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.