1 line
8.1 KiB
JavaScript
1 line
8.1 KiB
JavaScript
|
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6272],{7168:(e,a,t)=>{let l;t.d(a,{A:()=>g});var s=t(4848),i=t(6540),d=t(8589),n=t(6234),c=t(9020),o=t(65);async function r(e){var a,t,l,s,i,d,n;let{e:r,setLoading:u,dbImage:m,database:p,user:b}=e;u(!0);let g={db_description:(null===(t=r.target.database_description)||void 0===t?void 0:null===(a=t.value)||void 0===a?void 0:a.match(/./))?r.target.database_description.value:null,db_name:(null===(s=r.target.database_name)||void 0===s?void 0:null===(l=s.value)||void 0===l?void 0:l.match(/./))?r.target.database_name.value:null,db_slug:(null===(d=r.target.database_slug)||void 0===d?void 0:null===(i=d.value)||void 0===i?void 0:i.match(/./))?r.target.database_slug.value:null,db_full_name:p.db_full_name,id:p.id,active_clone:p.active_clone,active_clone_parent_db:p.active_clone_parent_db};if(m){if("string"==typeof m)g.db_image=m;else if("object"==typeof m){let e=await (0,c.A)("/api/addUserMedia",{method:"post",body:{media:[m],folder:g.db_slug.replace(/_/g,"-"),type:"image"}},!0);g.db_image=(null==e?void 0:null===(n=e.mediaData[0])||void 0===n?void 0:n.media_thumbnail_url)?e.mediaData[0].media_thumbnail_url:"/images/database-placeholder.png"}}else g.db_image="/images/database-placeholder.png";(0,c.A)("/api/updateUserDatabase",{method:"post",body:g},!0).then(e=>{e.success?(0,o.A)().then(()=>{window.location.pathname="/admin/".concat(null==b?void 0:b.id,"/databases"),setTimeout(()=>{u(!1)},1e3)}):(alert("Error! Please Try Again"),setTimeout(()=>{u(!1)},1e3))})}var u=t(1335);let m=t.n(u)().fetch.fetchApi;async function p(e){var a,t,l;let{e:s,setLoading:i,dbImage:d,keepUpdated:n,keepDataUpdated:c,query:r,user:u}=e;i(!0);let p={db_name:s.target.database_name.value,db_slug:s.target.database_slug.value,db_description:(null===(t=s.target.database_description)||void 0===t?void 0:null===(a=t.value)||void 0===a?void 0:a.match(/./))?s.target.database_description.value:null};if(d){if("string"==typeof d)p.db_image=d;else if("object"==typeof d){let e=await m("/api/addUserMedia",{method:"post",body:{media:[d],folder:p.db_slug.replace(/_/g,"-"),type:"image"}},!0);p.db_image=(null==e?void 0:null===(l=e.mediaData[0])||void 0===l?void 0:l.media_thumbnail_url)?e.mediaData[0].media_thumbnail_url:"/images/database-placeholder.png"}}(null==r?void 0:r.duplicate)&&(p.duplicate=r.duplicate,p.keepUpdated=!!n&&n,p.keepDataUpdated=!!c&&c),m("/api/createUserDatabase",{method:"POST",body:p},!0).then(e=>{e.success?(0,o.A)().then(()=>{window.location.pathname="/admin/".concat(null==u?void 0:u.id,"/databases/").concat(p.db_slug)}):setTimeout(()=>{i(!1)},1e3)})}var b=t(2408);function g(e){let{user:a,dbImage:t,setDbImage:c,database:o,setLoading:u,query:m}=e;async function g(e){return(null==o?void 0:o.db_slug)===e?null:await (0,d.A)({tableName:"user_databases",columnName:"db_slug",value:e,userId:a.id})}let[h,v]=i.useState(null),[f,_]=i.useState(!1),[x,w]=i.useState(!1);return(0,s.jsxs)("form",{className:"w-full max-w-none xl:max-w-lg flex flex-col items-start gap-4 relative",onSubmit:e=>{e.preventDefault(),o?r({e,setLoading:u,dbImage:t,database:o,user:a}):p({e,setLoading:u,dbImage:t,keepUpdated:f,keepDataUpdated:x,query:m,user:a})},children:[h&&(0,s.jsx)(n.A,{message:h}),(0,s.jsxs)("div",{className:"flex flex-col items-start gap-0.5 w-full",children:[(0,s.jsx)("label",{htmlFor:"database_name",children:"Name"}),(0,s.jsx)("input",{type:"text",name:"database_name",id:"database_name",placeholder:"Database Name",onInput:async e=>{let a=e.target,t=a.closest("form");if(a.value.match(/./)?(a.classList.remove("warning"),v(null)):a.classList.add("warning"),t){t.database_slug.value=a.value.toLowerCase().replace(/ /g,"_").replace(/[^a-zA-Z0-9-_]/g,"");let e=t.database_slug.value;window.clearTimeout(l),l=setTimeout(()=>{g(e).then(e=>{(null==e?void 0:e.result)?(t.database_slug.classList.add("warning"),v("Duplicate Database Name")):(t.database_slug.classList.remove("warning"),v(null))})},300)}},defaultValue:o?o.db_name:"",required:!0})]}),(0,s.jsxs)("div",{className:"flex flex-col items-start gap-0.5 w-full",childre
|