1 line
10 KiB
JavaScript
1 line
10 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 a=s(95155),r=s(12115),i=s(35695),n=s(12108),l=s(87481),c=s(32941),o=s(49903);function d(){let{data:e,status:t}=(0,n.useSession)(),s=(0,i.useRouter)(),[d,h]=(0,r.useState)([]),[u,p]=(0,r.useState)(!0),[m,x]=(0,r.useState)(null),[f,g]=(0,r.useState)(!1),[y,b]=(0,r.useState)("all");(0,r.useEffect)(()=>{"loading"!==t&&(e||s.push("/admin/login"))},[e,t,s]),(0,r.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();h(t)}catch(e){console.error("Error fetching FAQs:",e),(0,l.o)({title:"Error",description:"Failed to load FAQs",status:"error"})}finally{p(!1)}};e&&t()},[e]);let j=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();h(t)}catch(e){console.error("Error fetching FAQs:",e)}};await t(),(0,l.o)({title:"Success",description:"FAQ deleted successfully",status:"success"})}catch(e){console.error("Error deleting FAQ:",e),(0,l.o)({title:"Error",description:"Failed to delete FAQ",status:"error"})}},w=async e=>{if(e.preventDefault(),m)try{let e;if(!(e=m.id?await fetch("/api/faq/".concat(m.id),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(m)}):await fetch("/api/faq",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(m)})).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();h(t)}catch(e){console.error("Error fetching FAQs:",e)}};await t(),g(!1),x(null),(0,l.o)({title:"Success",description:"FAQ saved successfully",status:"success"})}catch(e){console.error("Error saving FAQ:",e),(0,l.o)({title:"Error",description:"Failed to save FAQ",status:"error"})}},A=async(e,t)=>{let s=d.findIndex(t=>t.id===e);if(-1===s)return;let a=[...d],r="up"===t?s-1:s+1;if(!(r<0)&&!(r>=d.length)){[a[s],a[r]]=[a[r],a[s]],a.forEach((e,t)=>e.order=t);try{let e=a.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();h(t)}catch(e){console.error("Error fetching FAQs:",e)}};await t()}catch(e){console.error("Error reordering FAQs:",e),(0,l.o)({title:"Error",description:"Failed to reorder FAQs",status:"error"})}}},v=async e=>{try{let t=d.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 a=async()=>{try{let e=await fetch("/api/faq");if(!e.ok)throw Error("Failed to fetch FAQs");let t=await e.json();h(t)}catch(e){console.error("Error fetching FAQs:",e)}};await a(),(0,l.o)({title:"Success",description:"FAQ ".concat(s.published?"published":"unpublished"," successfully"),status:"success"})}catch(e){console.error("Error updating FAQ:",e),(0,l.o)({title:"Error",description:"Failed to update FAQ",status:"error"})}},S=["all",...Array.from(new Set(d.map(e=>"General")))],N="all"===y?d:d.filter(e=>"General"===y);return"loading"===t||u?(0,a.jsx)("div",{className:"flex items-center justify-center min-h-[40vh]",children:(0,a.jsx)("span",{className:"spinner w-8 h-8"})}):(0,a.jsxs)("div",{children:[(0,a.jsx)(c.zY,{title:"Manage FAQs",subtitle:"Organize common questions and answers.",actions:(0,a.jsxs)("div",{className:"flex items-center gap-3",children:[(0,a.jsx)("select",{value:y,onChange:e=>b(e.target.value),className:"input w-auto",children:S.map(e=>(0,a.jsx)("option",{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))}),(0,a.jsx)(o.$n,{onClick:()=>{x({id:"",question:"",answer:"",order:d.length,published:!0,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}),g(!0)},children:"Add New FAQ"})]})}),(0,a.jsx)("div",{className:"space-y-4",children:N.sort((e,t)=>e.order-t.order).map((e,t)=>(0,a.jsx)("div",{className:"card",children:(0,a.jsxs)("div",{className:"flex items-start justify-between",children:[(0,a.jsxs)("div",{className:"flex-grow",children:[(0,a.jsx)("h3",{className:"text-lg font-semibold text-white mb-2",children:e.question}),(0,a.jsx)("p",{className:"text-text-muted mb-3",children:e.answer}),(0,a.jsxs)("div",{className:"flex items-center space-x-4 text-sm",children:[(0,a.jsx)("span",{className:"badge",children:"General"}),(0,a.jsx)("span",{className:e.published?"text-green-400":"text-yellow-400",children:e.published?"Published":"Draft"})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2 ml-4",children:[(0,a.jsx)(o.$n,{variant:"ghost",onClick:()=>A(e.id,"up"),disabled:0===t,children:"↑"}),(0,a.jsx)(o.$n,{variant:"ghost",onClick:()=>A(e.id,"down"),disabled:t===N.length-1,children:"↓"}),(0,a.jsx)(o.$n,{variant:e.published?"secondary":"primary",onClick:()=>v(e.id),children:e.published?"Unpublish":"Publish"}),(0,a.jsx)(o.$n,{variant:"secondary",onClick:()=>{x(e),g(!0)},children:"Edit"}),(0,a.jsx)(o.$n,{variant:"danger",onClick:()=>j(e.id),children:"Delete"})]})]})},e.id))}),f&&m&&(0,a.jsx)("div",{className:"modal-backdrop flex items-center justify-center p-6",onClick:e=>{e.target===e.currentTarget&&(g(!1),x(null))},children:(0,a.jsxs)("div",{className:"modal-content left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 max-w-2xl w-full p-6 max-h-[90vh] overflow-y-auto",children:[(0,a.jsx)("h2",{className:"text-2xl font-semibold text-white mb-6",children:m.id?"Edit FAQ":"Add New FAQ"}),(0,a.jsxs)("form",{onSubmit:w,className:"space-y-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"label",children:"Question"}),(0,a.jsx)("input",{type:"text",value:m.question,onChange:e=>x({...m,question:e.target.value}),className:"input",required:!0})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"label",children:"Answer"}),(0,a.jsx)("textarea",{value:m.answer,onChange:e=>x({...m,answer:e.target.value}),className:"input",rows:4,required:!0})]}),(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm font-medium mb-2",children:"Order"}),(0,a.jsx)("input",{type:"number",value:m.order,onChange:e=>x({...m,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,a.jsx)("div",{className:"flex items-center",children:(0,a.jsxs)("label",{className:"flex items-center space-x-2",children:[(0,a.jsx)("input",{type:"checkbox",checked:m.published,onChange:e=>x({...m,published:e.target.checked}),className:"w-4 h-4 text-accent bg-bg-dark border-bg-light rounded focus:ring-accent"}),(0,a.jsx)("span",{className:"text-sm",children:"Published"})]})})]}),(0,a.jsxs)("div",{className:"flex justify-end gap-3 pt-4",children:[(0,a.jsx)(o.$n,{type:"button",variant:"ghost",onClick:()=>{g(!1),x(null)},children:"Cancel"}),(0,a.jsx)(o.$n,{type:"submit",children:"Save FAQ"})]})]})]})})]})}},32941:(e,t,s)=>{"use strict";s.d(t,{mc:()=>n,wn:()=>i,xA:()=>l,zY:()=>r});var a=s(95155);function r(e){let{title:t,subtitle:s,actions:r}=e;return(0,a.jsx)("div",{className:"mb-8",children:(0,a.jsxs)("div",{className:"flex items-start justify-between",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("h1",{className:"text-4xl font-display tracking-tight text-white mb-2",children:t}),s&&(0,a.jsx)("p",{className:"text-text-muted text-lg max-w-3xl",children:s})]}),r&&(0,a.jsx)("div",{className:"flex items-center gap-3",children:r})]})})}function i(e){let{children:t,className:s=""}=e;return(0,a.jsx)("section",{className:"section-spacing ".concat(s),children:t})}function n(e){let{children:t,className:s=""}=e;return(0,a.jsx)("div",{className:"container-custom ".concat(s),children:t})}function l(e){let{children:t,cols:s=3,gap:r="md",className:i=""}=e;return(0,a.jsx)("div",{className:"grid ".concat({1:"grid-cols-1",2:"grid-cols-1 md:grid-cols-2",3:"grid-cols-1 md:grid-cols-2 lg:grid-cols-3",4:"grid-cols-1 md:grid-cols-2 lg:grid-cols-4"}[s]," ").concat({sm:"gap-4",md:"gap-6",lg:"gap-8"}[r]," ").concat(i),children:t})}s(12115)},49903:(e,t,s)=>{"use strict";s.d(t,{$n:()=>n,z9:()=>l});var a=s(95155),r=s(6874),i=s.n(r);function n(e){let{variant:t="primary",size:s="md",isLoading:r=!1,children:i,className:n="",disabled:l,...c}=e;return(0,a.jsx)("button",{className:"".concat({primary:"btn-primary",secondary:"btn-secondary",ghost:"btn-ghost",danger:"btn bg-red-500 hover:bg-red-600 text-white"}[t]," ").concat({sm:"px-3 py-1.5 text-sm",md:"px-4 py-2",lg:"px-6 py-3 text-lg"}[s]," ").concat(n," ").concat(r?"opacity-75 cursor-wait":""),disabled:l||r,...c,children:r?(0,a.jsxs)("span",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"spinner w-4 h-4"}),"Loading..."]}):i})}function l(e){let{variant:t="primary",size:s="md",children:r,className:n="",href:l="#",...c}=e;return(0,a.jsx)(i(),{href:l,className:"".concat({primary:"btn-primary",secondary:"btn-secondary",ghost:"btn-ghost"}[t]," ").concat({sm:"px-3 py-1.5 text-sm",md:"px-4 py-2",lg:"px-6 py-3 text-lg"}[s]," ").concat(n),...c,children:r})}s(12115)},57651:(e,t,s)=>{Promise.resolve().then(s.bind(s,995))},87481:(e,t,s)=>{"use strict";s.d(t,{d:()=>d,o:()=>o});var a=s(12115);let r={ADD_TOAST:"ADD_TOAST",UPDATE_TOAST:"UPDATE_TOAST",DISMISS_TOAST:"DISMISS_TOAST",REMOVE_TOAST:"REMOVE_TOAST"},i=0,n=[],l={toasts:[]};function c(e){l=((e,t)=>{switch(t.type){case r.ADD_TOAST:return{...e,toasts:[t.toast,...e.toasts].slice(0,3)};case r.DISMISS_TOAST:{let{toastId:s}=t;return{...e,toasts:e.toasts.map(e=>e.id===s?{...e,status:"error"}:e)}}case r.REMOVE_TOAST:return{...e,toasts:e.toasts.filter(e=>e.id!==t.toastId)}}})(l,e),n.forEach(e=>{e(l)})}function o(e){var t;let{...s}=e,a=(i=(i+1)%Number.MAX_SAFE_INTEGER).toString();return c({type:r.ADD_TOAST,toast:{...s,id:a,status:null!=(t=s.status)?t:"info",title:s.title,description:s.description,action:s.action}}),{id:a,dismiss:()=>c({type:r.DISMISS_TOAST,toastId:a}),update:e=>c({type:r.UPDATE_TOAST,toast:{...e,id:a}})}}function d(){let[e,t]=a.useState(l);return a.useEffect(()=>(n.push(t),()=>{let e=n.indexOf(t);e>-1&&n.splice(e,1)}),[e]),{...e,toast:o,dismiss:e=>c({type:r.DISMISS_TOAST,toastId:e})}}}},e=>{e.O(0,[6874,6454,8441,5964,7358],()=>e(e.s=57651)),_N_E=e.O()}]); |