1 line
12 KiB
JavaScript
1 line
12 KiB
JavaScript
|
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3867],{7168:(e,a,t)=>{let l;t.d(a,{A:()=>g});var s=t(4848),i=t(6540),n=t(8589),d=t(6234),o=t(9020),r=t(65);async function c(e){var a,t,l,s,i,n,d;let{e:c,setLoading:u,dbImage:m,database:p,user:h}=e;u(!0);let g={db_description:(null===(t=c.target.database_description)||void 0===t?void 0:null===(a=t.value)||void 0===a?void 0:a.match(/./))?c.target.database_description.value:null,db_name:(null===(s=c.target.database_name)||void 0===s?void 0:null===(l=s.value)||void 0===l?void 0:l.match(/./))?c.target.database_name.value:null,db_slug:(null===(n=c.target.database_slug)||void 0===n?void 0:null===(i=n.value)||void 0===i?void 0:i.match(/./))?c.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,o.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===(d=e.mediaData[0])||void 0===d?void 0:d.media_thumbnail_url)?e.mediaData[0].media_thumbnail_url:"/images/database-placeholder.png"}}else g.db_image="/images/database-placeholder.png";(0,o.A)("/api/updateUserDatabase",{method:"post",body:g},!0).then(e=>{e.success?(0,r.A)().then(()=>{window.location.pathname="/admin/".concat(null==h?void 0:h.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:n,keepUpdated:d,keepDataUpdated:o,query:c,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(n){if("string"==typeof n)p.db_image=n;else if("object"==typeof n){let e=await m("/api/addUserMedia",{method:"post",body:{media:[n],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==c?void 0:c.duplicate)&&(p.duplicate=c.duplicate,p.keepUpdated=!!d&&d,p.keepDataUpdated=!!o&&o),m("/api/createUserDatabase",{method:"POST",body:p},!0).then(e=>{e.success?(0,r.A)().then(()=>{window.location.pathname="/admin/".concat(null==u?void 0:u.id,"/databases/").concat(p.db_slug)}):setTimeout(()=>{i(!1)},1e3)})}var h=t(2408);function g(e){let{user:a,dbImage:t,setDbImage:o,database:r,setLoading:u,query:m}=e;async function g(e){return(null==r?void 0:r.db_slug)===e?null:await (0,n.A)({tableName:"user_databases",columnName:"db_slug",value:e,userId:a.id})}let[b,f]=i.useState(null),[v,x]=i.useState(!1),[_,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(),r?c({e,setLoading:u,dbImage:t,database:r,user:a}):p({e,setLoading:u,dbImage:t,keepUpdated:v,keepDataUpdated:_,query:m,user:a})},children:[b&&(0,s.jsx)(d.A,{message:b}),(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"),f(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"),f("Duplicate Database Name")):(t.database_slug.classList.remove("warning"),f(null))})},300)}},defaultValue:r?r.db_name:"",required:!0})]}),(0,s.jsxs)("div",{className:"flex flex-col items-start gap-0.5 w-full",childre
|