PageSourceSearch

https://goneat.co.uk/assets/list-BAT83wyI.js

js goneat.co.uk collected 2026-10-02 02:10:56 UTC 11,257 bytes, 1 lines download raw bytes

1import{j as e}from"./vendor-query-D1Mshrk-.js";import{r as n,h as Q,L as y}from"./vendor-react-BfQMi0FG.js";import{L as D,a8 as g,B as r,t as w,C as X,d as Z,z as ee,P as se,I as ae,e as T,f as o,an as h,j as $}from"./index-BrXTQpUj.js";import{C as L,d as A}from"./card-BPl9i0oB.js";import{S as F,a as B,b as _,c as V,d as E}from"./select-CxlFVGv9.js";import{b as te,c as ie,d as re}from"./use-products-C-d5SucD.js";import{u as H}from"./use-categories-BSxZIg5k.js";import{P as ne}from"./page-header-C7x1KRLA.js";import{D as le}from"./data-table-DtJFZiUu.js";import{C as R}from"./confirm-dialog-NWiIykoS.js";import{B as ce,L as U}from"./bulk-price-update-dialog-ev8me6nr.js";import{D as de,a as oe,b as me,c as he,d as xe,e as ue}from"./dialog-OAqv1hEh.js";import{C as je}from"./checkbox-C2zjyH3b.js";import{S as ge}from"./switch-DAP1aJKg.js";import{P as pe}from"./percent-B9Lw0RAW.js";import{P as Y}from"./pencil-DXFkiqC-.js";import"./vendor-ui-87y9m6y2.js";import"./check-DjZQULyt.js";import"./table-DJGYHiNt.js";import"./alert-dialog-ktYZjlA1.js";const k="_all";function fe({open:a,onOpenChange:l,defaultCategoryId:x}){const[m,p]=n.useState(x||k),[f,i]=n.useState(["collectionPrice","eatInPrice"]),[C,N]=n.useState(!0),{data:u}=H({limit:100}),v=te(),c=u?.categories??[],z=t=>{i(j=>j.includes(t)?j.filter(S=>S!==t):[...j,t])},b=()=>{i(["collectionPrice","eatInPrice"]),N(!0)},P=t=>{t&&p(x||k),t||b(),l(t)},O=()=>{f.length!==0&&v.mutate({...m!==k?{categoryId:m}:{},targets:f,includeSizePrices:C},{onSuccess:t=>{w.success(`Copied to ${t.updatedProducts} product(s)`+(t.updatedSizePrices>0?` and ${t.updatedSizePrices} size price(s)`:"")),l(!1),b()},onError:()=>w.error("Failed to copy prices")})},I=f.length>0;return e.jsx(de,{open:a,onOpenChange:P,children:e.jsxs(oe,{className:"sm:max-w-md",children:[e.jsxs(me,{children:[e.jsx(he,{children:"Copy Delivery Price to Collection & Eat-In"}),e.jsx(xe,{children:"Copy the main (delivery) price into the selected order-type prices. This overwrites any existing collection/eat-in prices with the current delivery price."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{children:"Category"}),e.jsxs(F,{value:m,onValueChange:p,children:[e.jsx(B,{children:e.jsx(_,{})}),e.jsxs(V,{children:[e.jsx(E,{value:k,children:"All categories"}),c.map(t=>e.jsxs(E,{value:t.id,children:[g(t.name)," ",t._count?`(${t._count.products})`:""]},t.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{children:"Copy Into"}),e.jsx("div",{className:"space-y-2",children:[["collectionPrice","Collection Price"],["eatInPrice","Eat-In Price"]].map(([t,j])=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(je,{id:`target-${t}`,checked:f.includes(t),onCheckedChange:()=>z(t)}),e.jsx(D,{htmlFor:`target-${t}`,className:"font-normal cursor-pointer",children:j})]},t))})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(D,{htmlFor:"include-sizes",className:"cursor-pointer",children:"Include size prices"}),e.jsx(ge,{id:"include-sizes",checked:C,onCheckedChange:N})]})]}),e.jsxs(ue,{children:[e.jsx(r,{variant:"outline",onClick:()=>P(!1),children:"Cancel"}),e.jsx(r,{onClick:O,disabled:!I||v.isPending,children:v.isPending?"Copying...":"Copy Prices"})]})]})})}const Ne={DELIVERY:"Del",COLLECTION:"Col",EATIN:"Eat",TAKEAWAY:"Take"};function G(a){return a.isActive===!1?!0:(a.visibilityOrderTypes??[]).length===0}function K({types:a}){return a.length===0?e.jsx(o,{variant:"secondary",children:"Hidden"}):a.length===4?e.jsx(o,{variant:"default",children:"All"}):e.jsx(o,{variant:"default",children:a.map(l=>Ne[l]??l).join(", ")})}function M({channels:a}){return a.length===0?e.jsx(o,{variant:"secondary",children:"None"}):a.length===2?e.jsx(o,{variant:"default",children:"All"}):e.jsx(o,{variant:"default",children:a.includes("ONLINE")?"Online":"EPOS"})}function He(){const[a,l]=Q(),[x,m]=n.useState(1),[p,f]=n.useState(""),[i,C]=n.useState(a.get("categoryId")??""),N=s=>{C(s),l(s?{categoryId:s}:{},{replace:!0})},{data:u,isLoading:v}=ie({page:x,limit:30,sortBy:"position",...p?{search:p}:{},...i?{categoryId:i}:{}}),{data:c}=H({limit:100}),z=re(),[b,P]=n.useState(!1),[O,I]=n.useState(!1),[t,j]=n.useState(!!a.get("categoryId"));n.useEffect(()=>{!t&&c?.categories?.length&&(N(c.categories[0].id),j(!0))},[c,t]),n.useEffect(()=>{i&&c?.categories?.length&&!c.categories.some(s=>s.id===i)&&N(c.categories[0]?.id??"")},[c,i]);const S=s=>{z.mutate(s,{onSuccess:()=>w.success("Product deleted"),onError:()=>w.error("Failed to delete product")})},W=[{header:"Name",cell:s=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:g(s.name)}),s.category&&e.jsx("p",{className:"text-xs text-muted-foreground",children:g(s.category.name)})]}),G(s)&&e.jsx(o,{variant:"outline",className:"text-xs text-muted-foreground",children:"Not Visible"})]})},{header:"Position",cell:s=>s.position},{header:"Delivery",cell:s=>h(s.mainPrice)},{header:"Collection",cell:s=>s.collectionPrice!=null?h(s.collectionPrice):e.jsx("span",{className:"text-muted-foreground",children:h(s.mainPrice)})},{header:"Eat-In",cell:s=>s.eatInPrice!=null?h(s.eatInPrice):e.jsx("span",{className:"text-muted-foreground",children:h(s.mainPrice)})},{header:"Order Types",cell:s=>e.jsx(K,{types:s.visibilityOrderTypes??[]})},{header:"Channels",cell:s=>e.jsx(M,{channels:s.visibilityChannels??[]})},{header:"Featured",cell:s=>s.isFeatured?e.jsx(o,{variant:"outline",children:"Featured"}):"-"},{header:"Actions",cell:s=>e.jsxs("div",{className:"flex gap-1",children:[e.jsx(r,{variant:"ghost",size:"icon",asChild:!0,title:"Edit product",children:e.jsx(y,{to:`/dashboard/products/${s.id}`,children:e.jsx(Y,{className:"h-4 w-4"})})}),e.jsx(r,{variant:"ghost",size:"icon",asChild:!0,title:"Linked 
1sub-menus",children:e.jsx(y,{to:`/dashboard/products/${s.id}/submenus`,children:e.jsx(U,{className:"h-4 w-4"})})}),e.jsx(R,{trigger:e.jsx(r,{variant:"ghost",size:"icon",children:e.jsx($,{className:"h-4 w-4 text-destructive"})}),title:"Delete Product",description:`Are you sure you want to delete "${g(s.name)}"?`,onConfirm:()=>S(s.id)})]})}],d=u?.meta,q=d&&d.totalPages>1&&e.jsxs("div",{className:"flex items-center justify-between px-2",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Page ",d.page," of ",d.totalPages," (",d.total," total)"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(r,{variant:"outline",size:"sm",disabled:d.page<=1,onClick:()=>m(d.page-1),children:e.jsx(X,{className:"h-4 w-4"})}),e.jsx(r,{variant:"outline",size:"sm",disabled:d.page>=d.totalPages,onClick:()=>m(d.page+1),children:e.jsx(Z,{className:"h-4 w-4"})})]})]});return e.jsxs("div",{className:"space-y-6",children:[e.jsx(ne,{title:"Products",description:"Manage your product catalog",action:e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(r,{variant:"outline",onClick:()=>I(!0),children:[e.jsx(ee,{className:"mr-2 h-4 w-4"}),"Copy Delivery → Collection/Eat-In"]}),e.jsxs(r,{variant:"outline",onClick:()=>P(!0),children:[e.jsx(pe,{className:"mr-2 h-4 w-4"}),"Bulk Price Update"]}),e.jsx(r,{asChild:!0,children:e.jsxs(y,{to:i?`/dashboard/products/new?categoryId=${i}`:"/dashboard/products/new",children:[e.jsx(se,{className:"mr-2 h-4 w-4"}),"New Product"]})})]})}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row",children:[e.jsx(ae,{placeholder:"Search products...",value:p,onChange:s=>{f(s.target.value),m(1)},className:"sm:max-w-xs"}),e.jsxs(F,{value:i||"_all",onValueChange:s=>{N(s==="_all"?"":s),m(1)},children:[e.jsx(B,{className:"sm:w-48",children:e.jsx(_,{placeholder:"All categories"})}),e.jsxs(V,{children:[e.jsx(E,{value:"_all",children:"All categories"}),(c?.categories??[]).map(s=>e.jsx(E,{value:s.id,children:g(s.name)},s.id))]})]})]}),e.jsx("div",{className:"hidden md:block",children:e.jsx(le,{columns:W,data:u?.products??[],meta:u?.meta,onPageChange:m,isLoading:v})}),e.jsxs("div",{className:"md:hidden space-y-3",children:[v?Array.from({length:5}).map((s,J)=>e.jsx(L,{children:e.jsxs(A,{className:"space-y-3 pt-4",children:[e.jsx(T,{className:"h-5 w-3/4"}),e.jsx(T,{className:"h-4 w-1/2"}),e.jsx(T,{className:"h-4 w-1/3"})]})},J)):u?.products.length===0?e.jsx(L,{children:e.jsx(A,{className:"py-8 text-center text-muted-foreground",children:"No products found."})}):u?.products.map(s=>e.jsx(ve,{product:s,onDelete:()=>S(s.id)},s.id)),q]}),e.jsx(ce,{open:b,onOpenChange:P,defaultCategoryId:i}),e.jsx(fe,{open:O,onOpenChange:I,defaultCategoryId:i})]})}function ve({product:a,onDelete:l}){const x=g(a.name);return e.jsx(L,{children:e.jsxs(A,{className:"pt-4",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"font-semibold truncate",children:x}),G(a)&&e.jsx(o,{variant:"outline",className:"text-xs text-muted-foreground shrink-0",children:"Not Visible"})]}),a.category&&e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:g(a.category.name)})]}),e.jsx("p",{className:"ml-2 shrink-0 text-lg font-bold",children:h(a.mainPrice)})]}),e.jsxs("div",{className:"mt-3 grid grid-cols-3 gap-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Delivery"}),e.jsx("p",{children:h(a.mainPrice)})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Collection"}),e.jsx("p",{className:a.collectionPrice==null?"text-muted-foreground":"",children:h(a.collectionPrice??a.mainPrice)})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Eat-In"}),e.jsx("p",{className:a.eatInPrice==null?"text-muted-foreground":"",children:h(a.eatInPrice??a.mainPrice)})]})]}),e.jsxs("div",{className:"mt-3 grid grid-cols-3 gap-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Position"}),e.jsx("p",{children:a.position})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Order Types"}),e.jsx("div",{className:"mt-0.5",children:e.jsx(K,{types:a.visibilityOrderTypes??[]})})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Channels"}),e.jsx("div",{className:"mt-0.5",children:e.jsx(M,{channels:a.visibilityChannels??[]})})]})]}),a.isFeatured&&e.jsx("div",{className:"mt-2",children:e.jsx(o,{variant:"outline",children:"Featured"})}),e.jsxs("div",{className:"mt-3 flex justify-end gap-1",children:[e.jsx(r,{variant:"outline",size:"icon",className:"h-8 w-8",asChild:!0,title:"Edit",children:e.jsx(y,{to:`/dashboard/products/${a.id}`,children:e.jsx(Y,{className:"h-3.5 w-3.5"})})}),e.jsx(r,{variant:"outline",size:"icon",className:"h-8 w-8",asChild:!0,title:"Sub-menus",children:e.jsx(y,{to:`/dashboard/products/${a.id}/submenus`,children:e.jsx(U,{className:"h-3.5 w-3.5"})})}),e.jsx(R,{trigger:e.jsx(r,{variant:"outline",size:"icon",className:"h-8 w-8",children:e.jsx($,{className:"h-3.5 w-3.5 text-destructive"})}),title:"Delete Product",description:`Are you sure you want to delete "${x}"?`,onConfirm:l})]})]})})}export{He as ProductListPage};

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.