1 line
17 KiB
JavaScript
1 line
17 KiB
JavaScript
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,6655,e=>{"use strict";let s=e.i(47167).default.env.NEXT_PUBLIC_API_URL??"/admin/api/v1";e.s(["ADMIN_API_BASE",0,s])},86025,e=>{"use strict";var s=e.i(43476),a=e.i(71645),n=e.i(6655);let t=["OWNER","MANAGER","AGENT"],i=["STARTER","GROWTH","PRO"],l=["INTERNAL_PAGE","EXTERNAL_LINK","PARENT_MENU","SECTION_LABEL","DIVIDER"],c="mt-1 w-full rounded-xl border border-zinc-700 bg-zinc-800 px-3 py-2 text-sm text-zinc-100 outline-none focus:ring-2 focus:ring-orange-500",r="text-xs font-medium uppercase tracking-wider text-zinc-500";async function d(e,s){let a=await fetch(`${n.ADMIN_API_BASE}${e}`,{...s,credentials:"include",headers:{"Content-Type":"application/json",...s?.headers??{}}}),t=await a.json();if(!a.ok)throw Error(t?.message??"Request failed");return t?.data??t}function m(){return{label:"",systemKey:"",itemType:"INTERNAL_PAGE",routeOrUrl:"",icon:"",parentId:"",displayOrder:"0",openInNewTab:!1,isRequired:!1,isActive:!0,roles:["OWNER","MANAGER","AGENT"],plans:["STARTER","GROWTH","PRO"],companyIds:[]}}function o(e,a="default"){return(0,s.jsx)("span",{className:`inline-flex rounded-full px-2.5 py-1 text-[11px] font-medium ${"success"===a?"bg-emerald-950/40 text-emerald-400":"warn"===a?"bg-orange-950/40 text-orange-400":"bg-zinc-800 text-zinc-300"}`,children:e})}e.s(["default",0,function(){let[e,n]=(0,a.useState)([]),[x,p]=(0,a.useState)([]),[u,h]=(0,a.useState)([]),[g,b]=(0,a.useState)(null),[N,y]=(0,a.useState)(""),[j,f]=(0,a.useState)("OWNER"),[v,z]=(0,a.useState)(null),[w,A]=(0,a.useState)(m()),[T,R]=(0,a.useState)(!0),[O,I]=(0,a.useState)(!1),[C,S]=(0,a.useState)(!1),[E,k]=(0,a.useState)(null),[P,U]=(0,a.useState)(null),$=(0,a.useMemo)(()=>e.filter(e=>"PARENT_MENU"===e.itemType&&e.id!==v),[e,v]);function L(e,s){A(a=>({...a,[e]:s}))}function _(e,s){A(a=>{let n=a[e];return{...a,[e]:n.includes(s)?n.filter(e=>e!==s):[...n,s]}})}async function D(){let[e,s]=await Promise.all([d("/admin/menu-items"),d("/admin/menu-audit-logs?page=1&pageSize=20")]);n(e),h(s.data)}async function K(e){e.preventDefault();try{I(!0),k(null),U(null);let e={label:w.label,systemKey:w.systemKey||null,itemType:w.itemType,routeOrUrl:w.routeOrUrl||null,icon:w.icon||null,parentId:w.parentId||null,displayOrder:Number(w.displayOrder||0),openInNewTab:w.openInNewTab,isRequired:w.isRequired,isActive:w.isActive,roles:w.roles,subscriptionPlans:w.plans.map(e=>({plan:e,displayOrder:Number(w.displayOrder||0),isActive:!0})),companyAssignments:w.companyIds.map(e=>({companyId:e,displayOrder:Number(w.displayOrder||0),isActive:!0}))};v?(await d(`/admin/menu-items/${v}`,{method:"PUT",body:JSON.stringify(e)}),U("Menu item updated.")):(await d("/admin/menu-items",{method:"POST",body:JSON.stringify(e)}),U("Menu item created.")),z(null),A(m()),await D()}catch(e){k(e.message??"Failed to save menu item.")}finally{I(!1)}}function M(){z(null),A(m()),U(null),k(null)}async function q(e){try{k(null),await d(`/admin/menu-items/${e.id}/status`,{method:"PATCH",body:JSON.stringify({isActive:!e.isActive})}),await D()}catch(e){k(e.message??"Failed to update status.")}}async function G(e){if(window.confirm(`Delete "${e.label}"?`))try{k(null),await d(`/admin/menu-items/${e.id}`,{method:"DELETE"}),v===e.id&&(z(null),A(m())),await D()}catch(e){k(e.message??"Failed to delete menu item.")}}async function B(){if(N)try{S(!0),k(null);let e=await d("/admin/menu-preview",{method:"POST",body:JSON.stringify({companyId:N,role:j})});b(e)}catch(e){k(e.message??"Failed to load menu preview.")}finally{S(!1)}}return(0,a.useEffect)(()=>{!async function(){try{R(!0),k(null);let[e,s,a]=await Promise.all([d("/admin/menu-items"),d("/admin/companies?page=1&pageSize=100"),d("/admin/menu-audit-logs?page=1&pageSize=20")]);n(e),p(s.data),h(a.data),!N&&s.data[0]?.id&&y(s.data[0].id)}catch(e){k(e.message??"Failed to load menu management data.")}finally{R(!1)}}()},[]),T?(0,s.jsx)("div",{className:"shell py-8",children:(0,s.jsx)("div",{className:"panel p-8 text-sm text-zinc-500",children:"Loading menu management…"})}):(0,s.jsxs)("div",{className:"shell py-8 space-y-6 text-zinc-100",children:[(0,s.jsx)("section",{className:"panel p-8",children:(0,s.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-xs uppercase tracking-[0.2em] text-orange-400",children:"Platform"}),(0,s.jsx)("h1",{className:"mt-1 text-3xl font-black",children:"Menu Management"}),(0,s.jsx)("p",{className:"mt-1 max-w-3xl text-sm text-zinc-400",children:"Control company dashboard navigation by plan, role, and company-specific exceptions from one admin surface."})]}),(0,s.jsx)("button",{type:"button",onClick:M,className:"rounded-lg bg-orange-500 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-orange-400",children:"Create menu item"})]})}),(E||P)&&(0,s.jsxs)("section",{className:"space-y-3",children:[E&&(0,s.jsx)("div",{className:"panel p-4 text-sm text-red-400",children:E}),P&&(0,s.jsx)("div",{className:"panel p-4 text-sm text-emerald-400",children:P})]}),(0,s.jsxs)("div",{className:"grid gap-8 xl:grid-cols-[1.4fr,0.95fr]",children:[(0,s.jsxs)("section",{className:"panel overflow-hidden",children:[(0,s.jsx)("div",{className:"flex items-center justify-between",children:(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{className:"px-5 pt-5 text-xl font-semibold text-zinc-100",children:"Menu items"}),(0,s.jsxs)("p",{className:"px-5 pb-1 pt-1 text-sm text-zinc-400",children:[e.length," configured items"]})]})}),(0,s.jsx)("div",{className:"overflow-x-auto",children:(0,s.jsxs)("table",{className:"min-w-full text-left text-sm",children:[(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{className:"border-b border-zinc-800",children:[(0,s.jsx)("th",{className:"px-5 py-3 text-xs font-medium uppercase tracking-wider text-zinc-500",children:"Item"}),(0,s.jsx)("th",{className:"px-5 py-3 text-xs font-medium uppercase tracking-wider text-zinc-500",children:"Type"}),(0,s.jsx)("th",{className:"px-5 py-3 text-xs font-medium uppercase tracking-wider text-zinc-500",children:"Assignments"}),(0,s.jsx)("th",{className:"px-5 py-3 text-xs font-medium uppercase tracking-wider text-zinc-500",children:"Status"}),(0,s.jsx)("th",{className:"px-5 py-3 text-xs font-medium uppercase tracking-wider text-zinc-500",children:"Actions"})]})}),(0,s.jsx)("tbody",{className:"divide-y divide-zinc-800/60",children:e.map(e=>(0,s.jsxs)("tr",{className:"align-top transition-colors hover:bg-zinc-800/30",children:[(0,s.jsx)("td",{className:"px-5 py-4",children:(0,s.jsxs)("div",{className:"space-y-1",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsx)("span",{className:"font-semibold text-zinc-100",children:e.label}),e.isRequired&&o("Required","warn"),e.systemKey&&o(e.systemKey)]}),(0,s.jsxs)("p",{className:"text-xs text-zinc-500",children:[e.routeOrUrl||"No route"," • order ",e.displayOrder,e.parent?` • child of ${e.parent.label}`:""]})]})}),(0,s.jsx)("td",{className:"px-5 py-4 text-xs text-zinc-300",children:e.itemType}),(0,s.jsx)("td",{className:"px-5 py-4",children:(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)("div",{className:"flex flex-wrap gap-2",children:e.subscriptionAssignments.length>0?e.subscriptionAssignments.map(a=>(0,s.jsx)("span",{className:"inline-flex rounded-full bg-zinc-800 px-2.5 py-1 text-[11px] font-medium text-zinc-300",children:a.plan},`${e.id}-${a.plan}`)):(0,s.jsx)("span",{className:"text-xs text-zinc-500",children:"No plan assignments"})}),(0,s.jsxs)("div",{className:"flex flex-wrap gap-2",children:[e.companyAssignments.slice(0,3).map(a=>(0,s.jsx)("span",{className:"inline-flex rounded-full bg-zinc-800 px-2.5 py-1 text-[11px] font-medium text-zinc-300",children:a.company.name},`${e.id}-${a.companyId}`)),e.companyAssignments.length>3&&o(`+${e.companyAssignments.length-3} more`)]}),(0,s.jsx)("div",{className:"flex flex-wrap gap-2",children:e.roleVisibilities.map(a=>(0,s.jsx)("span",{className:"inline-flex rounded-full bg-zinc-800 px-2.5 py-1 text-[11px] font-medium text-zinc-300",children:a.role},`${e.id}-${a.role}`))})]})}),(0,s.jsx)("td",{className:"px-5 py-4",children:e.isActive?o("Active","success"):o("Inactive")}),(0,s.jsx)("td",{className:"px-5 py-4",children:(0,s.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,s.jsx)("button",{type:"button",onClick:()=>{z(e.id),A({label:e.label,systemKey:e.systemKey??"",itemType:e.itemType,routeOrUrl:e.routeOrUrl??"",icon:e.icon??"",parentId:e.parentId??"",displayOrder:String(e.displayOrder),openInNewTab:e.openInNewTab,isRequired:e.isRequired,isActive:e.isActive,roles:e.roleVisibilities.map(e=>e.role),plans:e.subscriptionAssignments.map(e=>e.plan),companyIds:e.companyAssignments.map(e=>e.companyId)}),U(null),k(null)},className:"rounded-lg border border-zinc-700 bg-zinc-800 px-3 py-1.5 text-xs text-zinc-300 transition-colors hover:bg-zinc-700",children:"Edit"}),(0,s.jsx)("button",{type:"button",onClick:()=>q(e),className:"rounded-lg border border-zinc-700 bg-zinc-800 px-3 py-1.5 text-xs text-zinc-300 transition-colors hover:bg-zinc-700",children:e.isActive?"Disable":"Enable"}),(0,s.jsx)("button",{type:"button",onClick:()=>G(e),className:"rounded-lg border border-red-900/60 bg-red-950/20 px-3 py-1.5 text-xs text-red-300 transition-colors hover:bg-red-900/30",children:"Delete"})]})})]},e.id))})]})})]}),(0,s.jsxs)("section",{className:"panel p-6",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{className:"text-xl font-semibold text-zinc-100",children:v?"Edit menu item":"New menu item"}),(0,s.jsx)("p",{className:"mt-1 text-sm text-zinc-400",children:"Configure menu metadata, role visibility, plan defaults, and company-specific overrides."})]}),v&&(0,s.jsx)("button",{type:"button",onClick:M,className:"text-sm font-medium text-orange-400 hover:text-orange-300",children:"Clear"})]}),(0,s.jsxs)("form",{className:"mt-6 space-y-5",onSubmit:K,children:[(0,s.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2",children:[(0,s.jsxs)("label",{children:[(0,s.jsx)("span",{className:r,children:"Label"}),(0,s.jsx)("input",{className:c,value:w.label,onChange:e=>L("label",e.target.value)})]}),(0,s.jsxs)("label",{children:[(0,s.jsx)("span",{className:r,children:"System key"}),(0,s.jsx)("input",{className:c,value:w.systemKey,onChange:e=>L("systemKey",e.target.value),placeholder:"dashboard"})]})]}),(0,s.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2",children:[(0,s.jsxs)("label",{children:[(0,s.jsx)("span",{className:r,children:"Type"}),(0,s.jsx)("select",{className:c,value:w.itemType,onChange:e=>L("itemType",e.target.value),children:l.map(e=>(0,s.jsx)("option",{value:e,children:e},e))})]}),(0,s.jsxs)("label",{children:[(0,s.jsx)("span",{className:r,children:"Icon"}),(0,s.jsx)("input",{className:c,value:w.icon,onChange:e=>L("icon",e.target.value),placeholder:"LayoutDashboard"})]})]}),(0,s.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2",children:[(0,s.jsxs)("label",{children:[(0,s.jsx)("span",{className:r,children:"Route or URL"}),(0,s.jsx)("input",{className:c,value:w.routeOrUrl,onChange:e=>L("routeOrUrl",e.target.value),placeholder:"/reports or https://…"})]}),(0,s.jsxs)("label",{children:[(0,s.jsx)("span",{className:r,children:"Parent menu"}),(0,s.jsxs)("select",{className:c,value:w.parentId,onChange:e=>L("parentId",e.target.value),children:[(0,s.jsx)("option",{value:"",children:"No parent"}),$.map(e=>(0,s.jsx)("option",{value:e.id,children:e.label},e.id))]})]})]}),(0,s.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2",children:[(0,s.jsxs)("label",{children:[(0,s.jsx)("span",{className:r,children:"Display order"}),(0,s.jsx)("input",{className:c,type:"number",min:"0",value:w.displayOrder,onChange:e=>L("displayOrder",e.target.value)})]}),(0,s.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2",children:[(0,s.jsxs)("label",{className:"flex items-center gap-2 rounded-xl border border-zinc-700 bg-zinc-900/40 px-3 py-2 text-sm text-zinc-200",children:[(0,s.jsx)("input",{type:"checkbox",checked:w.isActive,onChange:e=>L("isActive",e.target.checked)}),"Active"]}),(0,s.jsxs)("label",{className:"flex items-center gap-2 rounded-xl border border-zinc-700 bg-zinc-900/40 px-3 py-2 text-sm text-zinc-200",children:[(0,s.jsx)("input",{type:"checkbox",checked:w.openInNewTab,onChange:e=>L("openInNewTab",e.target.checked)}),"New tab"]})]})]}),(0,s.jsxs)("label",{className:"flex items-center gap-2 rounded-xl border border-zinc-700 bg-zinc-900/40 px-3 py-2 text-sm text-zinc-200",children:[(0,s.jsx)("input",{type:"checkbox",checked:w.isRequired,onChange:e=>L("isRequired",e.target.checked)}),"Required system item"]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:r,children:"Role visibility"}),(0,s.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:t.map(e=>(0,s.jsxs)("label",{className:"flex items-center gap-2 rounded-full border border-zinc-700 bg-zinc-900/40 px-3 py-2 text-sm text-zinc-200",children:[(0,s.jsx)("input",{type:"checkbox",checked:w.roles.includes(e),onChange:()=>_("roles",e)}),e]},e))})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:r,children:"Subscription plans"}),(0,s.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:i.map(e=>(0,s.jsxs)("label",{className:"flex items-center gap-2 rounded-full border border-zinc-700 bg-zinc-900/40 px-3 py-2 text-sm text-zinc-200",children:[(0,s.jsx)("input",{type:"checkbox",checked:w.plans.includes(e),onChange:()=>_("plans",e)}),e]},e))})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:r,children:"Company-specific assignments"}),(0,s.jsx)("div",{className:"mt-2 max-h-56 space-y-2 overflow-y-auto rounded-2xl border border-zinc-700 bg-zinc-900/30 p-3",children:x.map(e=>(0,s.jsxs)("label",{className:"flex items-center justify-between gap-3 rounded-xl px-2 py-2 text-sm text-zinc-200 transition-colors hover:bg-zinc-800/40",children:[(0,s.jsxs)("span",{className:"flex items-center gap-2",children:[(0,s.jsx)("input",{type:"checkbox",checked:w.companyIds.includes(e.id),onChange:()=>_("companyIds",e.id)}),(0,s.jsx)("span",{children:e.name})]}),(0,s.jsxs)("span",{className:"text-xs text-zinc-500",children:[e.subscription?.plan??"No plan"," • ",e.status]})]},e.id))})]}),(0,s.jsx)("button",{type:"submit",disabled:O,className:"w-full rounded-lg bg-orange-500 px-5 py-2.5 text-sm font-medium text-white transition-colors hover:bg-orange-400 disabled:opacity-60",children:O?"Saving…":v?"Update menu item":"Create menu item"})]})]})]}),(0,s.jsxs)("div",{className:"grid gap-8 xl:grid-cols-[1.1fr,0.9fr]",children:[(0,s.jsxs)("section",{className:"panel p-6",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-end gap-4",children:[(0,s.jsxs)("div",{className:"flex-1",children:[(0,s.jsx)("h2",{className:"text-xl font-semibold text-zinc-100",children:"Preview company menu"}),(0,s.jsx)("p",{className:"mt-1 text-sm text-zinc-400",children:"Test the generated menu for a company and role before troubleshooting or saving follow-up changes."})]}),(0,s.jsxs)("div",{className:"min-w-[220px]",children:[(0,s.jsx)("label",{className:r,children:"Company"}),(0,s.jsx)("select",{className:c,value:N,onChange:e=>y(e.target.value),children:x.map(e=>(0,s.jsx)("option",{value:e.id,children:e.name},e.id))})]}),(0,s.jsxs)("div",{className:"min-w-[160px]",children:[(0,s.jsx)("label",{className:r,children:"Role"}),(0,s.jsx)("select",{className:c,value:j,onChange:e=>f(e.target.value),children:t.map(e=>(0,s.jsx)("option",{value:e,children:e},e))})]}),(0,s.jsx)("button",{type:"button",onClick:B,disabled:C||!N,className:"rounded-lg bg-orange-500 px-5 py-2.5 text-sm font-medium text-white transition-colors hover:bg-orange-400 disabled:opacity-60",children:C?"Previewing…":"Run preview"})]}),g&&(0,s.jsxs)("div",{className:"mt-6 space-y-4",children:[(0,s.jsxs)("div",{className:"rounded-2xl border border-zinc-700 bg-zinc-900/30 p-4",children:[(0,s.jsx)("p",{className:"text-sm font-semibold text-zinc-100",children:g.company.name}),(0,s.jsxs)("p",{className:"mt-1 text-xs text-zinc-500",children:["Plan: ",g.subscriptionPlan??"None"," • Role: ",g.role," • Company status: ",g.company.status]})]}),(0,s.jsx)("div",{className:"space-y-3",children:g.items.map(e=>(0,s.jsxs)("div",{className:"rounded-2xl border border-zinc-700 bg-zinc-900/30 p-4",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsx)("span",{className:"font-semibold text-zinc-100",children:e.label}),e.visible?o("Visible","success"):o("Hidden"),o("none"===e.source?"unassigned":e.source)]}),(0,s.jsxs)("p",{className:"mt-1 text-xs text-zinc-500",children:[e.routeOrUrl||"No route"," • order ",e.displayOrder]}),(0,s.jsx)("ul",{className:"mt-3 space-y-1 text-sm text-zinc-300",children:e.reasons.map((a,n)=>(0,s.jsx)("li",{children:a},`${e.id}-${n}`))})]},e.id))})]})]}),(0,s.jsxs)("section",{className:"panel p-6",children:[(0,s.jsx)("h2",{className:"text-xl font-semibold text-zinc-100",children:"Recent menu audit activity"}),(0,s.jsx)("p",{className:"mt-1 text-sm text-zinc-400",children:"Recent platform-side changes to menu items and assignments."}),(0,s.jsx)("div",{className:"mt-6 space-y-3",children:u.map(e=>(0,s.jsxs)("div",{className:"rounded-2xl border border-zinc-700 bg-zinc-900/30 p-4",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,s.jsx)("p",{className:"text-sm font-semibold text-zinc-100",children:e.action}),(0,s.jsx)("span",{className:"text-xs text-zinc-500",children:new Date(e.createdAt).toLocaleString()})]}),(0,s.jsx)("p",{className:"mt-1 text-xs text-zinc-500",children:e.adminUser?`${e.adminUser.firstName} ${e.adminUser.lastName} • ${e.adminUser.email}`:"Unknown admin"})]},e.id))})]})]})]})}])}]); |