1 line
9.6 KiB
JavaScript
1 line
9.6 KiB
JavaScript
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[645],{995:(e,t,s)=>{"use strict";s.r(t),s.d(t,{default:()=>d});var r=s(95155),a=s(12115),i=s(35695),l=s(12108),o=s(6874),c=s.n(o),n=s(87481);function d(){let{data:e,status:t}=(0,l.useSession)(),s=(0,i.useRouter)(),[o,d]=(0,a.useState)([]),[u,h]=(0,a.useState)(!0),[p,x]=(0,a.useState)(null),[b,f]=(0,a.useState)(!1),[m,g]=(0,a.useState)("all");(0,a.useEffect)(()=>{"loading"!==t&&(e||s.push("/admin/login"))},[e,t,s]),(0,a.useEffect)(()=>{let t=async()=>{try{let e=await fetch("/api/faq");if(!e.ok)throw Error("Failed to fetch FAQs");let t=await e.json();d(t)}catch(e){console.error("Error fetching FAQs:",e),(0,n.o)({title:"Error",description:"Failed to load FAQs",status:"error"})}finally{h(!1)}};e&&t()},[e]);let y=async e=>{if(confirm("Are you sure you want to delete this FAQ?"))try{if(!(await fetch("/api/faq/".concat(e),{method:"DELETE"})).ok)throw Error("Failed to delete FAQ");let t=async()=>{try{let e=await fetch("/api/faq");if(!e.ok)throw Error("Failed to fetch FAQs");let t=await e.json();d(t)}catch(e){console.error("Error fetching FAQs:",e)}};await t(),(0,n.o)({title:"Success",description:"FAQ deleted successfully",status:"success"})}catch(e){console.error("Error deleting FAQ:",e),(0,n.o)({title:"Error",description:"Failed to delete FAQ",status:"error"})}},w=async e=>{if(e.preventDefault(),p)try{let e;if(!(e=p.id?await fetch("/api/faq/".concat(p.id),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(p)}):await fetch("/api/faq",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(p)})).ok){let t=await e.json();throw Error(t.error||"Failed to save FAQ")}let t=async()=>{try{let e=await fetch("/api/faq");if(!e.ok)throw Error("Failed to fetch FAQs");let t=await e.json();d(t)}catch(e){console.error("Error fetching FAQs:",e)}};await t(),f(!1),x(null),(0,n.o)({title:"Success",description:"FAQ saved successfully",status:"success"})}catch(e){console.error("Error saving FAQ:",e),(0,n.o)({title:"Error",description:"Failed to save FAQ",status:"error"})}},j=async(e,t)=>{let s=o.findIndex(t=>t.id===e);if(-1===s)return;let r=[...o],a="up"===t?s-1:s+1;if(!(a<0)&&!(a>=o.length)){[r[s],r[a]]=[r[a],r[s]],r.forEach((e,t)=>e.order=t);try{let e=r.map(e=>fetch("/api/faq/".concat(e.id),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}));await Promise.all(e);let t=async()=>{try{let e=await fetch("/api/faq");if(!e.ok)throw Error("Failed to fetch FAQs");let t=await e.json();d(t)}catch(e){console.error("Error fetching FAQs:",e)}};await t()}catch(e){console.error("Error reordering FAQs:",e),(0,n.o)({title:"Error",description:"Failed to reorder FAQs",status:"error"})}}},A=async e=>{try{let t=o.find(t=>t.id===e);if(!t)return;let s={...t,published:!t.published};if(!(await fetch("/api/faq/".concat(e),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)})).ok)throw Error("Failed to update FAQ");let r=async()=>{try{let e=await fetch("/api/faq");if(!e.ok)throw Error("Failed to fetch FAQs");let t=await e.json();d(t)}catch(e){console.error("Error fetching FAQs:",e)}};await r(),(0,n.o)({title:"Success",description:"FAQ ".concat(s.published?"published":"unpublished"," successfully"),status:"success"})}catch(e){console.error("Error updating FAQ:",e),(0,n.o)({title:"Error",description:"Failed to update FAQ",status:"error"})}},N=["all",...Array.from(new Set(o.map(e=>"General")))],S="all"===m?o:o.filter(e=>"General"===m);return"loading"===t||u?(0,r.jsx)("div",{className:"min-h-screen bg-bg-dark flex items-center justify-center",children:(0,r.jsx)("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-accent"})}):(0,r.jsxs)("div",{className:"min-h-screen bg-bg-dark",children:[(0,r.jsx)("header",{className:"bg-bg-light border-b border-bg-light/50",children:(0,r.jsxs)("div",{className:"max-w-7xl mx-auto px-6 py-4 flex items-center justify-between",children:[(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsx)(c(),{href:"/admin",className:"text-text-muted hover:text-white",children:"← Back"}),(0,r.jsx)("h1",{className:"text-2xl font-bold text-white",children:"Manage FAQs"})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsx)("select",{value:m,onChange:e=>g(e.target.value),className:"px-3 py-2 bg-bg-dark border border-bg-light rounded focus:border-accent focus:outline-none",children:N.map(e=>(0,r.jsx)("option",{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))}),(0,r.jsx)("button",{onClick:()=>{x({id:"",question:"",answer:"",order:o.length,published:!0,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}),f(!0)},className:"bg-accent text-bg-dark px-4 py-2 rounded hover:bg-accent/90 transition-colors",children:"Add New FAQ"})]})]})}),(0,r.jsx)("main",{className:"max-w-7xl mx-auto px-6 py-8",children:(0,r.jsx)("div",{className:"space-y-4",children:S.sort((e,t)=>e.order-t.order).map((e,t)=>(0,r.jsx)("div",{className:"bg-bg-light rounded-lg p-6",children:(0,r.jsxs)("div",{className:"flex items-start justify-between",children:[(0,r.jsxs)("div",{className:"flex-grow",children:[(0,r.jsx)("h3",{className:"text-lg font-semibold text-white mb-2",children:e.question}),(0,r.jsx)("p",{className:"text-text-muted mb-3",children:e.answer}),(0,r.jsxs)("div",{className:"flex items-center space-x-4 text-sm",children:[(0,r.jsx)("span",{className:"px-2 py-1 bg-bg-dark rounded",children:"General"}),(0,r.jsx)("span",{className:e.published?"text-green-400":"text-yellow-400",children:e.published?"Published":"Draft"})]})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2 ml-4",children:[(0,r.jsx)("button",{onClick:()=>j(e.id,"up"),disabled:0===t,className:"p-2 text-text-muted hover:text-white disabled:opacity-50",children:"↑"}),(0,r.jsx)("button",{onClick:()=>j(e.id,"down"),disabled:t===S.length-1,className:"p-2 text-text-muted hover:text-white disabled:opacity-50",children:"↓"}),(0,r.jsx)("button",{onClick:()=>A(e.id),className:"px-3 py-1 rounded text-white ".concat(e.published?"bg-yellow-500 hover:bg-yellow-600":"bg-green-500 hover:bg-green-600"),children:e.published?"Unpublish":"Publish"}),(0,r.jsx)("button",{onClick:()=>{x(e),f(!0)},className:"px-3 py-1 bg-blue-500 text-white rounded hover:bg-blue-600",children:"Edit"}),(0,r.jsx)("button",{onClick:()=>y(e.id),className:"px-3 py-1 bg-red-500 text-white rounded hover:bg-red-600",children:"Delete"})]})]})},e.id))})}),b&&p&&(0,r.jsx)("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-6",onClick:e=>{e.target===e.currentTarget&&(f(!1),x(null))},children:(0,r.jsxs)("div",{className:"bg-bg-light rounded-lg p-6 max-w-2xl w-full max-h-[90vh] overflow-y-auto",children:[(0,r.jsx)("h2",{className:"text-2xl font-bold mb-6",children:p.id?"Edit FAQ":"Add New FAQ"}),(0,r.jsxs)("form",{onSubmit:w,className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-sm font-medium mb-2",children:"Question"}),(0,r.jsx)("input",{type:"text",value:p.question,onChange:e=>x({...p,question:e.target.value}),className:"w-full px-3 py-2 bg-bg-dark border border-bg-light rounded focus:border-accent focus:outline-none",required:!0})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-sm font-medium mb-2",children:"Answer"}),(0,r.jsx)("textarea",{value:p.answer,onChange:e=>x({...p,answer:e.target.value}),className:"w-full px-3 py-2 bg-bg-dark border border-bg-light rounded focus:border-accent focus:outline-none",rows:4,required:!0})]}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-sm font-medium mb-2",children:"Order"}),(0,r.jsx)("input",{type:"number",value:p.order,onChange:e=>x({...p,order:parseInt(e.target.value)||0}),className:"w-full px-3 py-2 bg-bg-dark border border-bg-light rounded focus:border-accent focus:outline-none"})]}),(0,r.jsx)("div",{className:"flex items-center",children:(0,r.jsxs)("label",{className:"flex items-center space-x-2",children:[(0,r.jsx)("input",{type:"checkbox",checked:p.published,onChange:e=>x({...p,published:e.target.checked}),className:"w-4 h-4 text-accent bg-bg-dark border-bg-light rounded focus:ring-accent"}),(0,r.jsx)("span",{className:"text-sm",children:"Published"})]})})]}),(0,r.jsxs)("div",{className:"flex justify-end space-x-4 pt-4",children:[(0,r.jsx)("button",{type:"button",onClick:()=>{f(!1),x(null)},className:"px-4 py-2 text-text-muted hover:text-white",children:"Cancel"}),(0,r.jsx)("button",{type:"submit",className:"px-4 py-2 bg-accent text-bg-dark rounded hover:bg-accent/90",children:"Save FAQ"})]})]})]})})]})}},57651:(e,t,s)=>{Promise.resolve().then(s.bind(s,995))},87481:(e,t,s)=>{"use strict";s.d(t,{d:()=>d,o:()=>n});var r=s(12115);let a={ADD_TOAST:"ADD_TOAST",UPDATE_TOAST:"UPDATE_TOAST",DISMISS_TOAST:"DISMISS_TOAST",REMOVE_TOAST:"REMOVE_TOAST"},i=0,l=[],o={toasts:[]};function c(e){o=((e,t)=>{switch(t.type){case a.ADD_TOAST:return{...e,toasts:[t.toast,...e.toasts].slice(0,3)};case a.DISMISS_TOAST:{let{toastId:s}=t;return{...e,toasts:e.toasts.map(e=>e.id===s?{...e,status:"error"}:e)}}case a.REMOVE_TOAST:return{...e,toasts:e.toasts.filter(e=>e.id!==t.toastId)}}})(o,e),l.forEach(e=>{e(o)})}function n(e){var t;let{...s}=e,r=(i=(i+1)%Number.MAX_SAFE_INTEGER).toString();return c({type:a.ADD_TOAST,toast:{...s,id:r,status:null!=(t=s.status)?t:"info",title:s.title,description:s.description,action:s.action}}),{id:r,dismiss:()=>c({type:a.DISMISS_TOAST,toastId:r}),update:e=>c({type:a.UPDATE_TOAST,toast:{...e,id:r}})}}function d(){let[e,t]=r.useState(o);return r.useEffect(()=>(l.push(t),()=>{let e=l.indexOf(t);e>-1&&l.splice(e,1)}),[e]),{...e,toast:n,dismiss:e=>c({type:a.DISMISS_TOAST,toastId:e})}}}},e=>{e.O(0,[874,454,441,964,120],()=>e(e.s=57651)),_N_E=e.O()}]); |