PageSourceSearch

https://rpa-client-portal.replit.app/assets/admin-research-CqnuxLYe.js

js rpa-client-portal.replit.app collected 2026-10-03 03:51:41 UTC 12,156 bytes, 1 lines download raw bytes

1import{b5 as J,u as Z,aD as _,e as X,d as q,r,f as ee,h as P,j as b,k as e,C as I,q as A,af as se,aL as M,B as a,P as te,m as ae,aB as $,n as re,o as ie,p as ne,I as T,ah as le,ai as ce,aj as de,ak as oe,al as F,an as D,H as me,b6 as xe,v as k,aJ as ue,ao as he,K as pe}from"./index-Br5xoWIw.js";import{A as ge}from"./arrow-right-left-DaPqAX2i.js";import{T as je}from"./trash-2-BKDlXnVU.js";const fe={"pmi.com":{companyName:"Philip Morris International",excludedNames:["Project Management Institute","US Performance Marketing Institute"]},"uspmi.com":{companyName:"Philip Morris International",excludedNames:["Project Management Institute","US Performance Marketing Institute"]},"cha.com":{companyName:"Colorado Hospital Association",excludedNames:["CHA Consulting","CHA Solutions"]}};function ye(l){try{const f=new URL(J(l)).hostname.toLowerCase().replace(/^www\./,"");return fe[f]??null}catch{return null}}function be(){const{user:l}=Z(),[,f]=_(),{toast:d}=X(),C=q(),[x,z]=r.useState(""),[u,H]=r.useState("all"),[K,h]=r.useState(null),[U,y]=r.useState(null),[Q,R]=r.useState(null),[S,N]=r.useState(""),[i,E]=r.useState(1);r.useEffect(()=>{l&&!l.isAdmin&&f("/")},[l,f]);const{data:c,isLoading:B,refetch:G,isRefetching:L}=ee({queryKey:["/api/admin/research-requests"],queryFn:async()=>{const s=await b("GET","/api/admin/research-requests");if(!s.ok)throw new Error("Failed to fetch");return s.json()},enabled:!!l?.isAdmin}),w=P({mutationFn:async({id:s,refundCredit:t})=>{const n=await b("DELETE",`/api/admin/research-requests/${s}`,{refundCredit:t});if(!n.ok){const m=await n.json().catch(()=>({}));throw new Error(m.error||"Failed to delete report")}return n.json()},onSuccess:s=>{C.invalidateQueries({queryKey:["/api/admin/research-requests"]}),h(null),d({title:s.creditRefunded?"Report deleted & credit refunded":"Report deleted"})},onError:s=>d({title:s.message,variant:"destructive"})}),p=P({mutationFn:async({id:s,email:t})=>{const n=await b("POST",`/api/admin/research-requests/${s}/reassign`,{targetEmail:t}),m=await n.json().catch(()=>({}));if(!n.ok)throw new Error(m.error||"Failed to reassign report");return m},onSuccess:s=>{C.invalidateQueries({queryKey:["/api/admin/research-requests"]}),y(null),N("");const t=s.alreadyOwned?"This account already owns the report.":`Report reassigned to ${s.targetEmail}${s.researchAccessEnabled?" and Research access enabled":""}.`;d({title:"Report ownership updated",description:t})},onError:s=>d({title:s.message,variant:"destructive"})}),v=P({mutationFn:async s=>(await b("POST",`/api/admin/research-requests/${s}/credit-safe-rerun`)).json(),onSuccess:s=>{R(null),C.invalidateQueries({queryKey:["/api/admin/research-requests"]}),d({title:s.alreadyExists?`Report #${s.id} already exists`:s.retried?`Report #${s.id} retry started`:`Replacement report #${s.id} started`,description:"The original remains available. No additional research credit is used."})},onError:s=>d({title:"Could not start no-credit rerun",description:s.message,variant:"destructive"})}),o=r.useMemo(()=>c?c.filter(s=>{const t=x.toLowerCase(),n=s.companyName.toLowerCase().includes(t)||s.userEmail?.toLowerCase().includes(t)||!1||s.userFirstName?.toLowerCase().includes(t)||!1||s.userLastName?.toLowerCase().includes(t)||!1,m=u==="all"||s.status===u;return n&&m}):[],[c,x,u]),O=s=>({completed:"bg-green-100 text-green-800",pending:"bg-yellow-100 text-yellow-800",processing:"bg-blue-100 text-blue-800",error:"bg-red-100 text-red-800"})[s]||"bg-gray-100 text-gray-800",V=s=>s.userFirstName||s.userLastName?`${s.userFirstName||""} ${s.userLastName||""}`.trim():s.userEmail||"Guest",W=r.useMemo(()=>c?Array.from(new Set(c.map(s=>s.status))):[],[c]),g=10,j=Math.ceil(o.length/g),Y=o.slice((i-1)*g,i*g);return r.useEffect(()=>{E(1)},[x,u]),l?.isAdmin?e.jsxs("div",{className:"min-h-screen",style:{backgroundColor:"#f8f9fa"},children:[e.jsx(te,{}),e.jsx(ae,{icon:$,title:"Company Intelligence Reports",subtitle:"View and filter all research requests from users"}),e.jsx("main",{className:"container mx-auto px-4 py-8",children:e.jsxs(I,{children:[e.jsx(re,{children:e.jsxs("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx(ie,{children:"All Research Requests"}),e.jsxs(ne,{children:[o.length," of ",c?.length||0," requests shown",j>1&&` · page ${i} of ${j}`]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-stretch sm:items-center gap-3 w-full md:w-auto",children:[e.jsxs("div",{className:"relative flex-1 sm:flex-initial",children:[e.jsx($,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400"}),e.jsx(T,{placeholder:"Search company or user...",value:x,onChange:s=>
1z(s.target.value),className:"pl-9 w-full sm:w-64","data-testid":"input-search-research"})]}),e.jsxs(le,{value:u,onValueChange:H,children:[e.jsx(ce,{className:"w-full sm:w-36","data-testid":"select-status-filter",children:e.jsx(de,{placeholder:"All statuses"})}),e.jsxs(oe,{children:[e.jsx(F,{value:"all",children:"All statuses"}),W.map(s=>e.jsx(F,{value:s,children:s},s))]})]}),e.jsx(a,{variant:"outline",size:"sm",onClick:()=>G(),disabled:L,"data-testid":"button-refresh-research",children:e.jsx(D,{className:`h-4 w-4 ${L?"animate-spin":""}`})})]})]})}),e.jsx(A,{children:B?e.jsx("div",{className:"text-center py-12 text-gray-500",children:"Loading research requests..."}):o.length===0?e.jsxs("div",{className:"text-center py-12 text-gray-500",children:[e.jsx($,{className:"h-12 w-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"No research requests found"}),x&&e.jsx("p",{className:"text-sm mt-2",children:"Try adjusting your search or filters"})]}):e.jsxs(e.Fragment,{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-3 px-2 font-medium text-gray-600",children:"ID"}),e.jsx("th",{className:"text-left py-3 px-2 font-medium text-gray-600",children:"Company"}),e.jsx("th",{className:"text-left py-3 px-2 font-medium text-gray-600",children:"User"}),e.jsx("th",{className:"text-left py-3 px-2 font-medium text-gray-600",children:"Status"}),e.jsx("th",{className:"text-left py-3 px-2 font-medium text-gray-600",children:"Type"}),e.jsx("th",{className:"text-left py-3 px-2 font-medium text-gray-600",children:"Created"}),e.jsx("th",{className:"text-left py-3 px-2 font-medium text-gray-600",children:"Actions"})]})}),e.jsx("tbody",{children:Y.map(s=>e.jsxs("tr",{className:"border-b last:border-0 hover:bg-gray-50","data-testid":`row-research-${s.id}`,children:[e.jsxs("td",{className:"py-3 px-2 text-gray-600",children:["#",s.id]}),e.jsxs("td",{className:"py-3 px-2",children:[e.jsx("div",{className:"font-medium",style:{color:"#091540"},children:s.companyName}),e.jsx("div",{className:"text-xs text-gray-500",children:s.website})]}),e.jsxs("td",{className:"py-3 px-2",children:[e.jsx("div",{className:"text-gray-700",children:V(s)}),s.userEmail&&s.userFirstName&&e.jsx("div",{className:"text-xs text-gray-500",children:s.userEmail})]}),e.jsxs("td",{className:"py-3 px-2",children:[e.jsx("span",{className:`px-2 py-1 rounded-full text-xs font-medium ${O(s.status)}`,children:s.status}),s.status==="processing"&&s.progress>0&&e.jsxs("div",{className:"text-xs text-gray-500 mt-1",children:[s.progress,"%"]}),s.errorMessage&&e.jsx("div",{className:"text-xs text-red-500 mt-1 max-w-32 truncate",title:s.errorMessage,children:s.errorMessage})]}),e.jsx("td",{className:"py-3 px-2",children:e.jsx("span",{className:`px-2 py-1 rounded text-xs ${s.isInterviewPrep?"bg-purple-100 text-purple-800":"bg-gray-100 text-gray-600"}`,children:s.isInterviewPrep?"Interview Prep":"Research"})}),e.jsxs("td",{className:"py-3 px-2 text-gray-600",children:[e.jsx("div",{children:new Date(s.createdAt).toLocaleDateString()}),e.jsx("div",{className:"text-xs text-gray-400",children:new Date(s.createdAt).toLocaleTimeString()})]}),e.jsx("td",{className:"py-3 px-2",children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(M,{href:xe(s.companyName),children:e.jsx(a,{variant:"ghost",size:"sm","data-testid":`button-view-${s.id}`,children:e.jsx(me,{className:"h-4 w-4"})})}),(s.status==="completed"||s.status==="error")&&s.creditDebited&&ye(s.website)&&(Q===s.id?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-xs text-gray-600",children:s.status==="error"?"Retry this report, email client, no credit?":"Keep old report, email client, no credit?"}),e.jsx(a,{size:"sm",className:"h-7 px-2 text-xs",disabled:v.isPending,onClick:()=>v.mutate(s.id),"data-testid":`button-confirm-credit-safe-rerun-${s.id}`,children:v.isPending?e.jsx(k,{className:"h-3 w-3 animate-spin"}):"Start"}),e.jsx(a,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",disabled:v.isPending,onClick:()=>R(null),children:"Cancel"})]}):e.jsxs(a,{variant:"outline",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>{R(s.id),h(null),y(null)},"data-testid":`button-credit-safe-rerun-${s.id}`,children:[e.jsx(D,{className:"h-3 w-3 mr-1"})," Rerun · no credit"]})),U===s.id?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(T,{type:"email",value:S,onChange:t=>N(t.target.value),placeholder:"New owner email",className:"h-7 w-48 text-xs",disabled:p.isPending,"data-testid":`input-reassign-email-${s.id}`}),e.jsx(a,{size:"sm",className:"h-7 px-2 text-xs",onClick:()=>p.mutate({id:s.id,email:S}),disabled:!S.trim()||p.isPending,"data-testid":`button-confirm-reassign-${s.id}`,children:p.isPending?e.jsx(k,{className:"h-3 w-3 animate-spin"}):"Move"}),e.jsx(a,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs text-gray-500",onClick:()=>{y(null),N("")},disabled:p.isPending,"data-testid":`button-cancel-reassign-${s.id}`,children:"Cancel"})]}):e.jsx(a,{variant:"ghost",size:"sm",className:"text-gray-400 hover:text-blue-700 hover:bg-blue-50",onClick:()=>{h(null),y(s.id),N("")},title:"Move this report to another portal account","data-testid":`button-reassign-${s.id}`,children:e.jsx(ge,{className:"h-4 w-4"})}),K===s.id?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-xs text-gray-500 whitespace-nowrap",children:s.creditDebited?"+1 report?":"Delete?"}),e.jsx(a,{variant:"destructive",size:"sm",className:"h-7 text-xs px-2",onClick:()=>w.mutate({id:s.id,refundCredit:!!s.creditDebited}),disabled:w.isPending,"data-testid":`button-confirm-delete-${s.id}`,children:w.isPending?e.jsx(k,{className:"h-3 w-3 animate-spin"}):"Yes"}),e.jsx(a,{variant:"ghost",size:"sm",className:"h-7 text-xs px-2 text-gray-500",onClick:()=>h(null),disabled:w.isPending,"data-testid":`button-cancel-delete-${s.id}`,children:"No"})]}):e.jsx(a,{variant:"ghost",size:"sm",className:"text-gray-400 hover:text-red-600 hover:bg-red-50",onClick:()=>h(s.id),title:"Delete report","data-testid":`button-delete-${s.id}`,children:e.jsx(je,{className:"h-4 w-4"})})]})})]},s.id))})]})}),j>1&&e.jsxs("div",{className:"flex items-center justify-between pt-4 text-sm text-gray-500",children:[e.jsxs("span",{children:["Showing ",(i-1)*g+1,"–",Math.min(i*g,o.length)," of ",o.length]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(a,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>E(s=>s-1),disabled:i===1,children:e.jsx(ue,{className:"h-4 w-4"})}),e.jsxs("span",{className:"px-2 tabular-nums",children:[i," / ",j]}),e.jsx(a,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>E(s=>s+1),disabled:i===j,children:e.jsx(he,{className:"h-4 w-4"})})]})]})]})})]})}),e.jsx(pe,{})]}):e.jsx("div",{className:"min-h-screen flex items-center justify-center",style:{backgroundColor:"#f8f9fa"},children:e.jsx(I,{className:"max-w-md",children:e.jsxs(A,{className:"pt-6 text-center",children:[e.jsx(se,{className:"h-12 w-12 mx-auto mb-4 text-red-500"}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:"Access Denied"}),e.jsx("p",{className:"text-gray-600 mb-4",children:"You need admin access to view this page."}),e.jsx(M,{href:"/",children:e.jsx(a,{variant:"outline",children:"Return Home"})})]})})})}export{be 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.