PageSourceSearch

https://dorihandcraftsfrontend.vercel.app/_next/static/chunks/pages/admin/testimonial-cee15e0bbb5b5d45.js

js dorihandcraftsfrontend.vercel.app collected 2026-10-03 06:48:07 UTC 7,672 bytes, 1 lines download raw bytes

1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[867],{7185:function(e,t,s){(window.__NEXT_P=window.__NEXT_P||[]).push(["/admin/testimonial",function(){return s(64418)}])},64418:function(e,t,s){"use strict";s.r(t),s.d(t,{default:function(){return E}});var a=s(85893),i=s(67294),l=s(11163),n=s(28753),r=s(60970),o=s(54927),m=s(44345),d=s(69216),c=s(72567),u=s(15411),g=s(49281),x=s(55678),h=s(30381),f=s.n(h),p=s(15733),w=s(49346),j=s(9131),v=s(55066),b=s(16310),N=s(62627),y=s(97846);let A=b.Ry({name:b.Z_().required("Name is required"),msg:b.Z_().required("Message is required")}),C=e=>{let{setFieldValue:t,values:s,existingImages:l,previews:n,setPreviews:r,isLoading:o,handleDeleteImage:m}=e;return(0,i.useEffect)(()=>(r([...l.map(e=>e+"?t=".concat(Date.now())),...s.images.map(e=>URL.createObjectURL(e))]),()=>{s.images.forEach(e=>URL.revokeObjectURL(e))}),[s.images,l]),(0,a.jsxs)(v.l0,{className:"flex flex-col gap-4",children:[(0,a.jsx)(y.Z,{name:"name",label:"Customer Name",value:s.name,onChange:e=>t("name",e.target.value)}),(0,a.jsx)(y.Z,{name:"msg",label:"Customer Message",value:s.msg,onChange:e=>t("msg",e.target.value)}),(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsx)("label",{className:"font-semibold",children:"Images"}),(0,a.jsx)("input",{type:"file",accept:"image/*",multiple:!0,className:"border p-2 rounded",onChange:e=>{let a=Array.from(e.target.files||[]);t("images",[...s.images,...a])}}),n.length>0&&(0,a.jsx)("div",{className:"grid grid-cols-3 gap-3 mt-3",children:n.map((e,i)=>(0,a.jsxs)("div",{className:"relative w-24 h-24 group rounded overflow-hidden",children:[(0,a.jsx)("img",{src:e,alt:"Preview ".concat(i),className:"w-24 h-24 object-cover rounded border"}),(0,a.jsx)("button",{type:"button",className:"absolute top-1 right-1 bg-red-600 text-white text-xs w-5 h-5 flex items-center justify-center rounded-full shadow opacity-0 group-hover:opacity-100 transition",onClick:()=>m(i,s,t),children:"✕"})]},i))})]}),(0,a.jsx)("div",{className:"flex justify-end mt-4",children:(0,a.jsx)(N.zx,{type:"submit",disabled:o,className:"bg-[#7B3F00] hover:bg-[#5C3A1E] text-white px-4 py-2 rounded-md",children:o?"Updating...":"Update"})})]})};var _=e=>{let{openDialog:t,setOpenDialog:s,data:l,mutate:r}=e,{mutation:o,isLoading:m}=(0,n.Db)(),[d,c]=(0,i.useState)([]),[u,g]=(0,i.useState)([]);(0,i.useEffect)(()=>{l&&c(Array.isArray(l.images)?l.images:l.image?[l.image]:[])},[l]),(0,i.useEffect)(()=>{g([...d.map(e=>e+"?t=".concat(Date.now()))])},[d]);let h={name:(null==l?void 0:l.name)||"",msg:(null==l?void 0:l.msg)||"",images:[]},f=async e=>{try{let a=new FormData;a.append("name",e.name),a.append("msg",e.msg),e.images.forEach(e=>a.append("images",e)),a.append("existingImages",JSON.stringify(d));let i=await o("testimonial/".concat(l._id),{method:"PUT",body:a,isFormData:!0,isAlert:!1});if((null==i?void 0:i.success)||(null==i?void 0:i.status)===200)x.Am.success("Testimonial updated successfully!"),r(),s(!1),c([]),g([]);else{var t;x.Am.error((null==i?void 0:null===(t=i.results)||void 0===t?void 0:t.msg)||"Failed to update testimonial")}}catch(e){console.error(e),x.Am.error("Something went wrong")}},b=(e,t,s)=>{if(e<d.length)c(d.filter((t,s)=>s!==e));else{let a=e-d.length,i=[...t.images];i.splice(a,1),s("images",i)}};return(0,a.jsxs)(p.Z,{open:t,onClose:()=>s(!1),maxWidth:"sm",fullWidth:!0,children:[(0,a.jsx)(w.Z,{className:"text-lg font-bold text-[#7B3F00]",children:"Edit Testimonial"}),(0,a.jsx)(j.Z,{children:(0,a.jsx)(v.J9,{enableReinitialize:!0,initialValues:h,validationSchema:A,onSubmit:f,children:e=>{let{setFieldValue:t,values:s}=e;return(0,a.jsx)(C,{setFieldValue:t,values:s,existingImages:d,previews:u,setPreviews:g,isLoading:m,handleDeleteImage:b})}})})]})},E=()=>{let e=(0,l.useRouter)(),[t,s]=(0,i.useState)(""),[h,p]=(0,i.useState)(!1),[w,j]=(0,i.useState)(!1),[v,b]=(0,i.useState)(null),{data:N,mutate:y,isValidating:A}=(0,n.YE)("testimonial"),{mutation:C}=(0,n.Db)(),E=(0,i.useMemo)(()=>N?N.filter(e=>e.name.toLowerCase().includes(t.toLowerCase())||e.msg.toLowerCase().includes(t.toLowerCase())).map((e,t)=>{let s=e.images&&e.images.length>0?e.images[0]:"/userDefaultImage.png";return{sl:t+1,_id:e._id,name:e.name,msg:e.msg,img:s+"?t=".concat(Date.now()),createdAt:e.createdAt?f()(e.createdAt).format("DD MMM YYYY, h:mm A"):"-"}}):[],[N,t]),D=async e=>{if(confirm("Are you sure you want to delete this testimonial?"))try{p(!0);let s=await C("testimonial/".concat(e),{method:"DELETE",isAlert:!1});if((null==s?void 0:s.status)===200||(null==s?void 0:s.success))x.Am.success("Testimonial deleted successfully!"),await y();else{var t;x.Am.error((null==s?void 0:null===(t=s.results)||void 0===t?void 0:t.msg)||"Failed to delete testimonial")}}catch(e){console.error(e),x.Am.error("Something went wrong")}finally{p(!1)}},S=e=>{let t=null==N?void 0:N.find(t=>t._id===e._id);t&&(b(t),j(!0))};return(0,a.jsxs)(r.lq,{title:"Testimonial | Admin",children:[v&&(0,a.jsx)(_,{openDialog:w,setOpenDialog:()=>{j(!1),b(null)},data:v,mutate:y}),(0,a.jsxs)("section",{className:"w-full p-5 flex flex-col gap-5",children:[(0,a.jsxs)("div",{className:"flex justify-between items-center mb-2",children:[(0,a.jsx)("h2",{className:"text-xl md:text-2xl font-bold text-[#7B3F00]",children:"Testimonials"}),(0,a.jsxs)("button",{onClick:()=>e.push("/admin/testimonial/create"),className:"flex items-center gap-1 bg-[#7B3F00] px-3 py-1.5 rounded-md cursor-pointer hover:bg-[#5C3A1E] transition-colors",children:[(0,a.jsx)(g.ffM,{className:"text-white text-lg"}),(0,a.jsx)("span",{className:"text-white text-sm font-medium tracking-wider",children:"Add Testimonial"})]})]}),(0,a.jsx)("div",{className:"w-full flex items-center justify-start mb-3",children:(0,a.jsxs)("div",{className:"relative w-[20rem] flex items-center gap-2 bg-white rounded-md px-3 shadow-sm border border-gray-200",children:[(0,a.jsx)(c.y5k,{className:"text-gray-400 text-xl"}),(0,a.jsx)("input",{value:t,onChange:e=>s(e.target.value),type:"text",placeholder:"Search Testimonial...",className:"bg-transparent text-gray-600 p-2 outline-none placeholder:text-gray-400 w-full text-sm"})]})}),(0,a.jsx)(m.ZP,{title:"",isLoading:A||h,components:{Container:e=>(0,a.jsx)(d.Z,{...e,className:"!shadow-none"})},data:E,options:{...(0,o.JH)(),search:!1,exportMenu:[],toolbar:!1,pageSize:10,actionsColumnIndex:-1},columns:[{title:"#",field:"sl",editable:"never",width:"5%"},{title:"Customer Image",field:"img",width:"10%",render:e=>(0,a.jsx)("div",{className:"flex justify-center items-center",children:(0,a.jsx)("img",{src:e.img,alt:e.name,className:"w-12 h-12 rounded-full object-cover border",onError:e=>{"/userDefaultImage.png"!==e.currentTarget.src&&(e.currentTarget.src="/userDefaultImage.png")}})})},{title:"Name",field:"name",width:"20%",render:e=>(0,a.jsx)("p",{className:"text-gray-800 font-medium",children:e.name})},{title:"Message",field:"msg",width:"45%",render:e=>(0,a.jsx)("p",{className:"text-gray-700 text-sm line-clamp-3",children:e.msg})},{title:"Created At",field:"createdAt",width:"20%",render:e=>(0,a.jsx)("p",{className:"text-gray-600 text-xs",children:e.createdAt})},{title:"Action",field:"action",width:"10%",render:e=>(0,a.jsxs)("div",{className:"flex gap-3 justify-center",children:[(0,a.jsx)(g.Hlf,{className:"text-2xl cursor-pointer text-gray-900 hover:text-blue-600 transition",onClick:()=>S(e)}),(0,a.jsx)(u.YK6,{className:"text-2xl cursor-pointer text-red-500 hover:text-red-700 transition",onClick:()=>D(e._id)})]})}]})]})]})}},9008:function(e,t,s){e.exports=s(7828)}},function(e){e.O(0,[5445,6556,5937,9866,1739,8166,955,5062,4885,1664,9169,307,8593,485,5670,970,2888,9774,179],function(){return e(e.s=7185)}),_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.