2024-12-08 08:57:48 +00:00
|
|
|
"use strict";exports.id=2996,exports.ids=[2996],exports.modules={55312:(e,a,t)=>{t.d(a,{A:()=>o});var s=t(8732),l=t(82015),i=t.n(l),n=t(32415),r=t(2471);t(27462),t(55158);var d=t(56987),c=t(12042);function o(e){let{user:a,dbImage:t,setDbImage:l,query:o}=i().useContext(r.AddDatabaseContext);if(!a)return(0,s.jsx)(i().Fragment,{});let[u,m]=i().useState(null),[g,p]=i().useState(!1);return(0,s.jsx)("section",{className:"card",children:(0,s.jsxs)("div",{className:"w-full grid grid-cols-1 xl:grid-cols-2 gap-6 items-stretch",children:[g&&(0,s.jsx)(n.A,{}),(0,s.jsxs)("div",{className:"flex-col items-start",children:[(0,s.jsx)("h2",{className:"text-xl m-0 text-left w-full",children:"New Database Information"}),a&&t&&l&&(0,s.jsx)(d.A,{user:a,dbImage:t,setDbImage:l,setLoading:p,query:o})]}),a&&t&&l&&(0,s.jsx)(c.A,{user:a,dbImage:t,setDbImage:l})]})})}},56987:(e,a,t)=>{let s;t.d(a,{A:()=>p});var l=t(8732),i=t(82015),n=t.n(i),r=t(27462),d=t(64535);t(22326);var c=t(63715),o=t(86152);async function u({e,setLoading:a,dbImage:t,database:s,user:l}){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:s.db_full_name,id:s.id,active_clone:s.active_clone,active_clone_parent_db:s.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,o.A)().then(()=>{window.location.pathname=`/admin/${l?.id}/databases`,setTimeout(()=>{a(!1)},1e3)}):(alert("Error! Please Try Again"),setTimeout(()=>{a(!1)},1e3))})}async function m({e,setLoading:a,dbImage:t,keepUpdated:s,keepDataUpdated:l,query:i,user:n}){a(!0);let r={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)r.db_image=t;else if("object"==typeof t){let e=await (0,c.A)("/api/addUserMedia",{method:"post",body:{media:[t],folder:r.db_slug.replace(/_/g,"-"),type:"image"}},!0);r.db_image=e?.mediaData[0]?.media_thumbnail_url?e.mediaData[0].media_thumbnail_url:"/images/database-placeholder.png"}}i?.duplicate&&(r.duplicate=i.duplicate,r.keepUpdated=!!s&&s,r.keepDataUpdated=!!l&&l),(0,c.A)("/api/createUserDatabase",{method:"post",body:r},!0).then(e=>{e.success?(0,o.A)().then(()=>{window.location.pathname=`/admin/${n?.id}/databases/${r.db_slug}`}):setTimeout(()=>{a(!1)},1e3)})}var g=t(58403);function p({user:e,dbImage:a,setDbImage:t,database:i,setLoading:c,query:o}){async function p(a){return i?.db_slug===a?null:await (0,r.A)({tableName:"user_databases",columnName:"db_slug",value:a,userId:e.id})}let[h,b]=n().useState(null),[x,f]=n().useState(!1),[_,w]=n().useState(!1);return(0,l.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?u({e:t,setLoading:c,dbImage:a,database:i,user:e}):m({e:t,setLoading:c,dbImage:a,keepUpdated:x,keepDataUpdated:_,query:o,user:e})},children:[h&&(0,l.jsx)(d.A,{message:h}),(0,l.jsxs)("div",{className:"flex flex-col items-start gap-0.5 w-full",children:[(0,l.jsx)("label",{htmlFor:"database_name",children:"Name"}),(0,l.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"),b(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(s),s=setTimeout(()=>{
|