@@ -7,8 +7,9 @@ import { redirect, typeddefer, useTypedLoaderData } from "remix-typedjson";
77import { URL } from "url" ;
88import { UsageBar } from "~/components/billing/UsageBar" ;
99import { PageBody , PageContainer } from "~/components/layout/AppLayout" ;
10+ import { Card } from "~/components/primitives/charts/Card" ;
1011import type { ChartConfig } from "~/components/primitives/charts/Chart" ;
11- import { ChartBar } from "~/components/primitives/charts/ChartBar " ;
12+ import { Chart } from "~/components/primitives/charts/ChartCompound " ;
1213import { Header2 } from "~/components/primitives/Headers" ;
1314import { InfoPanel } from "~/components/primitives/InfoPanel" ;
1415import { NavBar , PageTitle } from "~/components/primitives/PageHeader" ;
@@ -166,30 +167,30 @@ export default function Page() {
166167 </ Suspense >
167168 </ div >
168169 </ div >
169- < div >
170- < Header2 spacing className = "pl-3" >
171- Usage by day
172- </ Header2 >
173- < div className = "p-3" >
174- < Suspense
175- fallback = {
176- < div className = "flex min-h-40 items-center justify-center" >
177- < Spinner />
178- </ div >
179- }
180- >
181- < Await
182- resolve = { usage }
183- errorElement = {
170+ < div className = "px-3" >
171+ < Card >
172+ < Card . Header > Usage by day</ Card . Header >
173+ < Card . Content >
174+ < Suspense
175+ fallback = {
184176 < div className = "flex min-h-40 items-center justify-center" >
185- < Paragraph variant = "small" > Failed to load graph. </ Paragraph >
177+ < Spinner / >
186178 </ div >
187179 }
188180 >
189- { ( u ) => < UsageChart data = { u . timeSeries } /> }
190- </ Await >
191- </ Suspense >
192- </ div >
181+ < Await
182+ resolve = { usage }
183+ errorElement = {
184+ < div className = "flex min-h-40 items-center justify-center" >
185+ < Paragraph variant = "small" > Failed to load graph.</ Paragraph >
186+ </ div >
187+ }
188+ >
189+ { ( u ) => < UsageChart data = { u . timeSeries } /> }
190+ </ Await >
191+ </ Suspense >
192+ </ Card . Content >
193+ </ Card >
193194 </ div >
194195 < div >
195196 < Header2 spacing className = "pl-3" >
@@ -289,47 +290,40 @@ const tooltipDateFormatter = new Intl.DateTimeFormat("en-US", {
289290 day : "numeric" ,
290291} ) ;
291292
293+ const xAxisTickFormatter = ( value : string ) => {
294+ if ( ! value ) return "" ;
295+ const date = new Date ( value ) ;
296+ return `${ date . getDate ( ) } ` ;
297+ } ;
298+
299+ const tooltipLabelFormatter = ( label : string ) => {
300+ if ( ! label ) return "" ;
301+ return tooltipDateFormatter . format ( new Date ( label ) ) ;
302+ } ;
303+
292304function UsageChart ( { data } : { data : UsageSeriesData } ) {
293305 const maxDollar = Math . max ( ...data . map ( ( d ) => d . dollars ) ) ;
294306 const decimalPlaces = maxDollar < 1 ? 4 : 2 ;
295307
296- const xAxisTickFormatter = useMemo (
297- ( ) => ( value : string ) => {
298- if ( ! value ) return "" ;
299- const date = new Date ( value ) ;
300- return `${ date . getDate ( ) } ` ;
301- } ,
302- [ ]
303- ) ;
304-
305308 const yAxisTickFormatter = useMemo (
306309 ( ) => ( value : number ) => `$${ value . toFixed ( decimalPlaces ) } ` ,
307310 [ decimalPlaces ]
308311 ) ;
309312
310- const tooltipLabelFormatter = useMemo (
311- ( ) => ( _label : string , payload : Array < { payload ?: Record < string , unknown > } > ) => {
312- const dateString = payload . at ( 0 ) ?. payload ?. date as string | undefined ;
313- if ( ! dateString ) {
314- return "" ;
315- }
316- return tooltipDateFormatter . format ( new Date ( dateString ) ) ;
317- } ,
318- [ ]
319- ) ;
320-
321313 return (
322- < ChartBar
314+ < Chart . Root
323315 config = { chartConfig }
324316 data = { data }
325317 dataKey = "date"
326318 showLegend = { false }
327319 enableZoom = { false }
328- xAxisProps = { { tickFormatter : xAxisTickFormatter } }
329- yAxisProps = { { tickFormatter : yAxisTickFormatter , allowDecimals : true } }
330- tooltipLabelFormatter = { tooltipLabelFormatter }
331320 minHeight = "160px"
332- className = "max-h-96"
333- />
321+ >
322+ < Chart . Bar
323+ xAxisProps = { { tickFormatter : xAxisTickFormatter } }
324+ yAxisProps = { { tickFormatter : yAxisTickFormatter , allowDecimals : true } }
325+ tooltipLabelFormatter = { tooltipLabelFormatter }
326+ />
327+ </ Chart . Root >
334328 ) ;
335329}
0 commit comments