1import{h as y,d as w,c as C,r as c,j as e,A as v,M as A,S as i}from"./index-rhtSfL_o.js";import{d as g}from"./default-DqreOtmv.js";import{S as T}from"./Spinner-Cw8tp9bk.js";import"./index-C-wprNP5.js";import"./ThemeProvider-DRbeUseU.js";const D=()=>{const{id:u}=y(),m=w(),{adminToken:p}=C(t=>t.auth),[s,x]=c.useState({name:"",occupation:"",message:"",rating:""}),[f,N]=c.useState(null),[b,j]=c.useState(g),[h,l]=c.useState(!1);c.useEffect(()=>{(async()=>{var r,o;l(!0);try{const a=await v.get(`/testimonials/${u}`,{headers:{Authorization:`Bearer ${p}`}});if(a.data.status){const n=a.data.data;x({name:n.name||"",occupation:n.occupation||"",message:n.message||"",rating:n.rating||""}),j(n.avatar?`${A}/${n.avatar.replaceAll("\\","/")}`:g)}}catch(a){i.fire("Error",((o=(r=a.response)==null?void 0:r.data)==null?void 0:o.message)||a.message,"error"),m("/admin/testimonial-list")}finally{l(!1)}})()},[u,p,m]);const d=t=>{const{name:r,value:o}=t.target;x(a=>({...a,[r]:o}))},E=t=>{const r=t.target.files[0];r&&(N(r),j(URL.createObjectURL(r)))},S=async t=>{var r,o;if(t.preventDefault(),!s.name.trim()){i.fire("Error","Name are required","error"),l(!1);return}if(!s.message.trim()){i.fire("Error","Message are required","error"),l(!1);return}if(!s.occupation.trim()){i.fire("Error","Occupation are required","error"),l(!1);return}if(!s.rating||s.rating<1||s.rating>5){i.fire("Error","Rating must be between 1 and 5","error");return}l(!0);try{const a=new FormData;a.append("name",s.name),a.append("occupation",s.occupation),a.append("message",s.message),a.append("rating",s.rating),f&&a.append("avatar",f);const n=await v.put(`/testimonials/${u}`,a,{headers:{Authorization:`Bearer ${p}`,"Content-Type":"multipart/form-data"}});n.data.status?i.fire("Success","Testimonial updated successfully!","success").then(()=>m("/admin/testimonial-list")):i.fire("Error",n.data.message||"Failed to update testimonial","error")}catch(a){i.fire("Error",((o=(r=a.response)==null?void 0:r.data)==null?void 0:o.message)||a.message,"error")}finally{l(!1)}};return e.jsx("section",{className:"tableSection",children:e.jsx("div",{className:"card customCardRes",children:e.jsxs("div",{className:"card-body",children:[e.jsx("div",{className:"d-flex justify-content-between align-items-center flex-wrap mb-3",children:e.jsx("h2",{className:"mb-0",children:"Edit Testimonial"})}),h?e.jsx("div",{className:"text-center p-4",children:e.jsx(T,{})}):e.jsx("form",{onSubmit:S,className:"customForm",children:e.jsxs("div",{className:"row",children:[e.jsx("div",{className:"col-md-4",children:e.jsxs("div",{className:"form-group mb-3 ",children:[e.jsxs("label",{children:["Name ",e.jsx("span",{className:"text-danger",children:"*"})]}),e.jsx("input",{type:"text",name:"name",className:"form-control",value:s.name,onChange:d,placeholder:"Enter name",required:!0})]})}),e.jsx("div",{className:"col-md-4",children:e.jsxs("div",{className:"form-group mb-3",children:[e.jsxs("label",{children:["Occupation",e.jsx("span",{className:"text-danger",children:"*"})]}),e.jsx("input",{type:"text",name:"occupation",className:"form-control",required:!0,value:s.occupation,onChange:d,placeholder:"Enter occupation (e.g. Teacher, Student)"})]})}),e.jsx("div",{className:"col-md-4",children:e.jsxs("div",{className:"form-group mb-3",children:[e.jsxs("label",{children:["Rating (1â5) ",e.jsx("span",{className:"text-danger",children:"*"})]}),e.jsxs("select",{name:"rating",required:!0,className:"form-control form-select",value:s.rating,onChange:d,children:[e.jsx("option",{value:"",children:"Select Rating"}),e.jsx("option",{value:"1",children:"1"}),e.jsx("option",{value:"2",children:"2"}),e.jsx("option",{value:"3",children:"3"}),e.jsx("option",{value:"4",children:"4"}),e.jsx("option",{value:"5",children:"5"})]})]})}),e.jsx("div",{className:"col-md-12",children:e.jsxs("div",{className:"form-group mb-3",children:[e.jsxs("label",{children:["Message ",e.jsx("span",{className:"text-danger",children:"*"})]}),e.jsx("textarea",{name:"message",className:"form-control",value:s.message,onChange:d,rows:"4",placeholder:"Enter testimonial message",required:!0})]})}),e.jsx("div",{className:"col-md-4",children:e.jsxs("div",{className:"form-group mb-3",children:[e.jsxs("label",{children:["Avatar ",e.jsx("small",{children:"( Supported formats: JPG, PNG, GIF, WEBP )"})]}),e.jsx("input",{type:"file",className:"form-control",accept:"image/*",onChange:E}),e.jsx("div",{className:"previewImg mt-3",children:e.jsx("img",{src:b,alt:"Avatar Preview",width:"120",className:"img-thumbnail rounded",onError:t=>{t.target.onerror=null,t.target.src=g}})})]})}),e.jsxs("div",{className:"form-group mt-3 col-12 text-end gap-3",children:[e.jsx("button",{type:"submit",className:"mainbutton me-2",disabled:h,children:h?"Updating...":"Update Testimonial"}),e.jsx("button",{type:"button",className:"secondmainbutton",onClick:()=>m("/admin/testimonial-list"),children:"Cancel"})]})]})})]})})})};export{D as default};
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.