Skip to content

Commit 20f1e66

Browse files
committed
Show upgrade message for free users to get static IPs
1 parent 9a9fb2c commit 20f1e66

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

apps/webapp/app/presenters/v3/RegionsPresenter.server.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
import { type z } from "zod";
2-
import { type PrismaClient, prisma } from "~/db.server";
31
import { type Project } from "~/models/project.server";
42
import { type User } from "~/models/user.server";
5-
import { FEATURE_FLAG, flags, makeFlags } from "~/v3/featureFlags.server";
3+
import { FEATURE_FLAG, makeFlags } from "~/v3/featureFlags.server";
64
import { BasePresenter } from "./basePresenter.server";
5+
import { getCurrentPlan } from "~/services/platform.v3.server";
76

87
export type Region = {
98
id: string;
109
name: string;
1110
description?: string;
1211
cloudProvider?: string;
1312
location?: string;
14-
staticIPs?: string;
13+
staticIPs?: string | null;
1514
isDefault: boolean;
1615
};
1716

@@ -122,13 +121,25 @@ export class RegionsPresenter extends BasePresenter {
122121
});
123122

124123
// Remove later duplicates
125-
const unique = sorted.filter((region, index, self) => {
124+
let unique = sorted.filter((region, index, self) => {
126125
const firstIndex = self.findIndex((t) => t.id === region.id);
127126
return index === firstIndex;
128127
});
129128

129+
// Don't show static IPs for free users
130+
// Even if they had the IPs they wouldn't work, but this makes it less confusing
131+
const currentPlan = await getCurrentPlan(project.organizationId);
132+
const isPaying = currentPlan?.v3Subscription.isPaying === true;
133+
if (!isPaying) {
134+
unique = unique.map((region) => ({
135+
...region,
136+
staticIPs: region.staticIPs ? null : undefined,
137+
}));
138+
}
139+
130140
return {
131141
regions: unique.sort((a, b) => a.name.localeCompare(b.name)),
142+
isPaying,
132143
};
133144
}
134145
}

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.regions/route.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
ArrowRightIcon,
3+
ArrowUpCircleIcon,
34
BookOpenIcon,
45
ChatBubbleLeftEllipsisIcon,
56
MapPinIcon,
@@ -44,6 +45,7 @@ import {
4445
TableRow,
4546
} from "~/components/primitives/Table";
4647
import { TextLink } from "~/components/primitives/TextLink";
48+
import { useOrganization } from "~/hooks/useOrganizations";
4749
import { redirectWithErrorMessage, redirectWithSuccessMessage } from "~/models/message.server";
4850
import { findProjectBySlug } from "~/models/project.server";
4951
import { type Region, RegionsPresenter } from "~/presenters/v3/RegionsPresenter.server";
@@ -53,6 +55,7 @@ import {
5355
EnvironmentParamSchema,
5456
ProjectParamSchema,
5557
regionsPath,
58+
v3BillingPath,
5659
} from "~/utils/pathBuilder";
5760
import { SetDefaultRegionService } from "~/v3/services/setDefaultRegion.server";
5861

@@ -121,7 +124,8 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
121124
};
122125

123126
export default function Page() {
124-
const { regions } = useTypedLoaderData<typeof loader>();
127+
const { regions, isPaying } = useTypedLoaderData<typeof loader>();
128+
const organization = useOrganization();
125129

126130
return (
127131
<PageContainer>
@@ -215,7 +219,19 @@ export default function Page() {
215219
</span>
216220
</TableCell>
217221
<TableCell>
218-
{region.staticIPs ? (
222+
{region.staticIPs === null ? (
223+
<LinkButton
224+
variant="secondary/small"
225+
to={v3BillingPath(
226+
organization,
227+
"Upgrade your plan to unlock static IPs"
228+
)}
229+
LeadingIcon={ArrowUpCircleIcon}
230+
leadingIconClassName="text-indigo-500"
231+
>
232+
Unlock static IPs
233+
</LinkButton>
234+
) : region.staticIPs !== undefined ? (
219235
<ClipboardField
220236
value={region.staticIPs}
221237
variant={"secondary/small"}

0 commit comments

Comments
 (0)