PageSourceSearch

https://vivaors.com.br/assets/AdminSignupConnect-BusObD6k.js

js vivaors.com.br collected 2026-10-06 05:31:12 UTC 10,516 bytes, 1 lines download raw bytes

1import{a as se,u as M,b as te,j as s}from"./query-pTPNpZtY.js";import{i as ae,r as d,L as ne}from"./react-vendor-DXQsCdhI.js";import{s as _,C as P,d as T,a as ie,b as re,a2 as A,I as K,a3 as O,a4 as Q,a5 as V,a6 as R,a7 as f,L as le,N as B,bg as oe,aS as ce,B as v,bf as de,bi as me,bk as ue,bl as xe,bm as pe,bn as he,bx as ge,t as U,aU as fe}from"./index-B5OGvPOn.js";import{A as je}from"./AdminLayout-DWJU8O-h.js";import{M as ve}from"./ModuleTabs-ChM679Z2.js";import{S as be}from"./moduleTabGroups-tcvuXWRn.js";import{S as Ne}from"./SignupConvertDialog-INl-mAWD.js";import{e as we}from"./signupToPlace-DRjkhyX8.js";import{L as $}from"./link-2-RYLBT9hb.js";import{U as ye}from"./unlink-3Uyo56E-.js";import"./supabase-C6OG0I2D.js";import"./charts-IsTpienw.js";import"./carousel-CtlbL2Hu.js";import"./tiptap-DaxmquCz.js";import"./layout-grid-DRB2MxP9.js";import"./folder-open-BeXpwn13.js";import"./list-checks-4xDbuwgY.js";import"./upload-mYV-_1BB.js";import"./fetchAllRows-BS4K9u3o.js";const H={establishment:"Empreendimento",event:"Evento",experience:"Experiência"};function C(m){return(m||"").normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/[^a-z0-9\s]/g," ").replace(/\s+/g," ").trim()}const _e=new Set(["de","da","do","das","dos","e","a","o","as","os","em","no","na"]);function J(m){return C(m).split(" ").filter(h=>h.length>2&&!_e.has(h))}function G(m,h){const u=C(m),j=C(h);if(!u||!j)return 0;if(u===j)return 1;const x=J(m),b=J(h);if(!x.length||!b.length)return 0;const N=new Set(b),l=x.filter(w=>N.has(w)).length/Math.max(x.length,b.length);return u.includes(j)||j.includes(u)?Math.max(l,.85):l}
1function Re(){const m=se(),h=ae(),[u,j]=d.useState("pending"),[x,b]=d.useState("unlinked"),[N,F]=d.useState(""),[l,w]=d.useState(null),[c,k]=d.useState(null),[L,S]=d.useState(""),{data:o,isLoading:W}=M({queryKey:["admin-signup-connect",u],queryFn:async()=>{let e=_.from("signup_submissions").select("id, name, email, status, kind, city, place_item_id, created_at").order("created_at",{ascending:!1}).limit(1e3);u!=="all"&&(e=e.eq("status",u));const{data:t,error:a}=await e;if(a)throw a;return t||[]}}),{data:i}=M({queryKey:["admin-signup-connect-names",(o||[]).map(e=>e.id).join(",")],enabled:!!(o!=null&&o.length),queryFn:async()=>{const e=(o||[]).map(r=>r.id),t={},{data:a}=await _.from("signup_questions").select("id, question_text, field_type"),n=60;for(let r=0;r<e.length;r+=n){const p=e.slice(r,r+n),{data:Y}=await _.from("signup_answers").select("submission_id, question_id, answer_text").in("submission_id",p);for(const E of p){const Z=(Y||[]).filter(ee=>ee.submission_id===E);t[E]=we(Z,a||[])}}return t}}),{data:g}=M({queryKey:["admin-signup-connect-places"],queryFn:async()=>{const{data:e,error:t}=await _.from("place_items").select("id, title, kind, city, is_published").order("title").limit(5e3);if(t)throw t;return e||[]}}),y=te({mutationFn:async({id:e,placeItemId:t})=>{const{error:a}=await _.from("signup_submissions").update({place_item_id:t,converted_at:t?new Date().toISOString():null}).eq("id",e);if(a)throw a},onSuccess:(e,t)=>{m.invalidateQueries({queryKey:["admin-signup-connect"]}),m.invalidateQueries({queryKey:["admin-signup-review-list"]}),U({title:t.placeItemId?"Pré-cadastro conectado ao site":"Vínculo removido"}),k(null),S("")},onError:e=>U({title:"Erro",description:(e==null?void 0:e.message)||"Não foi possível salvar o vínculo.",variant:"destructive"})}),D=d.useMemo(()=>{const e={};if(!o||!g)return e;for(const t of o){if(t.place_item_id){e[t.id]=null;continue}const a=(i==null?void 0:i[t.id])||t.name;let n=null;for(const r of g){const p=G(a,r.title);p>=.6&&(!n||p>n.score)&&(n={place:r,score:p})}e[t.id]=n}return e},[o,g,i]),I=d.useMemo(()=>{const e=N.trim().toLowerCase();return(o||[]).filter(t=>x==="linked"&&!t.place_item_id||x==="unlinked"&&t.place_item_id?!1:e?[i==null?void 0:i[t.id],t.name,t.email,t.city].filter(Boolean).some(a=>String(a).toLowerCase().includes(e)):!0)},[o,N,x,i]),q=d.useMemo(()=>{const e=o||[],t=e.filter(n=>n.place_item_id).length,a=e.filter(n=>!n.place_item_id&&D[n.id]).length;return{total:e.length,linked:t,unlinked:e.length-t,suggested:a}},[o,D]),X=d.useMemo(()=>{const e={};for(const t of g||[])e[t.id]=t;return e},[g]),z=d.useMemo(()=>{const e=L.trim(),t=g||[];if(!e){const n=c?(i==null?void 0:i[c.id])||c.name:"";return[...t].map(r=>({p:r,score:G(n,r.title)})).sort((r,p)=>p.score-r.score).slice(0,30).map(r=>r.p)}const a=C(e);return t.filter(n=>C(n.title).includes(a)).slice(0,30)},[g,L,c,i]);return s.jsxs(je,{children:[s.jsx(ve,{tabs:[{label:"Curadoria",to:"/admin/signup-pending"},{label:"Conexão com o site",to:"/admin/signup-connect"},...be]}),s.jsxs("div",{className:"mb-4",children:[s.jsx("h1",{className:"text-xl font-semibold",children:"Conexão de pré-cadastros"}),s.jsx("p",{className:"text-sm text-muted-foreground",children:"Veja quais pré-cadastros já têm cadastro no site, vincule os que já existem e leve os demais para o cadastro real."})]}),s.jsx("div",{className:"mb-4 grid grid-cols-2 gap-3 md:grid-cols-4",children:[{label:"Pré-cadastros",value:q.total},{label:"Já conectados",value:q.linked},{label:"Sem cadastro no site",value:q.unlinked},{label:"Com sugestão automática",value:q.suggested}].map(e=>s.jsx(P,{children:s.jsxs(T,{className:"p-4",children:[s.jsx("p",{className:"text-2xl font-semibold",children:e.value}),s.jsx("p",{className:"text-xs text-muted-foreground",children:e.label})]})},e.label))}),s.jsxs(P,{children:[s.jsxs(ie,{className:"gap-3",children:[s.jsxs(re,{className:"flex items-center gap-2 text-base",children:[s.jsx($,{className:"h-5 w-5"}),I.length," pré-cadastro(s)"]}),s.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.jsxs("div",{className:"relative w-full max-w-xs",children:[s.jsx(A,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),s.jsx(K,{value:N,onChange:e=>F(e.target.value),placeholder:"Buscar por nome, e-mail ou cidade",className:"h-9 pl-8"})]}),s.jsxs(O,{value:u,onValueChange:j,children:[s.jsx(Q,{className:"h-9 w-[150px]",children:s.jsx(V,{})}),s.jsxs(R,{children:[s.jsx(f,{value:"pending",children:"Pendentes"}),s.jsx(f,{value:"approved",children:"Aprovados"}),s.jsx(f,{value:"rejected",children:"Rejeitados"}),s.jsx(f,{value:"all",children:"Todos"})]})]}),s.jsxs(O,{value:x,onValueChange:e=>b(e),children:[s.jsx(Q,{className:"h-9 w-[200px]",children:s.jsx(V,{})}),s.jsxs(R,{children:[s.jsx(f,{value:"unlinked",children:"Sem cadastro no site"}),s.jsx(f,{value:"linked",children:"Já conectados"}),s.jsx(f,{value:"all",children:"Todos"})]})]})]})]}),s.jsx(T,{children:W?s.jsx("div",{className:"flex justify-center py-10",children:s.jsx(le,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):I.length?s.jsx("div",{className:"space-y-2",children:I.map(e=>{const t=(i==null?void 0:i[e.id])||e.name,a=e.place_item_id?X[e.place_item_id]:null,n=D[e.id];return s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-lg border border-border/60 p-3",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("p",{className:"truncate text-sm font-medium",children:t}),s.jsx(B,{variant:"secondary",className:"text-[10px]",children:H[e.kind]||e.kind}),e.place_item_id?s.jsxs(B,{className:"text-[10px]",children:[s.jsx(oe,{className:"mr-1 h-3 w-3"})," Conectado"]}):s.jsx(B,{variant:"outline",className:"text-[10px]",children:"Sem cadastro no site"})]}),s.jsxs("p",{className:"truncate text-xs text-muted-foreground",children:[e.name," · ",e.email,e.city?` · ${e.city}`:""," ·"," ",ce(new Date(e.created_at),"dd/MM/yyyy",{locale:fe})]}),a&&s.jsxs("p",{className:"mt-0.5 text-xs",children:["Cadastro no site:"," ",s.jsx(ne,{className:"underline",to:`/admin/places/${a.id}`,children:a.title}),a.is_published?"":" (não publicado)"]}),!a&&n&&s.jsxs("p",{className:"mt-0.5 text-xs text-muted-foreground",children:["Possível correspondência:"," ",s.jsx("span",{className:"font-medium text-foreground",children:n.place.title})," ","(",Math.round(n.score*100),"%)"]})]}),s.jsxs("div",{className:"flex shrink-0 flex-wrap items-center gap-2",children:[!a&&n&&s.jsxs(v,{size:"sm",className:"h-8 text-xs",disabled:y.isPending,onClick:()=>y.mutate({id:e.id,placeItemId:n.place.id}),children:[s.jsx($,{className:"mr-1 h-3.5 w-3.5"})," Vincular sugestão"]}),!a&&s.jsxs(s.Fragment,{children:[s.jsxs(v,{variant:"secondary",size:"sm",className:"h-8 text-xs",onClick:()=>{k(e),S("")},children:[s.jsx(A,{className:"mr-1 h-3.5 w-3.5"})," Buscar cadastro"]}),s.jsxs(v,{variant:"outline",size:"sm",className:"h-8 text-xs",onClick:()=>w(e),children:[s.jsx(de,{className:"mr-1 h-3.5 w-3.5"})," Criar cadastro"]})]}),a&&s.jsxs(s.Fragment,{children:[s.jsx(v,{variant:"secondary",size:"sm",className:"h-8 text-xs",onClick:()=>h(`/admin/places/${a.id}`),children:"Abrir cadastro"}),s.jsxs(v,{variant:"ghost",size:"sm",className:"h-8 text-xs text-destructive",onClick:()=>y.mutate({id:e.id,placeItemId:null}),children:[s.jsx(ye,{className:"mr-1 h-3.5 w-3.5"})," Desvincular"]})]})]})]},e.id)})}):s.jsx("p",{className:"py-10 text-center text-sm text-muted-foreground",children:"Nenhum pré-cadastro nesse filtro."})})]}),s.jsx(me,{open:!!c,onOpenChange:e=>{e||(k(null),S(""))},children:s.jsxs(ue,{className:"max-w-lg",children:[s.jsxs(xe,{children:[s.jsx(pe,{children:"Conectar ao cadastro do site"}),s.jsx(he,{children:c?(i==null?void 0:i[c.id])||c.name:""})]}),s.jsx(K,{value:L,onChange:e=>S(e.target.value),placeholder:"Buscar pelo nome do cadastro..."}),s.jsxs("div",{className:"max-h-80 space-y-1 overflow-y-auto",children:[z.map(e=>s.jsxs("button",{type:"button",className:"flex w-full items-center justify-between gap-2 rounded-md border border-border/60 p-2 text-left text-sm hover:bg-muted",disabled:y.isPending,onClick:()=>c&&y.mutate({id:c.id,placeItemId:e.id}),children:[s.jsx("span",{className:"truncate",children:e.title}),s.jsxs("span",{className:"shrink-0 text-xs text-muted-foreground",children:[H[e.kind]||e.kind,e.city?` · ${e.city}`:""]})]},e.id)),!z.length&&s.jsx("p",{className:"py-6 text-center text-sm text-muted-foreground",children:"Nenhum cadastro encontrado."})]}),s.jsx(ge,{children:s.jsx(v,{variant:"outline",onClick:()=>{const e=c;k(null),e&&w(e)},children:"Não existe — criar cadastro"})})]})}),s.jsx(Ne,{open:!!l,onOpenChange:e=>!e&&w(null),submissionId:(l==null?void 0:l.id)??null,signupKind:l==null?void 0:l.kind,entityName:l?(i==null?void 0:i[l.id])||l.name:null})]})}
1export{Re 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.