A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
web: show plans on login & signup
Abdullah Attaef235dd0aa97
diff --git a/apps/web/src/bootstrap.tsx b/apps/web/src/bootstrap.tsxindex 453970eb6..c05ca0caa 100644--- a/apps/web/src/bootstrap.tsx+++ b/apps/web/src/bootstrap.tsx@@ -52,6 +52,9 @@ export type Routes = keyof typeof routes;// | "default";const routes = {+ "/plans": {+ component: () => import("./views/plans")+ },"/checkout": {component: () => import("./views/checkout")},diff --git a/apps/web/src/dialogs/buy-dialog/buy-dialog.tsx b/apps/web/src/dialogs/buy-dialog/buy-dialog.tsxindex aa6378197..16f4bec01 100644--- a/apps/web/src/dialogs/buy-dialog/buy-dialog.tsx+++ b/apps/web/src/dialogs/buy-dialog/buy-dialog.tsx@@ -49,16 +49,17 @@ import { usePromise } from "@notesnook/common";type BuyDialogProps = BaseDialogProps<false> & {couponCode?: string;+ onShowPlans?: () => void;+ onCheckoutComplete?: () => void;onClose: () => void;};export const BuyDialog = DialogManager.register(function BuyDialog(props: BuyDialogProps) {- const { onClose, couponCode } = props;+ const { onClose, onShowPlans, onCheckoutComplete, couponCode } = props;const applyCoupon = useCheckoutStore((store) => store.applyCoupon);- const isCheckoutCompleted = useCheckoutStore((store) => store.isCompleted);const user = useUserStore((store) => store.user);const selectedPlan = useCheckoutStore((state) => state.selectedPlan);const selectPlan = useCheckoutStore((state) => state.selectPlan);@@ -77,10 +78,10 @@ export const BuyDialog = DialogManager.register(function BuyDialog(<BaseDialogisOpen={true}width={"868px"}- onClose={() => props.onClose(false)}+ onClose={() => onClose(false)}noScroll={!!selectedPlan}sx={{- width: ["95%", "80%", isCheckoutCompleted ? "400px" : "60%"]+ width: ["95%", "80%", "60%"]}}>{selectedPlan ? (@@ -106,26 +107,45 @@ export const BuyDialog = DialogManager.register(function BuyDialog(flexShrink: 0,// alignItems: "center",// justifyContent: "center",- width: ["100%", "100%", isCheckoutCompleted ? "100%" : 350],+ width: ["100%", "100%", 350],p: 4}}><CheckoutSideBar- onClose={() => onClose(false)}selectedPlan={selectedPlan}- onShowPlans={() => {- selectPlan(undefined);- }}+ onShowPlans={+ onShowPlans ??+ (() => {+ selectPlan(undefined);+ })+ }user={user}/></ScopedThemeProvider>- <CheckoutDetails user={user} />+ <CheckoutDetails+ onComplete={onCheckoutComplete ?? (() => {})}+ user={user}+ /></Flex>) : (- <PlansList- selectedPlan={user?.subscription.plan || SubscriptionPlan.FREE}- onPlanSelected={(plan) => selectPlan(plan)}- />+ <Flex sx={{ flexDirection: "column", py: 25, flex: 1, px: 25 }}>+ <Flex sx={{ flexDirection: "column", alignSelf: "center" }}>+ <Text variant="heading" sx={{ textAlign: "center" }}>+ Select a plan+ </Text>+ <Text+ variant="title"+ mt={1}+ sx={{ color: "heading-secondary", textAlign: "center" }}+ >+ One subscription for a lifetime of notes.+ </Text>+ </Flex>+ <PlansList+ selectedPlan={user?.subscription.plan || SubscriptionPlan.FREE}+ onPlanSelected={(plan) => selectPlan(plan)}+ />+ </Flex>)}</BaseDialog>);@@ -134,15 +154,11 @@ export const BuyDialog = DialogManager.register(function BuyDialog(type SideBarProps = {selectedPlan: Plan;onShowPlans: () => void;- onClose: () => void;user?: User;};export function CheckoutSideBar(props: SideBarProps) {- const { onShowPlans, selectedPlan, onClose, user } = props;+ const { onShowPlans, selectedPlan, user } = props;const pricingInfo = useCheckoutStore((state) => state.pricingInfo);- const isCheckoutCompleted = useCheckoutStore((store) => store.isCompleted);-- if (isCheckoutCompleted) return <CheckoutCompleted onClose={onClose} />;if (user && selectedPlan)return (@@ -165,62 +181,22 @@ export function CheckoutSideBar(props: SideBarProps) {}return null;- // if (user)- // return (- // <PlansList- // selectedPlan={selectedPlan?.plan || initialPlan}- // onPlansLoaded={(plans) => {- // // if (!initialPlan || showPlans) return;- // // const plan = plans.find((p) => p.id === initialPlan);- // // onPlanSelected(plan);- // }}- // onPlanSelected={onPlanSelected}- // />- // );-- // return (- // <TrialOrUpgrade- // couponCode={couponCode}- // user={user}- // onShowPlans={onShowPlans}- // onTrialRequested={async () => {- // try {- // const result = await TaskManager.startTask({- // type: "status",- // id: "trialActivation",- // title: strings.activatingTrial(),- // action: () => db.user.activateTrial()- // });- // if (result) onClose();- // } catch (e) {- // if (e instanceof Error)- // showToast(- // "error",- // `${strings.couldNotActivateTrial()} ${strings.error()}: ${- // e.message- // }`- // );- // }- // }}- // />- // );}export function CheckoutDetails({- user+ user,+ onComplete}: {user?: { id: string; email: string };+ onComplete: () => void;}) {const selectedPlan = useCheckoutStore((state) => state.selectedPlan);const onPriceUpdated = useCheckoutStore((state) => state.updatePrice);- const completeCheckout = useCheckoutStore((state) => state.completeCheckout);- const isCheckoutCompleted = useCheckoutStore((store) => store.isCompleted);const couponCode = useCheckoutStore((store) => store.couponCode);const setIsApplyingCoupon = useCheckoutStore((store) => store.setIsApplyingCoupon);const theme = useThemeStore((store) => store.colorScheme);- if (isCheckoutCompleted) return null;if (selectedPlan && user)return (@@ -229,20 +205,10 @@ export function CheckoutDetails({theme={theme}user={user}coupon={couponCode}- onCompleted={completeCheckout}+ onCompleted={onComplete}onPriceUpdated={(pricingInfo) => {onPriceUpdated(pricingInfo);setIsApplyingCoupon(false);- // console.log(- // initialCouponCode,- // "applying coupon",- // couponCode,- // pricingInfo.coupon- // );-- // if (!initialCouponCode || initialCouponCode === couponCode) return;- // console.log(initialCouponCode, "applying coupon");- // onApplyCoupon(initialCouponCode);}}/>);diff --git a/apps/web/src/dialogs/buy-dialog/plan-list.tsx b/apps/web/src/dialogs/buy-dialog/plan-list.tsxindex 6f562c01d..14803cca6 100644--- a/apps/web/src/dialogs/buy-dialog/plan-list.tsx+++ b/apps/web/src/dialogs/buy-dialog/plan-list.tsx@@ -129,23 +129,7 @@ export function PlansList(props: PlansListProps) {const [selectedPeriod, setPeriod] = useState<Period>("yearly");return (- <Flex sx={{ flexDirection: "column", py: 25, flex: 1, px: 25 }}>- {/* <Image- src={Nomad}- style={{ flexShrink: 0, width: 150, height: 150, marginTop: 20 }}- /> */}- <Flex sx={{ flexDirection: "column", alignSelf: "center" }}>- <Text variant="heading" sx={{ textAlign: "center" }}>- Select a plan- </Text>- <Text- variant="title"- mt={1}- sx={{ color: "heading-secondary", textAlign: "center" }}- >- One subscription for a lifetime of notes.- </Text>- </Flex>+ <><Flexsx={{mt: 25,@@ -344,11 +328,16 @@ export function PlansList(props: PlansListProps) {))}</Flex><Testimonial />- <ComparePlans />+ </>+ );+}+export function Footer() {+ return (+ <><Textvariant="heading"- sx={{ fontSize: "subheading", textAlign: "center", mt: 50 }}+ sx={{ fontSize: "subheading", textAlign: "center", mt: 100 }}>Trusted and recommended by over 200K users</Text>@@ -387,7 +376,7 @@ export function PlansList(props: PlansListProps) {>Subscribe to Pro</Button>- </Flex>+ </>);}@@ -474,12 +463,11 @@ function OneTimePricing(props: PricingProps) {}const rows = getFeaturesTable();-function ComparePlans() {+export function ComparePlans() {return (<Flexsx={{flexDirection: "column",- mt: 50,// alignSelf: "center",bg: "background-secondary",border: "1px solid var(--border)",diff --git a/apps/web/src/dialogs/buy-dialog/plans.ts b/apps/web/src/dialogs/buy-dialog/plans.tsindex bdc5377e9..31a570958 100644--- a/apps/web/src/dialogs/buy-dialog/plans.ts+++ b/apps/web/src/dialogs/buy-dialog/plans.ts@@ -159,7 +159,7 @@ export const EDUCATION_PLAN: Plan = createPlan(let CACHED_PLANS: Plan[];export async function getPlans(): Promise<Plan[] | null> {- if (IS_TESTING || import.meta.env.DEV) return DEFAULT_PLANS;+ // if (IS_TESTING || import.meta.env.DEV) return DEFAULT_PLANS;if (CACHED_PLANS) return CACHED_PLANS;const plans = await db.pricing.products();diff --git a/apps/web/src/dialogs/buy-dialog/store.ts b/apps/web/src/dialogs/buy-dialog/store.tsindex e76887f3e..826474309 100644--- a/apps/web/src/dialogs/buy-dialog/store.ts+++ b/apps/web/src/dialogs/buy-dialog/store.ts@@ -23,8 +23,6 @@ import { create as produce } from "mutative";import { DEFAULT_PLANS } from "./plans";interface ICheckoutStore {- isCompleted: boolean;- completeCheckout: () => void;selectedPlan?: Plan;selectPlan: (plan?: Plan) => void;pricingInfo?: PricingInfo;@@ -36,18 +34,11 @@ interface ICheckoutStore {reset: () => void;}export const useCheckoutStore = create<ICheckoutStore>((set) => ({- isCompleted: false,selectedPlan: undefined,selectedPrice: undefined,pricingInfo: undefined,couponCode: undefined,isApplyingCoupon: false,- completeCheckout: () =>- set(- produce((state: ICheckoutStore) => {- state.isCompleted = true;- })- ),selectPlan: (plan) =>set(produce((state: ICheckoutStore) => {diff --git a/apps/web/src/views/auth.tsx b/apps/web/src/views/auth.tsxindex 6daf1afb1..a24d7730a 100644--- a/apps/web/src/views/auth.tsx+++ b/apps/web/src/views/auth.tsx@@ -321,7 +321,7 @@ function LoginPassword(props: BaseAuthComponentProps<"login:password">) {Config.get("sessionExpired", false));Config.set("sessionExpired", false);- openURL("/", { authenticated: true });+ openURL("/plans", { authenticated: true });}}>{(form?: PasswordFormData) => (@@ -379,7 +379,7 @@ function Signup(props: BaseAuthComponentProps<"signup">) {}await userstore.signup(form);- openURL("/notes/#/welcome", { authenticated: true });+ openURL("/plans", { authenticated: true });}}>{(form?: SignupFormData) => (diff --git a/apps/web/src/views/plans.tsx b/apps/web/src/views/plans.tsxnew file mode 100644index 000000000..9ebd0618c--- /dev/null+++ b/apps/web/src/views/plans.tsx@@ -0,0 +1,136 @@+/*+This file is part of the Notesnook project (https://notesnook.com/)++Copyright (C) 2023 Streetwriters (Private) Limited++This program is free software: you can redistribute it and/or modify+it under the terms of the GNU General Public License as published by+the Free Software Foundation, either version 3 of the License, or+(at your option) any later version.++This program is distributed in the hope that it will be useful,+but WITHOUT ANY WARRANTY; without even the implied warranty of+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+GNU General Public License for more details.++You should have received a copy of the GNU General Public License+along with this program. If not, see <http://www.gnu.org/licenses/>.+*/++import { SubscriptionPlan } from "@notesnook/core";+import {+ ComparePlans,+ Footer,+ PlansList+} from "../dialogs/buy-dialog/plan-list";+import { FlexScrollContainer } from "../components/scroll-container";+import { Button, Flex, Text } from "@theme-ui/components";+import { useCheckoutStore } from "../dialogs/buy-dialog/store";+import { BuyDialog } from "../dialogs/buy-dialog";+import { useStore as useUserStore } from "../stores/user-store";+import { useEffect } from "react";+import { getQueryParams, hardNavigate } from "../navigation";+import { Close } from "../components/icons";+import { isUserSubscribed } from "../hooks/use-is-user-premium";++function Plans() {+ const selectPlan = useCheckoutStore((state) => state.selectPlan);+ const user = useUserStore((store) => store.user);++ useEffect(() => {+ useUserStore.getState().init();+ }, []);++ if (isUserSubscribed(user)) {+ openURL("/");+ return null;+ }++ return (+ <Flex+ id="app"+ bg="background"+ sx={{+ overflow: "hidden",+ flexDirection: "column",+ height: "100%"+ }}+ >+ <Flex variant="columnFill" sx={{ overflowY: "hidden" }}>+ <FlexScrollContainer>+ <Button+ variant="icon"+ sx={{+ position: "absolute",+ top: 5,+ right: 5,+ borderRadius: "100%"+ }}+ onClick={() => openURL("/")}+ >+ <Close size={28} />+ </Button>+ <Flex+ sx={{+ flexDirection: "column",+ flex: 1,+ px: 25,+ height: "100vh",+ justifyContent: "center"+ }}+ >+ <Flex sx={{ flexDirection: "column", alignSelf: "center" }}>+ <Text+ variant="heading"+ sx={{ fontSize: 32, textAlign: "center" }}+ >+ Select a plan+ </Text>+ <Text+ variant="title"+ mt={1}+ sx={{+ fontSize: "subheading",+ color: "heading-secondary",+ textAlign: "center"+ }}+ >+ One subscription for a lifetime of notes.+ </Text>+ </Flex>+ <PlansList+ onPlanSelected={(plan) => {+ selectPlan(plan);+ BuyDialog.show({+ onShowPlans: () => BuyDialog.close(),+ onCheckoutComplete: () => {+ BuyDialog.close();+ openURL("/");+ }+ }).catch(console.error);+ }}+ selectedPlan={SubscriptionPlan.FREE}+ />+ </Flex>+ <Flex+ sx={{+ flexDirection: "column",+ flex: 1,+ px: "20%"+ }}+ >+ <ComparePlans />+ <Footer />+ </Flex>+ </FlexScrollContainer>+ </Flex>+ </Flex>+ );+}+export default Plans;++function openURL(url: string) {+ const queryParams = getQueryParams();+ const redirect = queryParams?.redirect;+ hardNavigate(redirect || url);+}