PageSourceSearch

https://plateiafun.lovable.app/assets/ProfilePage-BWlCcISP.js

js plateiafun.lovable.app collected 2026-10-03 03:39:21 UTC 7,488 bytes, 2 lines download raw bytes

1import{n as F,u as P,r,s as y,j as e,B as k}from"./index-CWJ-XTna.js";import{D as z}from"./DashboardLayout-D3_1jWvB.js";import{I as m}from"./input-Dctq5cvL.js";import{T as A}from"./textarea-dvs_1FbU.js";import{C as B}from"./checkbox-Bim5cA0G.js";import{E as C}from"./eye-off-fYl4NkRK.js";import{E as w}from"./eye-TdFXK2yW.js";import{o as R,s as v,l as b}from"./types-Bj839tgj.js";import"./use-mobile-BNKwfm0U.js";import"./triangle-alert-CGtwFhMA.js";import"./loader-circle-BVd4I_gm.js";import"./user-plus-BUcaUJZ3.js";import"./chart-column-2lRxiU-0.js";import"./globe-DsqqBd51.js";import"./ticket-B9XKSI7n.js";import"./search-B9tfCcvZ.js";import"./plus-C5XMo8wr.js";import"./index-B6RwP5Dn.js";function q(){const[a,s]=r.useState(""),[f,u]=r.useState(""),[d,h]=r.useState(!1),[p,g]=r.useState(!1),[l,n]=r.useState(!1),{toast:c}=P(),x=async()=>{if(!a||a.length<6){c({title:"A senha deve ter pelo menos 6 caracteres",variant:"destructive"});return}if(a!==f){c({title:"As senhas não coincidem",variant:"destructive"});return}n(!0);const{error:i}=await y.auth.updateUser({password:a});if(n(!1),i){c({title:"Erro ao alterar senha",description:i.message,variant:"destructive"});return}c({title:"Senha alterada com sucesso!"}),s(""),u("")};return e.jsxs("div",{className:"space-y-3 border-t border-border pt-4",children:[e.jsx("label",{className:"text-sm font-medium",children:"Alterar senha"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 sm:gap-4",children:[e.jsxs("div",{className:"space-y-1 relative",children:[e.jsx(m,{type:d?"text":"password",value:a,onChange:i=>s(i.target.value),placeholder:"Nova senha"}),e.jsx("button",{type:"button",className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground",onClick:()=>h(!d),children:d?e.jsx(C,{size:16}):e.jsx(w,{size:16})})]}),e.jsxs("div",{className:"space-y-1 relative",children:[e.jsx(m,{type:p?"text":"password",value:f,onChange:i=>u(i.target.value),placeholder:"Confirmar nova senha"}),e.jsx("button",{type:"button",className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground",onClick:()=>g(!p),children:p?e.jsx(C,{size:16}):e.jsx(w,{size:16})})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx(k,{type:"button",variant:"outline",size:"sm",onClick:x,disabled:l,children:l?"Alterando...":"Alterar senha"})})]})}function S(a){const s=a.replace(/\D/g,"").slice(0,11);return s.length<=2?s:s.length<=7?`(${s.slice(0,2)}) ${s.slice(2)}`:`(${s.slice(0,2)}) ${s.slice(2,7)}-${s.slice(7)}`}function $(a){const s=a.replace(/\D/g,"").slice(0,14);return s.length<=3?s:s.length<=6?`${s.slice(0,3)}.${s.slice(3)}`:s.length<=9?`${s.slice(0,3)}.${s.slice(3,6)}.${s.slice(6)}`:s.length<=11?`${s.slice(0,3)}.${s.slice(3,6)}.${s.slice(6,9)}-${s.slice(9)}`:s.length<=12?`${s.slice(0,2)}.${s.slice(2,5)}.${s.slice(5,8)}/${s.slice(8)}`:`${s.slice(0,2)}.${s.slice(2,5)}.${s.slice(5,8)}/${s.slice(8,12)}-${s.slice(12)}`}const I=R({full_name:v().trim().min(2,"Nome muito curto").max(120,"Nome muito longo"),phone:v().trim().max(30,"Telefone muito longo").optional().or(b("")),cpf_cnpj:v().trim().max(20,"CPF/CNPJ muito longo").optional().or(b("")),bio:v().trim().max(500,"Bio muito longa").optional().or(b(""))});function oe(){const{user:a}=F(),{toast:s}=P(),[f,u]=r.useState(!0),[d,h]=r.useState(!1),[p,g]=r.useState(null),[l,n]=r.useState({full_name:"",phone:"",cpf_cnpj:"",bio:""}),[c,x]=r.useState(!0),i=r.useMemo(()=>a?.email??"",[a?.email]);r.useEffect(()=>{document.title="Dados do usuário — plateia.fun"},[]),r.useEffect(()=>{a&&N()},[a?.id]);const N=async()=>{u(!0);try{const{data:t,error:o}=await y.from("profiles").select("id,user_id,email,full_name,phone,cpf_cnpj,bio,receive_ticket_copy").eq("user_id",a.id).maybeSingle();if(o)throw o;g(t??null),n({full_name:t?.full_name??a?.user_metadata?.full_name??"",phone:t?.phone?S(t.phone):"",cpf_cnpj:t?.cpf_cnpj?$(t.cpf_cnpj):"",bio:t?.bio??""}),x(t?.receive_ticket_copy??!0)}catch(t){console.error(t),s({title:"Não foi possível carregar seu perfil",description:"Tente novamente em alguns instantes.",variant:"destructive"})}finally{u(!1)}},D=async t=>{if(t.preventDefault(),!a)return;const o=I.safeParse(l);if(!o.success){s({title:"Revise os campos",description:o.error.issues[0]?.message,variant:"destructive"});return}const E=(o.data.phone||"").replace(/\D/g,""),T=(o.data.cpf_cnpj||"").replace(/\D/g,"");h(!0);try{const j={user_id:a.id,full_name:o.data.full_name,phone:E||null,cpf_cnpj:T||null,bio:o.data.bio||null,email:i||null,receive_ticket_copy:c},{error:_}=await y.from("profiles").upsert(j,{onConflict:"user_id"});if(_)throw _;s({title:"Dados salvos",description:"Seu perfil foi atualizado com sucesso."}),await N()}catch(j){console.error(j),s({title:"Erro ao salvar",description:"Verifique sua conexão e tente novamente.",variant:"destructive"})}finally{h(!1)}};return e.jsx(z,{children:e.jsxs("div",{className:"max-w-2xl",children:[e.jsxs("header",{className:"mb-6",children:[e.jsx("h1",{className:"font-heading text-2xl font-bold",children:"Dados do usuário"}),e.jsx("p",{className:"text-muted-foreground",children:"Atualize suas informações de conta."})]}),f?e.jsx("div",{className:"flex items-center justify-center py-10",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-t-2 border-b-2 border-wine"})}):e.jsxs("form",{onSubmit:D,className:"space-y-5 bg-card border border-border rounded-xl p-4 sm:p-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",htmlFor:"email",children:"E-mail"}),e.jsx(m,{id:"email",value:i,disabled:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",htmlFor:"full_name",children:"Nome completo *"}),e.jsx(m,{id:"full_name",value:l.full_name,onChange:t=>n(o=>({...o,full_name:t.target.value})),placeholder:"Seu nome completo",required:!0})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 sm:gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",htmlFor:"phone",children:"Telefone *"}),e.jsx(m,{id:"phone",value:l.phone??"",onChange:t=>n(o=>({...o,phone:S(t.target.value)})),placeholder:"(11) 99999-9999"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",htmlFor:"cpf_cnpj",children:"CPF ou CNPJ *"}),e.jsx(m,{id:"cpf_cnpj",value:l.cpf_cnpj??"",onChange:t=>n(o=>({...o,cpf_cnpj:$(t.target.value)})),placeholder:"000.000.000-00"})]})]}),e.jsx(q,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",htmlFor:"bio",children:"Bio"}),e.jsx(A,{id:"bio",value:l.bio??"",onChange:t=>n(o=>({...o,bio:t.target.value})),placeholder:"Conte um pouco sobre você / sua produtora...",rows:4})]}),e.jsxs("div",{className:"flex items-start gap-3 pt-1",children:[e.jsx(B,{id:"receive_ticket_copy",checked:c,onCheckedChange:t=>x(!!t)}),e.jsx("label",{htmlFor:"receive_ticket_copy",className:"text-sm text-muted-foreground font-normal cursor-pointer leading-snug",children:"Receber uma cópia dos ingressos vendidos em minha caixa de e-mail"})]}),e.jsx("div",{className:"pt-2 flex justify-end",children:e.jsx(k,{type:"submit",variant:"default",disabled:d,children:d?"Salvando...":"Salvar"})}),p===null&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Observação: seu registro de perfil será criado automaticamente ao salvar."})]})]})})}export{oe as default};
2//# sourceMappingURL=ProfilePage-BWlCcISP.js.map

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.