PageSourceSearch

https://testivo.tech/assets/dashboard.collection-page-BJtL7vhU.js

js testivo.tech collected 2026-09-24 15:13:16 UTC 18,124 bytes, 1 lines download raw bytes

1import{r as i,j as e}from"./react-RN8z7mqm.js";import{g as B,u as R,L as C}from"./index-BwX0UczS.js";import{s as h}from"./supabase-D7bm-uKx.js";import{r as H}from"./utils-6PQrid_T.js";import{toast as m}from"./sonner-CSA395gJ.js";import{D as E,g as K,W as U,a_ as V,a4 as L,ad as S,ah as G,S as J,a$ as Q,b0 as X,ap as Z,at as P,z as ee,C as se,y as te,b1 as re,r as ae,a2 as oe}from"./icons-CFy5kY0-.js";import"./clsx-B-dksMZM.js";const ne=[{key:"blank",name:"Blank",icon:P,desc:"Start from scratch.",header_message:"Tell us what you think!",prompt_question:"What problem did this solve for you?",thank_you_message:"",require_rating:!1,ask_nps:!1,allow_video:!0,allow_text:!0},{key:"saas",name:"SaaS",icon:te,desc:"Case-study style for software.",header_message:"Share your experience",prompt_question:"What problem were you facing before, and how did we help?",thank_you_message:"Thank you! This helps other teams discover us. 💜",require_rating:!0,ask_nps:!0,allow_video:!0,allow_text:!0},{key:"service",name:"Service / Agency",icon:re,desc:"For client & agency work.",header_message:"How was working with us?",prompt_question:"What results did we deliver for you?",thank_you_message:"Thanks so much — it means the world! 🙏",require_rating:!0,ask_nps:!1,allow_video:!0,allow_text:!0},{key:"course",name:"Course / Coaching",icon:ae,desc:"For students & program clients.",header_message:"Share your transformation",prompt_question:"What changed for you after the program?",thank_you_message:"Thank you! Your story will inspire future students. ✨",require_rating:!0,ask_nps:!1,allow_video:!0,allow_text:!0},{key:"ecommerce",name:"Product",icon:oe,desc:"For physical or digital products.",header_message:"Love your purchase? Tell us!",prompt_question:"What do you love most about it?",thank_you_message:"Thanks for the love! 🛍️",require_rating:!0,ask_nps:!1,allow_video:!0,allow_text:!0}];function ge(){const{user:c,activeProfile:f}=B(),r=f?.id??c?.id,n=R(),[a,_]=i.useState([]),[u,D]=i.useState([]),[p,j]=i.useState(null),[q,w]=i.useState(null),[M,N]=i.useState(!1),[$,T]=i.useState(!1),v=async()=>{if(!c||!r)return;const[{data:s},{data:t},{data:l}]=await Promise.all([h.from("collection_pages").select("id, name, slug, header_message, prompt_question, thank_you_message, accent_color, allow_video, allow_text, require_rating, ask_nps, is_paused, created_at").eq("user_id",r).order("created_at",{ascending:!0}),h.from("testimonials").select("form_id, customer_name, customer_role, customer_avatar_url, message, rating, status, consent_public, created_at").eq("user_id",r).order("created_at",{ascending:!1}),h.from("collection_pages").select("id, view_count").eq("user_id",r)]),x=new Map((l??[]).map(b=>[b.id,b.view_count??0])),d=(s??[]).map(b=>({...b,view_count:x.get(b.id)??0}));_(d),D(t??[]),d.length>0&&!p&&j(d[0].id)};i.useEffect(()=>{v()},[r]);const F=i.useMemo(()=>{const s=new Map;return u.forEach(t=>{t.form_id&&s.set(t.form_id,(s.get(t.form_id)??0)+1)}),s},[u]),A=i.useMemo(()=>u.filter(s=>!s.form_id).length,[u]),g=i.useMemo(()=>a.find(s=>s.id===p)??null,[a,p]),o=i.useMemo(()=>u.find(s=>s.form_id===p)??null,[u,p]),y=g?F.get(g.id)??0:0,k=typeof window<"u"?window.location.origin:"",I=async s=>{if(!c||!r||$)return;T(!0);const t=`form-${Math.random().toString(36).slice(2,8)}`,{data:l,error:x}=await h.from("collection_pages").insert({user_id:r,name:s.key==="blank"?"New form":`${s.name} form`,slug:t,header_message:s.header_message,prompt_question:s.prompt_question,thank_you_message:s.thank_you_message,accent_color:"#6366f1",allow_video:s.allow_video,allow_text:s.allow_text,require_rating:s.require_rating,ask_nps:s.ask_nps}).select().single();if(T(!1),N(!1),x)return m.error(x.message);m.success("Form created"),n({to:"/dashboard/form/$id",params:{id:l.id}})},W=async s=>{if(!c||!r)return;const t=`${(s.slug??"form").slice(0,20)}-${Math.random().toString(36).slice(2,6)}`,{error:l}=await h.from("collection_pages").insert({user_id:r,name:`${s.name} copy`,slug:t,header_message:s.header_message,prompt_question:s.prompt_question,thank_you_message:s.thank_you_message??"",accent_color:s.accent_color,allow_video:s.allow_video,allow_text:s.allow_text,require_rating:s.require_rating,ask_nps:s.ask_nps});if(l)return m.error(l.message);m.success("Form duplicated"),v()},O=async s=>{const{error:t}=await h.from("collection_pages").delete().eq("id",s);if(t)return m.error(t.message);m.success("Form deleted"),p===s&&j(null),w(null),v()},Y=async s=>{const t=!s.is_paused,{error:l}=await h.from("collection_pages").update({is_paused:t}).eq("id",s.id);if(l)return m.error(l.message);m.success(t?"Form paused":"Form resumed"),v()},z=s=>{s&&(navigator.clipboard.writeText(`${k}/c/${s}`),m.success("Form link copied"))};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("header",{className:"flex flex-wrap items-end justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"font-serif text-3xl",children:"Forms"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Collect testimonials from your customers. Everything you collect lands in your Inbox."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(C,{to:"/dashboard/import",className:"inline-flex items-center gap-2 rounded-lg border bg-background px-4 py-2.5 text-sm font-semibold hover:bg-accent",children:[e.jsx(E,{className:"h-4 w-4"})," Import"]}),e.jsxs("button",{onClick:()=>N(!0),className:"inline-flex items-center gap-2 rounded-lg bg-primary px-4 py-2.5 text-sm font-semibold text-primary-foreground shadow-sm hover:opacity-90",children:[e.jsx(K,{className:"h-4 w-4"})," Add form"]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 lg:grid-cols-[1fr_360px]",children:[e.jsxs("div",{className:"space-y-3",children:[a.length===0?e.jsxs("div",{className:"rounded-2xl border bg-muted/20 px-6 py-16 text-center",children:[e.jsx(U,{className:"mx-auto h-10 w-10 text-muted-foreground
1/40"}),e.jsx("h3",{className:"mt-3 text-sm font-semibold",children:"No forms yet"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:'Click "Add form" to make your first form.'})]}):a.map(s=>{const t=p===s.id,l=F.get(s.id)??0,x=s.slug?`${k}/c/${s.slug}`:"";return e.jsxs("article",{onClick:()=>j(s.id),className:`group cursor-pointer rounded-2xl border bg-card p-4 transition hover:border-foreground/30 ${t?"border-foreground ring-2 ring-offset-0":""}`,style:t?{borderColor:s.accent_color,boxShadow:`0 0 0 2px ${s.accent_color}33`}:void 0,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"grid h-7 w-7 shrink-0 place-items-center rounded-md text-xs font-semibold text-white",style:{background:s.accent_color},children:s.name[0]?.toUpperCase()??"F"}),e.jsx("h2",{className:"truncate text-lg font-semibold",children:s.name}),t&&e.jsx("span",{className:"rounded-full bg-emerald-500/15 px-2 py-0.5 text-[10px] font-medium text-emerald-700 dark:text-emerald-400",children:"previewing"})]}),e.jsx("p",{className:"mt-1 line-clamp-1 text-xs text-muted-foreground",children:s.prompt_question}),s.slug&&e.jsxs("div",{className:"mt-2 flex min-w-0 max-w-full items-center gap-1.5 rounded-md bg-muted px-2 py-1 text-[11px] text-muted-foreground",onClick:d=>d.stopPropagation(),children:[e.jsx("a",{href:x,target:"_blank",rel:"noreferrer","aria-label":"Open public form",title:"Open public form",className:"grid h-4 w-4 place-items-center rounded text-muted-foreground transition hover:text-foreground",children:e.jsx(V,{className:"h-3 w-3"})}),e.jsx("span",{className:"min-w-0 truncate",children:x}),e.jsx("button",{onClick:()=>z(s.slug),"aria-label":"Copy form link",title:"Copy",className:"rounded p-0.5 text-muted-foreground hover:text-foreground",children:e.jsx(L,{className:"h-3 w-3"})})]})]}),e.jsxs("div",{className:"shrink-0 text-right",children:[e.jsx("div",{className:"text-xl font-semibold leading-none",children:l}),e.jsx("div",{className:"mt-1 text-[10px] text-muted-foreground",children:"testimonials"}),s.view_count>0&&e.jsxs("div",{className:"mt-2 border-t pt-1.5",children:[e.jsx("div",{className:"text-sm font-semibold leading-none",children:(()=>{const d=H(l,s.view_count);return d===null?"—":`${d}%`})()}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:["of ",s.view_count," ",s.view_count===1?"visit":"visits"]})]})]})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",onClick:d=>d.stopPropagation(),children:[e.jsxs("a",{href:x||"#",target:"_blank",rel:"noreferrer",onClick:d=>{s.slug||d.preventDefault()},className:`inline-flex items-center gap-1 rounded-md border bg-background px-2.5 py-1 text-xs font-medium hover:bg-accent ${s.slug?"":"opacity-50 pointer-events-none"}`,children:[e.jsx(S,{className:"h-3 w-3"})," Open"]}),e.jsxs("a",{href:"/dashboard/testimonials",className:"inline-flex items-center gap-1 rounded-md border bg-background px-2.5 py-1 text-xs font-medium hover:bg-accent",children:[e.jsx(G,{className:"h-3 w-3"})," Testimonials"]}),e.jsxs("button",{onClick:()=>n({to:"/dashboard/form/$id",params:{id:s.id}}),className:"inline-flex items-center gap-1 rounded-md border bg-background px-2.5 py-1 text-xs font-medium hover:bg-accent",children:[e.jsx(J,{className:"h-3 w-3"})," Manage"]}),e.jsx("button",{onClick:()=>W(s),className:"inline-flex items-center gap-1 rounded-md border bg-background px-2.5 py-1 text-xs font-medium text-muted-foreground hover:bg-accent hover:text-foreground",title:"Duplicate",children:e.jsx(L,{className:"h-3 w-3"})}),e.jsx("button",{onClick:()=>Y(s),className:`inline-flex items-center gap-1 rounded-md border bg-background px-2.5 py-1 text-xs font-medium hover:bg-accent ${s.is_paused?"text-amber-600 hover:text-amber-700":"text-muted-foreground hover:text-foreground"}`,title:s.is_paused?"Resume form":"Pause form",children:s.is_paused?e.jsx(Q,{className:"h-3 w-3"}):e.jsx(X,{className:"h-3 w-3"})}),e.jsx("button",{onClick:()=>w(s.id),disabled:a.length===1,className:"inline-flex items-center gap-1 rounded-md border bg-background px-2.5 py-1 text-xs font-medium text-muted-foreground hover:border-rose-500/40 hover:bg-rose-500/5 hover:text-rose-600 disabled:opacity-30 disabled:hover:bg-background disabled:hover:text-muted-foreground",title:a.length===1?"Can't delete your only form":"Delete",children:e.jsx(Z,{className:"h-3 w-3"})})]})]},s.id)}),e.jsxs(C,{to:"/dashboard/import",className:"group flex items-center gap-3 rounded-2xl border border-dashed bg-card p-4 transition hover:border-foreground
1/30",children:[e.jsx("span",{className:"grid h-9 w-9 shrink-0 place-items-center rounded-lg bg-emerald-500/10 text-emerald-600",children:e.jsx(E,{className:"h-4.5 w-4.5",style:{height:"1.1rem",width:"1.1rem"}})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-base font-semibold",children:"Imported testimonials"}),e.jsx("span",{className:"rounded-full bg-muted px-2 py-0.5 text-[10px] font-medium text-muted-foreground",children:"Source"})]}),e.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs text-muted-foreground",children:"From Senja, Testimonial.to, Trustpilot, a CSV, or a tweet — no form needed."})]}),e.jsxs("div",{className:"shrink-0 text-right",children:[e.jsx("div",{className:"text-xl font-semibold leading-none",children:A}),e.jsx("div",{className:"mt-1 text-[10px] text-muted-foreground",children:"imported"})]}),e.jsx(S,{className:"h-4 w-4 shrink-0 text-muted-foreground transition group-hover:text-foreground"})]})]}),e.jsx("aside",{className:"hidden lg:block lg:sticky lg:top-6 lg:self-start",children:e.jsxs("div",{className:"overflow-hidden rounded-2xl border bg-card",children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-4 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-muted-foreground",children:[e.jsx(P,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:"Preview"})]}),g?.slug&&e.jsxs("a",{href:`${k}/c/${g.slug}`,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-[11px] font-medium text-primary hover:underline",children:["Open ",e.jsx(S,{className:"h-3 w-3"})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2 px-4 py-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"Showing preview for"}),e.jsx("div",{className:"truncate text-sm font-semibold",children:g?.name??"—"})]}),e.jsxs("div",{className:"shrink-0 text-right",children:[e.jsx("div",{className:"text-lg font-bold leading-none",children:y}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"testimonials"})]})]}),e.jsxs("div",{className:"px-4 pb-4",children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"Latest testimonial"}),o?e.jsxs("div",{className:"rounded-xl border bg-background p-4",children:[o.rating!=null&&e.jsx("div",{className:"mb-2 flex","aria-label":`${o.rating} stars`,children:Array.from({length:5}).map((s,t)=>e.jsx(ee,{className:`h-4 w-4 ${t<(o.rating??0)?"fill-amber-400 text-amber-400":"text-muted-foreground/25"}`},t))}),o.message&&e.jsx("p",{className:"line-clamp-5 whitespace-pre-wrap text-sm leading-relaxed",children:`“${o.message}”`}),e.jsxs("div",{className:"mt-3 flex items-center gap-2.5",children:[o.customer_avatar_url?e.jsx("img",{src:o.customer_avatar_url,alt:"",className:"h-9 w-9 shrink-0 rounded-full object-cover"}):e.jsx("span",{className:"grid h-9 w-9 shrink-0 place-items-center rounded-full text-xs font-semibold text-white",style:{background:g?.accent_color||"#6366f1"},children:(o.customer_name||"?")[0]?.toUpperCase()}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-sm font-semibold",children:o.customer_name||"Anonymous"}),o.customer_role&&e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:o.customer_role})]})]}),e.jsxs("div",{className:"mt-3 flex items-center justify-between border-t pt-2.5",children:[e.jsx("span",{className:"text-[11px] text-muted-foreground",children:new Date(o.created_at).toLocaleDateString()}),o.status==="approved"&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary",children:[e.jsx(se,{className:"h-3 w-3"})," Verified"]})]})]}):e.jsxs("div",{className:"rounded-xl border border-dashed bg-muted/20 px-4 py-8 text-center",children:[e.jsx("p",{className:"text-sm font-medium",children:"No testimonials yet"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Share your collect link — your first one will show up here."})]}),y>1&&e.jsxs(C,{to:"/dashboard/testimonials",className:"mt-3 flex items-center justify-center gap-1.5 rounded-lg border py-2 text-xs font-medium text-muted-foreground hover:bg-accent",children:["You're viewing 1 of ",y," testimonials"]})]})]})})]}),q&&e.jsx(le,{title:"Delete this form?",body:"The form's testimonials stay — they get unlinked from the form. This can't be und
1one.",confirmLabel:"Delete",onConfirm:()=>O(q),onCancel:()=>w(null)}),M&&e.jsx(ie,{creating:$,onPick:s=>{I(s)},onCancel:()=>N(!1)})]})}function ie({creating:c,onPick:f,onCancel:r}){return i.useEffect(()=>{const n=a=>{a.key==="Escape"&&r()};return document.addEventListener("keydown",n),()=>document.removeEventListener("keydown",n)},[r]),e.jsxs("div",{className:"fixed inset-0 z-50 grid place-items-center px-4",role:"dialog","aria-modal":"true",children:[e.jsx("button",{"aria-label":"Close",onClick:r,className:"absolute inset-0 bg-black/40"}),e.jsxs("div",{className:"relative w-full max-w-lg rounded-2xl border bg-card p-5 shadow-xl",children:[e.jsx("h3",{className:"text-base font-semibold",children:"Pick a starting point"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Each template pre-fills the prompt and settings for a use-case. You can change everything after."}),e.jsx("div",{className:"mt-4 grid gap-2 sm:grid-cols-2",children:ne.map(n=>{const a=n.icon;return e.jsxs("button",{disabled:c,onClick:()=>f(n),className:"group flex items-start gap-3 rounded-xl border bg-background p-3 text-left transition hover:border-primary/50 hover:bg-accent disabled:opacity-50",children:[e.jsx("span",{className:"grid h-9 w-9 shrink-0 place-items-center rounded-lg bg-primary/10 text-primary",children:e.jsx(a,{className:"h-4.5 w-4.5",style:{height:"1.1rem",width:"1.1rem"}})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-sm font-semibold",children:n.name}),e.jsx("span",{className:"mt-0.5 block text-xs text-muted-foreground",children:n.desc})]})]},n.key)})}),c&&e.jsx("p",{className:"mt-3 text-center text-xs text-muted-foreground",children:"Creating your form…"}),e.jsx("div",{className:"mt-4 flex justify-end",children:e.jsx("button",{onClick:r,className:"rounded-md border px-3 py-1.5 text-sm hover:bg-accent",children:"Cancel"})})]})]})}function le({title:c,body:f,confirmLabel:r,onConfirm:n,onCancel:a}){return i.useEffect(()=>{const _=u=>{u.key==="Escape"&&a()};return document.addEventListener("keydown",_),()=>document.removeEventListener("keydown",_)},[a]),e.jsxs("div",{className:"fixed inset-0 z-50 grid place-items-center px-4",role:"dialog","aria-modal":"true",children:[e.jsx("button",{"aria-label":"Close",onClick:a,className:"absolute inset-0 bg-black/40"}),e.jsxs("div",{className:"relative w-full max-w-sm rounded-2xl border bg-card p-5 shadow-xl",children:[e.jsx("h3",{className:"text-base font-semibold",children:c}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:f}),e.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[e.jsx("button",{onClick:a,className:"rounded-md border px-3 py-1.5 text-sm hover:bg-accent",children:"Cancel"}),e.jsx("button",{onClick:n,className:"rounded-md bg-rose-600 px-3 py-1.5 text-sm font-medium text-white hover:bg-rose-700",children:r})]})]})]})}export{ge as component};

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.