PageSourceSearch

https://urbanmotion.com.br/assets/admin.memorias-C87VUf1S.js

js urbanmotion.com.br collected 2026-10-08 01:43:34 UTC 15,864 bytes, 1 lines download raw bytes

1import{u as V,r as n,s as C,j as e}from"./index-DSQdFK3i.js";import{b as B,U as q,E as L,c as $,S as U}from"./memories-BVynzHVH.js";import{L as I}from"./loader-circle-Dd6h4fs7.js";import{c as A,X as O}from"./x-CvC4FG7d.js";import{C as X}from"./check-CLUlKeZy.js";import{S as P}from"./star-DOPnu9Ug.js";const G=[["path",{d:"m16 17 5-5-5-5",key:"1bji2h"}],["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}]],J=A("log-out",G);const K=[["path",{d:"M13 21h8",key:"1jsn5i"}],["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}]],Q=A("pen-line",K);const W=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],Y=A("plus",W);const Z=[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]],F=A("save",Z);const ee=[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],ae=A("trash-2",ee);function xe(){const a=V(),[c,x]=n.useState(!1),[_,v]=n.useState(!1),[d,N]=n.useState([]),[E,g]=n.useState(!0),[f,j]=n.useState("approved"),[y,l]=n.useState(null),[k,m]=n.useState(!1);n.useEffect(()=>{(async()=>{const{data:t}=await C.auth.getUser();if(!t.user){a({to:"/login",replace:!0});return}const{data:o}=await C.from("user_roles").select("role").eq("user_id",t.user.id).eq("role","admin").maybeSingle();v(!!o),x(!0),o&&p()})()},[a]);async function p(){g(!0);try{const t=await B();N(t)}catch(t){console.error(t)}finally{g(!1)}}async function i(t,o){const{error:z}=await C.from("memories").update(o).eq("id",t);if(z){alert("Erro: "+z.message);return}await p()}async function w(t){if(!confirm("Remover esta avaliação permanentemente?"))return;const{error:o}=await C.from("memories").delete().eq("id",t);if(o){alert("Erro: "+o.message);return}await p()}async function u(){await C.auth.signOut(),a({to:"/login",replace:!0})}if(!c)return e.jsx("div",{className:"min-h-screen grid place-items-center",children:e.jsx(I,{className:"size-8 animate-spin text-[var(--brand-red)]"})});if(!_)return e.jsx("div",{className:"min-h-screen grid place-items-center px-4",children:e.jsxs("div",{className:"max-w-md text-center space-y-4",children:[e.jsx("h1",{className:"font-display text-3xl",children:"Acesso negado"}),e.jsxs("p",{className:"text-muted-foreground text-sm",children:["Sua conta está logada mas não tem permissão de administrador. Promova este usuário a ",e.jsx("code",{children:"admin"})," na tabela ",e.jsx("code",{children:"user_roles"})," do Backend."]}),e.jsx("button",{onClick:u,className:"px-5 py-2.5 rounded-full bg-[var(--brand-red)] text-white font-bold",children:"Sair"})]})});const S={pending:d.filter(t=>t.status==="pending").length,approved:d.filter(t=>t.status==="approved").length,featured:d.filter(t=>t.status==="featured").length,rejected:d.filter(t=>t.status==="rejected").length,all:d.length},r=f==="all"?d:d.filter(t=>t.status===f);return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx("header",{className:"sticky top-0 z-10 border-b border-border bg-background/95 backdrop-blur",children:e.jsxs("div",{className:"container-um flex items-center justify-between py-4 gap-4 flex-wrap",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"font-display text-xl",children:"Admin · Memórias Urban Motion"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Cadastre, edite e destaque avaliações reais."})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:()=>m(!0),className:"inline-flex items-center gap-2 px-4 py-2 rounded-full bg-[var(--brand-red)] text-white text-sm font-bold hover:brightness-110 shadow-glow-red",children:[e.jsx(Y,{className:"size-4"})," Nova avaliação"]}),e.jsxs("button",{onClick:u,className:"inline-flex items-center gap-2 text-sm font-semibold hover:text-[var(--brand-red)]",children:[e.jsx(J,{className:"size-4"})," Sair"]})]})]})}),k&&e.jsx(ne,{onClose:()=>m(!1),onCreated:async()=>{m(!1),await p()}}),e.jsxs("main",{className:"container-um py-8",children:[e.jsx("div",{className:"flex flex-wrap gap-2 mb-6",children:["pending","approved","featured","rejected","all"].map(t=>e.jsxs("button",{onClick:()=>j(t),className:`px-4 py-2 rounded-full text-sm font-semibold border transition ${f===t?"bg-[var(--brand-red)] text-white border-[var(--brand-red)]":"border-border hover:border-[var(--brand-red)]"}`,children:[te(t)," ",e.jsxs("span",{className:"opacity-70",children:["(",S[t],")"]})]},t))}),E?e.jsx("div",{className:"grid place-items-center py-20",children:e.jsx(I,{className:"size-8 animate-spin"})}):r.length===0?e.jsx("div",{className:"rounded-2xl border border-dashed border-border p-12 text-center text-muted-foreground",children:"Nenhuma avaliação nesta categoria."}):e.jsx("div",{className:"space-y-4",children:r.map(t=>e.jsx(se,{memory:t,editing:y===t.id,onEdit:()=>l(t.id),onCancelEdit:()=>l(null),onSave:async o=>{await i(t.id,o),l(null)},onApprove:()=>i(t.id,{status:"approved"}),onReject:()=>i(t.id,{status:"rejected"}),onFeature:()=>i(t.id,{status:"featured",featured:!0}),onUnfeature:()=>i(t.id,{status:"approved",featured:!1}),onDelete:()=>w(t.id)},t.id))})]})]})}function te(a){return{pending:"Pendentes",approved:"Aprovadas",featured:"Destaque",rejected:"Rejeitadas",all:"Todas"}[a]}function se({memory:a,editing:c,onEdit:x,onCancelEdit:_,onSave:v,onApprove:d,onReject:N,onFeature:E,onUnfeature:g,onDelete:f}){const[j,y]=n.useState(a.story),[l,k]=n.useState(a.rating),[m,p]=n.useState(a.source),[i,w]=n.useState(a.unit),[u,S]=n.useState(a.experience_type);return n.useEffect(()=>{y(a.story),k(a.rating),p(a.source),w(a.unit),S(a.experience_type)},[a.id,a.story,a.rating,a.source,a.unit,a.experience_type]),e.jsxs("article",{className:"rounded-2xl border border-border bg-surface/40 p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 flex-wrap",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap text-xs",children:[e.jsx(re,{status:a.status}),a.featured&&e.jsx("span",{className:"px-2 py-0.5 rounded-full bg-[var(--brand-yellow)] text-black font-bold",children:"★ Destaque"}),e.jsx("span",{className:"text-muted-foreground",children:new Date(a.created_at).toLocaleStr
1ing("pt-BR")})]}),e.jsxs("div",{className:"mt-2 font-bold",children:[a.name," ",e.jsxs("span",{className:"text-muted-foreground font-normal text-sm",children:["· ",a.email]})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[a.status!=="approved"&&a.status!=="featured"&&e.jsxs("button",{onClick:d,className:"px-3 py-1.5 rounded-full bg-green-600 text-white text-xs font-bold inline-flex items-center gap-1",children:[e.jsx(X,{className:"size-3.5"})," Aprovar"]}),a.status!=="rejected"&&e.jsxs("button",{onClick:N,className:"px-3 py-1.5 rounded-full bg-zinc-600 text-white text-xs font-bold inline-flex items-center gap-1",children:[e.jsx(O,{className:"size-3.5"})," Rejeitar"]}),a.featured?e.jsx("button",{onClick:g,className:"px-3 py-1.5 rounded-full bg-zinc-300 text-black text-xs font-bold",children:"Remover destaque"}):e.jsxs("button",{onClick:E,className:"px-3 py-1.5 rounded-full bg-[var(--brand-yellow)] text-black text-xs font-bold inline-flex items-center gap-1",children:[e.jsx(P,{className:"size-3.5"})," Destaque"]}),c?e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>v({story:j,rating:l,source:m,unit:i,experience_type:u}),className:"px-3 py-1.5 rounded-full bg-[var(--brand-red)] text-white text-xs font-bold inline-flex items-center gap-1",children:[e.jsx(F,{className:"size-3.5"})," Salvar"]}),e.jsx("button",{onClick:_,className:"px-3 py-1.5 rounded-full border border-border text-xs font-bold",children:"Cancelar"})]}):e.jsxs("button",{onClick:x,className:"px-3 py-1.5 rounded-full border border-border text-xs font-bold inline-flex items-center gap-1",children:[e.jsx(Q,{className:"size-3.5"})," Editar"]}),e.jsx("button",{onClick:f,className:"px-2.5 py-1.5 rounded-full border border-red-500/40 text-red-500 text-xs font-bold inline-flex items-center gap-1",children:e.jsx(ae,{className:"size-3.5"})})]})]}),c?e.jsxs("div",{className:"mt-4 grid gap-3 md:grid-cols-4",children:[e.jsxs("label",{className:"text-sm md:col-span-4",children:[e.jsx("span",{className:"block font-semibold mb-1",children:"Texto"}),e.jsx("textarea",{value:j,onChange:r=>y(r.target.value),className:"w-full min-h-28 rounded-lg border border-border bg-background p-2 text-sm",maxLength:4e3})]}),e.jsxs("label",{className:"text-sm",children:[e.jsx("span",{className:"block font-semibold mb-1",children:"Nota"}),e.jsx("select",{value:l,onChange:r=>k(Number(r.target.value)),className:"w-full h-10 rounded-lg border border-border bg-background px-2 text-sm",children:[1,2,3,4,5].map(r=>e.jsxs("option",{value:r,children:[r," estrela",r>1?"s":""]},r))})]}),e.jsxs("label",{className:"text-sm",children:[e.jsx("span",{className:"block font-semibold mb-1",children:"Origem"}),e.jsx("select",{value:m,onChange:r=>p(r.target.value),className:"w-full h-10 rounded-lg border border-border bg-background px-2 text-sm",children:$.map(r=>e.jsx("option",{value:r,children:U[r]},r))})]}),e.jsxs("label",{className:"text-sm",children:[e.jsx("span",{className:"block font-semibold mb-1",children:"Unidade"}),e.jsx("select",{value:i,onChange:r=>w(r.target.value),className:"w-full h-10 rounded-lg border border-border bg-background px-2 text-sm",children:q.map(r=>e.jsx("option",{value:r,children:r},r))})]}),e.jsxs("label",{className:"text-sm",children:[e.jsx("span",{className:"block font-semibold mb-1",children:"Tipo"}),e.jsx("select",{value:u,onChange:r=>S(r.target.value),className:"w-full h-10 rounded-lg border border-border bg-background px-2 text-sm",children:L.map(r=>e.jsx("option",{value:r,children:r},r))})]})]}):e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"flex items-center gap-1 text-[var(--brand-yellow)]",children:[Array.from({length:5}).map((r,t)=>e.jsx(P,{className:`size-4 ${t<a.rating?"fill-current":"text-muted-foreground/30"}`},t)),e.jsxs("span",{className:"ml-2 text-xs text-muted-foreground",children:[U[a.source]," · ",a.unit," · ",a.experience_type,a.child_age!=null?` · ${a.child_age} anos`:""]})]}),e.jsx("p",{className:"mt-2 text-sm leading-relaxed text-foreground/90",children:a.story})]})]})}function re({status:a}){const c={pending:"bg-yellow-500/20 text-yellow-700 dark:text-yellow-300",approved:"bg-green-500/20 text-green-700 dark:text-green-300",featured:"bg-[var(--brand-yellow)]/30 text-amber-700 dark:text-amber-200",rejected:"bg-zinc-500/20 text-zinc-600 dark:text-zinc-300"},x={pending:"Pendente",approved:"Aprovada",featured:"Destaque",rejected:"Rejeitada"};return e.jsx("span",{className:`px-2 py-0.5 rounded-full font-bold uppercase ${c[a]}`,children:x[a]})}function ne({onClose:a,onCreated:c}){const[x,_]=n.useState(""),[v,d]=n.useState("[email protected]"),[N,E]=n.useState(q[0]),[g,f]=n.useState(L[0]),[j,y]=n.useState("google"),[l,k]=n.useState("approved"),[m,p]=n.useState(!1),[i,w]=n.useState(5),[u,S]=n.useState(""),[r,t]=n.useState(""),[o,z]=n.useState(!1),[T,R]=n.useState(null);async function H(s){if(s.preventDefault(),R(null),!x.trim()||u.trim().length<10){R("Informe o nome do avaliador e um relato com pelo menos 10 caracteres.");return}z(!0);try{const M={name:x.trim(),email:v.trim(),unit:N,experience_type:g,rating:i,story:u.trim(),source:j,status:l,featured:m||l==="featured",child_age:r===""?null:Number(r),photo_urls:[],video_urls:[]};(l==="approved"||l==="featured")&&(M.approved_at=new Date().toISOString());const{error:D}=await C.from("memories").insert(M);if(D)throw D;await c()}catch(M){R(M instanceof Error?M.message:"Erro ao salvar.")}finally{z(!1)}}return e.jsx("div",{className:"fixed inset-0 z-50 bg-black/60 backdrop-blur-sm grid place-items-center p-4 overflow-y-auto",onClick:a,children:e.jsxs("form",{onClick:s=>s.stopPropagation(),onSubmit:H,className:"w-full max-w-2xl bg-background border border-border rounded-2xl p-6 md:p-8 my-8 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"font-display text-2xl",children:"Nova avaliação"}),e.jsx("button",{type:"button",onClick:a,className:"p-2 hover:text-[var(--brand-red)]",children:e.jsx(O,{className:"size-5"})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Cadastre manualmente uma avaliação real (ex.: copiada do Google ou Instagram com permissão do autor). Não invente dados."}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsx(h,{label:"Nome do avaliador*",children:e.jsx("input",{value:x,onChange:s=>_(s.target.value),className:b,maxLength:120,required:!0})}),e.jsx(h,{label:"E-mail (interno)",children:e.jsx("input",{type:"email",value:v,onCh
1ange:s=>d(s.target.value),className:b,maxLength:255,required:!0})}),e.jsx(h,{label:"Origem*",children:e.jsx("select",{value:j,onChange:s=>y(s.target.value),className:b,children:$.map(s=>e.jsx("option",{value:s,children:U[s]},s))})}),e.jsx(h,{label:"Status inicial*",children:e.jsxs("select",{value:l,onChange:s=>k(s.target.value),className:b,children:[e.jsx("option",{value:"approved",children:"Aprovada"}),e.jsx("option",{value:"featured",children:"Destaque"}),e.jsx("option",{value:"pending",children:"Pendente"}),e.jsx("option",{value:"rejected",children:"Rejeitada"})]})}),e.jsx(h,{label:"Unidade*",children:e.jsx("select",{value:N,onChange:s=>E(s.target.value),className:b,children:q.map(s=>e.jsx("option",{value:s,children:s},s))})}),e.jsx(h,{label:"Tipo de experiência*",children:e.jsx("select",{value:g,onChange:s=>f(s.target.value),className:b,children:L.map(s=>e.jsx("option",{value:s,children:s},s))})}),e.jsx(h,{label:"Nota*",children:e.jsx("select",{value:i,onChange:s=>w(Number(s.target.value)),className:b,children:[1,2,3,4,5].map(s=>e.jsxs("option",{value:s,children:[s," estrela",s>1?"s":""]},s))})}),e.jsx(h,{label:"Idade da criança (opcional)",children:e.jsx("input",{type:"number",min:0,max:18,value:r,onChange:s=>t(s.target.value),className:b})})]}),e.jsxs(h,{label:"Relato*",children:[e.jsx("textarea",{value:u,onChange:s=>S(s.target.value),className:`${b} min-h-32 resize-y`,maxLength:4e3,required:!0}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:[u.length,"/4000"]})]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:m,onChange:s=>p(s.target.checked)}),"Marcar como destaque"]}),T&&e.jsx("div",{className:"rounded-lg border border-[var(--brand-red)]/40 bg-[var(--brand-red)]/10 text-sm p-3",children:T}),e.jsxs("div",{className:"flex items-center justify-end gap-3 pt-2",children:[e.jsx("button",{type:"button",onClick:a,className:"px-5 py-2.5 rounded-full border border-border font-bold text-sm",children:"Cancelar"}),e.jsxs("button",{type:"submit",disabled:o,className:"px-6 py-2.5 rounded-full bg-[var(--brand-red)] text-white font-bold text-sm inline-flex items-center gap-2 disabled:opacity-60",children:[o?e.jsx(I,{className:"size-4 animate-spin"}):e.jsx(F,{className:"size-4"}),"Salvar avaliação"]})]})]})})}const b="w-full h-11 rounded-lg border border-border bg-background px-3 text-sm outline-none focus:border-[var(--brand-red)]";function h({label:a,children:c}){return e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"block text-sm font-semibold text-foreground mb-1.5",children:a}),c]})}export{xe 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.