PageSourceSearch

https://www.bestly.tech/assets/AdminHireRequests-BW9O-Gsn.js

js bestly.tech collected 2026-09-24 15:13:34 UTC 14,720 bytes, 2 lines download raw bytes

1import{c2 as l,cz as ye,ce as I,cv as Se,bS as e,aW as O,ay as Ce,o,aJ as ke,a6 as De,ac as oe,t as Ae,b4 as de,u as qe,K as Te,L as $e,O as _e,P as Re,N as Ee,n as Le}from"./main-BKZTvsEo.js";import{C as Pe,a as Be}from"./card-Co62idmN.js";import{B as V}from"./badge-CUEhLNBB.js";import{S as me,c as he,d as xe,a as ue,b as Y}from"./select-MZUdJgNc.js";import{C as G}from"./checkbox-3fr3hSSP.js";import{T as ze,d as Oe,e as J,c as h,a as He,b as d}from"./table-DuFLdc9q.js";import{P as Ue}from"./PageHeader-IldNMkLS.js";import{E as Me}from"./EmptyState-C90mddGj.js";import{A as H}from"./ActionMenu-CRflLzIq.js";import{A as Fe,c as Ie,f as Ve,g as Ye,d as Ge,e as Je,b as Ke,a as We}from"./alert-dialog-CSNb9Hkp.js";import{D as Xe}from"./download-DyQlZjnK.js";import{A as pe}from"./archive-CRnVVMRc.js";import{C as Ze}from"./chevron-left-2tM8YptF.js";import{R as je}from"./reply-iKZjfSie.js";import{E as Qe}from"./eye-BUpkk1qD.js";import"./index-D4jsuGfW.js";import"./inbox-DktwF70Q.js";import"./ellipsis-BHy0PnoE.js";const K=["new","contacted","proposal","accepted","declined","archived"],T={new:"New",contacted:"Contacted",proposal:"Proposal",accepted:"Accepted",declined:"Declined",archived:"Archived"},W=20,es=[{key:"name",label:"Name"},{key:"email",label:"Email"},{key:"company",label:"Company"},{key:"project_type",label:"Project Type"},{key:"budget_range",label:"Budget"},{key:"timeline",label:"Timeline"},{key:"status",label:"Status"},{key:"created_at",label:"Date"}];function ss(x,N,D){const p=g=>`"${String(g??"").replace(/^[=+\-@\t\r]/,"'$&").replace(/"/g,'""')}"`,$=[N.map(g=>p(g.label)).join(","),...x.map(g=>N.map(y=>p(g[y.key])).join(","))].join(`
2`),j=URL.createObjectURL(new Blob([$],{type:"text/csv;charset=utf-8;"})),w=document.createElement("a");w.href=j,w.download=`${D}-${new Date().toISOString().slice(0,10)}.csv`,w.click(),URL.revokeObjectURL(j)}function ge(x){return`mailto:${x.email}?subject=${encodeURIComponent(`Your ${x.project_type||"project"} inquiry${x.company?` — ${x.company}`:""}`)}`}function bs({embedded:x=!1}={}){const[N,D]=l.useState([]),[p,$]=l.useState(""),[j,w]=l.useState("All"),[g,y]=l.useState(0),[U,fe]=l.useState(!0),[X,Z]=l.useState(null),[t,u]=l.useState(null),[m,f]=l.useState(new Set),[Q,ee]=l.useState(new Set),[_,se]=l.useState(!1),[n,R]=l.useState(null),[E,ae]=l.useState(!1),{toast:S}=ye(),L=l.useCallback(async()=>{const{data:s,error:a}=await I.from("hire_requests").select("*").order("created_at",{ascending:!1});a?Z(a.message):(Z(null),D(s||[])),fe(!1)},[]);l.useEffect(()=>{L()},[L]);const[te,ve]=Se(),M=te.get("open");l.useEffect(()=>{if(!M||U)return;const s=N.find(C=>C.id===M);s&&u(s);const a=new URLSearchParams(te);a.delete("open"),ve(a,{replace:!0})},[M,U,N]);const P=async(s,a,{quiet:C=!1}={})=>{ee(i=>new Set([...i,...s]));const{data:r,error:q}=await I.from("hire_requests").update({status:a}).in("id",s).select("id");ee(i=>{const k=new Set(i);return s.forEach(we=>k.delete(we)),k});const c=(r==null?void 0:r.length)??0;if(q)return S({title:"Couldn't update status",description:`${q.message}. Nothing changed — try again.`,variant:"destructive"}),0;if(c===0)return S({title:"Status not changed",description:"No rows were updated. Your account may not have permission, or the request was removed. Refresh and try again.",variant:"destructive"}),0;const z=new Set(r.map(i=>i.id));return D(i=>i.map(k=>z.has(k.id)?{...k,status:a}:k)),u(i=>i&&z.has(i.id)?{...i,status:a}:i),C||S({title:s.length===1?`Marked ${T[a].toLowerCase()}`:`Marked ${c} request${c===1?"":"s"} ${T[a].toLowerCase()}`,description:c<s.length?`${s.length-c} could not be updated.`:void 0}),c},le=async s=>{se(!0);const a=await P(Array.from(m),s);se(!1),a>0&&f(new Set)},be=async s=>{ae(!0);const{data:a,error:C}=await I.from("hire_requests").delete().in("id",s).select("id");ae(!1);const r=(a==null?void 0:a.length)??0;if(C)S({title:"Couldn't delete",description:`${C.message}. Nothing was removed — try again.`,variant:"destructive"});else if(r===0)S({title:"Nothing was deleted",description:"Your account isn't allowed to delete these requests, or they were already removed. Refresh and try again.",variant:"destructive"});else{S({title:`Deleted ${r} request${r===1?"":"s"}`,description:r<s.length?`${s.length-r} could not be deleted.`:void 0,variant:r<s.length?"destructive":void 0});const q=new Set(a.map(c=>c.id));D(c=>c.filter(z=>!q.has(z.id))),f(new Set),t&&q.has(t.id)&&u(null)}R(null)},ne=s=>{const a=new Set(m);a.has(s)?a.delete(s):a.add(s),f(a)},A=N.filter(s=>{if(j!=="All"&&(s.status||"new")!==j)return!1;if(p){const a=p.toLowerCase();return(s.name||"").toLowerCase().includes(a)||(s.email||"").toLowerCase().includes(a)||(s.company||"").toLowerCase().includes(a)}return!0}),B=Math.max(1,Math.ceil(A.length/W)),v=Math.min(g,B-1),b=A.slice(v*W,(v+1)*W),Ne=b.length>0&&b.every(s=>m.has(s.id)),F=!!p||j!=="All",ie=s=>[{label:"Open request",icon:Qe,onSelect:()=>u(s)},{label:"Reply by email",icon:je,onSelect:()=>{window.location.href=ge(s)}},{label:"Delete…",icon:de,destructive:!0,onSelect:()=>R([s.id])}],re=s=>e.jsxs(me,{value:s.status||"new",onValueChange:a=>P([s.id],a),disabled:Q.has(s.id),children:[e.jsx(he,{"aria-label":`Status for request from ${s.name}`,className:"h-9 w-32 text-xs",children:e.jsx(xe,{})}),e.jsx(ue,{children:K.map(a=>e.jsx(Y,{value:a,children:T[a]},a))})]}),ce=e.jsx(Me,{icon:Le,title:F?"No matching requests":"No hire requests yet",description:F?"Try a different search or status filter.":"Project inquiries from the hire form will appear here.",action:F?e.jsx(o,{variant:"outline",size:"sm",onClick:()=>{$(""),w("All")},children:"Clear filters"}):void 0});return U?e.jsxs("div",{className:"space-y-6 max-w-6xl",children:[e.jsx(O,{className:"h-8 w-56"}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(O,{className:"h-10 w-72"}),e.jsx(O,{className:"h-10 w-36"})]}),e.jsx("div",{className:"space-y-2",children:Array.from({length:6}).map((s,a)=>e.jsx(O,{className:"h-12 w-full rounded-lg"},a))})]}):e.jsxs("div",{className:"space-y-6 max-w-6xl",children:[e.jsx(Ue,{embedded:x,title:"Hire Requests",description:"Project inquiries from the hire form.",actions:e.jsx(H,{items:[{group:"Export",label:`Export CSV (${A.length})`,icon:Xe,disabled:A.length===0,onSelect:()=>ss(A,es,"hire-requests")},{group:"View",label:"Refresh",icon:Ce,onSelect:L}]})}),X&&e.jsxs("div",{role:"alert",className:"flex flex-wrap items-center justify-between gap-3 rounded-lg border border-red-500/30 bg-red-500/[0.06] px-4 py-3 text-sm text-red-200",children:[e.jsxs("span",{children:["Couldn't load hire requests: ",X]}),e.jsx(o,{size:"sm",variant:"outline",onClick:L,children:"Retry"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsxs("div",{className:"relative max-w-xs flex-1",children:[e.jsx(ke,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground","aria-hidden":!0}),e.jsx(De,{"aria-label":"Search hire requests",placeholder:"Search name, email, company...",value:p,onChange:s=>{$(s.target.value),y(0),f(new Set)},className:"pl-9"})]}),e.jsxs(me,{value:j,onValueChange:s=>{w(s),y(0),f(new Set)},children:[e.jsx(he,{"aria-label":"Filter by status",className:"w-36",children:e.jsx(xe,{})}),e.jsxs(ue,{children:[e.jsx(Y,{value:"All",children:"All statuses"}),K.map(s=>e.jsx(Y,{value:s,children:T[s]},s))]})]})]}),m.size>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-lg border border-border bg-muted/50 px-3 sm:px-4 py-2",children:[e.jsxs("span",{className:"text-sm font-medium",children:[m.size," selected"]}),e.jsxs(o,{variant:"outline",size:"sm",className:"ml-2",disabled:_,onClick:()=>le("archived"),children:[_?e.jsx(oe,{className:"h-4 w-4 animate-spin"}):e.jsx(pe,{className:"h-4 w-4"})," Archive"]}),e.jsx(H,{label:"Set status for selected",align:"start",trigger:e.jsxs(o,{variant:"outline",size:"sm",disabled:_,children:["Mark as ",e.jsx(Ae,{className:"h-4 w-4"})]}),items:K.filter(s=>s!=="archived").map(s=>({label:T[s],onSelect:()=>le(s)}))}),e.jsxs(o,{variant:"outline",size:"sm",className:"text-red-400 hover:text-red-300 border-red-500/30",disabled:_,onClick:()=>R(Array.from(m)),children:[e.jsx(de,{className:"h-4 w-4"})," Delete"]}),e.jsx(o,{variant:"ghost",size:"sm",className:"ml-auto",onClick:()=>f(new Set),children:"Clear selection"})]}),e.jsx(Pe,{className:"border-border/50",children:e.jsxs(Be,{className:"p-0",children:[e.jsx("div",{className:"hidden md:block",children:e.jsxs(ze,{children:[e.jsx(Oe,{children:e.jsxs(J,{className:"hover:bg-transparent",children:[e.jsx(h,{className:"w-10",children:e.jsx(G,{"aria-label":"Select all on this page",checked:Ne,onCheckedChange:s=>
2f(s?new Set(b.map(a=>a.id)):new Set)})}),e.jsx(h,{className:"text-xs",children:"Name"}),e.jsx(h,{className:"text-xs",children:"Company"}),e.jsx(h,{className:"text-xs",children:"Type"}),e.jsx(h,{className:"text-xs",children:"Budget"}),e.jsx(h,{className:"text-xs",children:"Timeline"}),e.jsx(h,{className:"text-xs",children:"Status"}),e.jsx(h,{className:"text-xs",children:"Date"}),e.jsx(h,{className:"text-xs w-12",children:e.jsx("span",{className:"sr-only",children:"Actions"})})]})}),e.jsxs(He,{children:[b.map(s=>e.jsxs(J,{className:"even:bg-muted/30","data-state":m.has(s.id)?"selected":void 0,children:[e.jsx(d,{children:e.jsx(G,{"aria-label":`Select request from ${s.name}`,checked:m.has(s.id),onCheckedChange:()=>ne(s.id)})}),e.jsx(d,{className:"font-medium text-sm",children:e.jsx("button",{type:"button",onClick:()=>u(s),className:"text-left hover:underline rounded-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:s.name})}),e.jsx(d,{className:"text-muted-foreground text-sm",children:s.company||"—"}),e.jsx(d,{children:e.jsx(V,{variant:"outline",className:"text-xs",children:s.project_type})}),e.jsx(d,{className:"text-sm",children:s.budget_range||"—"}),e.jsx(d,{className:"text-sm",children:s.timeline||"—"}),e.jsx(d,{children:re(s)}),e.jsx(d,{className:"text-muted-foreground text-sm",children:s.created_at?new Date(s.created_at).toLocaleDateString():"—"}),e.jsx(d,{children:e.jsx(H,{label:`Actions for request from ${s.name}`,items:ie(s)})})]},s.id)),b.length===0&&e.jsx(J,{children:e.jsx(d,{colSpan:9,className:"p-0",children:ce})})]})]})}),e.jsxs("div",{className:"md:hidden divide-y divide-border",children:[b.map(s=>e.jsx("div",{className:"p-3 space-y-2",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(G,{"aria-label":`Select request from ${s.name}`,checked:m.has(s.id),onCheckedChange:()=>ne(s.id),className:"mt-1"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>u(s),className:"min-w-0 text-left rounded-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[e.jsx("p",{className:"text-sm font-medium text-foreground truncate",children:s.name}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s.company||"No company"})]}),e.jsx(H,{label:`Actions for request from ${s.name}`,items:ie(s)})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap mt-2",children:[e.jsx(V,{variant:"outline",className:"text-xs",children:s.project_type}),e.jsx("span",{className:"text-xs text-foreground",children:s.budget_range||"—"}),re(s),e.jsx("span",{className:"text-xs text-muted-foreground ml-auto",children:s.created_at?new Date(s.created_at).toLocaleDateString():"—"})]})]})]})},s.id)),b.length===0&&e.jsx("div",{className:"p-4",children:ce})]})]})}),B>1&&e.jsxs("div",{className:"flex items-center justify-center gap-3",children:[e.jsx(o,{variant:"outline",size:"icon",className:"h-9 w-9",disabled:v===0,onClick:()=>y(v-1),"aria-label":"Previous page",children:e.jsx(Ze,{className:"h-4 w-4"})}),e.jsxs("span",{className:"text-xs text-muted-foreground tabular-nums",children:["Page ",v+1," of ",B]}),e.jsx(o,{variant:"outline",size:"icon",className:"h-9 w-9",disabled:v>=B-1,onClick:()=>y(v+1),"aria-label":"Next page",children:e.jsx(qe,{className:"h-4 w-4"})})]}),e.jsx(Te,{open:!!t,onOpenChange:s=>{s||u(null)},children:e.jsxs($e,{className:"max-w-lg",children:[e.jsx(_e,{children:e.jsxs(Re,{children:["Hire request — ",t==null?void 0:t.name]})}),t&&e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Email:"})," ",e.jsx("span",{className:"break-all",children:t.email})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Company:"})," ",e.jsx("span",{children:t.company||"—"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Type:"})," ",e.jsx(V,{variant:"outline",children:t.project_type})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Budget:"})," ",e.jsx("span",{children:t.budget_range||"—"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Timeline:"})," ",e.jsx("span",{children:t.timeline||"—"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Referral:"})," ",e.jsx("span",{children:t.referral_source||"—"})]})]}),e.jsxs("div",{className:"border-t pt-3 max-h-[50vh] overflow-y-auto",children:[e.jsx("p",{className:"text-muted-foreground mb-1",children:"Description"}),e.jsx("p",{className:"whitespace-pre-wrap text-foreground",children:t.description})]})]}),t&&e.jsxs(Ee,{className:"gap-2 sm:gap-2",children:[e.jsxs(o,{variant:"outline",disabled:Q.has(t.id)||t.status==="archived",onClick:async()=>{await P([t.id],"archived")&&u(null)},children:[e.jsx(pe,{className:"h-4 w-4"})," Archive"]}),e.jsx(o,{asChild:!0,children:e.jsxs("a",{href:ge(t),onClick:()=>{(t.status||"new")==="new"&&P([t.id],"contacted",{quiet:!0})},children:[e.jsx(je,{className:"h-4 w-4"})," Reply"]})})]})]})}),e.jsx(Fe,{open:!!n,onOpenChange:s=>{!s&&!E&&R(null)},children:e.jsxs(Ie,{children:[e.jsxs(Ve,{children:[e.jsxs(Ye,{children:["Delete ",(n==null?void 0:n.length)===1?"hire request":`${n==null?void 0:n.length} hire requests`,"?"]}),e.jsxs(Ge,{children:["This permanently deletes the selected hire request",((n==null?void 0:n.length)||0)>
21?"s":"",". This can't be undone. Archive instead if you only want it out of the way."]})]}),e.jsxs(Je,{children:[e.jsx(Ke,{disabled:E,children:"Cancel"}),e.jsx(We,{disabled:E,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",onClick:s=>{s.preventDefault(),n&&be(n)},children:E?e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"h-4 w-4 animate-spin"})," Deleting…"]}):"Delete"})]})]})})]})}export{bs 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.