1"use strict";(self.webpackChunkfrontend=self.webpackChunkfrontend||[]).push([[5139],{85139:(e,t,s)=>{s.r(t),s.d(t,{default:()=>o});var a=s(89379),l=s(65043),n=s(91357),r=s(70579);const i="/api";function o(){const e=(0,n.Zp)(),[t,s]=(0,l.useState)([]),[o,c]=(0,l.useState)(!0),[d,u]=(0,l.useState)(!1),[x,m]=(0,l.useState)(null),[h,b]=(0,l.useState)({name:"",description:"",price:"",billing_cycle:"monthly",feature_key:"",included_in_plans:[]}),[p]=(0,l.useState)(["Business","Enterprise"]);(0,l.useEffect)(()=>{g()},[]);const g=async()=>{try{const e=localStorage.getItem("token"),t=await fetch("".concat(i,"/admin/add-ons"),{headers:{Authorization:"Bearer ".concat(e),"Cache-Control":"no-cache, no-store, must-revalidate",Pragma:"no-cache"}});if(!t.ok)throw new Error("HTTP ".concat(t.status));const a=await t.json();console.log("Fetched add-ons:",a.add_ons),s([...a.add_ons||[]])}catch(e){console.error("Error fetching add-ons:",e)}finally{c(!1)}},f=()=>{m(null),b({name:"",description:"",price:"",billing_cycle:"monthly",feature_key:"",included_in_plans:[]}),u(!0)};return(0,r.jsxs)("div",{className:"min-h-screen bg-gradient-to-br from-slate-900 via-blue-900 to-slate-900",children:[(0,r.jsx)("header",{className:"bg-slate-800/50 backdrop-blur-sm border-b border-slate-700 sticky top-0 z-50",children:(0,r.jsx)("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-4",children:(0,r.jsxs)("div",{className:"flex justify-between items-center",children:[(0,r.jsxs)("div",{className:"flex items-center gap-4",children:[(0,r.jsxs)("button",{onClick:()=>{e("/admin/dashboard")},className:"flex items-center gap-2 text-slate-300 hover:text-white transition-colors",children:[(0,r.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 19l-7-7m0 0l7-7m-7 7h18"})}),"Back to Dashboard"]}),(0,r.jsx)("div",{className:"h-6 w-px bg-slate-600"}),(0,r.jsx)("h1",{className:"text-2xl font-bold text-white",children:"Add-Ons Management"})]}),(0,r.jsx)("button",{onClick:()=>{localStorage.removeItem("token"),localStorage.removeItem("userType"),e("/admin/login")},className:"px-4 py-2 bg-red-600 hover:bg-red-700 text-white rounded-lg transition-colors",children:"Logout"})]})})}),(0,r.jsxs)("main",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8",children:[(0,r.jsxs)("div",{className:"mb-6 flex justify-between items-center",children:[(0,r.jsx)("p",{className:"text-slate-300 text-base",children:"Create and manage premium add-ons for your platform."}),(0,r.jsxs)("button",{onClick:f,className:"px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors flex items-center gap-2",children:[(0,r.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),"Create Add-On"]})]}),o?(0,r.jsx)("div",{className:"text-white text-center py-12",children:"Loading..."}):0===t.length?(0,r.jsxs)("div",{className:"bg-slate-800/50 backdrop-blur-sm rounded-xl border border-slate-700 p-12 text-center",children:[(0,r.jsx)("div",{className:"text-slate-400 text-lg mb-4",children:"No add-ons yet"}),(0,r.jsx)("button",{onClick:f,className:"px-6 py-3 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors",children:"Create Your First Add-On"})]}):(0,r.jsx)("div",{className:"grid gap-6",children:t.map(e=>{var t;return(0,r.jsx)("div",{className:"bg-slate-800/50 backdrop-blur-sm rounded-xl border border-slate-700 p-6",children:(0,r.jsxs)("div",{className:"flex justify-between items-start",children:[(0,r.jsxs)("div",{className:"flex-1",children:[(0,r.jsxs)("div",{className:"flex items-center gap-3 mb-2",children:[(0,r.jsx)("h3",{className:"text-xl font-semibold text-white",children:e.name}),(0,r.jsx)("span",{className:"px-3 py-1 rounded-full text-xs font-medium ".concat(e.is_active?"bg-green-500/10 text-green-400 border border-green-500/30":"bg-slate-500/10 text-slate-400 border border-slate-500/30"),children:e.is_active?"Active":"Inactive"})]}),(0,r.jsx)("p",{className:"text-slate-300 mb-3",children:e.description}),(0,r.jsxs)("div",{className:"flex flex-wrap gap-4 text-sm",children:[(0,r.jsxs)("div",{className:"text-slate-400",children:[(0,r.jsxs)("span",{className:"font-semibold text-white",children:["$",e.price]}),(0,r.jsx)("span",{className:"mx-1",children:"/"}),(0,r.jsx)("span",{children:e.billing_cycle})]}),(0,r.jsxs)("div",{className:"text-slate-400",children:[(0,r.jsx)("span",{className:"font-semibold",children:"Feature Key:"}),(0,r.jsx)("span",{className:"ml-2 text-blue-400 font-mono text-xs",children:e.feature_key})]}),(null===(t=e.included_in_plans)||void 0===t?void 0:t.length)>0&&(0,r.jsxs)("div",{className:"text-slate-400",children:[(0,r.jsx)("span",{className:"font-semibold",children:"Included in:"}),(0,r.jsx)("span",{className:"ml-2 text-green-400",children:e.included_in_plans.join(", ")})]})]})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2 ml-4",children:[(0,r.jsx)("button",{onClick:()=>(async e=>{try{const t=localStorage.getItem("token"),s=await fetch("".concat(i,"/admin/add-ons/").concat(e.id),{method:"PUT",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(t)},body:JSON.stringify({is_active:!e.is_active})});if(!s.ok){const e=await s.json().catch(()=>({detail:"Failed to toggle add-on"}));return void alert("Error: ".concat(e.detail||"Failed to toggle add-on status"))}alert("Add-on ".concat(e.is_active?"deactivated":"activated"," successfully!")),g()}catch(t){console.error("Error toggling add-on status:",t),alert("Network error: Failed to toggle add-on status")}})(e),className:"px-3 py-1 rounded-lg text-sm font-medium transition-colors ".concat(e.is_active?"bg-slate-700 text-slate-300 hover:bg-slate-600":"bg-green-600 text-white hover:bg-green-700"),children:e.is_active?"Deactivate":"Activate"}),(0,r.jsx)("button",{onClick:()=>(e=>{m(e),b({name:e.name,description:e.description,price:e.price.toString(),billing_cycle:e.billing_cycle,feature_key:e.feature_key,included_in_plans:e.included_in_plans||[]}),u(!0)})(e),className:"px-3 py-1 bg-blue-600 hover:bg-blue-700 text-white rounded-lg text-sm font-medium transition-colors",children:"Edit"}),(0,r.jsx)("button",{onClick:()=>(async e=>{if(window.confirm("Are you sure you want to delete this add-on?"))try{const t=localStorage.getItem("token"),s=await fetch("".concat(i,"/admin/add-ons/").concat(e),{method:"DELETE",headers:{Authorization:"Bearer ".concat(t)}});if(!s.ok){const e=await s.json().catch(()=>({detail:"Failed to delete add-on"}));return void alert("Error: ".concat(e.detail||"Failed to delete add-on"))}alert("Add-on deleted successfully!"),g()}catch(t){console.error("Error deleting add-on:",t),alert("Network error: Failed to delete add-on")}})(e.id),className:"px-3 py-1 bg-red-600 hover:bg-red-700 text-white rounded-lg text-sm font-medium transition-colors",children:"Delete"})]})]})},e.id)})})]}),d&&(0,r.jsx)("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center p-4 z-50",children:(0,r.jsxs)("div",{className:"bg-slate-800 rounded-xl border border-slate-700 p-6 max-w-2xl w-full max-h-[90vh] overflow-y-auto",children:[(0,r.jsx)("h2",{className:"text-2xl font-bold text-white mb-6",children:x?"Edit Add-On":"Create New Add-On"}),(0,r.jsxs)("form",{onSubmit:async e=>{e.preventDefault();try{const e=localStorage.getItem("token"),t={name:h.name,description:h.description,price:parseFloat(h.price),billing_cycle:h.billing_cycle,feature_key:h.feature_key,included_in_plans:h.included_in_plans};x?await fetch("".concat(i,"/admin/add-ons/").concat(x.id),{method:"PUT",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)},body:JSON.stringify(t)}):await fetch("".concat(i,"/admin/add-ons"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)},body:JSON.stringify(t)}),u(!1),g()}catch(t){console.error("Error saving add-on:",t)}},className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-sm font-medium text-slate-300 mb-2",children:"Name"}),(0,r.jsx)("input",{type:"text",value:h.name,onChange:e=>b((0,a.A)((0,a.A)({},h),{},{name:e.target.value})),className:"w-full px-3 py-2 bg-slate-900 border border-slate-700 rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-blue-500",required:!0})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-sm font-medium text-slate-300 mb-2",children:"Description"}),(0,r.jsx)("textarea",{value:h.description,onChange:e=>b((0,a.A)((0,a.A)({},h),{},{description:e.target.value})),className:"w-full px-3 py-2 bg-slate-900 border border-slate-700 rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-blue-500",rows:3,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 text-slate-300 mb-2",children:"Price ($)"}),(0,r.jsx)("input",{type:"number",step:"0.01",value:h.price,onChange:e=>b((0,a.A)((0,a.A)({},h),{},{price:e.target.value})),className:"w-full px-3 py-2 bg-slate-900 border border-slate-700 rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-blue-500",required:!0})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-sm font-medium text-slate-300 mb-2",children:"Billing Cycle"}),(0,r.jsxs)("select",{value:h.billing_cycle,onChange:e=>b((0,a.A)((0,a.A)({},h),{},{billing_cycle:e.target.value})),className:"w-full px-3 py-2 bg-slate-900 border border-slate-700 rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-blue-500",children:[(0,r.jsx)("option",{value:"monthly",children:"Monthly"}),(0,r.jsx)("option",{value:"yearly",children:"Yearly"})]})]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-sm font-medium text-slate-300 mb-2",children:"Feature Key (lowercase, underscores only)"}),(0,r.jsx)("input",{type:"text",value:h.feature_key,onChange:e=>b((0,a.A)((0,a.A)({},h),{},{feature_key:e.target.value.toLowerCase().replace(/[^a-z_]/g,"")})),className:"w-full px-3 py-2 bg-slate-900 border border-slate-700 rounded-lg text-white font-mono focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"remove_branding",required:!0})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-sm font-medium text-slate-300 mb-2",children:"Included in Plans (free for these subscribers)"}),(0,r.jsx)("div",{className:"flex gap-3",children:p.map(e=>(0,r.jsxs)("label",{className:"flex items-center gap-2 cursor-pointer",children:[(0,r.jsx)("input",{type:"checkbox",checked:h.included_in_plans.includes(e),onChange:()=>{return t=e,void b(e=>(0,a.A)((0,a.A)({},e),{},{included_in_plans:e.included_in_plans.includes(t)?e.included_in_plans.filter(e=>e!==t):[...e.included_in_plans,t]}));var t},className:"w-4 h-4 text-blue-600 bg-slate-900 border-slate-700 rounded focus:ring-blue-500"}),(0,r.jsx)("span",{className:"text-slate-300",children:e})]},e))})]}),(0,r.jsxs)("div",{className:"flex gap-3 pt-4",children:[(0,r.jsx)("button",{type:"submit",className:"flex-1 px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors font-medium",children:x?"Save Changes":"Create Add-On"}),(0,r.jsx)("button",{type:"button",onClick:()=>u(!1),className:"flex-1 px-4 py-2 bg-slate-700 hover:bg-slate-600 text-white rounded-lg transition-colors font-medium",children:"Cancel"})]})]})]})})]})}}}]); 2//# sourceMappingURL=5139.426a4a69.chunk.js.map
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.