PageSourceSearch

https://blueroots-production.up.railway.app/assets/sales-page-DOZE8XQd.js

js blueroots-production.up.railway.app collected 2026-10-03 12:13:10 UTC 34,708 bytes, 1 lines download raw bytes

1import{j as e,d as F,e as ae,b as $}from"./tanstack-raftEBQU.js";import{bj as te,b2 as Ne,g as be,i as f,aj as ye,ar as ke,aN as we,aP as Se,aQ as Y,aO as X,ak as Z,p as b,q as y,d as me,ac as Ce,bd as Te,ag as T,af as z,v as ee,bm as K,aM as se,ah as ne,aq as de,b as _e,ab as ue,n as Ee,B as qe,l as xe,w as he,O as ie,Q as le,T as V,U as Q,R as G,S as H,b0 as Oe,ad as pe}from"./index-CwEfLZlp.js";import{r as x}from"./react-vendor-DG9jHnNQ.js";import{T as I}from"./textarea-u-nF7bwL.js";import{U as Ae}from"./us-states-CPdDxbC4.js";import{B as Re}from"./briefcase-BXnHmI64.js";import{C as oe}from"./copy-DS2sWNpy.js";import{A as $e}from"./arrow-left-C1HgLhI-.js";import{S as De}from"./send-QQ2CR8ls.js";import{T as Pe}from"./trash-2-D8NernoQ.js";import{P as Le}from"./plus-B2Qz2fhA.js";import{T as Be}from"./triangle-alert-CxdbLZNa.js";import"./radix-B0zOOFBK.js";import"./charts-ycOWY838.js";import"./dnd-IADusAtS.js";const B="flex h-9 w-full rounded-md border border-input bg-background px-3 py-1 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",Fe=[{key:"needs_reply",label:"Needs reply"},{key:"new",label:"New"},{key:"in_review",label:"In review"},{key:"verified",label:"Verified"},{key:"activated",label:"Active"},{key:"rejected",label:"Rejected"},{key:"all",label:"All"}],ge={new:"New",in_review:"In review",verified:"Verified",activating:"Turning on",activated:"Active",rejected:"Rejected"},ze={new:"bg-blue-100 text-blue-800 dark:bg-blue-950 dark:text-blue-200",in_review:"bg-amber-100 text-amber-900 dark:bg-amber-950 dark:text-amber-200",verified:"bg-emerald-100 text-emerald-800 dark:bg-emerald-950 dark:text-emerald-200",activating:"bg-emerald-100 text-emerald-800 dark:bg-emerald-950 dark:text-emerald-200",activated:"bg-green-600 text-white",rejected:"bg-muted text-muted-foreground"},Ie={submitted:"Submitted",resubmitted:"Submitted again",confirmation_emailed:"Thank-you email sent",confirmation_email_failed:"Thank-you email failed",email_received:"Email received",email_sent:"Email sent",edited:"Edited details",assigned:"Assigned",checklist:"Checklist",note:"Note",verified:"Verified",rejected:"Rejected",reopened:"Reopened",activated:"Turned on",activation_failed:"Turn-on failed",turned_off:"Turned off",turned_on:"Turned back on"};async function C(s,a,l){return(await Oe(s,a,l)).json()}function D(s){if(!s)return"";const a=new Date(s);return Number.isNaN(a.getTime())?s:a.toLocaleString(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}function Ke(s){if(!s)return"";const[a,l,d]=s.split("-").map(Number);return a?new Date(a,l-1,d).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"}):s}function fe({status:s}){return e.jsx("span",{className:`inline-flex items-center rounded px-2 py-0.5 text-xs font-medium ${ze[s]||""}`,children:ge[s]||s})}function q(s){const a=s instanceof Error?s.message:String(s),l=a.indexOf("{");if(l>=0)try{return JSON.parse(a.slice(l)).message||a}catch{}return a.replace(/^\d{3}:\s*/,"")}function xs({standalone:s=!1}){const{user:a,logout:l}=te(),d=Ne(a?.role),[h,o]=x.useState("requests");return e.jsxs("div",{className:s?"h-screen overflow-y-auto":"h-full overflow-y-auto","data-testid":"sales-scroll",children:[s?e.jsxs("header",{className:"sticky top-0 z-20 text-sidebar-foreground shadow-sm",style:{background:"radial-gradient(circle at 15% 0%, hsl(211, 60%, 25%, 0.45) 0%, transparent 55%), linear-gradient(180deg, hsl(211, 55%, 13%) 0%, hsl(211, 55%, 9%) 100%)"},children:[e.jsx("div",{className:"h-[3px] bg-gradient-to-r from-[#1B3A5B] via-[#5B8BB8] to-[#D0E0F0]"}),e.jsxs("div",{className:"max-w-7xl mx-auto px-4 h-14 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsxs("div",{className:"relative flex items-center justify-center w-8 h-8 shrink-0",children:[e.jsx(be,{variant:"light",className:"w-8 h-8"}),e.jsx("div",{className:"absolute -inset-1 bg-sky-500/10 rounded-full blur-md -z-10"})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"text-sm font-bold tracking-tight text-sidebar-foreground
1/95",children:"Blueroots"}),e.jsx("p",{className:"text-[9px] uppercase tracking-[0.15em] text-sky-400/70 font-medium -mt-0.5",children:"Sales"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"text-right hidden sm:block leading-tight",children:[e.jsx("p",{className:"text-xs font-medium text-sidebar-foreground/85",children:a?.displayName}),e.jsx("p",{className:"text-[10px] text-sky-400/70",children:d?"Sales Manager":"Sales Team"})]}),e.jsxs(f,{variant:"ghost",size:"sm",onClick:l,className:"text-sidebar-foreground/60 hover:text-sidebar-foreground hover:bg-white/5","data-testid":"button-sales-logout",children:[e.jsx(ye,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"Sign out"})]})]})]})]}):null,e.jsxs("div",{className:s?"max-w-7xl mx-auto p-4 sm:p-6 pb-24 relative z-[1]":"p-4 sm:p-6 pb-24 sm:pb-6 relative z-[1]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(Re,{className:"h-5 w-5 text-sky-600","aria-hidden":!0}),e.jsx("h1",{className:"cc-page-title",children:"Campaign Requests"}),s?null:e.jsx("div",{className:"ml-auto",children:e.jsx(ke,{})})]}),e.jsxs(we,{value:h,onValueChange:o,children:[e.jsxs(Se,{children:[e.jsx(Y,{value:"requests","data-testid":"tab-requests",children:"Requests"}),e.jsx(Y,{value:"embed","data-testid":"tab-embed",children:"Website form"}),d?e.jsx(Y,{value:"team","data-testid":"tab-team",children:"Sales Team"}):null]}),e.jsx(X,{value:"requests",className:"mt-4",children:e.jsx(Ue,{manager:d})}),e.jsx(X,{value:"embed",className:"mt-4",children:e.jsx(We,{})}),d?e.jsx(X,{value:"team",className:"mt-4",children:e.jsx(Ye,{})}):null]})]})]})}function Ue({manager:s}){const[a,l]=x.useState("new"),[d,h]=x.useState(!1),[o,p]=x.useState(null),m=F({queryKey:["/api/sales/requests",a],queryFn:()=>C("GET",`/api/sales/requests?status=${a}`),refetchInterval:6e4}),n=m.data?.counts||{};x.useEffect(()=>{!d&&m.data&&(h(!0),a==="new"&&(m.data.counts?.needs_reply||0)>0&&l("needs_reply"))},[m.data,d,a]);const j=i=>i==="all"?Object.values(n).reduce((N,k)=>N+k,0):i==="verified"?(n.verified||0)+(n.activating||0):n[i]||0;return e.jsxs("div",{className:"grid gap-4 lg:grid-cols-[360px_minmax(0,1fr)]",children:[e.jsxs("div",{className:o?"hidden lg:block":"",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5 mb-3",role:"tablist","aria-label":"Request status",children:Fe.map(i=>e.jsxs("button",{role:"tab","aria-selected":a===i.key,onClick:()=>l(i.key),className:`rounded-full border px-3 py-1 text-xs ${a===i.key?"bg-primary text-primary-foreground border-primary":i.key==="needs_reply"&&j(i.key)>0?"bg-background border-primary text-primary font-medium":"bg-background"}`,"data-testid":`status-${i.key}`,children:[i.key==="needs_reply"?e.jsx(Z,{className:"inline h-3 w-3 mr-1 -mt-0.5","aria-hidden":!0}):null,i.label," ",e.jsx("span",{className:"tabular-nums opacity-80",children:j(i.key)})]},i.key))}),e.jsx(b,{className:"cc-card",children:e.jsxs(y,{className:"p-0 divide-y",children:[m.isLoading?e.jsx("div",{className:"p-6 text-sm text-muted-foreground",children:"Loading requests"}):null,m.error?e.jsx("div",{className:"p-6 text-sm text-destructive",children:q(m.error)}):null,m.data&&!m.data.requests.length?e.jsxs("div",{className:"p-6 text-sm text-muted-foreground",children:["No ",a==="all"?"":(ge[a]||"").toLowerCase()+" ","requests."]}):null,m.data?.requests.map(i=>e.jsxs("button",{onClick:()=>p(i.id),"data-testid":`request-${i.id}`,className:`w-full text-left p-3 hover:bg-muted/50 ${o===i.id?"bg-muted":""}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"font-medium text-sm truncate flex items-center gap-1.5",children:[i.unread_count>0?e.jsx("span",{className:"h-2 w-2 rounded-full bg-sky-500 shrink-0","aria-label":"Unread reply"}):null,e.jsx("span",{className:"truncate",children:i.details?.name})]}),e.jsxs("p",{className:"text-xs text-muted-foreground truncate",children:[i.details?.office," · ",i.details?.district,", ",i.details?.state]})]}),e.jsx(fe,{status:i.status})]}),e.jsx("div",{className:"flex flex-wrap gap-1 mt-2",children:(i.services||[]).map(N=>e.jsx(me,{variant:"secondary",className:"text-[10px] font-normal",children:Ce[N]||N},N))}),i.needs_reply?e.jsxs("p",{className:"text-[11px] mt-1.5 text-sky-700 dark:text-sky-400 font-medium flex items-center gap-1","data-testid":`needs-reply-${i.id}`,children:[e.jsx(Z,{className:"h-3 w-3","aria-hidden":!0}),i.unread_count>0?`${i.unread_count} new ${i.unread_count===1?"reply":"replies"}`:"Awaiting our reply",i.last_message_at?e.jsxs("span",{className:"text-muted-foreground font-normal",children:["· ",D(i.last_message_at)]}):null]}):null,e.jsxs("p",{className:"text-[11px] text-muted-foreground mt-1.5",children:[D(i.created_at),i.assigned_name?` · ${i.assigned_name}`:" · Unassigned",i.status==="activated"&&i.campaign_status&&i.campaign_status!=="active"?" · Off":""]})]},i.id))]})})]}),e.jsx("div",{className:o?"":"hidden lg:block",children:o?e.jsx(Me,{id:o,manager:s,onBack:()=>p(null)}):e.jsx(b,{className:"cc-card",children:e.jsx(y,{className:"p-10 text-center text-sm text-muted-foreground",children:"Select a request to review it."})})})]})}function Me({id:s,manager:a,onBack:l}){const d=ae(),{toast:h}=K(),{user:o}=te(),p=F({queryKey:["/api/sales/requests","detail",s],queryFn:()=>C("GET",`/api/sales/requests/${s}`)}),m=F({queryKey:["/api/sales/team"],queryFn:()=>C("GET","/api/sales/team")}),[n,j]=x.useState(null),[i,N]=x.useState([]),[k,u]=x.useState(""),[c,v]=x.useState(!1),[g,O]=x.use
1State(""),[P,re]=x.useState(!1),[je,ce]=x.useState(!1),r=p.data;x.useEffect(()=>{r&&(j({...r.details}),N([...r.services||[]]))},[r?.id,r?.updated_at]);const J=()=>{d.invalidateQueries({queryKey:["/api/sales/requests"]})},w=$({mutationFn:({method:t="POST",path:E,body:R})=>C(t,`/api/sales/requests/${s}${E}`,R),onSuccess:()=>J(),onError:t=>h({title:"Not saved",description:q(t),variant:"destructive"})});if(p.isLoading||!n)return e.jsx(b,{className:"cc-card",children:e.jsx(y,{className:"p-8 text-sm text-muted-foreground",children:"Loading"})});if(p.error)return e.jsx(b,{className:"cc-card",children:e.jsx(y,{className:"p-8 text-sm text-destructive",children:q(p.error)})});const U=r.status==="new"||r.status==="in_review"||r.status==="verified",M=JSON.stringify(n)!==JSON.stringify(r.details)||JSON.stringify(i)!==JSON.stringify(r.services),_=t=>E=>j(R=>({...R,[t]:E.target.value})),S=r.contact||{},L=r.campaign_status==="active",W=[...m.data||[]];return o&&!W.some(t=>t.id===o.id)&&W.unshift({id:o.id,displayName:`${o.displayName} (me)`}),e.jsxs("div",{className:"space-y-4","data-testid":"request-detail",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs(f,{variant:"ghost",size:"sm",className:"lg:hidden -ml-2 mb-1",onClick:l,children:[e.jsx($e,{className:"h-4 w-4 mr-1"}),"Back"]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("h2",{className:"text-lg font-semibold",children:r.details?.name}),e.jsx(fe,{status:r.status}),r.status==="activated"?e.jsx(me,{variant:L?"default":"outline",children:L?"On":"Off"}):null]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Submitted ",D(r.created_at),r.source_url?` from ${r.source_url}`:""]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[r.status==="new"||r.status==="in_review"?e.jsxs(e.Fragment,{children:[e.jsx(f,{variant:"outline",size:"sm",onClick:()=>v(!0),"data-testid":"button-reject",children:"Reject"}),e.jsxs(f,{size:"sm",disabled:!r.checklistComplete||M||w.isPending,onClick:()=>w.mutate({path:"/verify"}),"data-testid":"button-verify",title:r.checklistComplete?M?"Save your edits first":void 0:"Complete the checklist first",children:[e.jsx(ee,{className:"h-4 w-4 mr-1"}),"Verify"]})]}):null,r.status==="verified"?e.jsxs("div",{className:"flex items-center gap-2 rounded-md border px-3 py-1.5",children:[e.jsx(T,{htmlFor:"switch-activate",className:"text-sm",children:"Off"}),e.jsx(se,{id:"switch-activate",checked:!1,disabled:M,onCheckedChange:()=>re(!0),"data-testid":"switch-activate"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Turn on"})]}):null,r.status==="activating"?e.jsxs("span",{className:"text-sm text-muted-foreground flex items-center",children:[e.jsx(ne,{className:"h-4 w-4 mr-1 animate-spin"}),"Turning on"]}):null,r.status==="activated"?e.jsxs("div",{className:"flex items-center gap-2 rounded-md border px-3 py-1.5",children:[e.jsx(T,{htmlFor:"switch-power",className:"text-sm",children:L?"On":"Off"}),e.jsx(se,{id:"switch-power",checked:L,onCheckedChange:()=>ce(!0),"data-testid":"switch-power"})]}):null,r.status==="rejected"&&a?e.jsx(f,{variant:"outline",size:"sm",onClick:()=>w.mutate({path:"/reopen"}),"data-testid":"button-reopen",children:"Reopen"}):null]})]}),r.status==="rejected"&&r.reject_reason?e.jsx(b,{className:"cc-card",children:e.jsxs(y,{className:"p-3 text-sm",children:[e.jsx("span",{className:"font-medium",children:"Rejected:"})," ",r.reject_reason]})}):null,r.possibleDuplicates?.length?e.jsx(b,{className:"cc-card border-amber-300 dark:border-amber-800",children:e.jsxs(y,{className:"p-3 text-sm space-y-1",children:[e.jsx("p",{className:"font-medium",children:"Possible existing campaign"}),r.possibleDuplicates.map(t=>e.jsxs("p",{className:"text-muted-foreground",children:[t.name," · ",t.candidateName," · ",t.district,", ",t.state," (",t.status,")"]},t.id))]})}):null,e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1fr)_320px]",children:[e.jsxs("div",{className:"space-y-4 min-w-0",children:[e.jsx(Ve,{requestId:s}),e.jsx(b,{className:"cc-card",children:e.jsxs(y,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"font-semibold text-sm",children:"Campaign details"}),U&&M?e.jsxs("div",{className:"flex gap-2",children:[e.jsx(f,{size:"sm",variant:"ghost",onClick:()=>{j({...r.details}),N([...r.services])},children:"Discard"}),e.jsx(f,{size:"sm",disabled:w.isPending,onClick:()=>w.mutate({method:"PATCH",path:"",body:{details:n,services:i}},{onSuccess:()=>h({title:"Saved"})}),"data-testid":"button-save-details",children:"Save"})]}):null]}),e.jsxs("fieldset",{disabled:!U,className:"grid gap-3 sm:grid-cols-2",children:[e.jsx(A,{label:"Campaign name",value:n.name,onChange:_("name")}
1),e.jsx(A,{label:"Candidate name",value:n.candidateName,onChange:_("candidateName")}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs",children:"Office"}),e.jsxs("select",{className:B,value:n.office,onChange:_("office"),children:[de.includes(n.office)?null:e.jsx("option",{value:n.office,children:n.office}),de.map(t=>e.jsx("option",{value:t,children:t},t))]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs",children:"State"}),e.jsx("select",{className:B,value:n.state,onChange:_("state"),children:Ae.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))})]}),e.jsx(A,{label:"District or city",value:n.district,onChange:_("district")}),e.jsx(A,{label:"Website",value:n.campaignWebsite,onChange:_("campaignWebsite")}),e.jsx(A,{label:"Election date",type:"date",value:n.electionDate,onChange:_("electionDate")}),e.jsx(A,{label:"Primary date",type:"date",value:n.primaryDate,onChange:_("primaryDate")}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs",children:"Budget"}),e.jsx("select",{className:B,value:n.budgetRange,onChange:_("budgetRange"),children:_e.map(t=>e.jsx("option",{value:t.key,children:t.label},t.key))})]}),e.jsx(A,{label:"Opponent",value:n.opponentName,onChange:_("opponentName")})]}),e.jsxs("div",{className:"space-y-2 pt-1",children:[e.jsx(T,{className:"text-xs",children:"Services requested"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:ue.map(t=>{const E=i.includes(t.key);return e.jsxs("button",{type:"button",disabled:!U,onClick:()=>N(R=>E?R.filter(ve=>ve!==t.key):[...R,t.key]),className:`rounded-full border px-3 py-1 text-xs ${E?"bg-primary text-primary-foreground border-primary":"bg-background text-muted-foreground"} disabled:opacity-70`,"aria-pressed":E,children:[t.label,"comingSoon"in t&&t.comingSoon?" (coming soon)":""]},t.key)})})]})]})}),e.jsx(b,{className:"cc-card",children:e.jsxs(y,{className:"p-4 space-y-2 text-sm",children:[e.jsx("h3",{className:"font-semibold text-sm",children:"Submitted by"}),e.jsxs("p",{className:"font-medium",children:[S.firstName," ",S.lastName," ",e.jsxs("span",{className:"text-muted-foreground font-normal",children:["· ",Ee[S.role]||S.role]})]}),e.jsxs("p",{children:[e.jsx("a",{className:"underline",href:`mailto:${S.email}`,children:S.email})," · ",e.jsx("a",{className:"underline",href:`tel:${S.phone}`,children:S.phone})]}),S.heardFrom?e.jsxs("p",{className:"text-muted-foreground",children:["Heard about us: ",S.heardFrom]}):null,S.notes?e.jsx("p",{className:"whitespace-pre-wrap rounded bg-muted/50 p-2",children:S.notes}):null,e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Budget as submitted: ",qe[r.submitted?.campaign?.budgetRange]||"n/a"," · Election ",Ke(r.submitted?.campaign?.electionDate)]})]})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{className:"cc-card",children:e.jsxs(y,{className:"p-4 space-y-3",children:[e.jsx("h3",{className:"font-semibold text-sm",children:"Assigned to"}),e.jsxs("select",{className:B,value:r.assigned_to||"",disabled:r.status==="activated",onChange:t=>w.mutate({path:"/assign",body:{userId:t.target.value||null}}),"data-testid":"select-assign",children:[e.jsx("option",{value:"",children:"Unassigned"}),W.map(t=>e.jsx("option",{value:t.id,children:t.displayName||t.email},t.id))]})]})}),e.jsx(b,{className:"cc-card",children:e.jsxs(y,{className:"p-4 space-y-2",children:[e.jsx("h3",{className:"font-semibold text-sm",children:"Verification checklist"}),xe.map(t=>e.jsxs("label",{className:"flex items-start gap-2 text-sm cursor-pointer",children:[e.jsx(he,{checked:!!r.checklist?.[t.key],disabled:!U||w.isPending,onCheckedChange:E=>w.mutate({path:"/checklist",body:{key:t.key,value:E===!0}}),"data-testid":`check-${t.key}`,className:"mt-0.5"}),e.jsx("span",{children:t.label})]},t.key)),r.status==="verified"?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Unchecking an item moves this back to In review."}):null]})}),e.jsx(b,{className:"cc-card",children:e.jsxs(y,{className:"p-4 space-y-3",children:[e.jsx("h3",{className:"font-semibold text-sm",children:"Notes and activity"}),e.jsx("div",{className:"flex gap-2",children:e.jsx(I,{rows:2,value:k,onChange:t=>u(t.target.value),placeholder:"Add a note",className:"text-sm"})}),e.jsx(f,{size:"sm",variant:"outline",disabled:!k.trim()||w.isPending,onClick:()=>w.mutate({path:"/notes",body:{note:k}},{onSuccess:()=>u("")}),"data-testid":"button-add-note",children:"Add note"}),e.jsx("ol",{className:"space-y-2 text-xs max-h-80 overflow-auto",children:(r.activity||[]).map(t=>e.jsxs("li",{className:"border-l-2 pl-2",children:[e.jsxs("p",{children:[e.jsx("span",{className:"font-medium",children:Ie[t.action]||t.action}),t.user_name?` · ${t.user_name}`:""," ",e.jsx("span",{className:"text-muted-foreground",children:D(t.created_at)})]}),e.jsx(Ge,{action:t.action,detail:t.detail})]},t.id))})]})})]})]}),e.jsx(ie,{open:c,onOpenChange:v,children:e.jsxs(le,{children:[e.jsxs(V,{children:[e.jsx(Q,{children:"Reject this request"}),e.jsx(G,{children:"The submitter is not notified. A Sales Manager can reopen it later."})]}),e.jsx(I,{rows:3,value:g,onChange:t=>O(t.target.value),placeholder:"Reason","data-testid":"input-reject-reason"}
1),e.jsxs(H,{children:[e.jsx(f,{variant:"outline",onClick:()=>v(!1),children:"Cancel"}),e.jsx(f,{variant:"destructive",disabled:!g.trim()||w.isPending,onClick:()=>w.mutate({path:"/reject",body:{reason:g}},{onSuccess:()=>{v(!1),O("")}}),"data-testid":"button-confirm-reject",children:"Reject"})]})]})}),P?e.jsx(He,{request:r,onClose:()=>re(!1),onDone:J}):null,je?e.jsx(Je,{request:r,on:!L,onClose:()=>ce(!1),onDone:J}):null]})}function Ve({requestId:s}){const a=ae(),{toast:l}=K(),[d,h]=x.useState(""),p=F({queryKey:["/api/sales/requests","messages",s],queryFn:()=>C("GET",`/api/sales/requests/${s}/messages`),refetchInterval:3e4}),m=p.data?.unread||0;x.useEffect(()=>{m>0&&C("POST",`/api/sales/requests/${s}/messages/read`).then(()=>{a.invalidateQueries({queryKey:["/api/sales/requests"]})}).catch(()=>{})},[s,m]);const n=$({mutationFn:u=>C("POST",`/api/sales/requests/${s}/messages`,{body:u}),onSuccess:()=>{h(""),a.invalidateQueries({queryKey:["/api/sales/requests"]}),l({title:"Reply sent"})},onError:u=>l({title:"Not sent",description:q(u),variant:"destructive"})}),j=p.data,i=j?.messages||[],N=x.useRef(null);x.useEffect(()=>{const u=N.current;u&&(u.scrollTop=u.scrollHeight)},[i.length,s]);const k=!!d.trim()&&!n.isPending;return e.jsx(b,{"data-testid":"card-conversation",className:"cc-card min-w-0",children:e.jsxs(y,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("h3",{className:"font-semibold text-sm flex items-center gap-1.5",children:[e.jsx(Z,{className:"h-4 w-4 text-sky-600","aria-hidden":!0}),"Conversation"]}),j?e.jsxs("span",{className:"text-[11px] text-muted-foreground truncate min-w-0 hidden md:inline",title:j.replyTo,children:["Replies to ",j.replyTo]}):null]}),p.isLoading?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading conversation"}):null,p.error?e.jsx("p",{className:"text-sm text-destructive",children:q(p.error)}):null,j&&!i.length?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No emails yet."}):null,e.jsx("ol",{ref:N,className:"space-y-3 max-h-[28rem] overflow-auto pr-1","data-testid":"conversation-thread",children:i.map(u=>e.jsx(Qe,{m:u},u.id))}),j?e.jsxs("div",{className:"space-y-2 border-t pt-3",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:["To ",j.toName," <",j.toEmail,">"]}),e.jsx(I,{rows:4,value:d,onChange:u=>h(u.target.value),placeholder:`Write to ${j.toName.split(" ")[0]||"them"}`,className:"text-sm","data-testid":"input-sales-reply",onKeyDown:u=>{(u.metaKey||u.ctrlKey)&&u.key==="Enter"&&k&&(u.preventDefault(),n.mutate(d.trim()))}}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[11px] text-muted-foreground hidden sm:inline",children:"Their answer comes back to this request."}),e.jsxs(f,{size:"sm",disabled:!k,onClick:()=>n.mutate(d.trim()),"data-testid":"button-send-sales-reply",children:[n.isPending?e.jsx(ne,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(De,{className:"h-4 w-4 mr-1"}),"Send"]})]})]}):null]})})}function Qe({m:s}){const a=s.direction==="inbound",[l,d]=x.useState(!1);if(s.kind==="confirmation"&&!l)return e.jsx("li",{className:"flex justify-end","data-testid":`message-${s.id}`,children:e.jsxs("button",{type:"button",onClick:()=>d(!0),className:"rounded-lg border border-dashed bg-muted/40 px-3 py-1.5 text-[11px] text-muted-foreground hover:bg-muted",children:[e.jsx("span",{className:"font-medium text-foreground",children:"Automatic thank-you email"})," · ",D(s.createdAt),s.status==="failed"?e.jsx("span",{className:"text-destructive",children:" · Not delivered"}):null," · Show"]})});const h=a?s.fromName||s.fromEmail:s.kind==="confirmation"?"Automatic thank-you email":s.sentByName||"Sales";return e.jsx("li",{className:`flex ${a?"justify-start":"justify-end"}`,"data-testid":`message-${s.id}`,children:e.jsxs("div",{className:`max-w-[88%] rounded-lg border px-3 py-2 text-sm ${a?"bg-background":s.kind==="confirmation"?"bg-muted/40 border-dashed":"bg-sky-50 border-sky-200 dark:bg-sky-950/40 dark:border-sky-800/60"}`,children:[e.jsxs("p",{className:"text-[11px] text-muted-foreground mb-1",children:[e.jsx("span",{className:"font-medium text-foreground",children:h})," · ",D(s.createdAt),s.status==="failed"?e.jsx("span",{className:"text-destructive",children:" · Not delivered"}):null]}),s.senderMismatch?e.jsxs("p",{className:"text-[11px] text-amber-700 dark:text-amber-300 flex items-center gap-1 mb-1",children:[e.jsx(Be,{className:"h-3 w-3","aria-hidden":!0}),"From ",s.fromEmail,", not the email on this request"]}
1):null,s.bodyPending?e.jsx("p",{className:"text-muted-foreground italic",children:"Loading message"}):e.jsx("p",{className:"whitespace-pre-wrap break-words",children:s.bodyText}),s.status==="failed"&&s.error?e.jsx("p",{className:"text-[11px] text-destructive mt-1",children:s.error}):null]})})}function Ge({action:s,detail:a}){if(!a)return null;if(s==="note")return e.jsx("p",{className:"whitespace-pre-wrap text-muted-foreground",children:a.note});if(s==="assigned")return e.jsx("p",{className:"text-muted-foreground",children:a.to?"Reassigned":"Unassigned"});if(s==="rejected")return e.jsx("p",{className:"text-muted-foreground",children:a.reason});if(s==="checklist"){const l=xe.find(d=>d.key===a.key);return e.jsxs("p",{className:"text-muted-foreground",children:[a.value?"Checked":"Unchecked",": ",l?.label||a.key]})}return s==="activated"?e.jsxs("ul",{className:"text-muted-foreground",children:[a.featureError?e.jsxs("li",{className:"text-destructive",children:["Services not saved: ",a.featureError]}):null,(a.invites||[]).map(l=>e.jsxs("li",{children:[l.email," as ",pe.find(d=>d.key===l.role)?.label||l.role,": ",l.sent?"invite sent":l.skipped?"added, not emailed":`invite failed${l.error?` (${l.error})`:""}`]},l.email))]}):s==="activation_failed"?e.jsx("p",{className:"text-destructive",children:a.message}):(s==="turned_off"||s==="turned_on")&&a.reason?e.jsx("p",{className:"text-muted-foreground",children:a.reason}):null}function A({label:s,...a}){return e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs",children:s}),e.jsx(z,{className:"h-9",...a,value:a.value??""})]})}function He({request:s,onClose:a,onDone:l}){const{toast:d}=K(),h=s.contact||{},[o,p]=x.useState([...s.services||[]]),[m,n]=x.useState([{name:`${h.firstName||""} ${h.lastName||""}`.trim(),email:h.email||"",role:s.suggestedInviteRole||"staff",send:!0}]),[j,i]=x.useState(null),N=o.length>0&&m.every(c=>/^\S+@\S+\.\S+$/.test(c.email.trim())),k=$({mutationFn:()=>C("POST",`/api/sales/requests/${s.id}/activate`,{services:o,invites:m.map(c=>({name:c.name.trim()||void 0,email:c.email.trim(),role:c.role,send:c.send}))}),onSuccess:c=>{i(c),l()},onError:c=>d({title:"The campaign was not turned on",description:q(c),variant:"destructive"})}),u=(c,v)=>n(g=>g.map((O,P)=>P===c?{...O,...v}:O));return e.jsx(ie,{open:!0,onOpenChange:c=>{c||a()},children:e.jsx(le,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:j?e.jsxs(e.Fragment,{children:[e.jsxs(V,{children:[e.jsxs(Q,{children:[s.details?.name," is on"]}),e.jsx(G,{children:"The campaign workspace is created with the services below turned on."})]}),e.jsxs("ul",{className:"text-sm space-y-1","data-testid":"activation-result",children:[(j.invites||[]).map(c=>e.jsxs("li",{children:[c.email,": ",c.sent?"invite sent":c.skipped?"added without an email":`invite failed${c.error?` (${c.error})`:""}. Resend from the campaign's Team page.`]},c.email)),j.invites?.length?null:e.jsx("li",{className:"text-muted-foreground",children:"No one was invited."})]}),e.jsx(H,{children:e.jsx(f,{onClick:a,children:"Done"})})]}):e.jsxs(e.Fragment,{children:[e.jsxs(V,{children:[e.jsxs(Q,{children:["Turn on ",s.details?.name]}),e.jsx(G,{children:"Creates the campaign workspace, turns on the chosen services, and invites the people you pick. Reports and the campaign workspace are always included."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{className:"text-sm",children:"Services"}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2",children:ue.filter(c=>!("comingSoon"in c&&c.comingSoon)).map(c=>e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx(he,{checked:o.includes(c.key),onCheckedChange:v=>p(g=>v===!0?[...g,c.key]:g.filter(O=>O!==c.key))}),c.label]},c.key))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{className:"text-sm",children:"Invite to the campaign"}),m.map((c,v)=>e.jsxs("div",{className:"grid gap-2 sm:grid-cols-[1fr_1.3fr_1fr_auto_auto] items-center rounded-md border p-2","data-testid":`invite-row-${v}`,children:[e.jsx(z,{className:"h-9",placeholder:"Name",value:c.name,onChange:g=>u(v,{name:g.target.value})}),e.jsx(z,{className:"h-9",placeholder:"Email",type:"email",value:c.email,onChange:g=>u(v,{email:g.target.value})}),e.jsx("select",{className:B,value:c.role,onChange:g=>u(v,{role:g.target.value}),"aria-label":"Campaign role",children:pe.map(g=>e.jsx("option",{value:g.key,children:g.label},g.key))}),e.jsxs("label",{className:"flex items-center gap-1.5 text-xs whitespace-nowrap",children:[e.jsx(se,{checked:c.send,onCheckedChange:g=>u(v,{send:g}),"aria-label":"Send invite email"}),"Email invite"]}),e.jsx(f,{variant:"ghost",size:"icon","aria-label":"Remove",onClick:()=>n(g=>g.filter((O,P)=>P!==v)),children:e.jsx(Pe,{className:"h-4 w-4"})})]},v)),e.jsxs(f,{variant:"outline",size:"sm",onClick:()=>n(c=>[...c,{name:"",email:"",role:"staff",send:!0}]),disabled:m.length>=20,children:[e.jsx(Le,{className:"h-4 w-4 mr-1"}),"Add person"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"People with the email invite off are added to the campaign but not emailed."})]}
1),e.jsxs(H,{children:[e.jsx(f,{variant:"outline",onClick:a,children:"Cancel"}),e.jsxs(f,{disabled:!N||k.isPending,onClick:()=>k.mutate(),"data-testid":"button-confirm-activate",children:[k.isPending?e.jsx(ne,{className:"h-4 w-4 mr-1 animate-spin"}):null,"Turn on campaign"]})]})]})})})}function Je({request:s,on:a,onClose:l,onDone:d}){const{toast:h}=K(),[o,p]=x.useState(""),m=$({mutationFn:()=>C("POST",`/api/sales/requests/${s.id}/power`,{on:a,reason:o.trim()||void 0}),onSuccess:()=>{d(),l(),h({title:a?"Campaign turned back on":"Campaign turned off"})},onError:n=>h({title:"No change was made",description:q(n),variant:"destructive"})});return e.jsx(ie,{open:!0,onOpenChange:n=>{n||l()},children:e.jsxs(le,{children:[e.jsxs(V,{children:[e.jsx(Q,{children:a?"Turn campaign back on":"Turn campaign off"}),e.jsx(G,{children:a?"The campaign comes back with all its data. Texting and email stay paused until an admin resumes outreach.":"Archives the campaign: scheduled sends are cancelled, outreach stops, and it leaves the campaign list. All data is kept."})]}),e.jsx(I,{rows:2,value:o,onChange:n=>p(n.target.value),placeholder:"Reason (optional)"}
1),e.jsxs(H,{children:[e.jsx(f,{variant:"outline",onClick:l,children:"Cancel"}),e.jsx(f,{variant:a?"default":"destructive",disabled:m.isPending,onClick:()=>m.mutate(),"data-testid":"button-confirm-power",children:a?"Turn on":"Turn off"})]})]})})}function We(){const[s,a]=x.useState(""),l=x.useMemo(()=>Te("/start-campaign"),[]),d=`<iframe src="${l}?embed=1" title="Start a campaign" style="width:100%;min-height:1700px;border:0" loading="lazy"></iframe>`,h=async(o,p)=>{try{await navigator.clipboard.writeText(p),a(o),setTimeout(()=>a(""),1500)}catch{}};return e.jsx(b,{className:"cc-card max-w-3xl",children:e.jsxs(y,{className:"p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold",children:"Public campaign request form"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Requests land in the New tab. Nothing is created until Sales verifies and turns a campaign on."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(T,{children:"Direct link"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(z,{readOnly:!0,value:l,className:"font-mono text-xs"}),e.jsx(f,{variant:"outline",onClick:()=>h("link",l),children:s==="link"?e.jsx(ee,{className:"h-4 w-4"}):e.jsx(oe,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(T,{children:"Embed code for the website"}),e.jsx(I,{readOnly:!0,value:d,rows:3,className:"font-mono text-xs"}),e.jsxs(f,{variant:"outline",size:"sm",onClick:()=>h("snippet",d),"data-testid":"button-copy-embed",children:[s==="snippet"?e.jsx(ee,{className:"h-4 w-4 mr-1"}):e.jsx(oe,{className:"h-4 w-4 mr-1"}),"Copy embed code"]})]}),e.jsx("a",{className:"text-sm underline",href:l,target:"_blank",rel:"noreferrer",children:"Open the form"})]})})}function Ye(){const s=ae(),{toast:a}=K(),{user:l}=te(),[d,h]=x.useState(""),o=F({queryKey:["/api/sales/team"],queryFn:()=>C("GET","/api/sales/team")}),p=$({mutationFn:()=>C("POST","/api/sales/team",{email:d}),onSuccess:()=>{h(""),s.invalidateQueries({queryKey:["/api/sales/team"]}),a({title:"Added to the Sales Team"})},onError:n=>a({title:"Not added",description:q(n),variant:"destructive"})}),m=$({mutationFn:n=>C("DELETE",`/api/sales/team/${n}`),onSuccess:()=>s.invalidateQueries({queryKey:["/api/sales/team"]}),onError:n=>a({title:"Not removed",description:q(n),variant:"destructive"})});return e.jsx(b,{className:"cc-card max-w-3xl",children:e.jsxs(y,{className:"p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold",children:"Sales Team"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Add an existing Blueroots staff account by email. Sales Team members can review, verify, and turn on campaigns. Only a master admin can make someone a Sales Manager."})]}),e.jsxs("form",{className:"flex gap-2",onSubmit:n=>{n.preventDefault(),d.trim()&&p.mutate()},children:[e.jsx(z,{type:"email",placeholder:"[email protected]",value:d,onChange:n=>h(n.target.value),"data-testid":"input-sales-email"}),e.jsx(f,{type:"submit",disabled:!d.trim()||p.isPending,"data-testid":"button-add-sales",children:"Add"})]}),e.jsxs("div",{className:"divide-y rounded-md border",children:[o.isLoading?e.jsx("p",{className:"p-3 text-sm text-muted-foreground",children:"Loading"}):null,o.data&&!o.data.length?e.jsx("p",{className:"p-3 text-sm text-muted-foreground",children:"No one on the Sales Team yet."}):null,o.data?.map(n=>e.jsxs("div",{className:"flex items-center justify-between gap-2 p-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:n.displayName}),e.jsxs("p",{className:"text-xs text-muted-foreground truncate",children:[n.email," · ",n.role==="sales_manager"?"Sales Manager":"Sales Team"]})]}),n.role==="sales"&&n.id!==l?.id?e.jsx(f,{variant:"ghost",size:"sm",onClick:()=>m.mutate(n.id),disabled:m.isPending,children:"Remove"}):null]},n.id))]})]})})}export{xs 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.