fe
This commit is contained in:
1 parent
6bca0ed00b
commit
7b207f2ccb
15 files changed
+204
-15
No files matched your search
@@ -1,13 +1,11 @@
|
||||
import Box from "@mui/material/Box";
|
||||
import Box, { type BoxProps } from "@mui/material/Box";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import type { SxProps } from "@mui/material/styles";
|
||||
|
||||
type BaseBoxProps = React.PropsWithChildren<{ sx?: SxProps }>;
|
||||
|
||||
export const BaseBox: React.FC<BaseBoxProps> = ({ children, sx }) => {
|
||||
export const BaseBox = ({ sx, ...rest }: BoxProps) => {
|
||||
const theme = useTheme();
|
||||
return (
|
||||
<Box
|
||||
{...rest}
|
||||
sx={{
|
||||
backgroundColor: theme.palette.primary.main,
|
||||
border: 1,
|
||||
@@ -16,8 +14,6 @@ export const BaseBox: React.FC<BaseBoxProps> = ({ children, sx }) => {
|
||||
borderRadius: theme.shape.borderRadius,
|
||||
...sx,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</Box>
|
||||
/>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,57 @@
|
||||
import Stack from "@mui/material/Stack";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import { BaseBox } from "@/components/design-elements";
|
||||
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import type { Entitlements, PlanKey } from "@/types/entitlements";
|
||||
|
||||
export const PlanCard = ({
|
||||
plan,
|
||||
currentPlan,
|
||||
onClick,
|
||||
}: {
|
||||
plan: Entitlements;
|
||||
currentPlan: PlanKey | null;
|
||||
onClick?: (planKey: PlanKey) => void;
|
||||
}) => {
|
||||
const selected = plan.plan === currentPlan;
|
||||
const theme = useTheme();
|
||||
return (
|
||||
<BaseBox
|
||||
padding={theme.spacing(8)}
|
||||
sx={
|
||||
selected
|
||||
? {
|
||||
border: 2,
|
||||
borderColor: theme.palette.accent.main,
|
||||
}
|
||||
: { cursor: "pointer" }
|
||||
}
|
||||
onClick={selected ? undefined : () => onClick?.(plan.plan)}
|
||||
>
|
||||
<Stack spacing={theme.spacing(2)}>
|
||||
<Typography variant="h6" textTransform="capitalize">
|
||||
{plan.plan}
|
||||
</Typography>
|
||||
<Typography variant="body2" color="text.secondary">
|
||||
Monitors: {plan.monitorsMax}
|
||||
</Typography>
|
||||
<Typography variant="body2" color="text.secondary">
|
||||
Status pages: {plan.statusPagesMax}
|
||||
</Typography>
|
||||
<Typography variant="body2" color="text.secondary">
|
||||
Notification channels: {plan.notificationChannelsMax}
|
||||
</Typography>
|
||||
<Typography variant="body2" color="text.secondary">
|
||||
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>
|
||||
</Stack>
|
||||
</BaseBox>
|
||||
);
|
||||
};
|
||||
@@ -29,3 +29,4 @@ export { Tabs } from "./Tabs";
|
||||
export { Breadcrumb } from "./Breadcrumb";
|
||||
export { InfoBox } from "./InfoBox";
|
||||
export { Tooltip, TooltipWithInfo } from "./Tooltip";
|
||||
export { PlanCard } from "./PlanCard";
|
||||
@@ -9,6 +9,8 @@ import { useAppSelector } from "@/hooks/AppHooks";
|
||||
import { useState } from "react";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import { Tooltip } from "@/components/design-elements";
|
||||
const DEPLOYMENT_MODE = import.meta.env.VITE_APP_DEPLOYMENT_MODE;
|
||||
const IS_SAAS = DEPLOYMENT_MODE === "saas";
|
||||
|
||||
export const SettingsSwitch = () => {
|
||||
const navigate = useNavigate();
|
||||
@@ -105,7 +107,7 @@ export const SettingsSwitch = () => {
|
||||
<Typography>Invite</Typography>
|
||||
</MenuItem>
|
||||
)}
|
||||
{hasBilling && (
|
||||
{hasBilling && IS_SAAS && (
|
||||
<MenuItem onClick={() => handleClick("billing")}>
|
||||
<Typography>Billing</Typography>
|
||||
</MenuItem>
|
||||
|
||||
@@ -1,17 +1,53 @@
|
||||
import { BasePage, InfoBox } from "@/components/design-elements";
|
||||
import { BasePage, InfoBox, PlanCard } from "@/components/design-elements";
|
||||
import Grid from "@mui/material/Grid";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
|
||||
import { useAppSelector } from "@/hooks/AppHooks";
|
||||
import { useGet, usePost } from "@/hooks/UseApi";
|
||||
import type { ApiResponse } from "@/hooks/UseApi";
|
||||
import type { Entitlements, PlanKey } from "@/types/entitlements";
|
||||
|
||||
const BillingPage = () => {
|
||||
const { user } = useAppSelector((state) => state.auth);
|
||||
const { response } = useGet<ApiResponse<Entitlements[]>>(
|
||||
"/billing/plans",
|
||||
{},
|
||||
{}
|
||||
);
|
||||
const { post, loading: isPosting } = usePost();
|
||||
const plans = response?.data ?? [];
|
||||
const theme = useTheme();
|
||||
const selectedPlan = user?.entitlements?.plan || null;
|
||||
|
||||
const handlePlanClick = async (planKey: PlanKey) => {
|
||||
const result = await post("/billing/subscribe", { plan: planKey });
|
||||
const redirectUrl = result?.data?.redirectUrl;
|
||||
if (redirectUrl) {
|
||||
window.location.href = redirectUrl;
|
||||
}
|
||||
};
|
||||
|
||||
console.log(user);
|
||||
return (
|
||||
<BasePage>
|
||||
<InfoBox
|
||||
title="Choose a plan!"
|
||||
description="Choose a plan that fits your needs and start enjoying our services."
|
||||
/>
|
||||
<Grid
|
||||
container
|
||||
spacing={theme.spacing(10)}
|
||||
columns={{ xs: 1, sm: 2, md: 4 }}
|
||||
>
|
||||
{plans.map((plan) => (
|
||||
<Grid key={plan.plan} size={1}>
|
||||
<PlanCard
|
||||
plan={plan}
|
||||
currentPlan={selectedPlan}
|
||||
onClick={handlePlanClick}
|
||||
/>
|
||||
</Grid>
|
||||
))}
|
||||
</Grid>
|
||||
</BasePage>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export type EntitlemenstKey = keyof Entitlements;
|
||||
export type PlanKey = "free" | "pro" | "business" | "enterprise" | "unlimited";
|
||||
|
||||
export interface Entitlements {
|
||||
plan: string;
|
||||
plan: PlanKey;
|
||||
monitorsMax: number;
|
||||
notificationChannelsMax: number;
|
||||
statusPagesMax: number;
|
||||
|
||||
Reference in new issue
Block a user