Skip to content

Commit 794fd2b

Browse files
committed
bugfix(shopify): clearly indicated when the user is on a free plan
1 parent b8f0ea8 commit 794fd2b

File tree

3 files changed

+47
-21
lines changed

3 files changed

+47
-21
lines changed

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

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,23 @@ export const PlanView = () => {
7474
<div className="pb-4">
7575
<InlineStack align="space-between">
7676
<Text variant="headingMd" as="h2">
77-
Plan Details
77+
Plan Status
7878
</Text>
7979
<Badge>{organization.plan?.name}</Badge>
8080
</InlineStack>
8181
</div>
8282

83-
<Box>
83+
<BlockStack gap="400">
84+
{(organization.plan as StripePlan | undefined)?.amount == 0 && (
85+
<Box>
86+
<Banner
87+
title={`You are not on a paid plan. Test before you buy!`}
88+
tone="info"
89+
>
90+
<p>Trieve includes 50 AI messages per month for free.</p>
91+
</Banner>
92+
</Box>
93+
)}
8494
{usagePercentage >= 80 && usagePercentage < 90 && (
8595
<Box>
8696
<Banner
@@ -115,7 +125,7 @@ export const PlanView = () => {
115125
<div>{item.description}</div>
116126
</div>
117127
))}
118-
</Box>
128+
</BlockStack>
119129
</BlockStack>
120130
<div className="h-2"></div>
121131
<InlineStack gap="200" align="end" blockAlign="center">
@@ -131,15 +141,19 @@ export const PlanView = () => {
131141
);
132142
}}
133143
>
134-
Modify Plan
135-
</Button>
136-
<Button
137-
onClick={() => {
138-
setShowCancelModal(true);
139-
}}
140-
>
141-
Cancel Plan
144+
{(organization.plan as StripePlan | undefined)?.amount == 0
145+
? "Upgrade"
146+
: "Modify"}
142147
</Button>
148+
{(organization.plan as StripePlan | undefined)?.amount != 0 && (
149+
<Button
150+
onClick={() => {
151+
setShowCancelModal(true);
152+
}}
153+
>
154+
Cancel
155+
</Button>
156+
)}
143157
</InlineStack>
144158
</Card>
145159
</>

clients/trieve-shopify-extension/app/routes/app._dashboard._index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,17 @@ export const loader = createServerLoader(load);
3838
export const clientLoader = createClientLoader(load);
3939

4040
export const action = async ({ request }: ActionFunctionArgs) => {
41+
console.log("Receives action");
4142
const { redirect, billing } = await authenticate.admin(request);
4243
const formData = await request.formData();
4344
const action = formData.get("action");
4445
if (action === "modify") {
46+
console.log("Redirecting to pricing page");
4547
return redirect(process.env.SHOPIFY_PRICING_URL || "", {
4648
target: "_top",
4749
});
4850
} else if (action === "cancel") {
51+
console.log("Cancelling subscription");
4952
const subscription = await billing.check();
5053
if (subscription.hasActivePayment) {
5154
await billing.cancel({

clients/trieve-shopify-extension/app/routes/webhooks.app.app_subscriptions.update.tsx

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const action = async ({ request }: ActionFunctionArgs) => {
2020
const key = await validateTrieveAuthWehbook(shop);
2121
const trieve = sdkFromKey(key);
2222

23-
console.log(`Received ${topic} webhook for ${shop}`);
23+
console.log(`Received ${topic} webhook for ${shop}`, payload);
2424
const organization_id = await db.apiKey.findFirst({
2525
where: {
2626
shop: `https://${shop}`,
@@ -30,17 +30,24 @@ export const action = async ({ request }: ActionFunctionArgs) => {
3030
return new Response("Organization not found", { status: 404 });
3131
}
3232

33-
const data = await admin?.graphql(
34-
`
35-
query {
36-
currentAppInstallation {
37-
activeSubscriptions {
38-
currentPeriodEnd
33+
let data;
34+
try {
35+
data = await admin?.graphql(
36+
`
37+
query {
38+
currentAppInstallation {
39+
activeSubscriptions {
40+
currentPeriodEnd
41+
}
3942
}
4043
}
41-
}
42-
`,
43-
);
44+
`,
45+
);
46+
console.log("Subscription data", data);
47+
} catch (error) {
48+
console.error("Failed to fetch subscription data:", error);
49+
data = null;
50+
}
4451

4552
const trievePayload: ShopifyPlanChangePayload = {
4653
organization_id: organization_id?.organizationId,
@@ -59,6 +66,8 @@ export const action = async ({ request }: ActionFunctionArgs) => {
5966
},
6067
};
6168

69+
console.log("Trieve payload", trievePayload);
70+
6271
await trieve.handleShopifyPlanChange(
6372
trievePayload,
6473
process.env.SHOPIFY_SECRET_KEY || "",

0 commit comments

Comments
 (0)