2025-01-14 07:24:54 +00:00
|
|
|
"use strict";exports.id=194,exports.ids=[194],exports.modules={61347:(e,a,t)=>{let l;t.d(a,{A:()=>h});var s=t(8732),i=t(82015),d=t.n(i),n=t(24872),r=t(10621),c=t(46169),u=t(72390);async function o({e,setLoading:a,dbImage:t,database:l,user:s}){a(!0);let i={db_description:e.target.database_description?.value?.match(/./)?e.target.database_description.value:null,db_name:e.target.database_name?.value?.match(/./)?e.target.database_name.value:null,db_slug:e.target.database_slug?.value?.match(/./)?e.target.database_slug.value:null,db_full_name:l.db_full_name,id:l.id,active_clone:l.active_clone,active_clone_parent_db:l.active_clone_parent_db};if(t){if("string"==typeof t)i.db_image=t;else if("object"==typeof t){let e=await (0,c.A)("/api/addUserMedia",{method:"post",body:{media:[t],folder:i.db_slug.replace(/_/g,"-"),type:"image"}},!0);i.db_image=e?.mediaData[0]?.media_thumbnail_url?e.mediaData[0].media_thumbnail_url:"/images/database-placeholder.png"}}else i.db_image="/images/database-placeholder.png";(0,c.A)("/api/updateUserDatabase",{method:"post",body:i},!0).then(e=>{e.success?(0,u.A)().then(()=>{window.location.pathname=`/admin/${s?.id}/databases`,setTimeout(()=>{a(!1)},1e3)}):(alert("Error! Please Try Again"),setTimeout(()=>{a(!1)},1e3))})}var m=t(76102);let p=t.n(m)().fetch.fetchApi;async function b({e,setLoading:a,dbImage:t,keepUpdated:l,keepDataUpdated:s,query:i,user:d}){a(!0);let n={db_name:e.target.database_name.value,db_slug:e.target.database_slug.value,db_description:e.target.database_description?.value?.match(/./)?e.target.database_description.value:null};if(t){if("string"==typeof t)n.db_image=t;else if("object"==typeof t){let e=await p("/api/addUserMedia",{method:"post",body:{media:[t],folder:n.db_slug.replace(/_/g,"-"),type:"image"}},!0);n.db_image=e?.mediaData[0]?.media_thumbnail_url?e.mediaData[0].media_thumbnail_url:"/images/database-placeholder.png"}}i?.duplicate&&(n.duplicate=i.duplicate,n.keepUpdated=!!l&&l,n.keepDataUpdated=!!s&&s),p("/api/createUserDatabase",{method:"POST",body:n},!0).then(e=>{e.success?(0,u.A)().then(()=>{window.location.pathname=`/admin/${d?.id}/databases/${n.db_slug}`}):setTimeout(()=>{a(!1)},1e3)})}var g=t(2913);function h({user:e,dbImage:a,setDbImage:t,database:i,setLoading:c,query:u}){async function m(a){return i?.db_slug===a?null:await (0,n.A)({tableName:"user_databases",columnName:"db_slug",value:a,userId:e.id})}let[p,h]=d().useState(null),[f,_]=d().useState(!1),[x,w]=d().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:t=>{t.preventDefault(),i?o({e:t,setLoading:c,dbImage:a,database:i,user:e}):b({e:t,setLoading:c,dbImage:a,keepUpdated:f,keepDataUpdated:x,query:u,user:e})},children:[p&&(0,s.jsx)(r.A,{message:p}),(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"),h(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(()=>{m(e).then(e=>{e?.result?(t.database_slug.classList.add("warning"),h("Duplicate Database Name")):(t.database_slug.classList.remove("warning"),h(null))})},300)}},defaultValue:i?i.db_name:"",required:!0})]}),(0,s.jsxs)("div",{className:"flex flex-col items-start gap-0.5 w-full",children:[(0,s.jsx)("label",{htmlFor:"database_slug",children:"Slug"}),(0,s.jsx)("input",{type:"text",name:"database_slug",id:"database_slug",placeholder:"Database Slug",onInput:e=>{let a=e.target;a.value.match(/./)?(a.classList.remove("warning"),h(null)):a.classList.add("warning");let t=a.value;window.clearTimeout(l),l=setTimeout(()=>{m(t).then(e=>{e?.result?(a.classList.add("warning"),h("Duplicate Database Name")):(a.classList.remove("warning"),h(null))})},300)},defaultValue:i?i.db_slug:"
|