@@ -23,7 +23,7 @@ import {
2323 QuestionCircleIcon ,
2424 RefreshIcon ,
2525} from "@shopify/polaris-icons" ;
26- import { usageQuery } from "app/queries/usage" ;
26+ import { organizationUsageQuery , datasetUsageQuery } from "app/queries/usage" ;
2727import { useQuery } from "@tanstack/react-query" ;
2828import { Onboarding } from "app/components/onboarding/Onboarding" ;
2929import { Loader } from "app/loaders" ;
@@ -39,7 +39,7 @@ import { defaultSearchAnalyticsFilter } from "app/queries/analytics/search";
3939import { Granularity } from "trieve-ts-sdk" ;
4040import { ActionFunctionArgs } from "@remix-run/node" ;
4141import { authenticate } from "app/shopify.server" ;
42-
42+ import { PlanView } from "app/components/PlanView" ;
4343const load : Loader = async ( { adminApiFetcher, queryClient } ) => {
4444 await queryClient . ensureQueryData ( lastStepIdQuery ( adminApiFetcher ) ) ;
4545 return ;
@@ -79,11 +79,16 @@ export default function Dashboard() {
7979 const submit = useSubmit ( ) ;
8080
8181 const {
82- data : usage ,
82+ data : datasetUsage ,
8383 isLoading,
8484 dataUpdatedAt,
8585 refetch,
86- } = useQuery ( usageQuery ( trieve ) ) ;
86+ } = useQuery ( datasetUsageQuery ( trieve ) ) ;
87+
88+ const {
89+ data : organizationUsage ,
90+ isLoading : organizationUsageLoading ,
91+ } = useQuery ( organizationUsageQuery ( trieve ) ) ;
8792
8893 const planType = organization ?. plan ?. name || "Free" ;
8994
@@ -94,7 +99,7 @@ export default function Dashboard() {
9499 < SkeletonBodyText lines = { 1 } />
95100 ) : (
96101 < InlineStack align = "space-between" >
97- { usage ?. chunk_count . toLocaleString ( ) }
102+ { datasetUsage ?. chunk_count . toLocaleString ( ) }
98103 < Button
99104 icon = { RefreshIcon }
100105 onClick = { ( ) => {
@@ -123,25 +128,16 @@ export default function Dashboard() {
123128 } ,
124129 ] ;
125130
126- if ( ( organization ?. plan as any ) ?. type === "flat" ) {
131+ if ( organization ?. plan ?. type === "flat" ) {
127132 planItems . push (
128133 {
129- term : "Chunk Limit" ,
130- description : organization ?. plan ?. chunk_count ?. toLocaleString ( ) || "N/A" ,
131- } ,
132- {
133- term : "Dataset Limit" ,
134- description :
135- organization ?. plan ?. dataset_count ?. toLocaleString ( ) || "N/A" ,
136- } ,
137- {
138- term : "Message Limit" ,
139- description :
140- organization ?. plan ?. message_count . toLocaleString ( ) || "N/A" ,
134+ term : "Messages Sent" ,
135+ description : organizationUsage ?. current_months_message_count ?. toLocaleString ( ) || "N/A" ,
141136 } ,
142137 ) ;
143138 }
144139
140+
145141 return (
146142 < >
147143 < Modal open = { showCancelModal } onClose = { ( ) => { setShowCancelModal ( false ) } } title = "Cancel Subscription" >
@@ -281,41 +277,11 @@ export default function Dashboard() {
281277 </ Box >
282278 </ BlockStack >
283279 </ Card >
284- < Card >
285- < BlockStack gap = "400" >
286- < Box paddingInline = "400" paddingBlockStart = "400" >
287- < InlineStack align = "space-between" >
288- < Text variant = "headingMd" as = "h2" >
289- Plan Details
290- </ Text >
291- < div className = "flex gap-2" >
292- < Button
293- onClick = { ( ) => {
294- submit ( {
295- action : "modify" ,
296- } , {
297- method : "post" ,
298- } ) ;
299- } }
300- >
301- Modify
302- </ Button >
303- < Button
304- onClick = { ( ) => {
305- setShowCancelModal ( true ) ;
306- } }
307- >
308- Cancel
309- </ Button >
310- </ div >
311- </ InlineStack >
312- </ Box >
313-
314- < Box paddingInline = "400" >
315- < DescriptionList items = { planItems } />
316- </ Box >
317- </ BlockStack >
318- </ Card >
280+ < PlanView
281+ planItems = { planItems }
282+ setShowCancelModal = { setShowCancelModal }
283+ usagePercentage = { ( organizationUsage ?. current_months_message_count ?? 0 ) / organization ?. plan ?. component_loads }
284+ />
319285 </ BlockStack >
320286 </ Layout . Section >
321287 </ Layout >
0 commit comments