PageSourceSearch

https://www.visitecamposdojordao.org.br/assets/AssociadosList-BUCHv0SJ.js

js visitecamposdojordao.org.br collected 2026-10-02 22:27:12 UTC 18,504 bytes, 1 lines download raw bytes

1import{r as l,j as e}from"./vendor-react-CoH7wDUq.js";import{E as Ne,aJ as Re,aK as Ue,aL as qe,aM as Fe,aN as $e,aO as Pe,aP as Ge,aQ as Oe,aR as Be,aS as Je}from"./AdminApp-DKqxBNNv.js";import{A as ve}from"./AdminConfirmDialog-BuhGl2Ym.js";import"./vendor-pdf-DNjb9-t8.js";import"./index-DarzfxaQ.js";function ye(x){if(!x)return"";const c=new Date(x);if(Number.isNaN(c.getTime()))return"";const p=c.getFullYear(),u=String(c.getMonth()+1).padStart(2,"0"),S=String(c.getDate()).padStart(2,"0");return`${p}-${u}-${S}`}function Me(x){const c=String(x||"").trim();if(!c)return null;const p=new Date(`${c}T12:00:00.000Z`);return Number.isNaN(p.getTime())?null:p.toISOString()}function We(){var je;const[x,c]=l.useState([]),[p,u]=l.useState([]),[S,J]=l.useState(!0),[M,o]=l.useState(""),[E,z]=l.useState([]),[C,_]=l.useState(""),[g,K]=l.useState(null),[Q,V]=l.useState(!1),[T,W]=l.useState(null),[Y,Z]=l.useState(!1),[b,H]=l.useState(null),[d,f]=l.useState(null),[X,D]=l.useState(""),[ee,k]=l.useState(""),[te,I]=l.useState(""),[se,L]=l.useState(""),[ae,R]=l.useState(""),[U,h]=l.useState([]),[q,F]=l.useState(!1),[le,$]=l.useState(!1),[re,P]=l.useState(!1),[j,v]=l.useState(null),[oe,ne]=l.useState(!1),[m,ie]=l.useState(null),[de,ce]=l.useState(""),[me,ue]=l.useState(!0),[xe,G]=l.useState(""),[pe,O]=l.useState(!1),[N,y]=l.useState(null),[he,ge]=l.useState(!1);l.useEffect(()=>{let t=!1;async function s(){J(!0),o("");try{const[r,a,n]=await Promise.all([Re(),Ue(),Ne({limit:30})]);if(t)return;c(r),u(a),z(n)}catch(r){t||o(r instanceof Error?r.message:"Erro ao carregar associados")}finally{t||J(!1)}}return s(),()=>{t=!0}},[]),l.useEffect(()=>{const t=window.setTimeout(()=>{Ne({q:C,limit:30}).then(s=>z(s)).catch(()=>{})},250);return()=>window.clearTimeout(t)},[C]);const be=l.useMemo(()=>E.find(t=>t.id===g)||null,[E,g]);async function Ae(t){if(t.preventDefault(),!!g){V(!0),o(""),W(null);try{const s=await qe(g);W(s.credenciaisTemporarias),c(r=>[s.associado,...r]),K(null),_("")}catch(s){o(s instanceof Error?s.message:"Erro ao criar associado")}finally{V(!1)}}}function A(t){const s=t.imagensJson;return Array.isArray(s)?s.map(r=>typeof r=="string"?{url:r,legenda:null}:{url:r.url,legenda:r.legenda??null}):[]}function we(t){f(t),D(t.titulo),k(t.local||""),I(ye(t.dataReuniao)),L(t.integrantesRaw||""),R(t.conteudo),h(A(t))}function fe(){f(null),F(!1),$(!1),h([]),P(!1)}async function Se(t){if(t.preventDefault(),!!d){F(!0),o("");try{const s=await Fe(d.id,{titulo:X.trim(),local:ee.trim()||null,integrantesRaw:se.trim()||null,conteudo:ae.trim(),dataReuniao:Me(te),imagensJson:U});u(r=>r.map(a=>a.id===s.id?s:a)),f(s),h(A(s))}catch(s){o(s instanceof Error?s.message:"Erro ao guardar ATA")}finally{F(!1)}}}async function Ee(t){var r;const s=(r=t.target.files)==null?void 0:r[0];if(!(!s||!d)){$(!0),o("");try{const a=await $e(d.id,s);u(n=>n.map(i=>i.id===a.id?a:i)),f(a),D(a.titulo),k(a.local||""),I(ye(a.dataReuniao)),L(a.integrantesRaw||""),R(a.conteudo),h(A(a))}catch(a){o(a instanceof Error?a.message:"Erro ao substituir ficheiro")}finally{$(!1),t.target.value=""}}}async function Ce(t){var r;const s=(r=t.target.files)==null?void 0:r[0];if(t.target.value="",!(!s||!d)){P(!0),o("");try{const a=await Pe(d.id,s);f(a),h(A(a)),u(n=>n.map(i=>i.id===a.id?a:i))}catch(a){o(a instanceof Error?a.message:"Erro ao enviar imagem")}finally{P(!1)}}}function Te(t){ie(t),ce(t.nomeUsuario),ue(t.ativo),G("")}function B(){ie(null),O(!1),G("")}async function De(t){if(t.preventDefault(),!m)return;const s=de.trim();if(s.length<4){o("Nome de usuário deve ter pelo menos 4 caracteres.");return}const r=xe.trim();if(r&&r.length<6){o("Nova senha deve ter pelo menos 6 caracteres.");return}O(!0),o("");try{const a={nomeUsuario:s,ativo:me};r&&(a.novaSenha=r);const n=await Ge(m.id,a);c(i=>i.map(w=>w.id===n.id?n:w)),B()}catch(a){o(a instanceof Error?a.message:"Erro ao guardar associado")}finally{O(!1)}}async function ke(){if(N!=null){ge(!0),o("");try{await Oe(N),c(t=>t.filter(s=>s.id!==N)),(m==null?void 0:m.id)===N&&B(),y(null)}catch(t){o(t instanceof Error?t.message:"Erro ao excluir associado")}finally{ge(!1)}}}async function Ie(){if(j!=null){ne(!0),o("");try{await Be(j),u(t=>t.filter(s=>s.id!==j)),(d==null?void 0:d.id)===j&&fe(),v(null)}catch(t){o(t instanceof Error?t.message:"Erro ao excluir ATA")}finally{ne(!1)}}}async function Le(t){var n;t.preventDefault();const s=t.currentTarget,r=s.elements.namedItem("arquivo"),a=(n=r==null?void 0:r.files)==null?void 0:n[0];if(a){Z(!0),o(""),H(null);try{const i=await Je(a);H(i),u(w=>[i,...w]),s.reset()}catch(i){o(i instanceof Error?i.message:"Erro ao enviar ATA")}finally{Z(!1)}}}return e.jsxs("div",{className:"max-w-6xl",children:[e.jsx(ve,{open:j!=null,title:"Excluir ATA?",description:"Esta ação remove o registo e o ficheiro associado. Os associados deixam de ver esta ATA.",confirmText:"Excluir",danger:!0,busy:oe,onClose:()=>!oe&&v(null),onConfirm:Ie}),e.jsx(ve,{open:N!=null,title:"Excluir associado?",description:"Remove o acesso ao painel deste local. Os registos de ocupação enviados por este associado serão apagados. As ATAs publicadas não são removidas.",confirmText:"Excluir",danger:!0,busy:he,onClose:()=>!he&&y(null),onConfirm:ke}),m&&e.jsx("div",{className:"fixed inset-0 z-40 flex items-center justify-center bg-black/55 p-4 overflow-y-auto",children:e.jsxs("div",{className:"w-full max-w-md rounded-2xl bg-white border border-slate-200 shadow-xl my-8",children:[e.jsxs("div",{className:"p-4 border-b border-slate-200 flex items-start justify-between gap-2",children:[e.jsx("h2",{className:"text-lg font-semibold text-slate-800",children:"Editar associado"}),e.jsx("button",{type:"button",onClick:B,className:"text-slate-500 hover:text-slate-800 text-sm",children:"Fechar"})]}),e.jsxs("form",{onSubmit:De,className:"p-4 space-y-3",children:[e.jsxs("p",{className:"text-sm text-slate-600",children:["Local: ",e.jsx("strong",{children:((je=m.local)==null?void 0:je.nome)||`ID ${m.localId}`})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-slate-600 mb-1",children:"Nome de usuário"}),e.jsx("input",{value:de,onChange:t=>ce(t.target.value),className:"w-full rounded-lg border border-slate-300 px-3 py-2 text-sm",autoComplete:"off",required:!0,minLength:4})]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-slate-700 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:me,onChange:t=>ue(t.target.checked),className:"rounded border-slate-300"}),"Acesso ativo (pode entrar no painel)"]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-slate-600 mb-1",children:"Nova senha (opcional)"}),e.jsx("input",{type:"password",value:xe,onChange:t=>G(t.target.value),className:"w-full rounded-lg border border-slate-300 px-3 py-2 text-sm",autoComplete:"new-password",placeholder:"Deixe vazio para manter a senha atual"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Se preencher, a senha deixa de ser considerada temporária e o associado entra direto com esta senha."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 pt-2",children:[e.jsx("button",{type:"submit",disabled:pe,className:"px-4 py-2 rounded-lg bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50",children:pe?"A guardar…":"Guardar"}),e.jsx("button",{type:"button",onClick:()=>y(m.id),className:"px-4 py-2 rounded-lg border border-red-200 text-red-700 hover:bg-red-50",children:"Excluir associado"})]})]})]})}),d&&e.jsx("div",{className:"fixed inset-0 z-40 flex items-center justify-center bg-black/55 p-4 overflow-y-auto",children:e.jsxs("div",{className:"w-full max-w-3xl rounded-2xl bg-white border border-slate-200 shadow-xl my-8 max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"p-4 border-b border-slate-200 flex items-start justify-between gap-2 shrink-0",children:[e.jsx("h2",{className:"text-lg font-semibold text-slate-800",children:"Editar ATA"}),e.jsx("button",{type:"button",onClick:fe,className:"text-slate-500 hover:text-slate-800 text-sm",children:"Fechar"})]}),e.jsxs("form",{onSubmit:Se,className:"p-4 overflow-y-auto flex-1 space-y-3 min-h-0",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-slate-600 mb-1",children:"Título"}),e.jsx("input",{value:X,onChange:t=>D(t.target.value),className:"w-full rounded-lg border border-slate-300 px-3 py-2 text-sm",required:!0})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx("label",{className:"block text-xs font-medium text-slate-600 mb-1",children:"Local"}),e.jsx("textarea",{value:ee,onChange:t=>k(t.target.value),rows:2,className:"w-full rounded-lg border border-slate-300 px-3 py-2 text-sm",placeholder:"Local da reunião (texto longo permitido)"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-slate-600 mb-1",children:"Data da reunião"}),e.jsx("input",{type:"date",value:te,onChange:t=>I(t.target.value),className:"w-full rounded-lg border border-slate-300 px-3 py-2 text-sm"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-slate-600 mb-1",children:"Integrantes"}),e.jsx("textarea",{value:se,onChange:t=>L(t.target.value),rows:3,className:"w-full rounded-lg border border-slate-300 px-3 py-2 text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-slate-600 mb-1",children:"Conteúdo (texto completo)"}),e.jsx("textarea",{value:ae,onChange:t=>R(t.target.value),rows:12,className:"w-full rounded-lg border border-slate-300 px-3 py-2 text-sm font-mono",required:!0})]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-slate-200 bg-slate-50 p-3 text-sm",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-slate-700",children:"Imagens na ATA"}),e.jsxs("p",{className:"mt-0.5 text-xs text-slate-500",children:["JPG, PNG, WebP ou GIF at
1é 8 MB. O envio grava logo na ATA. Remover da lista ou alterar legenda exige ",e.jsx("strong",{className:"font-medium text-slate-600",children:"Guardar alterações"}),"."]})]}),U.length>0?e.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:U.map((t,s)=>e.jsxs("div",{className:"space-y-2 rounded-lg border border-slate-200 bg-white p-2",children:[e.jsx("img",{src:t.url,alt:"",className:"mx-auto max-h-36 w-full rounded-md bg-slate-100 object-contain"}),e.jsx("input",{type:"text",value:t.legenda||"",onChange:r=>h(a=>a.map((n,i)=>i===s?{...n,legenda:r.target.value}:n)),className:"w-full rounded border border-slate-200 px-2 py-1 text-xs",placeholder:"Legenda (opcional)"}),e.jsx("button",{type:"button",onClick:()=>h(r=>r.filter((a,n)=>n!==s)),className:"text-xs text-red-600 hover:underline",children:"Remover da lista"})]},`${t.url}-${s}`))}):e.jsx("p",{className:"text-xs text-slate-500",children:"Nenhuma imagem anexada ainda."}),e.jsxs("label",{className:"inline-flex cursor-pointer items-center gap-2 rounded-lg bg-white px-3 py-2 text-xs font-medium text-slate-700 ring-1 ring-slate-200 hover:bg-slate-50",children:[re?"A enviar…":"Adicionar imagem",e.jsx("input",{type:"file",accept:"image/jpeg,image/png,image/webp,image/gif",className:"hidden",disabled:re||q,onChange:t=>void Ce(t)})]})]}),e.jsxs("div",{className:"rounded-lg border border-slate-200 bg-slate-50 p-3 text-sm",children:[e.jsx("p",{className:"font-medium text-slate-700 mb-2",children:"Ficheiro .docx"}),d.arquivoUrl&&e.jsx("a",{className:"text-blue-700 hover:underline mr-4",href:d.arquivoUrl,target:"_blank",rel:"noreferrer",children:d.arquivoNome||"Download"}),e.jsxs("label",{className:"inline-block mt-2",children:[e.jsx("span",{className:"text-slate-600 cursor-pointer hover:underline",children:"Substituir ficheiro (.docx)"}),e.jsx("input",{type:"file",accept:".docx,application/vnd.openxmlformats-officedocument.wordprocessingml.document",className:"hidden",disabled:le,onChange:Ee})]}),le&&e.jsx("span",{className:"ml-2 text-slate-500",children:"A processar…"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 pt-2",children:[e.jsx("button",{type:"submit",disabled:q,className:"px-4 py-2 rounded-lg bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50",children:q?"A guardar…":"Guardar alterações"}),e.jsx("button",{type:"button",onClick:()=>v(d.id),className:"px-4 py-2 rounded-lg border border-red-200 text-red-700 hover:bg-red-50",children:"Excluir ATA"})]})]})]})}),e.jsx("h1",{className:"text-2xl md:text-3xl font-bold text-slate-800 mb-2",children:"Associados"}),e.jsx("p",{className:"text-slate-500 text-sm mb-6",children:"Crie acessos para associados e publique ATAs de reunião com extração automática dos dados."}),M&&e.jsx("div",{className:"mb-4 p-3 rounded-lg border border-red-200 bg-red-50 text-red-700 text-sm",children:M}),e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-5 mb-6",children:[e.jsxs("section",{className:"bg-white border border-slate-200 rounded-2xl p-4",children:[e.jsx("h2",{className:"text-lg font-semibold text-slate-800 mb-3",children:"Novo associado"}),e.jsxs("form",{onSubmit:Ae,className:"space-y-3",children:[e.jsx("input",{type:"search",value:C,onChange:t=>_(t.target.value),placeholder:"Pesquisar local por nome...",className:"w-full rounded-lg border border-slate-300 px-3 py-2"}),e.jsxs("select",{value:g??"",onChange:t=>K(t.target.value?Number(t.target.value):null),className:"w-full rounded-lg border border-slate-300 px-3 py-2",required:!0,children:[e.jsx("option",{value:"",children:"Selecione um local"}),E.map(t=>e.jsxs("option",{value:t.id,children:[t.nome," (",t.categoria,")"]},t.id))]}),e.jsx("button",{type:"submit",disabled:!g||Q,className:"px-4 py-2.5 rounded-lg bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50",children:Q?"Criando...":"Criar acesso"})]}),be&&e.jsxs("p",{className:"text-xs text-slate-500 mt-2",children:["Local selecionado: ",be.nome]}),T&&e.jsxs("div",{className:"mt-4 p-3 rounded-lg border border-amber-200 bg-amber-50 text-amber-900 text-sm",children:[e.jsx("p",{className:"font-semibold mb-1",children:"Credenciais temporárias geradas"}),e.jsxs("p",{children:["Usuário: ",e.jsx("strong",{children:T.nomeUsuario})]}),e.jsxs("p",{children:["Senha: ",e.jsx("strong",{children:T.senha})]})]})]}),e.jsxs("section",{className:"bg-white border border-slate-200 rounded-2xl p-4",children:[e.jsx("h2",{className:"text-lg font-semibold text-slate-800 mb-3",children:"Upload de ATA"}),e.jsxs("form",{onSubmit:Le,className:"space-y-3",children:[e.jsx("input",{type:"file",name:"arquivo",accept:".docx,application/vnd.openxmlformats-officedocument.wordprocessingml.document",className:"w-full rounded-lg border border-slate-300 px-3 py-2",required:!0}),e.jsx("button",{type:"submit",disabled:Y,className:"px-4 py-2.5 rounded-lg bg-slate-700 text-white hover:bg-slate-800 disabled:opacity-50",children:Y?"Enviando...":"Enviar ATA"})]}),b&&e.jsxs("div",{className:"mt-4 p-3 rounded-lg border border-emerald-200 bg-emerald-50 text-emerald-900 text-sm",children:[e.jsx("p",{className:"font-semibold mb-1",children:"ATA processada automaticamente"}),e.jsxs("p",{children:["Título: ",b.titulo]}),e.jsxs("p",{children:["Local: ",b.local||"—"]}),e.jsxs("p",{children:["Data: ",b.dataReuniao?new Date(b.dataReuniao).toLocaleDateString("pt-BR"):"—"]})]})]})]}),e.jsxs("section",{className:"bg-white border border-slate-200 rounded-2xl p-4 mb-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-slate-800 mb-3",children:"Acessos de associados"}),S?e.jsx("p",{className:"text-slate-500 text-sm",children:"Carregando..."}):x.length===0?e.jsx("p",{className:"text-slate-500 text-sm",children:"Nenhum associado cadastrado."}):e.jsx("div",{className:"overflow-auto",children:e.jsxs("table",{className:"min-w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-slate-500",children:[e.jsx("th",{className:"py-2 pr-3",children:"Local"}),e.jsx("th",{className:"py-2 pr-3",children:"Usuário"}),e.jsx("th",{className:"py-2 pr-3",children:"Senha temporária"}),e.jsx("th",{className:"py-2 pr-3",children:"Ativo"}),e.jsx("th",{className:"py-2 pr-3",children:"Último login"}),e.jsx("th",{className:"py-2 pr-3 text-right",children:"Ações"})]})}),e.jsx("tbody",{children:x.map(t=>{var s;return e.jsxs("tr",{className:"border-t border-slate-100",children:[e.jsx("td",{className:"py-2 pr-3",children:((s=t.local)==null?void 0:s.nome)||`Local #${t.localId}`}),e.jsx("td",{className:"py-2 pr-3",children:t.nomeUsuario}),e.jsx("td",{className:"py-2 pr-3",children:t.senhaTemporaria?"Sim"
1:"Não"}),e.jsx("td",{className:"py-2 pr-3",children:t.ativo?"Sim":"Não"}),e.jsx("td",{className:"py-2 pr-3",children:t.ultimoLoginEm?new Date(t.ultimoLoginEm).toLocaleString("pt-BR"):"Nunca"}),e.jsxs("td",{className:"py-2 pl-3 text-right whitespace-nowrap",children:[e.jsx("button",{type:"button",onClick:()=>Te(t),className:"px-2 py-1 rounded-lg bg-slate-100 text-slate-800 text-sm hover:bg-slate-200 mr-1",children:"Editar"}),e.jsx("button",{type:"button",onClick:()=>y(t.id),className:"px-2 py-1 rounded-lg border border-red-200 text-red-700 text-sm hover:bg-red-50",children:"Excluir"})]})]},t.id)})})]})})]}),e.jsxs("section",{className:"bg-white border border-slate-200 rounded-2xl p-4",children:[e.jsx("h2",{className:"text-lg font-semibold text-slate-800 mb-3",children:"ATAs publicadas"}),p.length===0?e.jsx("p",{className:"text-slate-500 text-sm",children:"Nenhuma ATA publicada."}):e.jsx("div",{className:"space-y-3",children:p.map(t=>e.jsxs("div",{className:"rounded-xl border border-slate-200 p-3 flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"font-semibold text-slate-800",children:t.titulo}),e.jsxs("p",{className:"text-xs text-slate-500",children:[t.local||"Sem local"," ·"," ",t.dataReuniao?new Date(t.dataReuniao).toLocaleDateString("pt-BR"):"Sem data"]}),t.arquivoUrl&&e.jsx("a",{className:"text-sm text-blue-700 hover:underline",href:t.arquivoUrl,target:"_blank",rel:"noreferrer",children:"Baixar arquivo"})]}),e.jsxs("div",{className:"flex gap-2 shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>we(t),className:"px-3 py-1.5 rounded-lg bg-slate-100 text-slate-800 text-sm hover:bg-slate-200",children:"Editar"}),e.jsx("button",{type:"button",onClick:()=>v(t.id),className:"px-3 py-1.5 rounded-lg border border-red-200 text-red-700 text-sm hover:bg-red-50",children:"Excluir"})]})]},t.id))})]})]})}export{We 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.