PageSourceSearch

https://os.sosme.ai/assets/PromotionsPage-_MLpx5os.js

js sosme.ai collected 2026-10-05 15:12:55 UTC 11,756 bytes, 6 lines download raw bytes

1import{c as z,b1 as W,a as K,r as m,aA as y,y as f,j as e,av as U,aB as Y,L as S,aR as T,bf as _}from"./index-DelWp-6b.js";import{u as j}from"./useQuery-B9eAwr7I.js";import{u as A}from"./useMutation-CwYdRQCa.js";import{b as u}from"./pricing.service-DoMmq53q.js";import{p as E}from"./posLookups.service-D1Jgtun7.js";import{P as H,b as h,p as b,c as Q}from"./PricingShell-C3jfPTD5.js";import{b as r,e as a,a as X}from"./pricing.types-DzR9kvvl.js";import{C as G}from"./chevron-down-B145rEUg.js";import{P as V}from"./plus-BjX2r5pd.js";import{P as J}from"./pencil-D8nokcWq.js";import{P as Z}from"./play-DvJeLViy.js";import{P as ee}from"./pause-DXRkz2rb.js";import{B as te}from"./ban-BU4lv9Ao.js";import"./unwrap-CuJafpqD.js";import"./paging-BO6Zj7Ff.js";/**
2 * @license lucide-react v0.441.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const L=z("Radar",[["path",{d:"M19.07 4.93A10 10 0 0 0 6.99 3.34",key:"z3du51"}],["path",{d:"M4 6h.01",key:"oypzma"}],["path",{d:"M2.29 9.62A10 10 0 1 0 21.31 8.35",key:"qzzz0"}],["path",{d:"M16.24 7.76A6 6 0 1 0 8.23 16.67",key:"1yjesh"}],["path",{d:"M12 18h.01",key:"mhygvu"}],["path",{d:"M17.99 11.66A6 6 0 0 1 15.77 16.67",key:"1u2y91"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}],["path",{d:"m13.41 10.59 5.66-5.66",key:"mhq4k0"}]]),M={[r.PercentOff]:"% off",[r.AmountOff]:"Amount off",[r.FixedPrice]:"Fixed price",[r.BuyXGetY]:"Buy X get Y",[r.MixAndMatch]:"Mix & match",[r.Bundle]:"Bundle",[r.HappyHour]:"Happy hour",[r.MemberPrice]:"Member price",[r.FamilyPack]:"Family pack",[r.NearExpiryMarkdown]:"Near-expiry markdown",[r.Clearance]:"Clearance",[r.Seasonal]:"Seasonal",[r.SupplierFunded]:"Supplier funded"},se={[a.Draft]:"bg-slate-100 dark:bg-slate-700 text-slate-600 dark:text-slate-300",[a.PendingApproval]:"bg-amber-100 dark:bg-amber-500/15 text-amber-700 dark:text-amber-300",[a.Active]:"bg-emerald-100 dark:bg-emerald-500/15 text-emerald-700 dark:text-emerald-300",[a.Paused]:"bg-sky-100 dark:bg-sky-500/15 text-sky-700 dark:text-sky-300",[a.Expired]:"bg-slate-100 dark:bg-slate-700 text-slate-500",[a.Cancelled]:"bg-rose-100 dark:bg-rose-500/15 text-rose-700 dark:text-rose-300"},ae={[a.Draft]:"Draft",[a.PendingApproval]:"Pending approval",[a.Active]:"Active",[a.Paused]:"Paused",[a.Expired]:"Expired",[a.Cancelled]:"Cancelled"};function re({p:s,onAction:i,onEdit:l,busy:p}){const n=s.status===a.Draft||s.status===a.PendingApproval||s.status===a.Paused,x=s.status===a.Active,d=s.status!==a.Cancelled&&s.status!==a.Expired;return e.jsxs("div",{className:"rounded-2xl border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-800/50 p-4 flex items-center gap-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl flex items-center justify-center shrink-0",style:{background:"rgba(var(--primary-rgb),0.12)",color:"var(--primary-600)"},children:e.jsx(T,{className:"w-5 h-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-bold text-sm",children:s.name}),e.jsx("span",{className:"font-mono text-[11px] text-slate-500",children:s.code}),e.jsx("span",{className:`text-[10px] font-semibold px-2 py-0.5 rounded-full ${se[s.status]}`,children:ae[s.status]??s.statusCode}),s.requiresCoupon&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] font-semibold px-2 py-0.5 rounded-full bg-violet-100 dark:bg-violet-500/15 text-violet-700 dark:text-violet-300",children:[e.jsx(_,{className:"w-3 h-3"})," Coupon"]}),s.isExclusive&&e.jsx("span",{className:"text-[10px] font-semibold px-2 py-0.5 rounded-full bg-slate-100 dark:bg-slate-700 text-slate-600 dark:text-slate-300",children:"Exclusive"})]}),e.jsxs("div",{className:"text-[12px] text-slate-500 mt-0.5",children:[M[s.promotionType]??s.promotionTypeCode," · priority ",s.priority,s.stackingPolicy===X.None&&" · never stacks",s.validTo&&` · until ${new Date(s.validTo).toLocaleDateString()}`,typeof s.redemptionCount=="number"&&` · ${s.redemptionCount} redeemed`,s.maxRedemptions?` of ${s.maxRedemptions}`:""]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>l(s.id),className:"w-8 h-8 rounded-lg border border-slate-200 dark:border-slate-700 hover:bg-slate-100 dar
6k:hover:bg-slate-700 flex items-center justify-center transition","aria-label":`Edit ${s.name}`,children:e.jsx(J,{className:"w-4 h-4"})}),n&&e.jsxs("button",{type:"button",onClick:()=>i("activate",s.id),disabled:p,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] font-semibold bg-emerald-50 dark:bg-emerald-500/15 text-emerald-700 dark:text-emerald-300 hover:bg-emerald-100 disabled:opacity-40 transition",title:"Needs the ApprovePromotion permission",children:[e.jsx(Z,{className:"w-3.5 h-3.5"})," Activate"]}),x&&e.jsxs("button",{type:"button",onClick:()=>i("pause",s.id),disabled:p,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] font-semibold border border-slate-200 dark:border-slate-700 hover:bg-slate-100 dark:hover:bg-slate-700 disabled:opacity-40 transition",children:[e.jsx(ee,{className:"w-3.5 h-3.5"})," Pause"]}),d&&e.jsx("button",{type:"button",onClick:()=>i("cancel",s.id),disabled:p,className:"w-8 h-8 rounded-lg hover:bg-rose-100 dark:hover:bg-rose-500/15 text-slate-400 hover:text-rose-500 flex items-center justify-center disabled:opacity-40 transition","aria-label":`Cancel ${s.name}`,children:e.jsx(te,{className:"w-4 h-4"})})]})]})}function fe(){var P,C;const s=W(),i=K(),[l,p]=m.useState(""),n=j({queryKey:["pricing","promotions"],queryFn:()=>u.list()}),x=A({mutationFn:({action:t,id:o})=>t==="activate"?u.activate(o):t==="pause"?u.pause(o):u.cancel(o),onSuccess:(t,o)=>{y.success(o.action==="activate"?"Promotion is live":o.action==="pause"?"Promotion paused":"Promotion cancelled"),s.invalidateQueries({queryKey:["pricing","promotions"]})},onError:t=>y.error(f(t,"Could not change the promotion."))}),[d,F]=m.useState(!1),[k,q]=m.useState(""),[N,B]=m.useState(""),[g,D]=m.useState(()=>{const t=new Date;return t.setMinutes(t.getMinutes()-t.getTimezoneOffset()),t.toISOString().slice(0,16)}),[v,R]=m.useState(""),I=j({queryKey:["pos","lk","warehouses"],queryFn:E.warehouses,enabled:d}),$=j({queryKey:["pos","lk","clients"],queryFn:E.clients,enabled:d}),c=A({mutationFn:()=>u.candidates({warehouseId:k||null,clientId:N||null,whenLocal:g?new Date(g).toISOString().slice(0,19):null,couponCodes:v.trim()?v.split(",").map(t=>t.trim()).filter(Boolean):[]}),onError:t=>y.error(f(t,"Could not work out what would fire."))}),w=(n.data??[]).filter(t=>!l.trim()||t.name.toLowerCase().includes(l.toLowerCase())||t.code.toLowerCase().includes(l.toLowerCase()));return e.jsx(H,{title:"Pricing & Promotions",subtitle:"What a product costs, and every rule that changes it",actions:e.jsxs("button",{type:"button",onClick:()=>i("/pricing/promotions/new"),className:"shrink-0 inline-flex items-center gap-2 px-4 py-2 rounded-xl text-[13px] font-semibold text-white transition",style:{background:"var(--primary-600)"},children:[e.jsx(V,{className:"w-4 h-4"}),"New promotion"]}),children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"relative max-w-sm",children:[e.jsx(U,{className:"w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx("input",{className:`${h} pl-9`,placeholder:"Search promotions…",value:l,onChange:t=>p(t.target.value)})]}),e.jsxs("div",{className:"rounded-2xl border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-800/50",children:[e.jsxs("button",{type:"button",onClick:()=>F(t=>!t),className:"w-full flex items-center gap-3 px-4 py-3 text-left",children:[e.jsx("span",{className:"w-8 h-8 rounded-lg flex items-center justify-center shrink-0",style:{background:"rgba(var(--primary-rgb),0.12)",color:"var(--primary-600)"},children:e.jsx(L,{className:"w-4 h-4"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block font-bold text-[13px]",children:"What would fire right now?"}),e.jsx("span",{className:"block text-[12px] text-slate-500",children:"The same question the till asks a basket — for a store, a customer and a moment."})]}),d?e.jsx(Y,{className:"w-4 h-4 text-slate-400"}):e.jsx(G,{className:"w-4 h-4 text-slate-400"})]}),d&&e.jsxs("div",{className:"px-4 pb-4 border-t border-slate-100 dark:border-slate-700 pt-3",children:[e.jsxs("div",{className:"grid sm:grid-cols-4 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:b,htmlFor:"pvw",children:"Store"}),e.jsxs("select",{id:"pvw",className:h,value:k,onChange:t=>q(t.target.value),children:[e.jsx("option",{value:"",children:"Any"}),(P=I.data)==null?void 0:P.map(t=>e.jsx("option",{value:t.id,children:t.label},t.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:b,htmlFor:"pvc",children:"Customer"}),e.jsxs("select",{id:"pvc",className:h,value:N,onChange:t=>B(t.target.value),children:[e.jsx("option",{value:"",children:"Any"}),(C=$.data)==null?void 0:C.map(t=>e.jsx("option",{value:t.id,children:t.label},t.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:b,htmlFor:"pvt",children:"Store time"}),e.jsx("input",{id:"pvt",type:"datetime-local",className:h,value:g,onChange:t=>D(t.target.value)})]}),e.jsxs("div",{children:[e.jsx("label",{className:b,htmlFor:"pvcp",children:"Coupon codes"}
6),e.jsx("input",{id:"pvcp",className:h,value:v,onChange:t=>R(t.target.value),placeholder:"SUMMER10, VIP"})]})]}),e.jsxs("button",{type:"button",onClick:()=>c.mutate(),disabled:c.isPending,className:"mt-3 inline-flex items-center gap-2 px-4 py-2 rounded-xl text-[13px] font-semibold border border-slate-200 dark:border-slate-700 hover:bg-slate-100 dark:hover:bg-slate-700 disabled:opacity-40",children:[c.isPending?e.jsx(S,{className:"w-4 h-4 animate-spin"}):e.jsx(L,{className:"w-4 h-4"}),"Check"]}),c.data&&(c.data.length===0?e.jsx("p",{className:"mt-3 text-[13px] text-slate-500",children:"Nothing would fire. An Active promotion can still sit out a basket — its window, its days, its scopes or its caps decide."}):e.jsx("ul",{className:"mt-3 space-y-1.5",children:c.data.map(t=>e.jsxs("li",{className:"flex items-center gap-2 text-[13px]",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-emerald-500 shrink-0"}),e.jsx("span",{className:"font-semibold",children:t.name}),e.jsx("span",{className:"font-mono text-[11px] text-slate-500",children:t.code}),e.jsxs("span",{className:"text-[12px] text-slate-500",children:[M[t.promotionType]??t.promotionTypeCode," · priority ",t.priority]})]},t.id))}))]})]}),n.isError&&e.jsx(Q,{message:f(n.error,"Could not load promotions."),onRetry:()=>n.refetch()}),n.isLoading&&e.jsx("div",{className:"space-y-3",children:[0,1,2].map(t=>e.jsx("div",{className:"h-20 rounded-2xl bg-slate-100 dark:bg-slate-800 animate-pulse"},t))}),!n.isLoading&&w.length===0&&e.jsxs("div",{className:"rounded-2xl border border-dashed border-slate-300 dark:border-slate-700 p-10 text-center",children:[e.jsx(T,{className:"w-10 h-10 mx-auto mb-3 text-slate-400"}),e.jsx("h2",{className:"font-bold text-sm mb-1",children:l?"Nothing matches":"No promotions"}),e.jsx("p",{className:"text-[13px] text-slate-500",children:l?"Try a different code or name.":"The pricing engine will fall back to price lists and standard prices."})]}),e.jsx("div",{className:"space-y-3",children:w.map(t=>e.jsx(re,{p:t,busy:x.isPending,onAction:(o,O)=>x.mutate({action:o,id:O}),onEdit:o=>i(`/pricing/promotions/${o}/edit`)},t.id))}),x.isPending&&e.jsxs("p",{className:"text-[12px] text-slate-500 flex items-center gap-2",children:[e.jsx(S,{className:"w-3.5 h-3.5 animate-spin"})," Applying…"]})]})})}export{fe 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.