1 line
7.5 KiB
JavaScript
1 line
7.5 KiB
JavaScript
"use strict";(()=>{var e={};e.id=189,e.ids=[189],e.modules={19881:(e,t,s)=>{s.r(t),s.d(t,{config:()=>U,default:()=>E,getServerSideProps:()=>D,getStaticPaths:()=>C,getStaticProps:()=>R,reportWebVitals:()=>I,routeModule:()=>k,unstable_getServerProps:()=>O,unstable_getServerSideProps:()=>W,unstable_getStaticParams:()=>H,unstable_getStaticPaths:()=>F,unstable_getStaticProps:()=>L});var a={};s.r(a),s.d(a,{SettingsContext:()=>A,default:()=>q,getServerSideProps:()=>M});var r=s(63865),i=s(9455),l=s(30671),n=s(49407),o=s(89600),c=s(8732),u=s(82015),d=s.n(u),m=s(95222),p=s(20048),g=s.n(p);s(26295);var h=s(58548),x=s(70045),f=s(79100),j=s(55158),S=s(62506);function w({user:e,image:t,setImage:s}){let a=d().useRef();return(0,c.jsxs)("div",{className:"paper w-full items-center",children:[(0,c.jsx)("h2",{className:"m-0 text-xl",children:"User Image"}),(0,c.jsx)("div",{className:"bg-white rounded-full overflow-hidden w-24 h-24",children:(0,c.jsx)("img",{src:t?"string"==typeof t?t:t.imageBase64Full:"/images/database-placeholder.png",alt:"User Image",width:100,className:"w-full h-full object-cover",ref:a,"data-imagepreview":"image"})}),(0,c.jsxs)("div",{className:"w-full flex-col",id:"upload-user-image-options",children:[(0,c.jsxs)(S.A,{column:!0,className:"w-full",children:[(0,c.jsx)("button",{className:"outlined gray w-full whitespace-normal",onClick:e=>{(0,j.PB)("user-media-popup")},children:"Choose image From your Uploads"}),(0,c.jsx)("button",{className:"secondary w-full whitespace-normal",onClick:e=>{let t=e.target;t.closest("#upload-user-image-options")?.querySelector("input")?.click()},children:(0,c.jsx)("span",{children:"Choose image From your Computer"})})]}),(0,c.jsx)("input",{type:"file",accept:".png,.jpg,.jpeg,.webp",placeholder:"Choose Image",className:"hidden",onChange:async e=>{let t=e.target,a=t?.files?.[0];a&&s(await (0,f.A)({imageInputFile:a,maxWidth:400}))}})]})]})}function v(e){let{user:t,image:s,setImage:a,activeUser:r}=d().useContext(A),[i,l]=d().useState(!1);return(0,c.jsxs)(d().Fragment,{children:[(0,c.jsxs)("div",{className:"flex-col items-start gap-0 w-full",children:[(0,c.jsxs)("div",{className:"w-full flex items-center justify-between",children:[(0,c.jsx)("h1",{className:"text-3xl m-0",children:"Settings"}),(0,c.jsx)("div",{children:!t?.social_login&&(0,c.jsx)("a",{href:"/send-password-reset-link",className:"button outlined",children:"Reset Password"})})]}),(0,c.jsx)(h.A,{user:t})]}),(0,c.jsx)("section",{className:"p-0",children:(0,c.jsxs)("div",{className:"w-full grid grid-cols-1 xl:grid-cols-2 gap-8 items-stretch",children:[(0,c.jsxs)("div",{className:"paper w-full",children:[(0,c.jsx)("h2",{className:"m-0 text-xl",children:"Account Information"}),(0,c.jsxs)("div",{className:"flex flex-row w-full",children:[(0,c.jsx)("span",{children:"USER ID"}),(0,c.jsx)("b",{className:"info w-auto",children:t.id})]}),(0,c.jsx)(x.A,{user:r,image:s})]}),(0,c.jsx)("div",{className:"items-stretch",children:(0,c.jsx)(w,{image:s,setImage:a})})]})}),!1]})}s(32415);var b=s(42105),N=s(41658),_=s.n(N),y=s(67216),P=s.n(y);let A=d().createContext({});function q({user:e,databases:t,activeUser:s}){let a=(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)("title",{children:"User Dashboard | Datasquirel"}),(0,c.jsx)("meta",{name:"description",content:"Welcome to your data app"})]}),[r,i]=d().useState(s.image);return(0,c.jsx)(m.A,{head:a,user:e,children:(0,c.jsxs)(A.Provider,{value:{user:e,image:r,setImage:i,activeUser:s},children:[(0,c.jsx)(v,{}),(0,c.jsx)(b.A,{setDbImage:i})]})})}async function M({req:e,res:t,query:s}){let a=await g()(e,t);if(!a?.logged_in_status)return{redirect:{destination:"/login",permanent:!1}};let r=await _()(`SELECT SCHEMA_NAME AS dbFullName FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME LIKE 'user_${a.id}%'`),i=await P()(`SELECT first_name,last_name,username,email,image,image_thumbnail FROM users WHERE id='${a.id}'`);return{props:{user:a,databases:r,activeUser:i[0]}}}let E=(0,l.M)(a,"default"),R=(0,l.M)(a,"getStaticProps"),C=(0,l.M)(a,"getStaticPaths"),D=(0,l.M)(a,"getServerSideProps"),U=(0,l.M)(a,"config"),I=(0,l.M)(a,"reportWebVitals"),L=(0,l.M)(a,"unstable_getStaticProps"),F=(0,l.M)(a,"unstable_getStaticPaths"),H=(0,l.M)(a,"unstable_getStaticParams"),O=(0,l.M)(a,"unstable_getServerProps"),W=(0,l.M)(a,"unstable_getServerSideProps"),k=new r.PagesRouteModule({definition:{kind:i.A.PAGES,page:"/admin/[user_id]/settings",pathname:"/admin/[user_id]/settings",bundlePath:"",filename:""},components:{App:o.default,Document:n.default},userland:a})},42105:(e,t,s)=>{s.d(t,{A:()=>o});var a=s(8732),r=s(82015),i=s.n(r);s(63715);var l=s(55158),n=s(32415);function o({setDbImage:e}){let[t,s]=i().useState(!0),[r,o]=i().useState(null);return(0,a.jsxs)(l.Ay,{title:"user-media-popup",children:[t&&(0,a.jsx)(n.A,{width:"20px"}),(0,a.jsx)("h4",{className:"m-0 text-lg",children:"Your Uploaded Images"}),(0,a.jsx)("div",{className:"grid grid-cols-2",children:r&&r[0]&&r.filter(e=>"image"==e.media_type).map((t,s)=>(0,a.jsx)("div",{className:"w-full h-44 cursor-pointer hover:opacity-70",onClick:s=>{e(t.media_thumbnail_url||null),(0,l.fs)()},children:(0,a.jsx)("img",{src:t.media_thumbnail_url,alt:"User Media",className:"w-full h-full object-contain"})},s+1))})]})}s(64417)},79100:(e,t,s)=>{s.d(t,{A:()=>a});async function a({imageInputFile:e,maxWidth:t}){let s,a,r=document.querySelector("[data-imagepreview='image']"),i=e.name.replace(/\..*/,""),l=document.createElement("canvas"),n=e.type,o=t||null,c=URL.createObjectURL(e),u=new Image;return u.src=c,s=await new Promise((e,t)=>{u.onerror=function(){URL.revokeObjectURL(this.src),console.log("Cannot load image")},u.onload=function(){if(URL.revokeObjectURL(this.src),o){let e=o/u.naturalWidth;l.width=u.naturalWidth<o?u.naturalWidth:o,l.height=u.naturalWidth<o?u.naturalHeight:u.naturalHeight*e}else l.width=u.naturalWidth,l.height=u.naturalHeight;let t=l.getContext("2d");t?.drawImage(u,0,0,l.width,l.height);let s=l.toDataURL(n,.95);r&&document.querySelectorAll("[data-imagepreview='image']").forEach(e=>{e.src=s}),e(s)}}),a=await new Promise((e,t)=>{l.toBlob(t=>{e(t?.size)},n,.95)}),{imageBase64:s.replace(/.*?base64,/,""),imageBase64Full:s,imageName:i,imageSize:a}}},41658:(e,t,s)=>{let a=s(29021),r=s(22373),i=s(13608);e.exports=async function(e){let t;"production".match(/dev/)&&a.appendFileSync("./.tmp/sqlQuery.sql",e+"\n"+Date()+"\n\n\n","utf8");try{t=await i(e)}catch(e){r({component:"noDatabaseDbHandler",message:e.message}),console.log("ERROR in noDatabaseDbHandler =>",e.message)}return t||null}},13608:(e,t,s)=>{let a=s(9973),r=s(31976),i=a({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,charset:"utf8mb4",ssl:r()}});e.exports=function(...e){try{return new Promise((t,s)=>{i.query(...e).then(e=>{i.end(),t(JSON.parse(JSON.stringify(e)))}).catch(e=>{i.end(),t({error:e.message,sql:e.sql})})})}catch(e){return{success:!1,error:e.message}}}},27825:e=>{e.exports=require("lodash")},40361:e=>{e.exports=require("next/dist/compiled/next-server/pages.runtime.prod.js")},27912:e=>{e.exports=require("next/head")},82015:e=>{e.exports=require("react")},22326:e=>{e.exports=require("react-dom")},1976:e=>{e.exports=require("react-dom/client")},8732:e=>{e.exports=require("react/jsx-runtime")},9973:e=>{e.exports=require("serverless-mysql")},79428:e=>{e.exports=require("buffer")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},81630:e=>{e.exports=require("http")},33873:e=>{e.exports=require("path")}};var t=require("../../../webpack-runtime.js");t.C(e);var s=e=>t(t.s=e),a=t.X(0,[883,9821,9600,7070,3737,8613,3460,2414,3247,45],()=>s(19881));module.exports=a})(); |