1import{j as e}from"./vendor-motion-C-bzc5iY.js";import{u as B,r as a,L}from"./vendor-react-BOEApJZp.js";import{s as n,a as i,au as I}from"./index-Do7XhUgZ.js";import{S as o,n as T,l as A}from"./nps-Cl28CPiI.js";import"./vendor-charts-ChcSPLBO.js";import"./vendor-supabase-CUfS5aUD.js";const p=l=>l?new Date(l).toLocaleDateString():"";function F(){const l=B(),[g,k]=a.useState(!1),[u,S]=a.useState(!1),[h,E]=a.useState([]),[c,$]=a.useState([]),[N,C]=a.useState("en"),[j,w]=a.useState(!1);a.useEffect(()=>{(async()=>{const{data:s}=await n.auth.getSession();if(!s.session){l("/admin/login",{replace:!0});return}const{data:t}=await n.from("user_roles").select("role").eq("user_id",s.session.user.id);S(!!(t!=null&&t.some(m=>m.role==="admin"))),k(!0)})()},[l]);const f=a.useCallback(async()=>{const[s,t]=await Promise.all([n.rpc("survey_admin_buyers",{_survey_key:o}),n.rpc("survey_admin_responses",{_survey_key:o})]);(s.error||t.error)&&i.error("Could not load feedback data"),E(s.data??[]),$(t.data??[])},[]);a.useEffect(()=>{u&&f()},[u,f]);const y=async(s,t)=>{if(!s.length){i.info("Nobody to email");return}w(!0);try{const{error:m}=await n.rpc("survey_admin_create_invites",{_survey_key:o,_lang:N,_user_ids:s});if(m){i.error(m.message);return}const{data:r,error:R}=await n.functions.invoke("send-buyer-feedback-invite",{body:{survey_key:o,user_ids:s,resend:t}});if(R){i.error("Could not send the emails");return}const v=(r==null?void 0:r.sent)??0,x=(r==null?void 0:r.skipped)??0,_=(r==null?void 0:r.failed)??0;v>0?i.success(`Sent ${v} email(s)${x?`, ${x} unsubscribed`:""}${_?`, ${_} failed`:""}`):x>0?i.info(`${x}
1 recipient(s) are unsubscribed, nothing was sent`):i.error("No email was sent")}finally{w(!1),f()}},P=async s=>{const t=s.invite_short_code??s.invite_token;t&&(await navigator.clipboard.writeText(A(t,s.invite_lang??"en")),i.success(`Links for ${s.email} copied`))},d=a.useMemo(()=>T(c.map(s=>s.score)),[c]),b=h.filter(s=>!s.invite_emailed_at).map(s=>s.user_id);return g?u?e.jsxs("main",{className:"min-h-screen bg-[#080808] text-white p-4 sm:p-8",children:[e.jsxs(I,{children:[e.jsx("title",{children:"Buyer feedback | Mockit admin"}),e.jsx("meta",{name:"robots",content:"noindex, nofollow"})]}),e.jsxs("div",{className:"max-w-6xl mx-auto space-y-8",children:[e.jsxs("header",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("h1",{className:"font-bebas tracking-wider text-3xl",children:["Buyer feedback ",e.jsx("span",{className:"text-white/40 text-lg",children:o})]}),e.jsx(L,{to:"/admin/analytics",className:"text-sm text-white/60 hover:text-white underline",children:"Back to analytics"})]}),e.jsx("section",{className:"grid grid-cols-2 sm:grid-cols-5 gap-3",children:[["Responses",d.total],["0 to 6",d.detractors],["7 to 8",d.passives],["9 to 10",d.promoters],["NPS",d.nps??"n/a"]].map(([s,t])=>e.jsxs("div",{className:"rounded-lg border border-white/10 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-xs text-white/50",children:s}),e.jsx("div",{className:`text-2xl font-bold ${s==="NPS"?"text-[#ff4d1c]":""}`,children:t})]},s))}),e.jsx("p",{className:"text-xs text-white/40 -mt-5",children:"Small sample: with only a handful of responses, one answer can swing the NPS a lot. Treat it as a direction, not a metric."}),e.jsxs("section",{className:"rounded-lg border border-white/10 bg-white/[0.02] p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 mb-4",children:[e.jsxs("h2",{className:"font-bold",children:["Buyers (",h.length,")"]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"text-white/50",children:"Invite language"}),e.jsxs("select",{value:N,onChange:s=>C(s.target.value),className:"bg-black border border-white/15 rounded px-2 py-1",children:[e.jsx("option",{value:"en",children:"EN"}),e.jsx("option",{value:"pt",children:"PT"})]}),e.jsx("button",{disabled:j,onClick:()=>y(b,!1),className:"rounded bg-[#ff4d1c] text-black font-bold px-3 py-1.5 disabled:opacity-40",children:j?"Sending...":`Email everyone not contacted (${b.length})`})]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"text-left text-white/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"py-2 pr-3",children:"Email"}),e.jsx("th",{className:"pr-3",children:"Pack"}),e.jsx("th",{className:"pr-3",children:"Paid"}),e.jsx("th",{className:"pr-3",children:"Invite"}),e.jsx("th",{className:"pr-3",children:"Email sent"}),e.jsx("th",{className:"pr-3",children:"Response"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[h.map(s=>e.jsxs("tr",{className:"border-t border-white/5",children:[e.jsx("td",{className:"py-2 pr-3",children:s.email}),e.jsx("td",{className:"pr-3 text-white/70",children:s.packs}),e.jsx("td",{className:"pr-3 text-white/70",children:p(s.last_paid_at)}),e.jsx("td",{className:"pr-3 text-white/70",children:s.invite_token?`${(s.invite_lang??"").toUpperCase()} ${p(s.invite_created_at)}`:"None"}),e.jsx("td",{className:"pr-3",children:s.invite_emailed_at?e.jsx("span",{className:"text-white/70",children:p(s.invite_emailed_at)}):e.jsx("span",{className:"text-white/40",children:"Not sent"})}),e.jsx("td",{className:"pr-3",children:s.responded?e.jsx("span",{className:"text-[#ff4d1c] font-bold",children:s.score}):e.jsx("span",{className:"text-white/40",children:"No"})}),e.jsxs("td",{className:"text-right whitespace-nowrap",children:[e.jsx("button",{disabled:j,onClick:()=>y([s.user_id],!!s.invite_emailed_at),className:"rounded border border-white/15 px-2 py-1 mr-2 hover:border-[#ff4d1c]/60 disabled:opacity-40",children:s.invite_emailed_at?"Resend email":"Send email"}),s.invite_token&&e.jsx("button",{onClick:()=>P(s),className:"rounded border border-white/15 px-2 py-1 hover:border-[#ff4d1c]/60",children:"Copy links"})]})]}
1,s.user_id)),!h.length&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"py-4 text-white/40",children:"No buyers yet."})})]})]})})]}),e.jsxs("section",{className:"rounded-lg border border-white/10 bg-white/[0.02] p-4",children:[e.jsxs("h2",{className:"font-bold mb-4",children:["Responses (",c.length,")"]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"text-left text-white/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"py-2 pr-3",children:"Email"}),e.jsx("th",{className:"pr-3",children:"Score"}),e.jsx("th",{className:"pr-3",children:"Use case"}),e.jsx("th",{className:"pr-3",children:"Improve"}),e.jsx("th",{className:"pr-3",children:"Quote"}),e.jsx("th",{children:"Date"})]})}),e.jsxs("tbody",{children:[c.map((s,t)=>e.jsxs("tr",{className:"border-t border-white/5 align-top",children:[e.jsx("td",{className:"py-2 pr-3",children:s.email}),e.jsxs("td",{className:"pr-3 font-bold text-[#ff4d1c]",children:[s.score,s.score_source&&e.jsx("span",{className:"block text-[10px] font-normal text-white/40",children:s.score_source==="link"?"via link":"via page"})]}),e.jsx("td",{className:"pr-3 text-white/80 whitespace-pre-wrap max-w-xs",children:s.use_case}),e.jsx("td",{className:"pr-3 text-white/80 whitespace-pre-wrap max-w-xs",children:s.improve}),e.jsx("td",{className:"pr-3",children:s.can_quote?"Yes":"No"}),e.jsx("td",{className:"text-white/60",children:p(s.updated_at)})]},t)),!c.length&&e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"py-4 text-white/40",children:"No responses yet."})})]})]})})]})]})]}):e.jsx("div",{className:"min-h-screen bg-[#080808] text-white p-8",children:"Not authorized."}):e.jsx("div",{className:"min-h-screen bg-[#080808]"})}export{F 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.