stripe
This commit is contained in:
1 parent
01c0e9ef4d
commit
1b162578c2
22 files changed
+450
-72
No files matched your search
@@ -7,7 +7,12 @@ import Tooltip from "@mui/material/Tooltip";
|
||||
import { useSelector } from "react-redux";
|
||||
import type { RootState } from "@/store";
|
||||
import { useMemo } from "react";
|
||||
import type { EntitlemenstKey } from "@/types/entitlements";
|
||||
type EntitlementsKey =
|
||||
| "monitorsMax"
|
||||
| "notificationChannelsMax"
|
||||
| "statusPagesMax"
|
||||
| "checksIntervalMsMin"
|
||||
| "teamsMax";
|
||||
export const HeaderCreate = ({
|
||||
label,
|
||||
isLoading,
|
||||
@@ -18,7 +23,7 @@ export const HeaderCreate = ({
|
||||
label?: string;
|
||||
isLoading: boolean;
|
||||
path: string;
|
||||
entitlement: EntitlemenstKey | null;
|
||||
entitlement: EntitlementsKey | null;
|
||||
entitlementCount: number;
|
||||
}) => {
|
||||
const theme = useTheme();
|
||||
@@ -29,7 +34,7 @@ export const HeaderCreate = ({
|
||||
if (!entitlement) return false;
|
||||
if (!ent || typeof ent[entitlement] !== "number") return false;
|
||||
return entitlementCount < ent[entitlement] ? false : true;
|
||||
}, [ent, entitlementCount]);
|
||||
}, [ent, entitlement, entitlementCount]);
|
||||
return (
|
||||
<Stack
|
||||
direction="row"
|
||||
|
||||
@@ -32,7 +32,6 @@ interface BasePageWithStatesProps extends StackProps {
|
||||
error: any;
|
||||
items: any[];
|
||||
bullets: string[] | unknown;
|
||||
|
||||
page: string;
|
||||
actionButtonText: string;
|
||||
actionLink: string;
|
||||
@@ -83,6 +82,7 @@ interface MonitorBasePageWithStatesProps extends StackProps {
|
||||
loading: boolean;
|
||||
error: any;
|
||||
items: any[];
|
||||
monitorLimitReached: boolean;
|
||||
page: string;
|
||||
actionLink?: string;
|
||||
children: React.ReactNode;
|
||||
@@ -100,6 +100,7 @@ export const MonitorBasePageWithStates: React.FC<
|
||||
loading,
|
||||
error,
|
||||
items,
|
||||
monitorLimitReached,
|
||||
page,
|
||||
actionLink,
|
||||
children,
|
||||
@@ -130,6 +131,7 @@ export const MonitorBasePageWithStates: React.FC<
|
||||
bullets={t(`${page}Monitor.fallback.checks`, { returnObjects: true })}
|
||||
actionButtonText={t(`${page}Monitor.fallback.actionButton`)}
|
||||
actionLink={actionLink || ""}
|
||||
monitorLimitReached={monitorLimitReached}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -123,12 +123,14 @@ export const EmptyMonitorFallback = ({
|
||||
bullets,
|
||||
actionButtonText,
|
||||
actionLink,
|
||||
monitorLimitReached,
|
||||
}: {
|
||||
page: string;
|
||||
title: string;
|
||||
bullets: any;
|
||||
actionButtonText: string;
|
||||
actionLink: string;
|
||||
monitorLimitReached: boolean;
|
||||
}) => {
|
||||
const theme = useTheme();
|
||||
const navigate = useNavigate();
|
||||
@@ -158,8 +160,9 @@ export const EmptyMonitorFallback = ({
|
||||
variant="contained"
|
||||
color="accent"
|
||||
onClick={() => navigate(actionLink)}
|
||||
disabled={monitorLimitReached}
|
||||
>
|
||||
{actionButtonText}
|
||||
{monitorLimitReached ? "Monitor limit reached" : actionButtonText}
|
||||
</Button>
|
||||
</Stack>
|
||||
</Stack>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { BasePage, InfoBox, PlanCard } from "@/components/design-elements";
|
||||
import Grid from "@mui/material/Grid";
|
||||
import Box from "@mui/material/Box";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import { Button } from "@/components/inputs";
|
||||
|
||||
import { useAppSelector } from "@/hooks/AppHooks";
|
||||
import { useGet, usePost } from "@/hooks/UseApi";
|
||||
@@ -27,6 +29,14 @@ const BillingPage = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleCancel = async () => {
|
||||
const result = await post("/billing/cancel", {});
|
||||
const redirectUrl = result?.data?.redirectUrl;
|
||||
if (redirectUrl) {
|
||||
window.location = redirectUrl;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<BasePage>
|
||||
<InfoBox
|
||||
@@ -48,6 +58,18 @@ const BillingPage = () => {
|
||||
</Grid>
|
||||
))}
|
||||
</Grid>
|
||||
{selectedPlan !== "free" && (
|
||||
<Box>
|
||||
<Button
|
||||
variant="contained"
|
||||
color="error"
|
||||
onClick={handleCancel}
|
||||
loading={isPosting}
|
||||
>
|
||||
Cancel subscription
|
||||
</Button>
|
||||
</Box>
|
||||
)}
|
||||
</BasePage>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,5 +1,37 @@
|
||||
import { BasePage } from "@/components/design-elements";
|
||||
import Stack from "@mui/material/Stack";
|
||||
import CircularProgress from "@mui/material/CircularProgress";
|
||||
import Typography from "@mui/material/Typography";
|
||||
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import { Navigate, useSearchParams } from "react-router-dom";
|
||||
import { useGet } from "@/hooks/UseApi";
|
||||
import type { ApiResponse } from "@/hooks/UseApi";
|
||||
|
||||
const BillingSuccessPage = () => {
|
||||
return "Great";
|
||||
const theme = useTheme();
|
||||
const [searchParams] = useSearchParams();
|
||||
const plan = searchParams.get("plan");
|
||||
|
||||
const { response } = useGet<ApiResponse<any>>(
|
||||
`/billing/confirm?plan=${plan}`,
|
||||
{},
|
||||
{}
|
||||
);
|
||||
|
||||
const success = response?.data?.success ?? false;
|
||||
if (success === true) {
|
||||
return <Navigate to="/billing" replace />;
|
||||
} else {
|
||||
return (
|
||||
<BasePage>
|
||||
<Stack direction="row" alignItems={"center"} gap={theme.spacing(10)}>
|
||||
<CircularProgress color="accent" />
|
||||
<Typography>Awaiting confirmation..</Typography>
|
||||
</Stack>
|
||||
</BasePage>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default BillingSuccessPage;
|
||||
@@ -19,12 +19,14 @@ import useMediaQuery from "@mui/material/useMediaQuery";
|
||||
import { useState } from "react";
|
||||
import { useDelete } from "@/hooks/UseApi";
|
||||
import { InitializingStatusBox } from "@/components/design-elements/StatusBox";
|
||||
import { useAppSelector } from "@/hooks/AppHooks";
|
||||
|
||||
const GLOBAL_REFRESH = import.meta.env.VITE_APP_GLOBAL_REFRESH;
|
||||
|
||||
const PageSpeedMonitorsPage = () => {
|
||||
const theme = useTheme();
|
||||
const { t } = useTranslation();
|
||||
const { user } = useAppSelector((state) => state.auth);
|
||||
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
||||
const [selectedMonitor, setSelectedMonitor] = useState<IMonitor | null>(null);
|
||||
const isDialogOpen = Boolean(selectedMonitor);
|
||||
@@ -64,6 +66,8 @@ const PageSpeedMonitorsPage = () => {
|
||||
const downCount = response?.data?.downCount || 0;
|
||||
const pausedCount = response?.data?.pausedCount || 0;
|
||||
|
||||
const monitorLimitReached = count >= (user?.entitlements?.monitorsMax || 0);
|
||||
|
||||
const handleConfirm = async () => {
|
||||
await deleteFn(`/monitors/${selectedMonitor?._id}`);
|
||||
setSelectedMonitor(null);
|
||||
@@ -79,6 +83,7 @@ const PageSpeedMonitorsPage = () => {
|
||||
loading={isValidating}
|
||||
error={error}
|
||||
items={monitors}
|
||||
monitorLimitReached={monitorLimitReached}
|
||||
page="infrastructure"
|
||||
actionLink="/infrastructure/create"
|
||||
>
|
||||
|
||||
@@ -19,11 +19,14 @@ import useMediaQuery from "@mui/material/useMediaQuery";
|
||||
import { useState } from "react";
|
||||
import { useDelete } from "@/hooks/UseApi";
|
||||
import { InitializingStatusBox } from "@/components/design-elements/StatusBox";
|
||||
import { useAppSelector } from "@/hooks/AppHooks";
|
||||
|
||||
const GLOBAL_REFRESH = import.meta.env.VITE_APP_GLOBAL_REFRESH;
|
||||
|
||||
const PageSpeedMonitorsPage = () => {
|
||||
const theme = useTheme();
|
||||
const { user } = useAppSelector((state) => state.auth);
|
||||
|
||||
const { t } = useTranslation();
|
||||
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
||||
const [selectedMonitor, setSelectedMonitor] = useState<IMonitor | null>(null);
|
||||
@@ -64,6 +67,8 @@ const PageSpeedMonitorsPage = () => {
|
||||
const downCount = response?.data?.downCount || 0;
|
||||
const pausedCount = response?.data?.pausedCount || 0;
|
||||
|
||||
const monitorLimitReached = count >= (user?.entitlements?.monitorsMax || 0);
|
||||
|
||||
const handleConfirm = async () => {
|
||||
await deleteFn(`/monitors/${selectedMonitor?._id}`);
|
||||
setSelectedMonitor(null);
|
||||
@@ -81,6 +86,7 @@ const PageSpeedMonitorsPage = () => {
|
||||
items={monitors}
|
||||
page="pageSpeed"
|
||||
actionLink="/pagespeed/create"
|
||||
monitorLimitReached={monitorLimitReached}
|
||||
>
|
||||
<InfoBox
|
||||
title="Website Performance Tracking"
|
||||
|
||||
@@ -10,6 +10,7 @@ import { HeaderCreate } from "@/components/common";
|
||||
import Stack from "@mui/material/Stack";
|
||||
import { Dialog } from "@/components/inputs";
|
||||
import { MonitorTable } from "@/pages/uptime/MonitorTable";
|
||||
import { InitializingStatusBox } from "@/components/design-elements/StatusBox";
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
@@ -26,12 +27,13 @@ import {
|
||||
import useMediaQuery from "@mui/material/useMediaQuery";
|
||||
import { useState } from "react";
|
||||
import { useDelete } from "@/hooks/UseApi";
|
||||
import { InitializingStatusBox } from "@/components/design-elements/StatusBox";
|
||||
import { useAppSelector } from "@/hooks/AppHooks";
|
||||
|
||||
const GLOBAL_REFRESH = import.meta.env.VITE_APP_GLOBAL_REFRESH;
|
||||
|
||||
const UptimeMonitors = () => {
|
||||
const theme = useTheme();
|
||||
const { user } = useAppSelector((state) => state.auth);
|
||||
const { t } = useTranslation();
|
||||
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
||||
const [selectedMonitor, setSelectedMonitor] = useState<IMonitor | null>(null);
|
||||
@@ -91,6 +93,8 @@ const UptimeMonitors = () => {
|
||||
const downCount = response?.data?.downCount || 0;
|
||||
const pausedCount = response?.data?.pausedCount || 0;
|
||||
|
||||
const monitorLimitReached = count >= (user?.entitlements?.monitorsMax || 0);
|
||||
|
||||
const handleConfirm = async () => {
|
||||
await deleteFn(`/monitors/${selectedMonitor?._id}`);
|
||||
setSelectedMonitor(null);
|
||||
@@ -120,6 +124,7 @@ const UptimeMonitors = () => {
|
||||
items={monitorItems}
|
||||
page="uptime"
|
||||
actionLink="/uptime/create"
|
||||
monitorLimitReached={monitorLimitReached}
|
||||
>
|
||||
<InfoBox
|
||||
title="Website & API Uptime Monitoring"
|
||||
|
||||
Vendored
+6
@@ -23,3 +23,9 @@ declare module "@mui/material/Button" {
|
||||
accent: true;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "@mui/material/CircularProgress" {
|
||||
interface CircularProgressPropsColorOverrides {
|
||||
accent: true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user