Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: prevent pro users from resubscribing

Abdullah Atta3b77d79997dd
diff --git a/apps/web/src/components/dialogs/buy-dialog/buy-dialog.tsx b/apps/web/src/components/dialogs/buy-dialog/buy-dialog.tsx
index baf7b7e56..d64998f71 100644
--- a/apps/web/src/components/dialogs/buy-dialog/buy-dialog.tsx
+++ b/apps/web/src/components/dialogs/buy-dialog/buy-dialog.tsx
@@ -41,6 +41,8 @@ import { useCheckoutStore } from "./store";
import { getCurrencySymbol } from "./helpers";
import { Theme } from "@notesnook/theme";
import { isMacStoreApp } from "../../../utils/platform";
+import { isUserSubscribed } from "../../../hooks/use-is-user-premium";
+import { SUBSCRIPTION_STATUS } from "../../../common/constants";
type BuyDialogProps = {
couponCode?: string;
@@ -156,7 +158,7 @@ type SideBarProps = {
};
function SideBar(props: SideBarProps) {
const { initialPlan, onClose } = props;
- const [showPlans, setShowPlans] = useState(!!initialPlan);
+ const [showPlans, setShowPlans] = useState(false);
const onPlanSelected = useCheckoutStore((state) => state.selectPlan);
const selectedPlan = useCheckoutStore((state) => state.selectedPlan);
const pricingInfo = useCheckoutStore((state) => state.pricingInfo);
@@ -176,7 +178,13 @@ function SideBar(props: SideBarProps) {
/>
);
- if (user && showPlans)
+ if (user && !showPlans && isUserSubscribed(user)) {
+ return (
+ <AlreadyPremium user={user} onShowPlans={() => setShowPlans(true)} />
+ );
+ }
+
+ if (user && (showPlans || !!initialPlan))
return (
<PlansList
onPlansLoaded={(plans) => {
@@ -347,6 +355,47 @@ function TrialOrUpgrade(props: TrialOrUpgradeProps) {
);
}
+type AlreadyPremiumProps = {
+ user: User | undefined;
+ onShowPlans: () => void;
+};
+function AlreadyPremium(props: AlreadyPremiumProps) {
+ const { user, onShowPlans } = props;
+
+ const isCanceled =
+ user?.subscription?.type === SUBSCRIPTION_STATUS.PREMIUM_CANCELED;
+
+ return (
+ <>
+ <Rocket width={200} />
+ <Text variant="heading" mt={4} sx={{ textAlign: "center" }}>
+ Notesnook Pro
+ </Text>
+ {isCanceled ? (
+ <>
+ <Text variant="body" mt={1} sx={{ textAlign: "center" }}>
+ Resubscribing to Notesnook Pro will replace your existing
+ subscription.
+ </Text>
+ <Button
+ variant="primary"
+ mt={2}
+ sx={{ borderRadius: 100, px: 6 }}
+ onClick={onShowPlans}
+ data-test-id="see-all-plans"
+ >
+ Continue
+ </Button>
+ </>
+ ) : (
+ <Text variant="body" mt={1} sx={{ textAlign: "center" }}>
+ You are already subscribed to Notesnook Pro.
+ </Text>
+ )}
+ </>
+ );
+}
+
type SelectedPlanProps = {
plan: Plan;
pricingInfo: PricingInfo | undefined;
diff --git a/apps/web/src/hooks/use-is-user-premium.ts b/apps/web/src/hooks/use-is-user-premium.ts
index d31c16eee..c32323e8b 100644
--- a/apps/web/src/hooks/use-is-user-premium.ts
+++ b/apps/web/src/hooks/use-is-user-premium.ts
@@ -41,3 +41,13 @@ export function isUserPremium(user?: User) {
subStatus === SUBSCRIPTION_STATUS.TRIAL
);
}
+
+export function isUserSubscribed(user?: User) {
+ if (!user) user = userstore.get().user;
+
+ const subStatus = user?.subscription?.type;
+ return (
+ subStatus === SUBSCRIPTION_STATUS.PREMIUM ||
+ subStatus === SUBSCRIPTION_STATUS.PREMIUM_CANCELED
+ );
+}