Skip to content

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

mobile: update paywall sheet

Ammar Ahmed0178e455f9c4
diff --git a/apps/mobile/app/components/premium/paywall.tsx b/apps/mobile/app/components/premium/paywall.tsx
index d5e18f6ee..071f02a21 100644
--- a/apps/mobile/app/components/premium/paywall.tsx
+++ b/apps/mobile/app/components/premium/paywall.tsx
@@ -139,7 +139,7 @@ const PayWall = (props: NavigationProps<"PayWall">) => {
gap: 5
}}
>
- <Icon name="crown" size={30} color={colors.static.orange} />
+ {/* <Icon name="crown" size={30} color={colors.static.orange} /> */}
<Heading
key="heading"
size={AppFontSize.xl}
diff --git a/apps/mobile/app/components/sheets/buy-plan/index.tsx b/apps/mobile/app/components/sheets/buy-plan/index.tsx
index 2eb318483..cb5543801 100644
--- a/apps/mobile/app/components/sheets/buy-plan/index.tsx
+++ b/apps/mobile/app/components/sheets/buy-plan/index.tsx
@@ -19,13 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import { useThemeColors } from "@notesnook/theme";
import dayjs from "dayjs";
import React from "react";
-import {
- Platform,
- ScrollView,
- Text,
- TouchableOpacity,
- View
-} from "react-native";
+import { ScrollView, Text, TouchableOpacity, View } from "react-native";
import * as RNIap from "react-native-iap";
import Icon from "react-native-vector-icons/MaterialCommunityIcons";
import useGlobalSafeAreaInsets from "../../../hooks/use-global-safe-area-insets";
@@ -33,7 +27,6 @@ import usePricingPlans from "../../../hooks/use-pricing-plans";
import { openLinkInBrowser } from "../../../utils/functions";
import { AppFontSize } from "../../../utils/size";
import { Button } from "../../ui/button";
-import { IconButton } from "../../ui/icon-button";
import Heading from "../../ui/typography/heading";
import Paragraph from "../../ui/typography/paragraph";
import { DefaultAppStyles } from "../../../utils/styles";
@@ -67,8 +60,7 @@ export const BuyPlan = (props: {
return (
<ScrollView
contentContainerStyle={{
- paddingBottom: 80,
- marginTop: DefaultAppStyles.GAP
+ marginTop: DefaultAppStyles.GAP_VERTICAL
}}
keyboardDismissMode="none"
keyboardShouldPersistTaps="always"
@@ -132,7 +124,9 @@ export const BuyPlan = (props: {
<View
style={{
flexDirection: "row",
- justifyContent: "space-between"
+ justifyContent: "space-between",
+
+ marginTop: DefaultAppStyles.GAP_VERTICAL
}}
>
<Heading color={colors.primary.paragraph} size={AppFontSize.sm}>
@@ -278,15 +272,11 @@ const ProductItem = (props: {
color={isSelected ? colors.primary.accent : colors.secondary.icon}
size={AppFontSize.lg}
/>
- <View
- style={{
- gap: DefaultAppStyles.GAP_VERTICAL
- }}
- >
+ <View>
<View
style={{
flexDirection: "row",
- gap: DefaultAppStyles.GAP_VERTICAL
+ gap: DefaultAppStyles.GAP_VERTICAL_SMALL
}}
>
<Heading size={AppFontSize.md}>
diff --git a/apps/mobile/app/components/sheets/paywall/index.tsx b/apps/mobile/app/components/sheets/paywall/index.tsx
index e377ad07e..3c8da753d 100644
--- a/apps/mobile/app/components/sheets/paywall/index.tsx
+++ b/apps/mobile/app/components/sheets/paywall/index.tsx
@@ -1,24 +1,232 @@
import { View, Text } from "react-native";
-import { presentSheet } from "../../../services/event-manager";
+import {
+ eSendEvent,
+ presentSheet,
+ ToastManager
+} from "../../../services/event-manager";
import { FeatureId, FeatureResult } from "@notesnook/common";
+import { useEffect, useState } from "react";
+import usePricingPlans from "../../../hooks/use-pricing-plans";
+import { BuyPlan } from "../buy-plan";
+import Heading from "../../ui/typography/heading";
+import { AppFontSize } from "../../../utils/size";
+import { DefaultAppStyles } from "../../../utils/styles";
+import Paragraph from "../../ui/typography/paragraph";
+import { Button } from "../../ui/button";
+import { eCloseSheet } from "../../../utils/events";
+import Navigation from "../../../services/navigation";
+import { useThemeColors } from "@notesnook/theme";
+import AppIcon from "../../ui/AppIcon";
+
+const INDEX_TO_PLAN = {
+ 0: "essential",
+ 1: "pro",
+ 2: "believer"
+};
+
+const Steps = {
+ Select: 0,
+ Buy: 1
+};
export default function PaywallSheet<Tid extends FeatureId>(props: {
feature: FeatureResult<Tid>;
}) {
+ const { colors } = useThemeColors();
+ const [step, setStep] = useState(Steps.Select);
+ const pricingPlans = usePricingPlans();
+ useEffect(() => {
+ console.log("PaywallSheet mounted with feature:", props.feature);
+ ToastManager.hide();
+ if (!props.feature.availableOn) return;
+ const plan = pricingPlans.pricingPlans.find(
+ //@ts-ignore
+ (p) => p.id === INDEX_TO_PLAN[props.feature.availableOn]
+ );
+ if (!plan) return;
+ pricingPlans.selectPlan(plan?.id);
+ pricingPlans.selectProduct(
+ plan?.subscriptionSkuList?.find((sku) => sku.includes("year"))
+ );
+ }, []);
+
+ console.log(pricingPlans.currentPlan, pricingPlans.selectedProduct);
+
return (
<View
style={{
- height: 400,
width: "100%",
justifyContent: "center",
- alignItems: "center"
+ alignItems: "center",
+ gap: DefaultAppStyles.GAP_VERTICAL,
+ paddingBottom: DefaultAppStyles.GAP
}}
>
- {/* Paywall content goes here */}
- <View>
- {/* Example content */}
- <Text>Upgrade to Pro for more features!</Text>
- </View>
+ {step === Steps.Select ? (
+ <>
+ <View
+ style={{
+ width: "100%",
+ paddingHorizontal: DefaultAppStyles.GAP,
+ gap: DefaultAppStyles.GAP_VERTICAL
+ }}
+ >
+ {/* <View
+ style={{
+ backgroundColor: colors.secondary.background,
+ borderRadius: 10,
+ height: 150,
+ width: "100%",
+ justifyContent: "center",
+ alignItems: "center"
+ }}
+ >
+ <Heading>{pricingPlans.currentPlan?.name}</Heading>
+ </View> */}
+
+ <Paragraph>
+ <AppIcon
+ name="crown"
+ size={AppFontSize.md}
+ color={colors.static.orange}
+ />{" "}
+ Upgrade plan to {pricingPlans.currentPlan?.name} to use this
+ feature.
+ </Paragraph>
+
+ <View
+ style={{
+ gap: DefaultAppStyles.GAP_VERTICAL_SMALL,
+ width: "100%"
+ }}
+ >
+ <Heading>Try it for free</Heading>
+
+ <Heading size={AppFontSize.sm}>
+ Get this and so much more:
+ </Heading>
+
+ <View
+ style={{
+ gap: DefaultAppStyles.GAP_SMALL,
+ flexDirection: "row"
+ }}
+ >
+ <AppIcon name="cloud" size={AppFontSize.xxl} />
+ <Paragraph
+ style={{
+ flexShrink: 1
+ }}
+ >
+ <Heading size={AppFontSize.sm}>25 GB</Heading> cloud storage
+ space for storing images and files upto 5 GB every month.
+ </Paragraph>
+ </View>
+
+ <View
+ style={{
+ gap: DefaultAppStyles.GAP_SMALL,
+ flexDirection: "row"
+ }}
+ >
+ <AppIcon name="lock" size={AppFontSize.xxl} />
+ <Paragraph
+ style={{
+ flexShrink: 1
+ }}
+ >
+ <Heading size={AppFontSize.sm}>App lock</Heading> for locking
+ your notes as soon as app enters background
+ </Paragraph>
+ </View>
+
+ <View
+ style={{
+ gap: DefaultAppStyles.GAP_SMALL,
+ flexDirection: "row"
+ }}
+ >
+ <AppIcon name="vector-link" size={AppFontSize.xxl} />
+ <Paragraph
+ style={{
+ flexShrink: 1
+ }}
+ >
+ Use advanced note taking features like{" "}
+ <Heading size={AppFontSize.sm}>
+ tables, outlines, block level note linking
+ </Heading>{" "}
+ and much more.
+ </Paragraph>
+ </View>
+ </View>
+ </View>
+
+ <View
+ style={{
+ width: "100%",
+ paddingHorizontal: DefaultAppStyles.GAP
+ }}
+ >
+ <Paragraph
+ style={{
+ marginVertical: 10
+ }}
+ size={AppFontSize.xs}
+ >
+ <Heading size={AppFontSize.xs}>Cancel anytime.</Heading> Google
+ will remind you 2 days before your trial ends.
+ </Paragraph>
+
+ <Button
+ type="accent"
+ title="Upgrade"
+ style={{
+ marginVertical: DefaultAppStyles.GAP_VERTICAL,
+ width: "100%"
+ }}
+ onPress={() => {
+ setStep(Steps.Buy);
+ }}
+ />
+ </View>
+
+ <Button
+ type="plain"
+ title="Explore all plans"
+ icon="arrow-right"
+ iconPosition="right"
+ onPress={() => {
+ eSendEvent(eCloseSheet);
+ Navigation.navigate("PayWall", {
+ context: "logged-in"
+ });
+ }}
+ />
+ </>
+ ) : null}
+
+ {pricingPlans.currentPlan &&
+ pricingPlans.selectedProduct &&
+ step === Steps.Buy ? (
+ <>
+ <View
+ style={{
+ width: "100%",
+ paddingHorizontal: DefaultAppStyles.GAP
+ }}
+ >
+ <Heading>{pricingPlans.currentPlan.name} plan</Heading>
+ <Paragraph>{pricingPlans.currentPlan.description}</Paragraph>
+ </View>
+ <BuyPlan
+ planId={pricingPlans.currentPlan?.id}
+ productId={pricingPlans.selectedProduct?.productId}
+ goBack={() => {}}
+ goNext={() => {}}
+ />
+ </>
+ ) : null}
</View>
);
}
diff --git a/apps/mobile/app/hooks/use-pricing-plans.ts b/apps/mobile/app/hooks/use-pricing-plans.ts
index 581fd82da..f03f1c98c 100644
--- a/apps/mobile/app/hooks/use-pricing-plans.ts
+++ b/apps/mobile/app/hooks/use-pricing-plans.ts
@@ -184,7 +184,7 @@ const usePricingPlans = (options?: PricingPlansOptions) => {
currentPlan,
selectedProductSku
) as RNIap.SubscriptionAndroid
- ).subscriptionOfferDetails?.[0]?.pricingPhases?.pricingPhaseList
+ )?.subscriptionOfferDetails?.[0]?.pricingPhases?.pricingPhaseList
?.length > 1;
};
@@ -261,7 +261,7 @@ const usePricingPlans = (options?: PricingPlansOptions) => {
product: RNIap.Subscription,
offerIndex: number
) {
- return (product as RNIap.SubscriptionAndroid).subscriptionOfferDetails?.[
+ return (product as RNIap.SubscriptionAndroid)?.subscriptionOfferDetails?.[
offerIndex
].offerToken;
}
@@ -279,16 +279,16 @@ const usePricingPlans = (options?: PricingPlansOptions) => {
}
useSettingStore.getState().setAppDidEnterBackgroundForAction(true);
- if (product.productId.includes("5year")) {
+ if (!product.productId.includes("5year")) {
if (Platform.OS === "android") {
androidOfferToken =
(
product as RNIap.SubscriptionAndroid
- ).subscriptionOfferDetails.find(
+ )?.subscriptionOfferDetails.find(
(offer) => offer.offerToken === androidOfferToken
)?.offerToken ||
- (product as RNIap.SubscriptionAndroid).subscriptionOfferDetails?.[0]
- .offerToken;
+ (product as RNIap.SubscriptionAndroid)
+ ?.subscriptionOfferDetails?.[0].offerToken;
if (!androidOfferToken) return;
}
@@ -329,6 +329,7 @@ const usePricingPlans = (options?: PricingPlansOptions) => {
setLoading(false);
options?.onBuy?.();
} catch (e) {
+ console.log(e);
setLoading(false);
}
}
@@ -340,8 +341,9 @@ const usePricingPlans = (options?: PricingPlansOptions) => {
const cycleText = isMonthly
? promoCyclesMonthly[
(Platform.OS === "android"
- ? (product as RNIap.SubscriptionAndroid).subscriptionOfferDetails[0]
- ?.pricingPhases.pricingPhaseList?.[0].billingCycleCount
+ ? (product as RNIap.SubscriptionAndroid)
+ ?.subscriptionOfferDetails[0]?.pricingPhases
+ .pricingPhaseList?.[0].billingCycleCount
: parseInt(
(product as RNIap.SubscriptionIOS)
.introductoryPriceNumberOfPeriodsIOS as string
@@ -349,8 +351,9 @@ const usePricingPlans = (options?: PricingPlansOptions) => {
]
: promoCyclesYearly[
(Platform.OS === "android"
- ? (product as RNIap.SubscriptionAndroid).subscriptionOfferDetails[0]
- ?.pricingPhases.pricingPhaseList?.[0].billingCycleCount
+ ? (product as RNIap.SubscriptionAndroid)
+ ?.subscriptionOfferDetails[0]?.pricingPhases
+ .pricingPhaseList?.[0].billingCycleCount
: parseInt(
(product as RNIap.SubscriptionIOS)
.introductoryPriceNumberOfPeriodsIOS as string
@@ -430,7 +433,7 @@ const usePricingPlans = (options?: PricingPlansOptions) => {
const getTrialInfo = (product: RNIap.Subscription) => {
if (Platform.OS === "android") {
const ProductAndroid = (product as RNIap.SubscriptionAndroid)
- .subscriptionOfferDetails?.[0];
+ ?.subscriptionOfferDetails?.[0];
if (ProductAndroid.pricingPhases.pricingPhaseList?.length === 1) return;
return {
period: