PageSourceSearch

https://app.metalbear.com/assets/Invoices-By8L7I8-.js

js metalbear.com collected 2026-10-01 11:33:51 UTC 4,691 bytes, 6 lines download raw bytes

1import{c as z,u as M,r as o,a as _,al as U,am as B,a5 as b,an as R,j as e,R as d,L as T,M as F,Z as $,ab as j,q as V,ao as q,ap as W,aq as k,ar as h,F as C,as as G,at as u,z as H}from"./index-CoH3pPWC.js";import{P as K}from"./PageHeading-DYRnTTdf.js";import{f as Z}from"./formatAmount-7XpBwXzF.js";import{A as J}from"./arrow-left-1_b87t9K.js";/**
2 * @license lucide-react v0.575.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 Q=[["path",{d:"M12 15V3",key:"m9g1x1"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["path",{d:"m7 10 5 5 5-5",key:"brsn70"}]],X=z("download",Q),Y="Back to Billing",ee="Download all",se="Download selected",ae="Failed to load invoices.",ne="No invoices yet.",te="Invoice",oe="Date",ce="Amount",le="Previous",ie="Page ",re="Next";function de(i,g){const m=URL.createObjectURL(i),c=document.createElement("a");c.href=m,c.download=g,document.body.appendChild(c),c.click(),c.remove(),URL.revokeObjectURL(m)}const ge=()=>{const{accessToken:i}=M(),[g,m]=o.useState([void 0]),[c,p]=o.useState(0),[r,N]=o.useState(new Set),[y,f]=o.useState(),[x,v]=o.useState(),{data:t,isLoading:D,error:L}=_(U(i,g[c])),l=o.useMemo(()=>(t==null?void 0:t.invoices)??[],[t]),A=l.length>0&&l.every(s=>r.has(s.id)),E=o.useCallback(()=>{N(s=>{const a=new Set(s);return l.every(n=>a.has(n.id))?l.forEach(n=>{a.delete(n.id)}):l.forEach(n=>{a.add(n.id)}),a})},[l]),O=o.useCallback(s=>{N(a=>{const n=new Set(a);return n.has(s)?n.delete(s):n.add(s),n})},[]),I=o.useCallback(()=>{const s=l.at(-1);!(t!=null&&t.hasMore)||!s||(m(a=>{const n=[...a];return n[c+1]=s.id,n}),p(a=>a+1))},[t==null?void 0:t.hasMore,l,c]),S=o.useCallback(()=>{p(s=>Math.max(0,s-1))},[]),P=o.useCallback(async s=>{f(s.id);try{const a=await B(i,s.id),n=document.createElement("a");n.href=a,n.target="_blank",n.rel="noopener",document.body.appendChild(n),n.click(),n.remove()}catch(a){b.error(`Failed to download invoice: ${a instanceof Error?a.message:String(a)}`)}finally{f(void 0)}},[i]),w=o.useCallback(async s=>{v(s&&s.length>0?"selected":"all");try{const a=await R(i,s);de(a,"invoices.zip")}catch(a){b.error(`Failed to download invoices: ${a instanceof Error?a.message:String(a)}`)}finally{v(void 0)}},[i]);return e.jsxs("div",{className:"space-y-6",children:[e.jsx(K,{title:"Invoices",description:"Download invoices for your subscription.",actions:e.jsx(d,{variant:"ghost",size:"sm",className:"gap-1.5",asChild:!0,children:e.jsxs(T,{to:"/billing",children:[e.jsx(J,{className:"h-3.5 w-3.5"}),Y]})})}),e.jsx(F,{className:"max-w-5xl",children:e.jsxs($,{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(d,{size:"sm",className:"text-xs gap-1.5",onClick:()=>{w()},disabled:x!==void 0,children:[x==="all"?e.jsx(j,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(X,{className:"h-3.5 w-3.5"}),ee]}),e.jsxs(d,{variant:"outline",size:"sm",className:"text-xs gap-1.5",onClick:()=>{w([...r])},disabled:x!==void 0||r.size===0,children:[x==="selected"&&e.jsx(j,{className:"h-3.5 w-3.5 animate-spin"}),se,r.size>0?` (${r.size})`:""]})]}),D?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(V,{fixed:!1})}):L?e.jsx("p",{className:"text-sm text-muted-foreground py-8 text-center",children:ae}):l.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-8 text-center",children:ne}):e.jsxs(e.Fragment,{children:[e.jsxs(q,{children:[e.jsx(W,{children:e.jsxs(k,{children:[e.jsx(h,{className:"w-10",children:e.jsx(C,{checked:A,onCheckedChange:E,"aria-label":"Select all invoices on this page"})}),e.jsx(h,{children:te}),e.jsx(h,{children:oe}),e.jsx(h,{children:ce})]})}),e.jsx(G,{children:l.map(s=>e.jsxs(k,{className:"cursor-pointer",title:"Download invoice",onClick:()=>{P(s)},children:[e.jsx(u,{onClick:a=>{a.stopPropagation()},children:e.jsx(C,{checked:r.has(s.id),onCheckedChange:()=>{O(s.id)},"aria-label":`Select invoice ${s.invoiceNumber??s.id}`})}),e.jsx(u,{className:"font-medium",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[y===s.id&&e.jsx(j,{className:"h-3.5 w-3.5 animate-spin"}),s.invoiceNumber??"—"]})}),e.jsx(u,{children:s.billedAt?H(new Date(s.billedAt)):"—"}),e.jsx(u,{children:Z(s)})]},s.id))})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(d,{variant:"outline",size:"sm",className:"text-xs",onClick:S,disabled:c===0,children:le}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[ie,c+1]}),e.jsx(d,{variant:"outline",size:"sm",className:"text-xs",onClick:I,disabled:!(t!=null&&t.hasMore),children:re})]})]})]})})]})};export{ge 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.