PageSourceSearch

https://redgo.in/assets/js/AddonsList-DfS7ybW8.js

js redgo.in collected 2026-09-24 15:03:21 UTC 14,742 bytes, 1 lines download raw bytes

1import{r as l,j as e,L as ae,t as o}from"./index-Cf_ajVON.js";import{S as le}from"./switch-Br_IXA23.js";import{a as E,c as re}from"./index-BZFWozEr.js";import{D as P,a as k,d as B,b as I}from"./dialog-CrMXwKWe.js";import{A as ie}from"./AdminListPagination-CaB04eOd.js";import{S as ne}from"./search-CI5-KVok.js";import{E as de}from"./eye-DP9IZTXG.js";import{P as ce}from"./pencil-u9GUEip8.js";import{T as oe}from"./trash-2-B1Y_baWX.js";import"./index-BH0fEq1S.js";import"./index-DvNrSChk.js";import"./index-Dr9tQ8T6.js";import"./index-J_fU13zv.js";import"./index-BLHo7-Gi.js";import"./index-Bkla0msJ.js";import"./tslib.es6-CwyXKlH1.js";import"./index-BgkASZz5.js";import"./x-BzwCsDoT.js";const q=(r={})=>[r.requestedAt,r.createdAt,r.updatedAt].map(n=>new Date(n).getTime()).find(n=>Number.isFinite(n)&&n>0)||0,G=r=>{if(!r)return"ADDON000000";const n=String(r).match(/\d+/g),u=n?n.join(""):"";return`ADDON${u?u.slice(-6).padStart(6,"0"):"000000"}`},w=r=>r?.draft?.name||r?.name||"Unnamed Add-on",Q=r=>r?.draft?.image||r?.draft?.images?.[0]||r?.published?.image||r?.published?.images?.[0]||"https://via.placeholder.com/40";function Pe(){const[r,y]=l.useState(""),[n,u]=l.useState(""),[m,S]=l.useState(1),[b,V]=l.useState(()=>{try{return Number(localStorage.getItem("admin_addons_pageSize"))||20}catch{return 20}}),[L,F]=l.useState(0),[A,g]=l.useState([]),[Y,_]=l.useState(!0),[f,j]=l.useState(!1),[d,H]=l.useState(null),[J,R]=l.useState(!1),[M,T]=l.useState(null),[W,N]=l.useState(!1),[i,x]=l.useState({name:"",price:"",description:"",isAvailable:!0}),[D,O]=l.useState(""),[z,C]=l.useState(null);l.useEffect(()=>{const t=setTimeout(()=>u(r.trim()),300);return()=>clearTimeout(t)},[r]),l.useEffect(()=>{S(1)},[n]),l.useEffect(()=>{(async()=>{try{_(!0);const s=await E.getRestaurantAddons({approvalStatus:"approved",search:n||void 0,page:m,limit:b}),a=s?.data?.data??s?.data,c=(Array.isArray(a?.addons)?a.addons:Array.isArray(a)?a:[]).filter(se=>String(se.approvalStatus||"").toLowerCase()==="approved");g(c),F(s?.data?.data?.total??s?.data?.total??c.length)}catch{o.error("Failed to load restaurant add-ons"),g([]),F(0)}finally{_(!1)}})()},[n,m,b]);const U=l.useMemo(()=>{const t=Array.isArray(A)?[...A]:[];return t.sort((s,a)=>q(a)-q(s)),t},[A]),$=L,K=t=>{H(t),R(!0)},X=t=>{T(t),x({name:t?.draft?.name||t?.name||"",price:t?.draft?.price??t?.price??"",description:t?.draft?.description||t?.description||"",isAvailable:t?.isAvailable!==!1});const s=t?.draft?.image||Array.isArray(t?.draft?.images)&&t.draft.images[0]||t?.image||Array.isArray(t?.images)&&t.images[0]||"";O(s||""),C(null),N(!0)},Z=async()=>{const t=M?.id||M?._id;if(!t)return;if(!i.name.trim()){o.error("Name is required");return}const s=Number(i.price);if(Number.isNaN(s)||s<0){o.error("Enter a valid price");return}try{j(!0);let a=D||"";if(z){const h=await re.uploadMedia(z,{folder:"appzeto/admin/addons"});a=h?.data?.data?.url||h?.data?.url||a}await E.updateRestaurantAddon(String(t),{name:i.name.trim(),price:s,description:i.description.trim(),isAvailable:i.isAvailable,image:a,images:a?[a]:[]}),g(h=>(h||[]).map(c=>String(c.id||c._id)===String(t)?{...c,...i,price:s,name:i.name.trim(),description:i.description.trim(),image:a||c.image,images:a?[a]:c.images}:c)),o.success("Add-on updated"),N(!1),T(null),C(null)}catch(a){o.error(a?.response?.data?.message||"Failed to update add-on")}finally{j(!1)}},[v,p]=l.useState(null),ee=async()=>{if(!v)return;const t=v?.id||v?._id;try{j(!0),await E.rejectRestaurantAddon(String(t),"Deleted by admin"),g(s=>(s||[]).filter(a=>String(a.id||a._id)!==String(t))),o.success("Add-on deleted")}catch(s){o.error(s?.response?.data?.message||"Failed to delete add-on")}finally{j(!1),p(null)}},te=t=>{p(t)};return e.jsxs("div",{className:"p-4 lg:p-6 bg-slate-50 min-h-screen space-y-6",children:[e.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-slate-200 p-6",children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center md:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsx("h1",{className:"text-2xl font-bold text-slate-900",children:"Restaurant add-ons"})}),e.jsx("div",{className:"text-sm text-slate-500 mt-1",children:"Manage add-ons submitted by restaurants."})]}),e.jsx("div",{className:"flex items-center gap-2"})]}),e.jsxs("div",{className:"mt-4 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[e.jsxs("div",{className:"relative w-full sm:w-96",children:[e.jsx(ne,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400"}),e.jsx("input",{type:"text",placeholder:"Search add-ons or restaurant...",value:r,onChange:t=>y(t.target.value),className:"pl-10 pr-4 py-2.5 w-full text-sm rounded-lg border border-slate-300 bg-white focus:outline-none focus:ring-2 focus:ring-slate-400 focus:border-slate-400"})]}),e.jsxs("div",{className:"text-sm text-slate-600",children:["Showing ",e.jsx("span",{className:"font-semibold",children:$})]})]})]}),e.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-slate-200 overflow-hidden",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{className:"bg-slate-50 border-b border-slate-200",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-6 py-4 text-left text-[10px] font-bold text-slate-700 uppercase tracking-wider",children:"SL"}),e.jsx("th",{className:"px-6 py-4 text-left text-[10px] font-bold text-slate-700 uppercase tracking-wider",children:"Image"}),e.jsx("th",{className:"px-6 py-4 text-left text-[10px] font-bold text-slate-700 uppercase tracking-wider",children:"Name"}),e.jsx("th",{className:"px-6 py-4 text-left text-[10px] font-bold text-slate-700 uppercase tracking-wider",children:"Restaurant"}),e.jsx("th",{className:"px-6 py-4 text-left text-[10px] font-bold text-slate-700 uppercase tracking-wider",children:"Price"}),e.jsx("th",{className:"px-6 py-4 text-center text-[10px] font-bold text-slate-700 uppercase tracking-wider",children:"Action"})]})}),e.jsx("tbody",{className:"bg-white divide-y divide-slate-100",children:Y?e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"px-6 py-20 text-center",children:e.jsxs("div",{className:"flex flex-col items-center justify-center",children:[e.jsx(ae,{className:"w-8 h-8 animate-spin text-blue-600 mb-2"}),e.jsx("p",{className:"text-sm text-slate-500",children:"Loading add-ons..."})]})})}):U.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"px-6 py-20 text-center",children:e.jsxs("div",{className:"flex flex-col items-center justify-center",children:[e.jsx("p",{className:"text-lg font-semibold text-slate-700 mb-1",children:"No Data Found"}),e.jsx("p",{className:"text-sm text-slate-500",children:"No add-ons match your search"})]})})}):U.map((t,s)=>e.jsxs("tr",{className:"hover:bg-slate-50 transition-colors",children:[e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("span",{className:"text-sm font-medium text-slate-700",children:(m-1)*b+s+1})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("div",{className:"w-10 h-10 rounded-full overflow-hidden bg-slate-100 flex items-center justify-center",children:e.jsx("img",{src:Q(t),alt:w(t),className:"w-full h-full object-cover",onError:a=>{a.target.src="https://via.placeholder.com/40"}})})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-sm font-medium text-slate-900",children:w(t)}),e.jsxs("span",{className:"text-xs text-slate-500",children:["ID #",G(t.i
1d||t._id)]})]})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-sm text-slate-900",children:t?.restaurant?.name||"-"}),t?.restaurant?.ownerPhone?e.jsx("span",{className:"text-xs text-slate-500",children:t.restaurant.ownerPhone}):null]})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsxs("span",{className:"text-sm font-medium text-slate-900",children:["₹",Number(t?.draft?.price??t?.price??0).toFixed(2)]})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-center",children:e.jsxs("div",{className:"flex items-center justify-center gap-2 flex-wrap",children:[e.jsx("button",{onClick:()=>K(t),className:"p-1.5 rounded text-blue-600 hover:bg-blue-50 transition-colors",title:"View",children:e.jsx(de,{className:"w-4 h-4"})}),e.jsxs("button",{onClick:()=>X(t),className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-semibold bg-blue-600 text-white hover:bg-blue-700 transition-colors",children:[e.jsx(ce,{className:"w-4 h-4"}),"Edit"]}),e.jsxs("button",{onClick:()=>te(t),className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-semibold bg-red-600 text-white hover:bg-red-700 transition-colors",children:[e.jsx(oe,{className:"w-4 h-4"}),"Delete"]})]})})]},String(t.id||t._id)))})]})}),e.jsx(ie,{currentPage:m,pageSize:b,totalItems:L,onPageChange:S,onPageSizeChange:t=>{V(t);try{localStorage.setItem("admin_addons_pageSize",String(t))}catch{}S(1)},itemLabel:"add-ons"})]}),e.jsx(P,{open:J,onOpenChange:R,children:e.jsxs(k,{className:"max-w-xl p-0 overflow-hidden",children:[e.jsx(B,{className:"px-6 py-4 border-b border-slate-200 bg-slate-50",children:e.jsx(I,{className:"text-lg font-semibold text-slate-900",children:"Add-on Details"})}),d&&e.jsxs("div",{className:"p-6 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("img",{src:Q(d),alt:w(d),className:"w-20 h-20 rounded-xl object-cover border border-slate-200",onError:t=>{t.target.src="https://via.placeholder.com/64"}}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-semibold text-slate-900",children:w(d)}),e.jsxs("p",{className:"text-sm text-slate-500 mt-0.5",children:["ID #",G(d.id||d._id)]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm bg-slate-50 border border-slate-200 rounded-lg p-4",children:[e.jsxs("p",{children:[e.jsx("span",{className:"font-semibold text-slate-700",children:"Restaurant:"})," ",e.jsx("span",{className:"text-slate-900",children:d?.restaurant?.name||"-"})]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-semibold text-slate-700",children:"Price:"})," ",e.jsxs("span",{className:"text-slate-900",children:["₹",Number(d?.draft?.price??0).toFixed(2)]})]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-semibold text-slate-700",children:"Available:"})," ",e.jsx("span",{className:"text-slate-900",children:d?.isAvailable?"Yes":"No"})]})]}),d?.draft?.description?e.jsxs("p",{className:"text-sm text-slate-700 leading-relaxed",children:[e.jsx("span",{className:"font-semibold text-slate-800",children:"Description:"})," ",d.draft.description]}):null]})]})}),e.jsx(P,{open:W,onOpenChange:N,children:e.jsxs(k,{className:"max-w-md p-0 overflow-hidden",children:[e.jsx(B,{className:"px-6 py-4 border-b border-slate-200 bg-slate-50",children:e.jsx(I,{className:"text-lg font-semibold text-slate-900",children:"Edit Add-on"})}),e.jsxs("div",{className:"p-6 space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[D?e.jsx("img",{src:D,alt:"Preview",className:"w-16 h-16 rounded-md object-cover border",onError:t=>t.target.style.display="none"}):e.jsx("div",{className:"w-16 h-16 rounded-md border border-dashed border-slate-300 flex items-center justify-center text-xs text-slate-500",children:"No image"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Change Image"}),e.jsx("input",{type:"file",accept:"image/*",onChange:t=>{const s=t.target.files?.[0];if(!s)return;const a=URL.createObjectURL(s);C(s),O(a)},className:"text-sm"}),e.jsx("p",{className:"text-xs text-slate-500",children:"PNG, JPG, WEBP up to 5MB"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Name"}),e.jsx("input",{type:"text",value:i.name,onChange:t=>x(s=>({...s,name:t.target.value})),className:"w-full px-3 py-2 border border-slate-300 rounded-md text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Price"}),e.jsx("input",{type:"number",min:"0",step:"0.01",value:i.price,onChange:t=>x(s=>({...s,price:t.target.value})),className:"w-full px-3 py-2 border border-slate-300 rounded-md text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Description"}),e.jsx("textarea",{rows:3,value:i.description,onChange:t=>x(s=>({...s,description:t.target.value})),className:"w-full px-3 py-2 border border-slate-300 rounded-md text-sm"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(le,{checked:i.isAvailable,onCheckedChange:t=>x(s=>({...s,isAvailable:t}))}),e.jsx("span",{className:"text-sm text-slate-700",children:"Available"})]})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-slate-200 flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>N(!1),className:"px-4 py-2 text-sm font-medium text-slate-700 bg-white border border-slate-300 rounded-md hover:bg-slate-50 transition-colors",children:"Cancel"}),e.jsx("button",{type:"button",onClick:Z,disabled:f,className:"px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-md hover:bg-blue-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:f?"
1Saving...":"Save"})]})]})}),e.jsx(P,{open:!!v,onOpenChange:t=>!t&&p(null),children:e.jsxs(k,{className:"max-w-md w-full rounded-xl p-0 overflow-hidden shadow-xl",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-slate-200",children:[e.jsx(I,{className:"text-lg font-semibold text-slate-900",children:"Delete add-on?"}),e.jsx("button",{type:"button",onClick:()=>p(null),className:"p-1.5 rounded-full hover:bg-slate-100 transition-colors","aria-label":"Close",children:"✕"})]}),e.jsx("div",{className:"px-5 pt-4 pb-2",children:e.jsx("p",{className:"text-sm text-slate-700",children:"This action cannot be undone."})}),e.jsxs("div",{className:"px-5 py-4 border-t border-slate-200 flex justify-end gap-2 bg-slate-50",children:[e.jsx("button",{type:"button",onClick:()=>p(null),className:"px-4 py-2 text-sm font-medium text-slate-700 bg-white border border-slate-300 rounded-md hover:bg-slate-100 transition-colors",children:"No"}),e.jsx("button",{type:"button",onClick:ee,disabled:f,className:"px-4 py-2 text-sm font-medium text-white bg-red-600 rounded-md hover:bg-red-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:f?"Deleting...":"Yes, delete"})]})]})})]})}export{Pe as default};

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.