price cards

This commit is contained in:
Alex Holliday committed 2025-12-02 20:52:27 +00:00
1 parent 07efd08837
commit 53355cad04
7 files changed
+155 -33

No files matched your search

@@ -30,11 +30,13 @@ export const HeaderCreate = ({
const { t } = useTranslation(); const { t } = useTranslation();
const navigate = useNavigate(); const navigate = useNavigate();
const ent = useSelector((s: RootState) => s.auth.user?.entitlements); const ent = useSelector((s: RootState) => s.auth.user?.entitlements);
const limitReached = useMemo(() => { const limitReached = useMemo(() => {
if (!entitlement) return false; if (!entitlement) return false;
if (!ent || typeof ent[entitlement] !== "number") return false; if (!ent || typeof ent[entitlement] !== "number") return false;
return entitlementCount < ent[entitlement] ? false : true; return entitlementCount < ent[entitlement] ? false : true;
}, [ent, entitlement, entitlementCount]); }, [ent, entitlement, entitlementCount]);
return ( return (
<Stack <Stack
direction="row" direction="row"
@@ -1,6 +1,15 @@
import Stack from "@mui/material/Stack"; import Stack from "@mui/material/Stack";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import { BaseBox } from "@/components/design-elements"; import { BaseBox } from "@/components/design-elements";
import {
PersonStanding,
BicepsFlexed,
Building2,
Briefcase,
Check,
} from "lucide-react";
import Divider from "@mui/material/Divider";
import Tooltip from "@mui/material/Tooltip";
import { useTheme } from "@mui/material/styles"; import { useTheme } from "@mui/material/styles";
import type { Entitlements, PlanKey } from "@/types/entitlements"; import type { Entitlements, PlanKey } from "@/types/entitlements";
@@ -16,6 +25,67 @@ export const PlanCard = ({
}) => { }) => {
const selected = plan.plan === currentPlan; const selected = plan.plan === currentPlan;
const theme = useTheme(); const theme = useTheme();
const checkColor =
plan.plan === "enterprise"
? theme.palette.success.main
: plan.plan === "free"
? theme.palette.text.secondary
: theme.palette.accent.main;
const Icon = (() => {
switch (plan.plan) {
case "free":
return PersonStanding;
case "pro":
return BicepsFlexed;
case "business":
return Briefcase;
case "enterprise":
return Building2;
default:
return PersonStanding;
}
})();
const priceLabel = (() => {
if (typeof plan.price === "number") {
const cents = plan.price;
if (cents === 0) return "Free";
const dollars = cents / 100;
const formatted = dollars.toFixed(2);
return `$${formatted}/mo`;
}
})();
const featureItems = [
{
label: "Monitors",
value: plan.monitorsMax,
tooltip: "Maximum number of monitors allowed.",
},
{
label: "Status pages",
value: plan.statusPagesMax,
tooltip: "Maximum public status pages you can create.",
},
{
label: "Notification channels",
value: plan.notificationChannelsMax,
tooltip: "Maximum alerting channels (email, Slack, etc.).",
},
{
label: "Teams",
value: plan.teamsMax,
tooltip: "Maximum number of teams in your org.",
},
{
label: "Retention",
value: `${plan.retentionDays} days`,
tooltip: "Oldest checks are automatically removed after retention.",
},
{
label: "Min interval",
value: `${Math.round(plan.checksIntervalMsMin / 1000)}s`,
tooltip: "Minimum check frequency allowed for this plan.",
},
];
return ( return (
<BaseBox <BaseBox
padding={theme.spacing(8)} padding={theme.spacing(8)}
@@ -29,28 +99,44 @@ export const PlanCard = ({
} }
onClick={selected ? undefined : () => onClick?.(plan.plan)} onClick={selected ? undefined : () => onClick?.(plan.plan)}
> >
<Stack spacing={theme.spacing(2)}> <Stack spacing={theme.spacing(3)}>
<Typography variant="h6" textTransform="capitalize"> <Stack
{plan.plan} direction="row"
</Typography> alignItems="center"
<Typography variant="body2" color="text.secondary"> justifyContent="space-between"
Monitors: {plan.monitorsMax} >
</Typography> <Typography variant="h6" textTransform="capitalize">
<Typography variant="body2" color="text.secondary"> {plan.plan}
Status pages: {plan.statusPagesMax} </Typography>
</Typography> <Icon size={18} />
<Typography variant="body2" color="text.secondary"> </Stack>
Notification channels: {plan.notificationChannelsMax} <Divider />
</Typography> <Typography variant="h4" fontWeight={700}>
<Typography variant="body2" color="text.secondary"> {priceLabel}
Teams: {plan.teamsMax}
</Typography>
<Typography variant="body2" color="text.secondary">
Min interval: {Math.round(plan.checksIntervalMsMin / 1000)}s
</Typography>
<Typography variant="body2" color="text.secondary">
Retention: {plan.retentionDays} days
</Typography> </Typography>
<Stack spacing={theme.spacing(2)}>
{featureItems.map((item) => (
<Stack
key={item.label}
direction="row"
alignItems="center"
gap={theme.spacing(2)}
>
<Check size={16} color={checkColor} />
{item.tooltip ? (
<Tooltip title={item.tooltip} arrow placement="right">
<Typography variant="body1" color="text.secondary">
{item.label}: {item.value}
</Typography>
</Tooltip>
) : (
<Typography variant="body1" color="text.secondary">
{item.label}: {item.value}
</Typography>
)}
</Stack>
))}
</Stack>
</Stack> </Stack>
</BaseBox> </BaseBox>
); );
+25 -1
View File
@@ -4,10 +4,13 @@ import Box from "@mui/material/Box";
import { useTheme } from "@mui/material/styles"; import { useTheme } from "@mui/material/styles";
import { Button } from "@/components/inputs"; import { Button } from "@/components/inputs";
import { useAppSelector } from "@/hooks/AppHooks"; import { useAppDispatch, useAppSelector } from "@/hooks/AppHooks";
import { useGet, usePost } from "@/hooks/UseApi"; import { useGet, usePost } from "@/hooks/UseApi";
import type { ApiResponse } from "@/hooks/UseApi"; import type { ApiResponse } from "@/hooks/UseApi";
import type { Entitlements, PlanKey } from "@/types/entitlements"; import type { Entitlements, PlanKey } from "@/types/entitlements";
import { useEffect } from "react";
import type { IUser } from "@/types/user";
import { setSelectedTeamId, setUser } from "@/features/authSlice";
const BillingPage = () => { const BillingPage = () => {
const { user } = useAppSelector((state) => state.auth); const { user } = useAppSelector((state) => state.auth);
@@ -16,10 +19,31 @@ const BillingPage = () => {
{}, {},
{} {}
); );
const { response: meResponse } = useGet<ApiResponse<IUser>>(
"/auth/me",
{},
{ refreshInterval: 10000 }
);
const { post, loading: isPosting } = usePost(); const { post, loading: isPosting } = usePost();
const plans = response?.data ?? []; const plans = response?.data ?? [];
const theme = useTheme(); const theme = useTheme();
const selectedPlan = user?.entitlements?.plan || null; const selectedPlan = user?.entitlements?.plan || null;
const dispatch = useAppDispatch();
const selectedTeamId = useAppSelector((s) => s.auth.selectedTeamId);
useEffect(() => {
const freshUser = meResponse?.data;
if (!freshUser) return;
dispatch(setUser(freshUser));
if (
!selectedTeamId ||
!freshUser.teams.find((t) => t.id === selectedTeamId)
) {
dispatch(setSelectedTeamId(freshUser.teams[0].id));
}
}, [meResponse, dispatch, selectedTeamId]);
const handlePlanClick = async (planKey: PlanKey) => { const handlePlanClick = async (planKey: PlanKey) => {
const result = await post("/billing/subscribe", { planKey }); const result = await post("/billing/subscribe", { planKey });
+1
View File
@@ -2,6 +2,7 @@ export type PlanKey = "free" | "pro" | "business" | "enterprise" | "unlimited";
export interface Entitlements { export interface Entitlements {
plan: PlanKey; plan: PlanKey;
price?: number;
monitorsMax: number; monitorsMax: number;
notificationChannelsMax: number; notificationChannelsMax: number;
statusPagesMax: number; statusPagesMax: number;
+1 -3
View File
@@ -1,9 +1,7 @@
import type { Request, Response, NextFunction } from "express"; import type { Request, Response, NextFunction } from "express";
import { type IBillingService } from "@/services/system/BillingService.js"; import { type IBillingService } from "@/services/system/BillingService.js";
import { Plans, type PlanKey } from "@/types/entitlements.js"; import { type PlanKey } from "@/types/entitlements.js";
import ApiError from "@/utils/ApiError.js"; import ApiError from "@/utils/ApiError.js";
import { config } from "@/config/index.js";
import { Org } from "@/db/models/index.js";
export interface IBillingController { export interface IBillingController {
listPlans: (req: Request, res: Response, next: NextFunction) => Promise<void>; listPlans: (req: Request, res: Response, next: NextFunction) => Promise<void>;
+11 -1
View File
@@ -31,7 +31,17 @@ class BillingService implements IBillingService {
} }
listPlans = async () => { listPlans = async () => {
const order: PlanKey[] = ["free", "pro", "business", "enterprise"]; const order: PlanKey[] = ["free", "pro", "business", "enterprise"];
return order.map((key) => Plans[key]); const prices = await this.stripeClient.prices.list({});
const plans = order.map((key) => {
const plan = Plans[key];
plan.price =
prices.data.find((p) => p.lookup_key === key)?.unit_amount || 0;
return plan;
});
console.log("Available plans:", plans);
return plans;
}; };
private buildSuccessUrl = (planKey: PlanKey) => private buildSuccessUrl = (planKey: PlanKey) =>
+8 -7
View File
@@ -17,6 +17,7 @@ export interface Entitlements {
teamsMax: number; teamsMax: number;
notificationsEnabled: boolean; notificationsEnabled: boolean;
retentionDays: number; retentionDays: number;
price?: number;
} }
export const Plans: Record<PlanKey, Entitlements> = { export const Plans: Record<PlanKey, Entitlements> = {
@@ -24,15 +25,15 @@ export const Plans: Record<PlanKey, Entitlements> = {
plan: "free", plan: "free",
monitorsMax: 3, monitorsMax: 3,
notificationChannelsMax: 2, notificationChannelsMax: 2,
statusPagesMax: 2, statusPagesMax: 1,
checksIntervalMsMin: 60_000, checksIntervalMsMin: 60_000,
teamsMax: 2, teamsMax: 1,
notificationsEnabled: true, notificationsEnabled: true,
retentionDays: 30, retentionDays: 30,
}, },
pro: { pro: {
plan: "pro", plan: "pro",
monitorsMax: 50, monitorsMax: 25,
notificationChannelsMax: 5, notificationChannelsMax: 5,
statusPagesMax: 5, statusPagesMax: 5,
checksIntervalMsMin: 30_000, checksIntervalMsMin: 30_000,
@@ -42,8 +43,8 @@ export const Plans: Record<PlanKey, Entitlements> = {
}, },
business: { business: {
plan: "business", plan: "business",
monitorsMax: 200, monitorsMax: 50,
notificationChannelsMax: 20, notificationChannelsMax: 10,
statusPagesMax: 20, statusPagesMax: 20,
checksIntervalMsMin: 15_000, checksIntervalMsMin: 15_000,
teamsMax: 10, teamsMax: 10,
@@ -52,8 +53,8 @@ export const Plans: Record<PlanKey, Entitlements> = {
}, },
enterprise: { enterprise: {
plan: "enterprise", plan: "enterprise",
monitorsMax: 5000, monitorsMax: 100,
notificationChannelsMax: 100, notificationChannelsMax: 20,
statusPagesMax: 100, statusPagesMax: 100,
checksIntervalMsMin: 10_000, checksIntervalMsMin: 10_000,
teamsMax: 20, teamsMax: 20,