1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[7229],{896:function(e,t,a){(window.__NEXT_P=window.__NEXT_P||[]).push(["/dashboard/edit/[slug]",function(){return a(7626)}])},7626:function(e,t,a){"use strict";a.r(t);var n=a(85893),l=a(67294),s=a(11163),r=a(93243),i=a(25675),d=a.n(i);t.default=()=>{let[e,t]=(0,l.useState)({name:"",slug:"",metaTitle:"",metaDescription:"",content:""}),[a,i]=(0,l.useState)(null),[c,o]=(0,l.useState)(""),[u,m]=(0,l.useState)(!1),[p,g]=(0,l.useState)(!1),h=(0,s.useRouter)(),{slug:x}=h.query;(0,l.useEffect)(()=>{x&&(m(!0),fetch("/api/pages?slug=".concat(x)).then(e=>e.json()).then(e=>{e?(e.content=function(e){let t=document.createElement("textarea");t.innerHTML=e;let a=t.value;return(a=(a=a.replace(/<br\s*\/?>/gi,"")).replace(/ /g," ")).replace(/<!--.*?-->/g,"")}(e.content),t(e),o(e.metaImage||"")):console.error("No data found for the given slug.")}).catch(e=>console.error("Error fetching page:",e)).finally(()=>m(!1)))},[x]),(0,l.useEffect)(()=>{p||(()=>{if(window.Laraberg&&window.wp){window.Laraberg.init("LarabergId",{height:"600px",showBlockInserter:!0});let t=document.getElementById("LarabergId");t&&setTimeout(()=>{t.innerHTML=e.content||"",g(!0)},1e3)}})()},[e.content,p]);let handleSubmit=async t=>{if(t.preventDefault(),!p){alert("Editor is not fully initialized yet. Please wait and try again.");return}try{let t=document.getElementById("LarabergId"),n=t.innerHTML,l={...e,content:n},s=new FormData;s.append("id",e._id),s.append("name",l.name),s.append("slug",l.slug),s.append("content",l.content),s.append("metaTitle",l.metaTitle),s.append("metaDescription",l.metaDescription),a?s.append("metaImage",a):s.append("existingMetaImage",c),m(!0);let r=await fetch("/api/pages",{method:"PUT",body:s});if(r.ok)alert("Page updated successfully"),h.push("/all-pages");else{let e=await r.text();console.error("Failed to update page:",e),alert("Failed to update page. Please try again later.")}}catch(e){console.error("Error during submission:",e),alert("Failed to update page. Please try again later.")}finally{m(!1)}};return(0,n.jsx)(r.default,{children:(0,n.jsx)("div",{className:"container mx-auto px-4",children:u?(0,n.jsx)("p",{children:"Loading..."}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("h1",{className:"text-2xl font-bold mb-4",children:"Edit Page"}),(0,n.jsxs)("form",{onSubmit:handleSubmit,children:[(0,n.jsxs)("div",{className:"mb-4",children:[(0,n.jsx)("label",{children:"Page Name"}),(0,n.jsx)("input",{type:"text",value:e.name,onChange:a=>t({...e,name:a.target.value}),required:!0,className:"w-full p-2 border"})]}),(0,n.jsxs)("div",{className:"mb-4",children:[(0,n.jsx)("label",{children:"Slug"}),(0,n.jsx)("input",{type:"text",value:e.slug,onChange:a=>t({...e,slug:a.target.value}),required:!0,className:"w-full p-2 border"})]}),(0,n.jsxs)("div",{className:"mb-6",children:[(0,n.jsx)("label",{htmlFor:"content",className:"block font-medium mb-2",children:"Content*"}),(0,n.jsx)("textarea",{id:"LarabergId",hidden:!0,defaultValue:e.content})]}),(0,n.jsxs)("div",{className:"mb-4",children:[(0,n.jsx)("label",{children:"Meta Title"}),(0,n.jsx)("input",{type:"text",value:e.metaTitle,onChange:a=>t({...e,metaTitle:a.target.value}),required:!0,className:"w-full p-2 border"})]}),(0,n.jsxs)("div",{className:"mb-4",children:[(0,n.jsx)("label",{children:"Meta Description"}),(0,n.jsx)("textarea",{value:e.metaDescription,onChange:a=>t({...e,metaDescription:a.target.value}),required:!0,className:"w-full p-2 border"})]}),(0,n.jsxs)("div",{className:"mb-4",children:[(0,n.jsx)("label",{children:"Meta Image"}),(0,n.jsx)("input",{type:"file",onChange:e=>{i(e.target.files[0])},className:"w-full p-2 border"}),c&&(0,n.jsxs)("div",{className:"mt-4",children:[(0,n.jsx)("p",{children:"Existing Image:"}),(0,n.jsx)(d(),{width:40,height:40,src:c,alt:"Existing Meta",className:"w-48 h-auto"})]})]}),(0,n.jsx)("button",{type:"submit",className:"bg-blue-500 text-white py-2 px-4 rounded",disabled:u,children:"Update Page"})]})]})})})}}},function(e){e.O(0,[2016,8227,3058,3243,9774,2888,179],function(){return e(e.s=896)}),_N_E=e.O()}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.