PageSourceSearch

https://iconaapp.com/assets/offers-Wra3Yom6.js

js iconaapp.com collected 2026-10-06 15:24:32 UTC 13,704 bytes, 1 lines download raw bytes

1import{r as o,a as ge,i as je,d as Ne,j as e,S as be,I as J,B as u,X as ye,N as ve,A as Ce,w as we,x as Se,y as Pe,z as Ae,C as De,D as ke,E as Oe,K as Me,F as U,M as _,g as Fe}from"./index-WHULU0jW.js";import{u as $}from"./useMutation-BYXU51OA.js";import{C as z,b as Q}from"./card-BlH5Drk3.js";import{B as Z}from"./badge-eSQGmkpG.js";import{S as Ee,a as Te,b as Le,c as Ie,d as v}from"./select-GrX3B2N2.js";import{D as qe,a as Ue,b as _e,c as $e,d as ze,e as Qe}from"./dialog-DjXxw1NJ.js";import{C as Be,a as Ke,b as Re}from"./collapsible-DyL88aQg.js";import{L as We}from"./label-Cp0G8FgB.js";import{S as He}from"./separator-mNzeeqmg.js";import{u as Ve}from"./use-currency-DCGG8bRS.js";import{A as Ye,a as Ge,b as Xe}from"./avatar-CiHUCdk-.js";import{S as D,f as Je}from"./skeleton-CFzjnIWk.js";import{T as Ze}from"./tag-Ba-AzLj1.js";import{f as ee}from"./format-CILBJ7El.js";import{C as et}from"./chevron-down-6yZoXBwj.js";import{C as te}from"./chevron-right-DeJyYtwC.js";import{A as tt}from"./arrow-up-down-B5A9y2Hh.js";import{C as st}from"./chevron-left-CzzQDnh7.js";import"./index-BdQq_4o_.js";import"./index-DXGq4QHA.js";import"./index-BFruoVYP.js";import"./chevron-up-CBx5ZPzc.js";import"./index-DUQr7vaR.js";import"./constructNow-BkTMlMS8.js";import"./en-US-Cc-9gH5A.js";import"./endOfMonth-DAoz7cdb.js";const B={pending:"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400",accepted:"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400",rejected:"bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400",declined:"bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400",countered:"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-400",expired:"bg-gray-100 text-gray-800 dark:bg-gray-900/30 dark:text-gray-400"},at=c=>c.charAt(0).toUpperCase()+c.slice(1),rt=10;function Ft(){const[c,se]=o.useState("all"),[k,ae]=o.useState(""),[re,C]=o.useState(!1),[n,K]=o.useState(null),[O,M]=o.useState(""),[ne,ie]=o.useState(new Set),[r,g]=o.useState(null),[j,R]=o.useState(1),{user:m}=ge(),{toast:d}=je(),{format:x,symbol:le}=Ve(),F=(m==null?void 0:m._id)||(m==null?void 0:m.id),{data:f,isLoading:E,error:nt,refetch:T}=Ne({queryKey:["/api/offers","seller",F,c,j],queryFn:async()=>{const t=new URLSearchParams;t.set("user",F),t.set("role","seller"),t.set("page",j.toString()),t.set("limit",rt.toString()),c!=="all"&&t.set("status",c);const s=await Fe(`/api/offers?${t}`);if(!s.ok)throw new Error("Failed to fetch offers");return s.json()},enabled:!!F,staleTime:0,refetchOnMount:!0}),W=(f==null?void 0:f.products)||[],h=f==null?void 0:f.pagination;h!=null&&h.total||W.length;const w=(h==null?void 0:h.pages)||1,oe=t=>{ie(s=>{const i=new Set(s);return i.has(t)?i.delete(t):i.add(t),i})},L=$({mutationFn:async t=>await _("POST","/api/offers/accept",{offerId:t,usertype:"seller"}),onSuccess:()=>{d({title:"Offer accepted successfully"}),U.invalidateQueries({queryKey:["/api/offers"]}),T()},onError:t=>{d({title:"Failed to accept offer",description:t.message,variant:"destructive"})}}),I=$({mutationFn:async t=>await _("POST","/api/offers/reject",{offerId:t,usertype:"seller"}),onSuccess:()=>{d({title:"Offer declined"}),U.invalidateQueries({queryKey:["/api/offers"]}),T()},onError:t=>{d({title:"Failed to decline offer",description:t.message,variant:"destructive"})}}),q=$({mutationFn:async({offerId:t,amount:s})=>await _("POST","/api/offers/counter",{offerId:t,counterPrice:s}),onSuccess:()=>{d({title:"Counter offer sent"}),C(!1),K(null),M(""),U.invalidateQueries({queryKey:["/api/offers"]}),T()},onError:t=>{d({title:"Failed to send counter offer",description:t.message,variant:"destructive"})}}),ce=t=>{g({offer:t,action:"accept"})},de=t=>{g({offer:t,action:"decline"})},ue=()=>{if(!r)return;const t=r.offer._id||r.offer.id;r.action==="accept"?L.mutate(t,{onSettled:()=>g(null)}):I.mutate(t,{onSettled:()=>g(null)})},S=L.isPending||I.isPending,me=(t,s)=>{var i;K({...t,product:s}),M(((i=t.offeredPrice||t.offerAmount)==null?void 0:i.toString())||""),C(!0)},xe=()=>{if(!n||!O)return;const t=parseFloat(O);if(isNaN(t)||t<=0){d({title:"Please enter a valid amount",variant:"destructive"});return}const s=n._id||n.id;q.mutate({offerId:s,amount:t})},H=W.filter(t=>{var s,i;if(k){const l=k.toLowerCase(),P=((s=t.name)==null?void 0:s.toLowerCase())||"",A=(i=t.offers)==null?void 0:i.some(a=>{var N,b;return(((N=a.buyer)==null?void 0:N.userName)||((b=a.buyer)==null?void 0:b.firstName)||"").toLowerCase().includes(l)});if(!P.includes(l)&&!A)return!1}return!0}),V=t=>(t.images||t.productimages||[])[0]||"/placeholder-product.png",fe=t=>{var i,l;return(((i=t.buyer)==null?void 0:i.userName)||((l=t.buyer)==null?void 0:l.firstName)||"U").charAt(0).toUpperCase()},he=t=>(t.offers||[]).filter(s=>s.status==="pending").length,pe=t=>(t.offers||[]).length;return E?e.jsxs("div",{className:"container max-w-7xl py-8",children:[e.jsxs("div",{className:"mb-8",children:[e.jsx("h1",{className:"text-3xl font-bold text-foreground",children:"Offers"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Manage offers from buyers"})]}),e.jsx("div",{className:"grid gap-4",children:[1,2,3].map(t=>e.jsx(z,{children:e.jsx(Q,{className:"py-4",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(D,{className:"h-16 w-16 rounded-lg"}),e.jsxs("div",{className:"flex-1",children:[e.jsx(D,{className:"h-4 w-48 mb-2"}),e.jsx(D,{className:"h-3 w-32"})]}),e.jsx(D,{className:"h-8 w-24"})]})})},t))})]}):e.jsxs("div",{className:"container max-w-7xl py-8",children:[e.jsxs("div",{className:"mb-8",children:[e.jsx("h1",{className:"text-3xl font-bold text-foreground","data-testid":"text-page-title",children:"Offers"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Manage offers from buyers on your products"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4 mb-6",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(be,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(J,{placeholder:"Search by product or buyer...",value:k,onChange:t=>ae(t.target.value),className:"pl-10","data-testid":"input-search-offers"})]}),e.jsxs(Ee,{value:c,onValueChange:se,children:[e.jsx(Te,{className:"w-full sm:w-[180px]","data-testid":"select-status-filter",children:e.jsx(Le,{placeholder:"Filter by status"})}),e.jsxs(Ie,{children:[e.jsx(v,{value:"all",children:"All Statuses"}),e.jsx(v,{value:"pending",children:"Pending"}),e.jsx(v,{value:"accepted",children:"Accepted"}),e.jsx(v,{value:"rejected",children:"Rejected"}),e.jsx(v,{value:"countered",children:"Countered"})]})]})]}),H.length===0?e.jsx(z,{children:e.jsxs(Q,{className:"py-12 text-center",children:[e.jsx(Ze,{className:"h-12 w-12 mx-auto text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-semibold text-foreground mb-2",children:"No offers yet"}),e.jsx("p",{className:"text-muted-foreground",children:"When buyers make offers on your products, they'll appear here."})]})}):e.jsx("div",{className:"space-y-4",children:H.map(t=>{const s=t._id||t.id,i=ne.has(s),l=he(t),P=pe(t),A=t.offers||[];return e.jsx(z,{"data-testid":`card-product-${s}`,children:e.jsxs(Be,{open:i,onOpenChange:()=>oe(s),children:[e.jsx(Ke,{asChild:!0,children:e.jsx("div",{className:"cursor-pointer hover-elevate",children:e.jsx(Q,{className:"py-4",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("img",{src:V(t),alt:t.name||"Product",className:"h-16 w-16 rounded-lg object-cover bg-muted"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"font-semibold text-foreground truncate","data-testid":"text-product-name",children:t.name||"Unknown Product"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["List Price: ",x(t.price||0)]}),e.jsxs("div",{className:"flex flex-wrap gap-x-3 gap-y-1 text-xs text-muted-foreground mt-1",children:[t.createdAt&&e.jsxs("span",{children:["Listed: ",ee(new Date(t.createdAt),"MMM d, yyyy")]}),t.expiresAt&&e.jsxs("span",{className:new Date(t.expiresAt)<new Date?"text-red-500":"",children:["Expires: ",ee(new Date(t.expiresAt),"MMM d, yyyy"),new Date(t.expiresAt)<new Date&&" (Expired)"]})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"text-right",children:e.jsxs("div",{className:"flex items-center gap-2",children:[l>0&&e.jsxs(Z,{className:B.pending,children:[l," pending"]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[P," offer",P!==1?"s":""]})]})}),i?e.jsx(et,{className:"h-5 w-5 text-muted-foreground"}):e.jsx(te,{className:"h-5 w-5 text-muted-foreground"})]})]})})})}),e.jsxs(Re,{children:[e.jsx(He,{}),e.jsx("div",{className:"bg-muted/30",children:A.length===0?e.jsx("div",{className:"p-4 text-center text-muted-foreground",children:"No offers for this product"}):e.jsx("div",{className:"divide-y",children:A.map(a=>{var Y,G,X;const p=a._id||a.id,N=a.offeredPrice||a.offerAmount||0,b=t.price?Math.round((1-N/t.price)*100):0;return e.jsx("div",{className:"p-4 hover:bg-muted/50 transition-colors","data-testid":`offer-row-${p}`,children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsxs(Ye,{className:"h-10 w-10",children:[e.jsx(Ge,{src:(Y=a.buyer)==null?void 0:Y.profilePhoto}),e.jsx(Xe,{children:fe(a)})]}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"font-medium text-foreground",children:["@",((G=a.buyer)==null?void 0:G.userName)||((X=a.buyer)==null?void 0:X.firstName)||"User"]}),e.jsxs("div",{className:"flex items-baseline gap-2 mt-1",children:[e.jsx("span",{className:"text-lg font-bold text-foreground","data-testid":"text-offer-amount",children:x(N)}),b>0&&e.jsxs("span",{className:"text-sm text-muted-foreground",children:["(",b,"% off)"]})]}),a.counterPrice&&e.jsxs("p",{className:"text-sm text-blue-600 dar
1k:text-blue-400 mt-1",children:["Your counter: ",x(a.counterPrice)]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:["Offered ",a.createdAt?Je(new Date(a.createdAt),{addSuffix:!0}):"N/A"]})]}),e.jsxs("div",{className:"flex flex-col items-end gap-2",children:[e.jsx(Z,{className:B[a.status]||B.pending,children:at(a.status)}),a.status==="pending"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(u,{size:"sm",variant:"outline",onClick:y=>{y.stopPropagation(),de(a)},disabled:I.isPending,"data-testid":`button-decline-${p}`,children:[e.jsx(ye,{className:"h-4 w-4 mr-1"}),"Decline"]}),e.jsxs(u,{size:"sm",variant:"outline",onClick:y=>{y.stopPropagation(),me(a,t)},"data-testid":`button-counter-${p}`,children:[e.jsx(tt,{className:"h-4 w-4 mr-1"}),"Counter"]}),e.jsxs(u,{size:"sm",onClick:y=>{y.stopPropagation(),ce(a)},disabled:L.isPending,"data-testid":`button-accept-${p}`,children:[e.jsx(ve,{className:"h-4 w-4 mr-1"}),"Accept"]})]}),a.status==="countered"&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Waiting for buyer response"})]})]})})]})},p)})})})]})]})},s)})}),w>1&&e.jsxs("div",{className:"flex items-center justify-between mt-4",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Page ",j," of ",w]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>R(t=>Math.max(1,t-1)),disabled:j===1||E,"data-testid":"button-prev-page",children:[e.jsx(st,{className:"h-4 w-4 mr-1"}),"Previous"]}),e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>R(t=>Math.min(w,t+1)),disabled:j===w||E,"data-testid":"button-next-page",children:["Next",e.jsx(te,{className:"h-4 w-4 ml-1"})]})]})]}),e.jsx(qe,{open:re,onOpenChange:C,children:e.jsxs(Ue,{children:[e.jsxs(_e,{children:[e.jsx($e,{children:"Make Counter Offer"}),e.jsxs(ze,{children:["Enter a new price to counter the buyer's offer of ",x((n==null?void 0:n.offeredPrice)||(n==null?void 0:n.offerAmount)||0)]})]}),e.jsx("div",{className:"py-4",children:e.jsxs("div",{className:"space-y-4",children:[(n==null?void 0:n.product)&&e.jsxs("div",{className:"flex items-center gap-3 p-3 bg-muted rounded-lg",children:[e.jsx("img",{src:V(n.product),alt:n.product.name,className:"h-12 w-12 rounded object-cover"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:n.product.name}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["List Price: ",x(n.product.price||0)]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(We,{htmlFor:"counter-amount",children:["Your Counter Price (",le,")"]}),e.jsx(J,{id:"counter-amount",type:"number",step:"0.01",min:"0",value:O,onChange:t=>M(t.target.value),placeholder:"Enter counter price","data-testid":"input-counter-amount"})]})]})}),e.jsxs(Qe,{children:[e.jsx(u,{variant:"outline",onClick:()=>C(!1),children:"Cancel"}),e.jsx(u,{onClick:xe,disabled:q.isPending,"data-testid":"button-submit-counter",children:q.isPending?"Sending...":"Send Counter Offer"})]})]})}),e.jsx(Ce,{open:!!r,onOpenChange:t=>!S&&!t&&g(null),children:e.jsxs(we,{children:[e.jsxs(Se,{children:[e.jsx(Pe,{children:(r==null?void 0:r.action)==="accept"?"Accept Offer?":"Decline Offer?"}),e.jsx(Ae,{children:(r==null?void 0:r.action)==="accept"?`Accept this offer of ${x((r==null?void 0:r.offer.offeredPrice)||(r==null?void 0:r.offer.offerAmount)||0)}? An order will be created automatically.`:"Are you sure you want to decline this offer?"})]}),e.jsxs(De,{children:[e.jsx(ke,{disabled:S,"data-testid":"button-cancel-action",children:"Cancel"}),e.jsxs(Oe,{onClick:ue,disabled:S,"data-testid":"button-confirm-action",children:[S?e.jsx(Me,{className:"h-4 w-4 animate-spin mr-2"}):null,(r==null?void 0:r.action)==="accept"?"Accept":"Decline"]})]})]})})]})}export{Ft 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.