Skip to content

Commit f838ffa

Browse files
committed
refactor(server+shopify) rename component_loads to messages_per_month in schema and related files
1 parent 70a098a commit f838ffa

10 files changed

Lines changed: 152 additions & 125 deletions

File tree

Lines changed: 85 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,94 @@
11
import { useSubmit } from "@remix-run/react";
2-
import { BlockStack, Box, Button, Card, DescriptionList, DescriptionListProps, InlineStack, Text, Banner } from "@shopify/polaris";
2+
import {
3+
BlockStack,
4+
Box,
5+
Button,
6+
Card,
7+
DescriptionList,
8+
DescriptionListProps,
9+
InlineStack,
10+
Text,
11+
Banner,
12+
} from "@shopify/polaris";
313
import { ProgressBar } from "./ProgressBar";
414

515
export const PlanView = ({
6-
planItems,
7-
setShowCancelModal,
8-
usagePercentage,
16+
planItems,
17+
setShowCancelModal,
18+
usagePercentage,
919
}: {
10-
planItems: DescriptionListProps["items"];
11-
setShowCancelModal: (show: boolean) => void;
12-
usagePercentage: number;
20+
planItems: DescriptionListProps["items"];
21+
setShowCancelModal: (show: boolean) => void;
22+
usagePercentage: number;
1323
}) => {
14-
const submit = useSubmit();
24+
const submit = useSubmit();
1525

16-
return (
17-
<Card>
18-
<BlockStack gap="400">
19-
<Box paddingInline="400" paddingBlockStart="400">
20-
<InlineStack align="space-between">
21-
<Text variant="headingMd" as="h2">
22-
Plan Details
23-
</Text>
24-
<div className="flex gap-2">
25-
<Button
26-
onClick={() => {
27-
submit({
28-
action: "modify",
29-
}, {
30-
method: "post",
31-
});
32-
}}
33-
>
34-
Modify
35-
</Button>
36-
<Button
37-
onClick={() => {
38-
setShowCancelModal(true);
39-
}}
40-
>
41-
Cancel
42-
</Button>
43-
</div>
44-
</InlineStack>
45-
</Box>
26+
return (
27+
<Card>
28+
<BlockStack gap="400">
29+
<Box paddingInline="400" paddingBlockStart="400">
30+
<InlineStack align="space-between">
31+
<Text variant="headingMd" as="h2">
32+
Plan Details
33+
</Text>
34+
<div className="flex gap-2">
35+
<Button
36+
onClick={() => {
37+
submit(
38+
{
39+
action: "modify",
40+
},
41+
{
42+
method: "post",
43+
},
44+
);
45+
}}
46+
>
47+
Modify
48+
</Button>
49+
<Button
50+
onClick={() => {
51+
setShowCancelModal(true);
52+
}}
53+
>
54+
Cancel
55+
</Button>
56+
</div>
57+
</InlineStack>
58+
</Box>
4659

47-
<Box paddingInline="400" paddingBlockEnd="400">
48-
{usagePercentage >= 80 && usagePercentage < 90 && (
49-
<Box paddingBlockEnd="400">
50-
<Banner
51-
title={`You are at ${usagePercentage}% of your usage limit.`}
52-
tone="warning"
53-
>
54-
<p>Consider upgrading your plan to avoid potential disruptions.</p>
55-
</Banner>
56-
</Box>
57-
)}
58-
{usagePercentage >= 90 && (
59-
<Box paddingBlockEnd="400">
60-
<Banner
61-
title={`You have reached ${usagePercentage}% of your usage limit.`}
62-
tone="critical"
63-
>
64-
<p>Upgrade your plan immediately to avoid service disruption.</p>
65-
</Banner>
66-
</Box>
67-
)}
68-
<div className="w-full">
69-
<span className="text-sm font-bold pb-1">
70-
Usage
71-
</span>
72-
<ProgressBar progress={usagePercentage} />
73-
</div>
74-
<DescriptionList items={planItems} />
75-
</Box>
76-
</BlockStack>
77-
</Card>
78-
);
60+
<Box paddingInline="400" paddingBlockEnd="400">
61+
{usagePercentage >= 80 && usagePercentage < 90 && (
62+
<Box paddingBlockEnd="400">
63+
<Banner
64+
title={`You are at ${usagePercentage.toPrecision(5)}% of your usage limit.`}
65+
tone="warning"
66+
>
67+
<p>
68+
Consider upgrading your plan to avoid potential disruptions.
69+
</p>
70+
</Banner>
71+
</Box>
72+
)}
73+
{usagePercentage >= 90 && (
74+
<Box paddingBlockEnd="400">
75+
<Banner
76+
title={`You have reached ${usagePercentage.toPrecision(5)}% of your usage limit.`}
77+
tone="critical"
78+
>
79+
<p>
80+
Upgrade your plan immediately to avoid service disruption.
81+
</p>
82+
</Banner>
83+
</Box>
84+
)}
85+
<div className="w-full">
86+
<span className="text-sm font-bold pb-1">Usage</span>
87+
<ProgressBar progress={usagePercentage} />
88+
</div>
89+
<DescriptionList items={planItems} />
90+
</Box>
91+
</BlockStack>
92+
</Card>
93+
);
7994
};

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

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,9 @@ export const action = async ({ request }: ActionFunctionArgs) => {
5353
const formData = await request.formData();
5454
const action = formData.get("action");
5555
if (action === "modify") {
56-
return redirect(
57-
process.env.SHOPIFY_PRICING_URL || "",
58-
{
59-
target: "_top",
60-
},
61-
);
56+
return redirect(process.env.SHOPIFY_PRICING_URL || "", {
57+
target: "_top",
58+
});
6259
} else if (action === "cancel") {
6360
const subscription = await billing.check();
6461
if (subscription.hasActivePayment) {
@@ -85,10 +82,7 @@ export default function Dashboard() {
8582
refetch,
8683
} = useQuery(datasetUsageQuery(trieve));
8784

88-
const {
89-
data: organizationUsage,
90-
isLoading: organizationUsageLoading,
91-
} = useQuery(organizationUsageQuery(trieve));
85+
const { data: organizationUsage } = useQuery(organizationUsageQuery(trieve));
9286

9387
const planType = organization?.plan?.name || "Free";
9488

@@ -129,34 +123,41 @@ export default function Dashboard() {
129123
];
130124

131125
if (organization?.plan?.type === "flat") {
132-
planItems.push(
133-
{
134-
term: "Message Usage",
135-
description: `${organizationUsage?.current_months_message_count?.toLocaleString() ?? 0} / ${(organization?.plan as StripePlan)?.message_count.toLocaleString()}`,
136-
},
137-
);
126+
planItems.push({
127+
term: "Message Usage",
128+
description: `${organizationUsage?.current_months_message_count?.toLocaleString() ?? 0} / ${((organization?.plan as StripePlan)?.messages_per_month ?? 1000).toLocaleString()}`,
129+
});
138130
}
139131

140-
141132
return (
142133
<>
143-
<Modal open={showCancelModal} onClose={() => { setShowCancelModal(false) }} title="Cancel Subscription">
144-
134+
<Modal
135+
open={showCancelModal}
136+
onClose={() => {
137+
setShowCancelModal(false);
138+
}}
139+
title="Cancel Subscription"
140+
>
145141
<div className="flex flex-col gap-4 p-4">
146-
<Text as="p">
147-
Do you want to cancel your subscription?
148-
</Text>
149-
<Button onClick={() => {
150-
submit({
151-
action: "cancel",
152-
}, {
153-
method: "post",
154-
});
155-
setShowCancelModal(false);
156-
setTimeout(() => {
157-
refetchTrieve();
158-
}, 5000);
159-
}}>Cancel Subscription</Button>
142+
<Text as="p">Do you want to cancel your subscription?</Text>
143+
<Button
144+
onClick={() => {
145+
submit(
146+
{
147+
action: "cancel",
148+
},
149+
{
150+
method: "post",
151+
},
152+
);
153+
setShowCancelModal(false);
154+
setTimeout(() => {
155+
refetchTrieve();
156+
}, 5000);
157+
}}
158+
>
159+
Cancel Subscription
160+
</Button>
160161
</div>
161162
</Modal>
162163
<Layout>
@@ -217,8 +218,8 @@ export default function Dashboard() {
217218
>
218219
support center
219220
</Link>{" "}
220-
for answers to common questions, video tutorials, documentation,
221-
and more.
221+
for answers to common questions, video tutorials,
222+
documentation, and more.
222223
</Text>
223224
<InlineStack align="start" gap="300">
224225
<Button
@@ -280,7 +281,12 @@ export default function Dashboard() {
280281
<PlanView
281282
planItems={planItems}
282283
setShowCancelModal={setShowCancelModal}
283-
usagePercentage={((organizationUsage?.current_months_message_count ?? 0) / (organization?.plan as StripePlan)?.message_count) * 100}
284+
usagePercentage={
285+
((organizationUsage?.current_months_message_count ?? 0) /
286+
((organization?.plan as StripePlan)?.messages_per_month ??
287+
1000)) *
288+
100
289+
}
284290
/>
285291
</BlockStack>
286292
</Layout.Section>

clients/trieve-shopify-extension/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"react-dom": "^18.2.0",
5353
"tailwind-merge": "^3.1.0",
5454
"tailwindcss": "^3.4.17",
55-
"trieve-ts-sdk": "0.0.83",
55+
"trieve-ts-sdk": "0.0.84",
5656
"vite-tsconfig-paths": "^5.0.1",
5757
"trieve-search-component": "0.4.55"
5858
},

clients/trieve-shopify-extension/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9357,10 +9357,10 @@ trieve-ts-sdk@0.0.73:
93579357
resolved "https://registry.yarnpkg.com/trieve-ts-sdk/-/trieve-ts-sdk-0.0.73.tgz#9de17428ddb4b1f6d68709695f371d185c4bda79"
93589358
integrity sha512-68iG/OlmKSGmnmI/J33S6VKleEAfq4txzARhvKv1g+CYSaG7HOH76n0cFDMtUUEEKn1PD4nV82uh5ZFtfIxD0A==
93599359

9360-
trieve-ts-sdk@0.0.83:
9361-
version "0.0.83"
9362-
resolved "https://registry.yarnpkg.com/trieve-ts-sdk/-/trieve-ts-sdk-0.0.83.tgz#a9bd0bbd71e09f3f9017844d91894fde95c5edb9"
9363-
integrity sha512-EPDy342dDTNVmzzALMtk9JExCn5yt1oyp9moiS4VLyN52hFaKY4MxoSsEp9/Bp7PRNXS2Z8u1H+PTn+joovhbw==
9360+
trieve-ts-sdk@0.0.84:
9361+
version "0.0.84"
9362+
resolved "https://registry.yarnpkg.com/trieve-ts-sdk/-/trieve-ts-sdk-0.0.84.tgz#4b39b77ea7ab6ec2a910dd84cfa484b08e33b6f7"
9363+
integrity sha512-yytEnukR2Z4QuTzOeqvJwTV5wEilQYshYJZsQlB8DNDT1BYHE5wv3/wmZCt9iKIdtKlArU7/zVta3OAHCJWIEg==
93649364

93659365
trim-lines@^3.0.0:
93669366
version "3.0.1"

clients/ts-sdk/openapi.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19700,11 +19700,6 @@
1970019700
"type": "integer",
1970119701
"format": "int32"
1970219702
},
19703-
"component_loads": {
19704-
"type": "integer",
19705-
"format": "int32",
19706-
"nullable": true
19707-
},
1970819703
"created_at": {
1970919704
"type": "string",
1971019705
"format": "date-time"
@@ -19725,6 +19720,11 @@
1972519720
"type": "integer",
1972619721
"format": "int32"
1972719722
},
19723+
"messages_per_month": {
19724+
"type": "integer",
19725+
"format": "int32",
19726+
"nullable": true
19727+
},
1972819728
"name": {
1972919729
"type": "string"
1973019730
},
@@ -19746,12 +19746,12 @@
1974619746
"example": {
1974719747
"amount": 1000,
1974819748
"chunk_count": 1000,
19749-
"component_loads": 1000,
1975019749
"created_at": "2021-01-01 00:00:00.000",
1975119750
"dataset_count": 1,
1975219751
"file_storage": 512,
1975319752
"id": "e3e3e3e3-e3e3-e3e3-e3e3-e3e3e3e3e3e3",
1975419753
"message_count": 1000,
19754+
"messages_per_month": 1000,
1975519755
"name": "Free",
1975619756
"stripe_id": "plan_123",
1975719757
"updated_at": "2021-01-01 00:00:00.000",

clients/ts-sdk/src/types.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3902,12 +3902,12 @@ export type StripeInvoice = {
39023902
export type StripePlan = {
39033903
amount: number;
39043904
chunk_count: number;
3905-
component_loads?: (number) | null;
39063905
created_at: string;
39073906
dataset_count: number;
39083907
file_storage: number;
39093908
id: string;
39103909
message_count: number;
3910+
messages_per_month?: (number) | null;
39113911
name: string;
39123912
stripe_id: string;
39133913
updated_at: string;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- This file should undo anything in `up.sql`
2+
ALTER TABLE stripe_plans
3+
RENAME COLUMN messages_per_month TO component_loads;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- Your SQL goes here
2+
ALTER TABLE stripe_plans
3+
RENAME COLUMN component_loads TO messages_per_month;

0 commit comments

Comments
 (0)