Skip to content

Commit 9031b01

Browse files
densumeshskeptrunedev
authored andcommitted
feature: refetch organization details on client
1 parent 0e1c15d commit 9031b01

3 files changed

Lines changed: 25 additions & 10 deletions

File tree

clients/trieve-shopify-extension/app/components/PlanView.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,22 @@ import {
1212
} from "@shopify/polaris";
1313
import { ProgressBar } from "./ProgressBar";
1414
import { StripePlan } from "trieve-ts-sdk";
15-
import { useState } from "react";
15+
import { useState, useEffect } from "react";
1616
import { useQuery } from "@tanstack/react-query";
1717
import { organizationUsageQuery } from "app/queries/usage";
1818
import { useTrieve } from "app/context/trieveContext";
19+
import { shopOrganizationQuery } from "app/queries/shopDataset";
1920

2021
export const PlanView = () => {
21-
const { organization, trieve, refetch: refetchTrieve } = useTrieve();
22+
const { trieve } = useTrieve();
2223
const [showCancelModal, setShowCancelModal] = useState(false);
2324
const submit = useSubmit();
2425

26+
const { data: organization, refetch: refetchOrganization } = useQuery({
27+
...shopOrganizationQuery(trieve),
28+
refetchInterval: 10000,
29+
});
30+
2531
const { data: organizationUsage } = useQuery(organizationUsageQuery(trieve));
2632

2733
let planItems = [];
@@ -61,7 +67,7 @@ export const PlanView = () => {
6167
);
6268
setShowCancelModal(false);
6369
setTimeout(() => {
64-
refetchTrieve();
70+
refetchOrganization();
6571
}, 5000);
6672
}}
6773
>
@@ -76,12 +82,12 @@ export const PlanView = () => {
7682
<Text variant="headingMd" as="h2">
7783
Plan Status
7884
</Text>
79-
<Badge>{organization.plan?.name}</Badge>
85+
<Badge>{organization?.plan?.name}</Badge>
8086
</InlineStack>
8187
</div>
8288

8389
<BlockStack gap="400">
84-
{(organization.plan as StripePlan | undefined)?.amount == 0 && (
90+
{(organization?.plan as StripePlan | undefined)?.amount == 0 && (
8591
<Box>
8692
<Banner
8793
title={`You are not on a paid plan. Test before you buy!`}
@@ -141,11 +147,11 @@ export const PlanView = () => {
141147
);
142148
}}
143149
>
144-
{(organization.plan as StripePlan | undefined)?.amount == 0
150+
{(organization?.plan as StripePlan | undefined)?.amount == 0
145151
? "Upgrade"
146152
: "Modify"}
147153
</Button>
148-
{(organization.plan as StripePlan | undefined)?.amount != 0 && (
154+
{(organization?.plan as StripePlan | undefined)?.amount != 0 && (
149155
<Button
150156
onClick={() => {
151157
setShowCancelModal(true);

clients/trieve-shopify-extension/app/context/trieveContext.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ export const TrieveContext = createContext<{
1717
dataset: Dataset;
1818
trieveKey: StrongTrieveKey;
1919
organization: OrganizationWithSubAndPlan;
20-
refetch: () => void;
2120
}>({
2221
trieve: null as any,
2322
dataset: null as any,
2423
trieveKey: null as any,
2524
organization: null as any,
26-
refetch: null as any,
2725
});
2826

2927
export const TrieveProvider = ({
@@ -78,7 +76,6 @@ export const TrieveProvider = ({
7876
dataset,
7977
trieveKey,
8078
organization,
81-
refetch: queryClient.refetchQueries,
8279
}}
8380
>
8481
{children}

clients/trieve-shopify-extension/app/queries/shopDataset.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,15 @@ export const shopDatasetQuery = (trieve: TrieveSDK) => {
1010
},
1111
} satisfies QueryOptions;
1212
};
13+
14+
export const shopOrganizationQuery = (trieve: TrieveSDK) => {
15+
return {
16+
queryKey: ["shop_organization", trieve.organizationId],
17+
queryFn: async () => {
18+
const shopOrganization = await trieve.getOrganizationById(
19+
trieve.organizationId!,
20+
);
21+
return shopOrganization;
22+
},
23+
} satisfies QueryOptions;
24+
};

0 commit comments

Comments
 (0)