PageSourceSearch

https://venda.academiaevolve.com.br/assets/IntegracaoMetaAdmin-Cbu3Hpjh.js

js academiaevolve.com.br collected 2026-10-08 08:13:07 UTC 10,515 bytes, 1 lines download raw bytes

1import{r as d,s as c,j as e,i as z,k as m}from"./index-v62AjHb9.js";import{C as $,a as B,b as O,d as D,c as L}from"./card-BYQxC_2C.js";import{B as p}from"./button-Ce_45wZc.js";import{I as h}from"./input-DfT5LGf6.js";import{L as f}from"./label-C8kB3kTQ.js";import{S as R}from"./switch-CQtoVRjO.js";import{C as V}from"./chevron-right-Bpp-t7XN.js";import{C as q}from"./chevron-down-CUZrL87G.js";import{E as H}from"./eye-off-ColxGrND.js";import{E as U}from"./eye-ClXoigt2.js";import{E as v}from"./external-link-C9Aogmiq.js";import{S as G}from"./save-BL3Mga0e.js";import"./index-Cqe9kOXq.js";const x=[{id:"vagas",title:"Pixel — Vagas / RH",description:e.jsxs(e.Fragment,{children:["Usado nas landing pages ",e.jsx("code",{className:"text-xs",children:"/trabalhe-conosco/:slug"}),"."]}),settingsSuffix:"",tokenKey:"meta_capi_access_token",legacyEnvKey:"META_CAPI_ACCESS_TOKEN"},{id:"teste_ab",title:"Pixel — Testes A/B",description:e.jsxs(e.Fragment,{children:["Usado nas páginas dos Testes A/B (",e.jsx("code",{className:"text-xs",children:"/reservar"})," e"," ",e.jsx("code",{className:"text-xs",children:"/oferta"}),') quando o teste tiver "Meta Pixel" habilitado. Este é um pixel ',e.jsx("strong",{children:"independente"})," do de Vagas."]}),settingsSuffix:"_teste_ab",tokenKey:"meta_capi_access_token_teste_ab",legacyEnvKey:"META_CAPI_ACCESS_TOKEN_TESTE_AB",tokenFallbackNote:"Se este token ficar vazio, o sistema usará o token de Vagas como fallback."},{id:"campanhas",title:"Pixel — Campanhas",description:e.jsxs(e.Fragment,{children:["Pixel extra para as LPs de Campanhas (lançamentos, diárias, eventos). Selecionável no editor de cada campanha em ",e.jsx("strong",{children:"Meta Ads → Pixel utilizado"}),"."]}),settingsSuffix:"_campanhas",tokenKey:"meta_capi_access_token_campanhas",tokenFallbackNote:"Se este token ficar vazio, o sistema usará o token de Vagas como fallback."}],j=i=>({pixelId:`meta_pixel_id${i.settingsSuffix}`,enabled:`meta_pixel_enabled${i.settingsSuffix}`,testCode:`meta_test_event_code${i.settingsSuffix}`,name:`meta_pixel_name${i.settingsSuffix}`}),y={name:"",pixelId:"",enabled:!0,testCode:"",token:"",showToken:!1,tokenSet:!1,tokenEnv:!1,tokenPreview:""},Q=i=>{if(!i)return"";const u=i.slice(0,6);return`${u}${"•".repeat(Math.max(8,Math.min(24,i.length-u.length)))}`};function le(){const[i,u]=d.useState(!0),[b,N]=d.useState(!1),[g,P]=d.useState({vagas:{...y},teste_ab:{...y},campanhas:{...y}}),[C,S]=d.useState(null),[_,w]=d.useState(null),[E,A]=d.useState({vagas:!1,teste_ab:!1,campanhas:!1}),I=a=>A(s=>({...s,[a]:!s[a]})),l=(a,s)=>P(n=>({...n,[a]:{...n[a],...s}}));async function k(){var o;const a=x.map(r=>r.tokenKey),{data:s}=await c.from("secure_settings").select("key, value").in("key",a),n={};for(const r of s??[])n[r.key]=r.value??"";let t={};try{const{data:r}=await c.functions.invoke("meta-capi-token-admin",{body:{action:"status"}});t=r??{}}catch{}for(const r of x){const T=n[r.tokenKey]??"";l(r.id,{tokenSet:T.length>0,tokenPreview:Q(T),tokenEnv:!!((o=t[r.id])!=null&&o.env)})}}d.useEffect(()=>{(async()=>{const a=x.flatMap(t=>Object.values(j(t))),{data:s}=await c.from("site_settings").select("key, value").in("key",a),n=Object.fromEntries((s??[]).map(t=>[t.key,t.value??""]));for(const t of x){const o=j(t);l(t.id,{name:n[o.name]??"",pixelId:n[o.pixelId]??"",enabled:n[o.enabled]!=="false",testCode:n[o.testCode]??""})}await k(),u(!1)})()},[]);async function M(){N(!0);try{const a=new Date().toISOString(),s=x.flatMap(t=>{const o=j(t),r=g[t.id];return[{key:o.name,value:r.name.trim()},{key:o.pixelId,value:r.pixelId.trim()},{key:o.enabled,value:r.enabled?"true":"false"},{key:o.testCode,value:r.testCode.trim()}]}).map(t=>({...t,updated_at:a})),{error:n}=await c.from("site_settings").upsert(s,{onConflict:"key"});if(n)throw n;m.success("Integração Meta atualizada")}catch(a){m.error(a instanceof Error?a.message:"Erro ao salvar")}N(!1)}async function K(a){var t;const s=x.find(o=>o.id===a),n=g[a].token.trim();if(!n){m.error("Cole o Access Token antes de salvar");return}S(a);try{const{data:o}=await c.auth.getUser(),{error:r}=await c.from("secure_settings").upsert({key:s.tokenKey,value:n,updated_by:((t=o.user)==null?void 0:t.id)??null,updated_at:new Date().toISOString()},{onConflict:"key"});if(r)throw r;
1m.success("Token CAPI atualizado"),l(a,{token:"",tokenSet:!0}),await k()}catch(o){m.error(o instanceof Error?o.message:"Erro ao salvar token")}S(null)}async function F(a){w(a);try{const{data:s,error:n}=await c.functions.invoke("meta-capi-token-admin",{body:{action:"import",context:a}});if(n)throw n;if(s!=null&&s.error)throw new Error(s.error);m.success("Token importado do secret"),await k()}catch(s){m.error(s instanceof Error?s.message:"Erro ao importar token")}w(null)}return i?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(z,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"max-w-3xl space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"font-display text-2xl font-bold",children:"Integração Meta"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Pixels separados por contexto. As LPs de Vagas (RH) usam o pixel de Vagas; os Testes A/B usam o pixel específico de Testes A/B; as Campanhas podem usar qualquer um dos três."})]}),x.map(a=>{const s=g[a.id],n=s.name.trim()||a.title;return e.jsxs($,{children:[e.jsx(B,{className:"pb-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(O,{className:"text-base",children:n}),e.jsx(D,{children:a.description})]}),e.jsx(p,{type:"button",variant:"ghost",size:"sm",className:"shrink-0 gap-1.5 text-muted-foreground",onClick:()=>I(a.id),children:E[a.id]?e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"h-4 w-4"})," Expandir"]}):e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"h-4 w-4"})," Minimizar"]})})]})}),!E[a.id]&&e.jsxs(L,{className:"space-y-5",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(f,{className:"text-sm",children:"Nome do Pixel (rótulo no painel)"}),e.jsx(h,{value:s.name,onChange:t=>l(a.id,{name:t.target.value}),placeholder:`Ex.: ${a.id==="vagas"?"Pixel Principal RH":a.id==="teste_ab"?"Pixel dos Testes":"Pixel Free Pass"}`}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Aparece aqui no título e na seleção de pixel do editor de campanhas."})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-md border px-4 py-3",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-medium",children:["Ativar ",a.title.replace("Pixel — ","Pixel de ")]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a.id==="teste_ab"?"Kill switch global para todos os testes — sobrescreve o toggle por teste.":"Quando desligado, nenhum evento é disparado com este pixel."})]}),e.jsx(R,{checked:s.enabled,onCheckedChange:t=>l(a.id,{enabled:t})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(f,{className:"text-sm",children:"Pixel ID"}),e.jsx(h,{value:s.pixelId,onChange:t=>l(a.id,{pixelId:t.target.value}),placeholder:"Ex.: 123456789012345",inputMode:"numeric"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(f,{className:"text-sm",children:"Test Event Code (opcional)"}),e.jsx(h,{value:s.testCode,onChange:t=>l(a.id,{testCode:t.target.value}),placeholder:"TEST12345"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(f,{className:"text-sm",children:"Access Token — Conversions API"}),e.jsx("span",{className:`text-xs ${s.tokenSet||s.tokenEnv?"text-emerald-600":"text-muted-foreground"}`,children:s.tokenSet?"● Configurado":s.tokenEnv?"● Disponível via secret (legado)":"○ Não configurado"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(h,{type:s.showToken?"text":"password",value:s.token,onChange:t=>l(a.id,{token:t.target.value}),placeholder:s.tokenSet?`${s.tokenPreview||"••••••••"} (salvo — cole um novo para substituir)`:"Cole o Access Token (EAAB…)",autoComplete:"off",className:"pr-10 font-mono text-xs"}),e.jsx("button",{type:"button",onClick:()=>l(a.id,{showToken:!s.showToken}),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground","aria-label":s.showToken?"Ocultar token":"Mostrar token",children:s.showToken?e.jsx(H,{className:"h-4 w-4"}):e.jsx(U,{className:"h-4 w-4"})})]}),e.jsx(p,{variant:"secondary",onClick:()=>K(a.id),disabled:C===a.id,children:C===a.id?"Salvando…":"Salvar token"})]}),a.legacyEnvKey&&s.tokenEnv&&!s.tokenSet&&e.jsxs("div",{className:"flex items-center justify-between rounded-md border border-dashed px-3 py-2",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Detectamos o secret ",e.jsx("code",{className:"text-[10px]",children:a.legacyEnvKey})," no backend. Importe para gerenciar daqui."]}),e.jsx(p,{size:"sm",variant:"outline",onClick:()=>F(a.id),disabled:_===a.id,children:_===a.id?"Importando…":"Importar do secret"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[a.tokenFallbackNote?`${a.tokenFallbackNote} `:"","Token armazenado como secret no backend. Para gerar um vá em"," ",e.jsxs("a",{href:"https://business.facebook.com/events_manager2",target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-foreground underline",children:["Events Manager ",e.jsx(v,{className:"h-3 w-3"})]})," ","→ Configurações → Conversions API → Gerar token de acesso."]})]}),a.id==="teste_ab"&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Para ativar em um teste específico abra"," ",e.jsxs("a",{href:"/admin/teste-ab",className:"inline-flex items-center gap-1 text-foreground underline",children:["Teste A/B ",e.jsx(v,{className:"h-3 w-3"})]})," ",'e ligue a opção "Meta Pixel" na configuração.']}),a.id==="campanhas"&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Para usar em uma campanha abra o editor da campanha em"," ",e.jsxs("a",{href:"/admin/campanhas",className:"inline-flex items-center gap-1 text-foreground underline",children:["Campanhas ",e.jsx(v,{className:"h-3 w-3"})]})," ",'e selecione este pixel em "Meta Ads → Pixel utilizado".']})]})]},a.id)}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(p,{onClick:M,disabled:b,children:[e.jsx(G,{className:"h-4 w-4 mr-2"}),b?"Salvando…":"Salvar alterações"]})})]})}export{le 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.