Files
Checkmate/client/src/components/design-elements/PlanCard.tsx
T

186 lines
5.3 KiB
TypeScript
Raw Normal View History

2025-12-01 00:35:53 +00:00
import Stack from "@mui/material/Stack";
import Typography from "@mui/material/Typography";
2025-12-03 21:21:00 +00:00
import Chip from "@mui/material/Chip";
import { Button } from "@/components/inputs";
2025-12-01 00:35:53 +00:00
import { BaseBox } from "@/components/design-elements";
2025-12-02 20:52:27 +00:00
import {
PersonStanding,
BicepsFlexed,
Building2,
Briefcase,
Check,
} from "lucide-react";
import Divider from "@mui/material/Divider";
import Tooltip from "@mui/material/Tooltip";
2025-12-01 00:35:53 +00:00
import { useTheme } from "@mui/material/styles";
import type { Entitlements, PlanKey } from "@/types/entitlements";
export const PlanCard = ({
plan,
currentPlan,
onClick,
2025-12-03 21:21:00 +00:00
loading,
2025-12-01 00:35:53 +00:00
}: {
plan: Entitlements;
currentPlan: PlanKey | null;
onClick?: (planKey: PlanKey) => void;
2025-12-03 21:21:00 +00:00
loading?: boolean;
2025-12-01 00:35:53 +00:00
}) => {
const selected = plan.plan === currentPlan;
const theme = useTheme();
2025-12-02 20:52:27 +00:00
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.",
},
];
2025-12-01 00:35:53 +00:00
return (
<BaseBox
2025-12-03 20:49:00 +00:00
padding={6}
2025-12-03 21:21:00 +00:00
sx={{
display: "flex",
flexDirection: "column",
height: "100%",
border: selected ? 2 : 1,
borderColor: selected ? theme.palette.accent.main : "divider",
transition:
"transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease",
...(selected
? {}
: {
cursor: "pointer",
"&:hover": {
transform: "scale(0.995)",
boxShadow: 2,
borderColor: theme.palette.action.active,
},
}),
position: "relative",
}}
2025-12-01 00:35:53 +00:00
onClick={selected ? undefined : () => onClick?.(plan.plan)}
>
2025-12-03 21:21:00 +00:00
<Stack spacing={3} sx={{ flexGrow: 1 }}>
2025-12-02 20:52:27 +00:00
<Stack
direction="row"
alignItems="center"
justifyContent="space-between"
>
<Typography variant="h6" textTransform="capitalize">
{plan.plan}
</Typography>
2025-12-03 21:21:00 +00:00
<Stack direction="row" alignItems="center" spacing={1}>
{plan.plan === "pro" && (
2025-12-04 20:26:21 +00:00
<Chip
size="small"
label="Most popular"
sx={{
bgcolor: theme.palette.accent.main,
color: theme.palette.getContrastText(
theme.palette.accent.main
),
}}
/>
2025-12-03 21:21:00 +00:00
)}
<Icon size={18} />
</Stack>
2025-12-02 20:52:27 +00:00
</Stack>
<Divider />
<Typography variant="h4" fontWeight={700}>
{priceLabel}
2025-12-01 00:35:53 +00:00
</Typography>
2025-12-03 20:49:00 +00:00
<Stack spacing={2}>
2025-12-02 20:52:27 +00:00
{featureItems.map((item) => (
2025-12-03 21:21:00 +00:00
<Stack key={item.label} direction="row" alignItems="center" gap={2}>
2025-12-02 20:52:27 +00:00
<Check size={16} color={checkColor} />
{item.tooltip ? (
<Tooltip title={item.tooltip} arrow placement="right">
2025-12-04 20:26:21 +00:00
<Typography variant="body1" color="text.secondary" fontSize={18}>
2025-12-02 20:52:27 +00:00
{item.label}: {item.value}
</Typography>
</Tooltip>
) : (
2025-12-04 20:26:21 +00:00
<Typography variant="body1" color="text.secondary" fontSize={18}>
2025-12-02 20:52:27 +00:00
{item.label}: {item.value}
</Typography>
)}
</Stack>
))}
</Stack>
2025-12-01 00:35:53 +00:00
</Stack>
2025-12-03 21:21:00 +00:00
<Stack direction="row" justifyContent="flex-end" pt={2}>
{selected ? null : (
// <Button variant="contained" color="accent" loading={loading}>
// Manage
// </Button>
<Button
loading={loading}
variant="contained"
color="accent"
onClick={(e) => {
e.stopPropagation();
onClick?.(plan.plan);
}}
>
Choose plan
</Button>
)}
</Stack>
2025-12-01 00:35:53 +00:00
</BaseBox>
);
};