PageSourceSearch

https://analyticsindiamag.com/assets/ManageContacts-CSm6RfFE.js

js analyticsindiamag.com collected 2026-09-24 08:27:30 UTC 8,245 bytes, 2 lines download raw bytes

1import{r as u,T as A,U as Q,j as e,B as p,q as $,I as V,y as H,s as _,f as b,N as K}from"./index-KSWbwNeY.js";import{u as G}from"./useMutation-eCaSwUD_.js";import{T as Z,a as J,b as C,c,d as W,e as o}from"./table-BWUN_Dp9.js";import{S as D,a as E,b as L,c as z,d}from"./select-DzTIkJMJ.js";import{D as X,a as Y,b as ee,c as se}from"./dialog-Bpfij23O.js";import{A as ae}from"./AdminNav-DsaLvjFx.js";import{D as te}from"./download-BtORIOsS.js";import{E as ne}from"./eye-Cwzmef_1.js";import{C as re}from"./chevron-left-C0OR5oyH.js";import{f as v}from"./format-hhvI2L0z.js";import"./index-BdQq_4o_.js";import"./chevron-down-D7IdZFzc.js";import"./chevron-up-B5q4f77c.js";import"./index-BpbyRUKB.js";import"./index-DsYLezIw.js";import"./user-cog-DvqSS7bY.js";import"./trash-2-CwcwS_bf.js";import"./book-open-DS7Nmuzn.js";import"./receipt-DgWJf9Ou.js";import"./en-US-BOoww7nS.js";const j=20,Me=()=>{const[w,R]=u.useState(""),[g,P]=u.useState("all"),[t,f]=u.useState(null),[T,x]=u.useState(1),k=A(),{data:N,isLoading:q}=Q({queryKey:["contact-submissions"],queryFn:async()=>{const{data:s,error:a}=await _.from("contact_submissions").select("*").order("created_at",{ascending:!1});if(a)throw a;return s}}),F=G({mutationFn:async({id:s,status:a})=>{const{error:l}=await _.from("contact_submissions").update({status:a}).eq("id",s);if(l)throw l},onSuccess:()=>{k.invalidateQueries({queryKey:["contact-submissions"]}),b.success("Status updated")},onError:s=>{b.error(s.message||"Failed to update status")}}),i=u.useMemo(()=>(N==null?void 0:N.filter(s=>{const a=w.toLowerCase(),l=!a||s.first_name.toLowerCase().includes(a)||s.last_name.toLowerCase().includes(a)||s.email.toLowerCase().includes(a)||s.organization.toLowerCase().includes(a),h=g==="all"||s.status===g;return l&&h}))||[],[N,w,g]),m=Math.max(1,Math.ceil(i.length/j)),r=Math.min(T,m),S=i.slice((r-1)*j,r*j),B=s=>{R(s),x(1)},I=s=>{P(s),x(1)},O=()=>{if(!i.length)return;const s=["Date","First Name","Last Name","Email","Phone","Organization","Designation","Reason","Message","Status"],a=i.map(n=>[v(new Date(n.created_at),"yyyy-MM-dd"),n.first_name,n.last_name,n.email,n.phone,n.organization,n.designation,n.reason,`"${(n.query||"").replace(/"/g,'""')}"`,n.status]),l=[s.join(","),...a.map(n=>n.join(","))].join(`
2`),h=new Blob([l],{type:"text/csv;charset=utf-8;"}),M=URL.createObjectURL(h),y=document.createElement("a");y.href=M,y.download=`contacts-${v(new Date,"yyyy-MM-dd")}.csv`,y.click(),URL.revokeObjectURL(M),b.success("Downloaded successfully")},U=s=>{const a={new:"default",in_progress:"secondary",resolved:"outline"};return e.jsx(K,{variant:a[s]||"default",className:"text-[10px] px-1.5 py-0",children:s.replace("_"," ").toUpperCase()})};return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(ae,{}),e.jsx("main",{className:"md:ml-52 p-4 md:p-6",children:e.jsxs("div",{className:"max-w-7xl mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"font-sans text-xl font-semibold",children:"Contact Submissions"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[i.length," submission",i.length!==1?"s":""]})]}),e.jsxs(p,{variant:"outline",size:"sm",onClick:O,className:"gap-1.5 text-xs",children:[e.jsx(te,{className:"h-3.5 w-3.5"}),"Export CSV"]})]}),e.jsxs("div",{className:"flex gap-3 mb-4",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx($,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),e.jsx(V,{placeholder:"Search name, email, org...",value:w,onChange:s=>B(s.target.value),className:"pl-8 h-8 text-xs"})]}),e.jsxs(D,{value:g,onValueChange:I,children:[e.jsx(E,{className:"w-[140px] h-8 text-xs",children:e.jsx(L,{placeholder:"Status"})}),e.jsxs(z,{children:[e.jsx(d,{value:"all",children:"All Status"}),e.jsx(d,{value:"new",children:"New"}),e.jsx(d,{value:"in_progress",children:"In Progress"}),e.jsx(d,{value:"resolved",children:"Resolved"})]})]})]}),q?e.jsx("div",{className:"text-center py-8 text-sm text-muted-foreground",children:"Loading..."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border rounded-md overflow-hidden",children:e.jsxs(Z,{children:[e.jsx(J,{children:e.jsxs(C,{className:"hover:bg-transparent",children:[e.jsx(c,{className:"text-[11px] h-8 px-3",children:"Date"}),e.jsx(c,{className:"text-[11px] h-8 px-3",children:"Name"}),e.jsx(c,{className:"text-[11px] h-8 px-3",children:"Email"}),e.jsx(c,{className:"text-[11px] h-8 px-3",children:"Organization"}),e.jsx(c,{className:"text-[11px] h-8 px-3",children:"Reason"}),e.jsx(c,{className:"text-[11px] h-8 px-3",children:"Status"}),e.jsx(c,{className:"text-[11px] h-8 px-3 text-right w-[60px]"})]})}),e.jsx(W,{children:S.length>0?S.map(s=>e.jsxs(C,{className:"cursor-pointer",onClick:()=>f(s),children:[e.jsx(o,{className:"text-[11px] py-2 px-3 whitespace-nowrap",children:v(new Date(s.created_at),"MMM d, yy")}),e.jsxs(o,{className:"text-[11px] py-2 px-3 font-medium whitespace-nowrap",children:[s.first_name," ",s.last_name]}),e.jsx(o,{className:"text-[11px] py-2 px-3 max-w-[180px] truncate",children:s.email}),e.jsx(o,{className:"text-[11px] py-2 px-3 max-w-[120px] truncate",children:s.organization||"—"}),e.jsx(o,{className:"text-[11px] py-2 px-3 max-w-[150px] truncate",children:s.reason}),e.jsx(o,{className:"py-2 px-3",children:U(s.status)}),e.jsx(o,{className:"py-2 px-3 text-right",children:e.jsx(p,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:a=>{a.stopPropagation(),f(s)},children:e.jsx(ne,{className:"h-3 w-3"})})})]},s.id)):e.jsx(C,{children:e.jsx(o,{colSpan:7,className:"text-center py-6 text-xs text-muted-foreground",children:"No submissions foun
2d"})})})]})}),m>1&&e.jsxs("div",{className:"flex items-center justify-between mt-3 text-xs text-muted-foreground",children:[e.jsxs("span",{children:[(r-1)*j+1,"–",Math.min(r*j,i.length)," of ",i.length]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(p,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:r<=1,onClick:()=>x(r-1),children:e.jsx(re,{className:"h-3.5 w-3.5"})}),Array.from({length:m},(s,a)=>a+1).filter(s=>s===1||s===m||Math.abs(s-r)<=1).reduce((s,a,l,h)=>(l>0&&a-h[l-1]>1&&s.push("..."),s.push(a),s),[]).map((s,a)=>typeof s=="string"?e.jsx("span",{className:"px-1",children:"…"},`e${a}`):e.jsx(p,{variant:s===r?"default":"ghost",size:"sm",className:"h-7 w-7 p-0 text-[11px]",onClick:()=>x(s),children:s},s)),e.jsx(p,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:r>=m,onClick:()=>x(r+1),children:e.jsx(H,{className:"h-3.5 w-3.5"})})]})]})]}),e.jsx(X,{open:!!t,onOpenChange:()=>f(null),children:e.jsxs(Y,{className:"max-w-lg max-h-[80vh] overflow-y-auto",children:[e.jsx(ee,{children:e.jsx(se,{className:"font-sans text-lg",children:"Submission Details"})}),t&&e.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsx("div",{className:"grid grid-cols-2 gap-3",children:[["Name",`${t.first_name} ${t.last_name}`],["Email",t.email],["Phone",t.phone],["Organization",t.organization||"—"],["Designation",t.designation||"—"],["Submitted",v(new Date(t.created_at),"MMM d, yyyy 'at' h:mm a")]].map(([s,a])=>e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-medium text-muted-foreground mb-0.5",children:s}),e.jsx("p",{className:"text-xs",children:a})]},s))}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-medium text-muted-foreground mb-0.5",children:"Reason"}),e.jsx("p",{className:"text-xs",children:t.reason})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-medium text-muted-foreground mb-1",children:"Message"}),e.jsx("div",{className:"bg-muted p-3 rounded-md",children:e.jsx("p",{className:"text-xs whitespace-pre-wrap",children:t.query})})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-medium text-muted-foreground mb-1",children:"Status"}),e.jsxs(D,{value:t.status,onValueChange:s=>{F.mutate({id:t.id,status:s}),f({...t,status:s})},children:[e.jsx(E,{className:"h-8 text-xs",children:e.jsx(L,{})}),e.jsxs(z,{children:[e.jsx(d,{value:"new",children:"New"}),e.jsx(d,{value:"in_progress",children:"In Progress"}),e.jsx(d,{value:"resolved",children:"Resolved"})]})]})]})]})]})})]})})]})};export{Me 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.