1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4160],{9153:function(e,t,a){(window.__NEXT_P=window.__NEXT_P||[]).push(["/user/edit/[edit_user]",function(){return a(3155)}])},3155:function(e,t,a){"use strict";a.r(t),a.d(t,{__N_SSP:function(){return d},default:function(){return m}});var r=a(5893),s=a(3598),n=a(1163),i=a(7294),l=a(3299),o=a(550),u=a(6770),c=a.n(u),d=!0;function m(e){let{userInfo:t,isDark:a,toggleDarkMode:u}=e,{user:d}=(0,i.useContext)(o.T),[m,x]=(0,i.useState)(null),f=(0,n.useRouter)(),h=(0,i.useRef)(),p=(0,i.useRef)(),b=(0,i.useRef)(""),g=(0,i.useRef)(""),v=(0,i.useRef)(""),w=(0,i.useRef)([]),j=(0,i.useRef)(""),y=(0,i.useRef)(""),[N,k]=(0,i.useState)(null),F=f.asPath.replace("/user/edit/",""),[S,E]=(0,i.useState)(null),[R,_]=(0,i.useState)(null);async function z(e,t,a,r,s,n,i,l,o){let u=await fetch("/api/user/edit_user",{method:"PATCH",body:JSON.stringify({username:e,email:t,password:a,name:r,website:s,ig:n,favHanzi:i,bio:l,image:o}),headers:{"Content-Type":"application/json"}}),c=await u.json();if(!u.ok)throw Error(c.message||"Something went wrong!");return u.ok&&f.push("/user/".concat(e)),c}async function P(e){e.preventDefault();let a=t.email,r=p.current.value,s=y.current.value.trim(),n=b.current.value.trim(),i=g.current.value.trim(),o=v.current.value.trim(),u=j.current.value,d=w.current.value.replaceAll("ï¼",",").replaceAll("ã",",").split(",").map(e=>e.trim()),m=await new Promise(e=>{c().imageFileResizer(S,500,500,"PNG",100,0,t=>{e(t)},"base64")});if(s<4||!/^[a-z0-9_-]+$/.test(s)){k("Seu nome de usu\xe1rio deve ter no m\xednimo 4 letras. Ele pode ser formado apenas por letras min\xfasculas, tra\xe7o (-) e sublinhado (_).");return}if(n.length<2){k("Seu nome precisa ter pelo menos dois caracteres.");return}if(d.length<1){k("Voc\xea precisa adicionar pelo menos um hanzi ou palavra em chin\xeas que mais gosta. \uD83D\uDE0A");return}if(!1===function(e){let t=/^[\u4e00-\u9fa5]+$/;for(let a=0;a<e.length;a++)if(!t.test(e[a]))return!1;return!0}(d)){k("Voc\xea adicionou caracteres n\xe3o chineses nos seus hanzis favoritos. Voc\xea deve adicionar apenas caracteres ou palavras chinesas.");return}try{let e=await z(s,a,r,n,i,o,d,u,m);k(e.message),await (0,l.signIn)("credentials",{redirect:!1,email:a,password:r})}catch(e){k(e.message)}}(0,i.useEffect)(()=>{N||(document.body.style.position="static"),N&&(document.body.style.position="fixed",document.body.style.top="-".concat(window.scrollY,"px"))},[N]),(0,i.useEffect)(()=>{b.current,y.current,w.current,v.current,g.current,h.current,j.current&&(b.current.value=t.name,y.current.value=t.username,w.current.value=t.favHanzi.map(e=>" "+e),v.current.value=t.ig,g.current.value=t.website,h.current.value=t.email,j.current.value=t.bio)},[t,h]),(0,i.useEffect)(()=>{if(!d||!d.username){f.replace("/login");return}return f.asPath.includes("/user/edit")&&F&&d.username!==F&&f.replace("/login"),()=>{}},[d,F]);let A=e=>{let t=e.target.files[0];E(t)};return(0,i.useEffect)(()=>{let e,t=!1;return S&&((e=new FileReader).onload=e=>{let{result:a}=e.target;a&&!t&&_(a)},e.readAsDataURL(S)),()=>{t=!0,e&&1===e.readyState&&e.abort()}},[S]),(0,r.jsx)(s.Z,{isDark:a,toggleDarkMode:u,className:N?"max-h-screen overflow-hidden":"",children:(0,r.jsxs)("div",{className:"h-full",children:[(0,r.jsx)("div",{className:"py-8 min-h-[calc(100vh-206px)] flex flex-col justify-center items-center h-full w-full lm:min-h-none lm:h-full bg-slate-100",children:(0,r.jsxs)("section",{className:"mx-auto w-[95%] max-w-[25rem] rounded-sm bg-[#e7e0d7] shadow-sm text-center md:max-w-[800px]",children:[(0,r.jsx)("h1",{className:"py-8 bg-gradient-to-b from-blue-400/50 to-transparent text-center text-xl font-bold",children:"Edit"}),(0,r.jsxs)("form",{className:"flex flex-col",onSubmit:P,children:[(0,r.jsxs)("div",{className:"flex flex-col items-center whitespace-nowrap px-4 pt-6 pb-4 duration-700 "+("name"===m?" bg-orange-200/50":""),children:[(0,r.jsxs)("label",{className:"flex items-center flex-col justify-center font-bold mb-1 w-full",htmlFor:"name",children:["Nome e sobrenome",(0,r.jsx)("div",{className:"text-xs text-neutral-600 md:max-w-[70%]",children:"Se quiser fazer um perfil para sua escola ou institui\xe7\xe3o, tamb\xe9m pode usar o nome dela."})]}),(0,r.jsx)("input",{className:"font-inherit bg-slate-50 rounded-sm border-[1px] border-white w-full text-center p-1 outline-stone-400/40",type:"text",id:"name",ref:b,required:!0,onFocus:()=>x("name")}
1)]}),(0,r.jsxs)("div",{className:"p-4 duration-700"+("username"===m?" bg-orange-200/50":""),children:[(0,r.jsxs)("label",{className:"flex flex-col items-center justify-center font-bold mb-1",htmlFor:"username",children:["Your Username",(0,r.jsx)("div",{className:"text-xs text-neutral-600 md:max-w-[70%]",children:"Crie um nome de usu\xe1rio s\xf3 para voc\xea. Ele precisa conter apenas letras, tra\xe7os ou pontos. Assim, voc\xea poder\xe1 acessar seu perfil no endere\xe7o www.bihua.app/user/seu-nome-de-usuario"})]}),(0,r.jsx)("input",{className:"font-inherit bg-slate-50 rounded-sm border-[1px] border-white w-full text-center p-1 outline-stone-400/40",type:"text",id:"username",ref:y,required:!0,onFocus:()=>x("username")})]}),(0,r.jsxs)("div",{className:"p-4 duration-700"+("file"===m?" bg-orange-200/50":""),children:[(0,r.jsxs)("label",{className:"flex flex-col items-center justify-center font-bold mb-1",htmlFor:"file",children:["Your Profile Photo",(0,r.jsx)("div",{className:"text-xs text-neutral-600 md:max-w-[70%]",children:"Adicione uma imagem para ser a sua foto de perfil."})]}),(0,r.jsx)("input",{className:"font-inherit bg-slate-50 rounded-sm border-[1px] border-white w-full text-center p-1 outline-stone-400/40 pl-[35%]",type:"file",id:"file",name:"file",accept:"image/*",required:!0,onChange:A,onFocus:()=>x("file")}),!R&&(null==t?void 0:t.image)&&(0,r.jsx)("div",{className:"mt-2 flex justify-center",children:(0,r.jsx)("img",{className:"max-w-[30%] max-h-[100px]",src:t.image,alt:"preview"})}),R&&(0,r.jsx)("div",{className:"mt-2 flex justify-center",children:(0,r.jsx)("img",{className:"max-w-[30%] max-h-[100px]",src:R,alt:"preview"})})]}),(0,r.jsxs)("div",{className:"p-4 duration-700"+("ig"===m?" bg-orange-200/50":""),children:[(0,r.jsxs)("label",{className:"block font-bold mb-1",htmlFor:"ig",children:["Your Instagram",(0,r.jsx)("div",{className:"text-xs text-neutral-600",children:"Escreva a sua @ no Instagram."})]}),(0,r.jsx)("input",{className:"font-inherit bg-slate-50 rounded-sm border-[1px] border-white w-full p-1 text-center outline-stone-400/40",type:"text",id:"ig",ref:v,defaultValue:"@",required:!0,onFocus:()=>x("ig")})]}),(0,r.jsxs)("div",{className:"p-4 duration-700"+("website"===m?" bg-orange-200/50":""),children:[(0,r.jsxs)("label",{className:"block font-bold mb-1",htmlFor:"website",children:["Your Website",(0,r.jsx)("div",{className:"text-xs text-neutral-600",children:"Se voc\xea n\xe3o tiver um website, tudo bem! Deixe em branco."})]}),(0,r.jsx)("input",{className:"font-inherit bg-slate-50 rounded-sm border-[1px] border-white w-full p-1 text-center outline-stone-400/40",type:"text",id:"website",ref:g,defaultValue:"https://",required:!0,onFocus:()=>x("website")})]}),(0,r.jsxs)("div",{className:"p-4 duration-700"+("bio"===m?" bg-yellow-100/40":""),children:[(0,r.jsxs)("label",{className:"block font-bold mb-1",htmlFor:"bio",children:["Your bio",(0,r.jsx)("div",{className:"text-xs text-neutral-600",children:"Escreva um pouco sobre voc\xea e sua rela\xe7\xe3o com a cultura e a l\xedngua chinesa."})]}),(0,r.jsx)("textarea",{className:"font-inherit bg-slate-50 rounded-sm border-[1px] border-white w-full p-1 text-center outline-stone-400/40",type:"text",id:"bio",ref:j,defaultValue:"",required:!0,rows:3,onFocus:()=>x("bio")})]}),(0,r.jsxs)("div",{className:"p-4 duration-700"+("favHanzi"===m?" bg-orange-200/50":""),children:[(0,r.jsxs)("label",{className:"flex items-center w-full flex-col font-bold mb-1",htmlFor:"favHanzi",children:["Your favorite Chinese characters",(0,r.jsx)("div",{className:"text-xs text-neutral-600 md:max-w-[70%]",children:"Escreva os hanzis ou palavras em chin\xeas que voc\xea mais adora. Eles ser\xe3o usados para personalizar a sua experi\xeancia no Bihua (de 1 a 6 itens, separados por v\xedrgula)"})]}),(0,r.jsx)("input",{className:"font-inherit bg-slate-50 rounded-sm border-[1px] border-white w-full p-1 text-center outline-stone-400/40 font-kaiti text-xl",type:"text",id:"favHanzi",ref:w,required:!0,onFocus:()=>x("favHanzi")})]}),(0,r.jsxs)("div",{className:"p-4 duration-700"+("email"===m?" bg-orange-200/50":""),children:[(0,r.jsxs)("label",{className:"block font-bold mb-1",htmlFor:"email",children:["Your Email",(0,r.jsx)("div",{className:"text-xs text-neutral-600",children:"Voc\xea n\xe3o pode modificar o e-mail associado ao seu usu\xe1rio."})]}),(0,r.jsx)("input",{className:"font-inherit bg-slate-200 rounded-sm border-[1px] border-slate-200 text-slate-500
1w-full text-center p-1 outline-stone-400/40",type:"email",id:"email",disabled:!0,ref:h,required:!0,onFocus:()=>x("email")})]}),(0,r.jsxs)("div",{className:"p-4 duration-700"+("password"===m?" bg-orange-200/50":""),children:[(0,r.jsxs)("label",{className:"block font-bold mb-1",htmlFor:"password",children:["Your Password",(0,r.jsx)("div",{className:"text-xs text-neutral-600",children:"Voc\xea precisa confirmar sua senha para salvar suas modifica\xe7\xf5es."})]}),(0,r.jsx)("input",{className:"font-inherit bg-slate-50 rounded-sm border-[1px] border-white w-full p-1 text-center outline-stone-400/40",type:"password",id:"password",ref:p,required:!0,onFocus:()=>x("password")})]}),(0,r.jsx)("div",{className:"mt-10 flex flex-col items-center mb-8",children:(0,r.jsx)("button",{className:"cursor-pointer bg-blue-400 border-[1px] border-white rounded-md py-4 px-10 hover:bg-black/10 hover:border-white/80 tracking-wider text-lg",children:"Salvar informa\xe7\xf5es"})})]})]})}),N&&(0,r.jsxs)("div",{className:"fixed top-0 left-0 bottom-0 right-0 h-full w-screen z-[1000] flex items-center justify-center",children:[(0,r.jsx)("div",{className:"overlay bg-black/30 absolute top-0 left-0 h-full w-screen"}),(0,r.jsxs)("div",{className:"bg-slate-200 min-w-[300px] min-h-[150px] flex items-center justify-center flex-col p-6 z-10 rounded-sm",children:[(0,r.jsx)("div",{className:"mb-6 text-center text-slate-900",children:N.split(". ").map((e,t)=>(0,r.jsx)("div",{children:e},t))}),(0,r.jsx)("div",{className:"cursor-pointer min-w-[80px] text-center px-4 py-1 bg-blue-400 rounded-md",onClick:()=>{k(null)},children:"ok!"})]})]})]})})}},6770:function(e){(()=>{"use strict";var t={d:(e,a)=>{for(var r in a)t.o(a,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:a[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},a={};t.r(a),t.d(a,{default:()=>s});var r=function(){var e;function t(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t)}return e=[{key:"changeHeightWidth",value:function(e,t,a,r,s,n){return a>r&&(e=Math.round(e*r/a),a=r),e>t&&(a=Math.round(a*t/e),e=t),s&&a<s&&(e=Math.round(e*s/a),a=s),n&&e<n&&(a=Math.round(a*n/e),e=n),{height:e,width:a}}},{key:"resizeAndRotateImage",value:function(e,t,a,r,s){var n=arguments.length>5&&void 0!==arguments[5]?arguments[5]:"jpeg",i=arguments.length>6&&void 0!==arguments[6]?arguments[6]:100,l=arguments.length>7&&void 0!==arguments[7]?arguments[7]:0,o=document.createElement("canvas"),u=e.width,c=e.height,d=this.changeHeightWidth(c,a,u,t,r,s);l&&(90===l||270===l)?(o.width=d.height,o.height=d.width):(o.width=d.width,o.height=d.height),u=d.width,c=d.height;var m=o.getContext("2d");return m.fillStyle="rgba(0, 0, 0, 0)",m.fillRect(0,0,u,c),m.imageSmoothingEnabled&&m.imageSmoothingQuality&&(m.imageSmoothingQuality="high"),l&&(m.rotate(l*Math.PI/180),90===l?m.translate(0,-o.width):180===l?m.translate(-o.width,-o.height):270===l?m.translate(-o.height,0):0!==l&&360!==l||m.translate(0,0)),m.drawImage(e,0,0,u,c),o.toDataURL("image/".concat(n),i/100)}},{key:"b64toByteArrays",value:function(e,t){t=t||"image/jpeg";for(var a=atob(e.toString().replace(/^data:image\/(png|jpeg|jpg|webp);base64,/,"")),r=[],s=0;s<a.length;s+=512){for(var n=a.slice(s,s+512),i=Array(n.length),l=0;l<n.length;l++)i[l]=n.charCodeAt(l);var o=new Uint8Array(i);r.push(o)}return r}},{key:"b64toBlob",value:function(e,t){var a=this.b64toByteArrays(e,t);return new Blob(a,{type:t,lastModified:new Date})}},{key:"b64toFile",value:function(e,t,a){var r=this.b64toByteArrays(e,a);return new File(r,t,{type:a,lastModified:new Date})}},{key:"createResizedImage",value:function(e,a,r,s,n,i,l){var o=arguments.length>7&&void 0!==arguments[7]?arguments[7]:"base64",u=arguments.length>8&&void 0!==arguments[8]?arguments[8]:null,c=arguments.length>9&&void 0!==arguments[9]?arguments[9]:null,d=new FileReader;if(!e)throw Error("File Not Found!");if(e.type&&!e.type.includes("image"))throw Error("File Is NOT Image!");d.readAsDataURL(e),d.onload=function(){var m=new Image;m.src=d.result,m.onload=function(){var d=t.resizeAndRotateImage(m,a,r,u,c,s,n,i),x="image/".concat(s);switch(o){case"blob":l(t.b64toBlob(d,x));break;case"base64":default:l(d);break;case"file":var f=e.name.toString().replace(/(png|jpeg|jpg|webp)$/i,"").concat(s.toString());l(t.b64toFile(d,f,x))}}},d.onerror=function(e){throw Error(e)}}}],function(e,t){for(var a=0;a<t.length;a++){var r=t[a];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(t,e),t}();let s={imageFileResizer:function(e,t,a,s,n,i,l,o,u,c){return r.createResizedImage(e,t,a,s,n,i,l,o,u,c)}};e.exports=a})()}},function(e){e.O(0,[2013,4617,31,3598,9774,2888,179],function(){return e(e.s=9153)}),_N_E=e.O()}]);
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.