Skip to content

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

web: fix `cannot use IS_DEV before initialization` error

Abdullah Atta860bc107471d
diff --git a/apps/web/src/dialogs/buy-dialog/buy-dialog.tsx b/apps/web/src/dialogs/buy-dialog/buy-dialog.tsx
index 2cdb1798a..7d8ca5c54 100644
--- a/apps/web/src/dialogs/buy-dialog/buy-dialog.tsx
+++ b/apps/web/src/dialogs/buy-dialog/buy-dialog.tsx
@@ -179,6 +179,7 @@ export function CheckoutSideBar(props: SideBarProps) {
if (user && selectedPlan)
return (
<SelectedPlan
+ user={user}
plan={selectedPlan}
pricingInfo={pricingInfo}
onChangePlan={onShowPlans}
@@ -299,11 +300,17 @@ export function CheckoutCompleted(props: {
type SelectedPlanProps = {
plan: Plan;
+ user: User;
pricingInfo: PricingInfo | undefined;
onChangePlan?: () => void;
};
function SelectedPlan(props: SelectedPlanProps) {
- const { plan, pricingInfo = toPricingInfo(plan), onChangePlan } = props;
+ const {
+ plan,
+ user,
+ pricingInfo = toPricingInfo(plan, user),
+ onChangePlan
+ } = props;
const selectPlan = useCheckoutStore((store) => store.selectPlan);
const upsellDetails = usePromise(() => getUpsellDetails(plan), [plan]);
diff --git a/apps/web/src/dialogs/buy-dialog/helpers.ts b/apps/web/src/dialogs/buy-dialog/helpers.ts
index 6dcd609de..16608d996 100644
--- a/apps/web/src/dialogs/buy-dialog/helpers.ts
+++ b/apps/web/src/dialogs/buy-dialog/helpers.ts
@@ -24,7 +24,6 @@ import {
import { getFeature } from "@notesnook/common";
import { Period, Plan, SubscriptionPlan, User } from "@notesnook/core";
import { PricingInfo } from "./types";
-import { useStore as useUserStore } from "../../stores/user-store";
export const IS_DEV = import.meta.env.DEV || IS_TESTING;
export function getCurrencySymbol(currency: string) {
@@ -56,7 +55,7 @@ const TRIAL_PERIODS: Record<Period, number> = {
"5-year": 30
};
-export function toPricingInfo(plan: Plan): PricingInfo {
+export function toPricingInfo(plan: Plan, user: User | undefined): PricingInfo {
return {
country: plan.country,
period: plan.period,
@@ -67,7 +66,7 @@ export function toPricingInfo(plan: Plan): PricingInfo {
subtotal: `${getCurrencySymbol(plan.currency)}${plan.price.net}`,
tax: `${getCurrencySymbol(plan.currency)}${plan.price.tax}`,
total: `${getCurrencySymbol(plan.currency)}${plan.price.gross}`,
- trial_period: isTrialAvailableForPlan(plan.plan)
+ trial_period: isTrialAvailableForPlan(plan.plan, user)
? {
frequency: TRIAL_PERIODS[plan.period]
}
@@ -86,8 +85,10 @@ export function toPricingInfo(plan: Plan): PricingInfo {
};
}
-export function isTrialAvailableForPlan(plan: SubscriptionPlan) {
- const user = useUserStore.getState().user;
+export function isTrialAvailableForPlan(
+ plan: SubscriptionPlan,
+ user: User | undefined
+) {
return (
!user?.subscription.trialsAvailed ||
!user?.subscription.trialsAvailed?.includes(plan)
diff --git a/apps/web/src/dialogs/buy-dialog/plan-list.tsx b/apps/web/src/dialogs/buy-dialog/plan-list.tsx
index 6113ce337..3a20eebd5 100644
--- a/apps/web/src/dialogs/buy-dialog/plan-list.tsx
+++ b/apps/web/src/dialogs/buy-dialog/plan-list.tsx
@@ -124,6 +124,7 @@ export function PlansList(props: PlansListProps) {
const { onPlanSelected, selectedPlan } = props;
const { isLoading, plans } = usePlans();
const [selectedPeriod, setPeriod] = useState<Period>("yearly");
+ const user = useUserStore((store) => store.user);
return (
<>
@@ -277,7 +278,7 @@ export function PlansList(props: PlansListProps) {
onClick={() => onPlanSelected(plan)}
sx={{ mt: 2 }}
>
- {isTrialAvailableForPlan(plan.plan)
+ {isTrialAvailableForPlan(plan.plan, user)
? "Start your free trial"
: "Select plan"}
</Button>