turboci-admin/dist/web/static/chunks/pages/admin/settings-f58d63b2752f72a6.js
2026-03-12 14:56:39 +01:00

1 line
10 KiB
JavaScript

(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[577],{48051:function(e,t,a){(window.__NEXT_P=window.__NEXT_P||[]).push(["/admin/settings",function(){return a(45913)}])},45913:function(e,t,a){"use strict";a.r(t),a.d(t,{__N_SSP:function(){return _},default:function(){return C}});var l=a(85893),n=a(33028),r=a(60705),s=a(60),i=a(67294),o=a(5606),c=a(79265),u=a(94495),d=a(62190),m=a(73682),g=a(6531),h=a(3668),f=a(57493);async function p(e){let{imageInput:t,maxWidth:a,mimeType:l,file:n}=e;try{var r;let e;let s=n||(null==t?void 0:null===(r=t.files)||void 0===r?void 0:r[0]);if(!s)throw Error("No Files found");let i=s.name.replace(/\..*/,""),o=l||s.type,c=a||null,u=URL.createObjectURL(s),d=new Image;return d.src=u,{imageBase64:null==(e=await new Promise((e,t)=>{d.onerror=function(){URL.revokeObjectURL(this.src),window.alert("Cannot load image!")},d.onload=function(){URL.revokeObjectURL(d.src);let t=document.createElement("canvas");if(c){let e=c/d.naturalWidth;t.width=d.naturalWidth<c?d.naturalWidth:c,t.height=d.naturalWidth<c?d.naturalHeight:d.naturalHeight*e}else t.width=d.naturalWidth,t.height=d.naturalHeight;let a=t.getContext("2d");null==a||a.drawImage(d,0,0,t.width,t.height);let l=t.toDataURL(o,.95);e(l)}}))?void 0:e.replace(/.*?base64,/,""),imageBase64Full:e,imageName:i,imageType:o}}catch(e){return console.log("Image Processing Error! =>",e.message),{imageBase64:void 0,imageBase64Full:void 0,imageName:void 0}}}var x=a(98388),y=a(88584),v=a(77827);function j(e){let{onChangeHandler:t,fileInputProps:a,placeHolderWrapper:n,previewImageWrapperProps:r,previewImageProps:o,label:c,disablePreview:j,existingImageUrl:w,externalSetImage:b,externalSetImages:N,externalImage:k,multiple:Z,restoreImageFn:_,setLoading:C,setImgURL:I,...S}=e,[E,U]=i.useState(k),[R,L]=i.useState(w),F=i.useRef(null),O=i.useRef("");return i.useEffect(()=>{null==I||I(R)},[R]),i.useEffect(()=>{w&&L(w)},[w]),(0,l.jsxs)(s.Z,{...S,className:(0,x.m6)("w-full h-[300px] overflow-hidden",null==S?void 0:S.className),children:[(0,l.jsx)("input",{type:"file",className:(0,x.m6)("hidden",null==a?void 0:a.className),multiple:Z,accept:"image/*",...a,onChange:e=>{null==C||C(!0),Z?(async()=>{let t=e.target.files;if(!(null==t?void 0:t[0]))return;let a=[];for(let e=0;e<t.length;e++){let l=t[e],n=await p({file:l});a.push(n)}null==N||N(a),null==C||C(!1)})():p({imageInput:e.target}).then(l=>{var n;L(l.imageBase64Full),null==t||t(l),null==U||U(l),null==b||b(l),null==a||null===(n=a.onChange)||void 0===n||n.call(a,e),null==C||C(!1)})},ref:F}),R||(null==E?void 0:E.imageBase64Full)?(0,l.jsxs)(g.Z,{className:"w-full relative h-full items-center justify-center",...r,children:[c&&(0,l.jsx)("label",{className:(0,x.m6)("absolute top-0 left-0 text-xs z-50"),children:(0,l.jsx)(y.Z,{color:"gray",children:(0,l.jsx)("span",{className:"opacity-70",children:c})})}),j?(0,l.jsx)(h.Z,{className:"opacity-50",size:"small",children:"Image Uploaded!"}):(0,l.jsx)("img",{src:(null==E?void 0:E.imageBase64Full)||R,className:"w-full h-full object-contain",...o}),(0,l.jsx)("div",{className:(0,x.m6)("absolute p-1 top-2 right-2 z-20 bg-background-light dark:bg-background-dark","cursor-pointer"),onClick:e=>{L(void 0),null==t||t(void 0),null==U||U(void 0),null==b||b(void 0),F.current&&F.current.value},title:"Cancel Image Upload Button",children:(0,l.jsx)(d.Z,{className:"text-slate-950 dark:text-white"})})]}):(0,l.jsx)(g.Z,{className:(0,x.m6)("w-full h-full cursor-pointer hover:bg-slate-100 dark:hover:bg-white/20",null==n?void 0:n.className),onClick:e=>{var t,a;let l=e.target;if(null==l?void 0:l.closest(".cancel-upload")){e.preventDefault();return}null===(t=F.current)||void 0===t||t.click(),null==n||null===(a=n.onClick)||void 0===a||a.call(n,e)},...n,children:(0,l.jsx)(f.Z,{children:(0,l.jsxs)(s.Z,{className:"items-center gap-2",children:[(0,l.jsx)(m.Z,{className:"text-slate-400"}),(0,l.jsx)(h.Z,{size:"smaller",variant:"faded",children:c||"Click to Upload Image"}),(0,l.jsxs)(s.Z,{className:"cancel-upload w-full items-stretch gap-1",children:[(0,l.jsx)(v.Z,{placeholder:"Eg. https://example.com/img.png",className:"text-sm twui-image-url-input",title:"Enter Image URL",wrapperWrapperProps:{className:"mt-2"},changeHandler:e=>{O.current=e},showLabel:!0}),(0,l.jsx)(u.Z,{title:"Restore Image Button",size:"smaller",variant:"outlined",color:"gray",onClick:()=>{O.current&&L(O.current)},children:"Set Image URL"})]}),w&&(0,l.jsx)(u.Z,{title:"Restore Image Button",size:"smaller",variant:"ghost",onClick:()=>{(null==_?void 0:_())||L(w)},className:"cancel-upload",children:"Restore Original Image"})]})})})]})}var w=a(94655),b=a(25808);function N(){let{setToast:e,pageProps:t}=(0,i.useContext)(o.AppContext),{formData:a,setFormData:n,loading:d,setLoading:m,user:g}=function(){let{pageProps:e}=(0,i.useContext)(o.AppContext),{user:t}=e,{loading:a,setLoading:l}=(0,b.Z)(),[n,r]=(0,i.useState)({first_name:(null==t?void 0:t.first_name)||"",last_name:(null==t?void 0:t.last_name)||"",email:(null==t?void 0:t.email)||"",image:(null==t?void 0:t.image)||""});return{formData:n,setFormData:r,loading:a,setLoading:l,user:t}}(),f=t.deployment_user;async function p(){var t;if(null===(t=a.first_name)||void 0===t?void 0:t.match(/./)){m(!0);try{let t=await (0,c.Z)("/api/admin/settings",{method:"POST",body:{new_user:a}});t.success?(e({toastOpen:!0,toastMessage:"Settings saved",toastStyle:"success",closeDelay:3e3}),window.location.reload()):e({toastOpen:!0,toastMessage:t.msg||"Failed to save settings",toastStyle:"error",closeDelay:4e3})}finally{m(!1)}}}return(null==f?void 0:f.id)?(0,l.jsxs)(s.Z,{className:"w-full max-w-[600px] items-stretch gap-6",children:[(0,l.jsxs)(s.Z,{className:"gap-1",children:[(0,l.jsx)(h.Z,{size:"small",variant:"faded",children:"Username"}),(0,l.jsx)(h.Z,{children:(0,l.jsx)("strong",{children:g.super_admin?"root":(null==f?void 0:f.username)||"—"})})]}),(0,l.jsx)(r.Z,{}),(0,l.jsxs)(w.Z,{className:"gap-4 items-stretch",children:[(0,l.jsx)(v.Z,{title:"First Name",placeholder:"Eg. John",value:a.first_name,changeHandler:e=>n(t=>({...t,first_name:e})),required:!0,showLabel:!0}),(0,l.jsx)(v.Z,{title:"Last Name",placeholder:"Eg. Doe",value:a.last_name,changeHandler:e=>n(t=>({...t,last_name:e})),showLabel:!0})]}),(0,l.jsx)(v.Z,{title:"Email",placeholder:"Eg. john@example.com",type:"email",value:a.email,changeHandler:e=>n(t=>({...t,email:e})),required:!0,showLabel:!0}),(0,l.jsx)(j,{label:"Profile Image",existingImageUrl:a.image||void 0,onChangeHandler:e=>{n(t=>({...t,image:(null==e?void 0:e.imageBase64Full)||t.image}))},className:"h-[200px]"}),(0,l.jsx)(u.Z,{title:"Save Settings",loading:d,onClick:p,children:"Save Settings"})]}):null}function k(){return(0,l.jsxs)(i.Fragment,{children:[(0,l.jsx)(n.Z,{title:"Settings",description:"Update your profile information"}),(0,l.jsx)(r.Z,{}),(0,l.jsx)(s.Z,{className:"grid-cell-content",children:(0,l.jsx)(N,{})})]})}var Z=a(89350),_=!0;function C(){return(0,l.jsx)(Z.Z,{children:(0,l.jsx)(k,{})})}},88584:function(e,t,a){"use strict";a.d(t,{Z:function(){return r}});var l=a(85893);a(67294);var n=a(98388);function r(e){let{color:t,variant:a,children:r,href:s,newTab:i,linkProps:o,...c}=e,u=(0,l.jsx)("div",{...c,className:(0,n.m6)("text-xs px-2 py-0.5 rounded-full outline-0","text-center flex items-center justify-center","secondary"==t?"bg-secondary text-white outline-secbg-secondary":"success"==t?"bg-success outline-success text-white":"error"==t?"bg-orange-700 outline-orange-700":"gray"==t?(0,n.m6)("bg-slate-100 outline-slate-200 dark:bg-gray-dark dark:outline-gray-dark","text-slate-800 dark:text-white"):"bg-primary text-white outline-primbg-primary twui-tag-primary","outlined"==a?"!bg-transparent outline-1 "+("secondary"==t?"text-secondary":"success"==t?"text-success dark:text-success-dark":"error"==t?"text-orange-700":"gray"==t?"text-slate-700 dark:text-white/80":"text-primary dark:text-primary-dark twui-tag-primary-outlined"):"ghost"==a?"!bg-transparent outline-none border-none "+("secondary"==t?"text-secondary":"success"==t?"text-success dark:text-success-dark":"error"==t?"text-orange-700":"gray"==t?"text-slate-700 dark:text-white/80":"text-primary dark:text-primary-dark"):"","twui-tag",c.className),children:r});return s?(0,l.jsx)("a",{href:s,target:i?"_blank":void 0,...o,className:(0,n.m6)("hover:opacity-80",null==o?void 0:o.className),children:u}):u}},57493:function(e,t,a){"use strict";a.d(t,{Z:function(){return r}});var l=a(85893),n=a(98388);function r(e){let{...t}=e;return(0,l.jsx)("div",{...t,className:(0,n.m6)("flex flex-col items-center justify-center gap-4 p-2 w-full","h-full twui-center",t.className),children:t.children})}},79265:function(e,t,a){"use strict";a.d(t,{Z:function(){return s}});var l=a(96486),n=a.n(l),r={stringify:function(e,t,a){try{return JSON.stringify(e,t||void 0,a)}catch(e){return}}};async function s(e,t){let a;let l={"Content-Type":"application/json"};(null==t?void 0:t.csrfKey)&&t.csrfValue&&(l[t.csrfKey]=t.csrfValue);let s=e;if((null==t?void 0:t.query)&&(s+=function(e){let t="?";if("object"!=typeof e)return console.log("Invalid Query type"),t;if(Array.isArray(e))return console.log("Query is an Array. This is invalid."),t;if(!e)return console.log("No Query provided."),t;let a=Object.keys(e),l=[];return a.forEach(t=>{if(!t||!e[t])return;let a=e[t];if("object"==typeof a){let e=r.stringify(a);l.push("".concat(t,"=").concat(encodeURIComponent(String(e))))}else"string"==typeof a||"number"==typeof a?l.push("".concat(t,"=").concat(encodeURIComponent(a))):l.push("".concat(t,"=").concat(String(a)))}),t+=l.join("&")}(t.query)),"string"==typeof t)try{a="post"===t?(await fetch(s,{method:t,headers:l})).json():(await fetch(s)).json()}catch(e){console.log("FetchAPI error #1:",e.message),a=null}else if("object"==typeof t)try{let e;if(t.body&&"object"==typeof t.body){let e=n().cloneDeep(t.body);t.body=JSON.stringify(e)}if(t.headers){t.headers=n().merge(t.headers,l);let a={...t};e=await fetch(s,a)}else{let a={...t,headers:l};e=await fetch(s,a)}a=e.json()}catch(e){console.log("FetchAPI error #2:",e.message),a=null}else try{let e=await fetch(s);a=await e.json()}catch(e){console.log("FetchAPI error #3:",e.message),a=null}return a}},9008:function(e,t,a){e.exports=a(23867)}},function(e){e.O(0,[662,75,664,433,7,827,910,888,774,179],function(){return e(e.s=48051)}),_N_E=e.O()}]);