mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-05-18 05:05:36 +02:00
mobile: refactor
This commit is contained in:
committed by
Abdullah Atta
parent
aecf4f1ee8
commit
7ad3fd4057
@@ -18,7 +18,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { getFeaturesTable } from "@notesnook/common";
|
||||
import { EV, EVENTS, Plan, SubscriptionPlan, User } from "@notesnook/core";
|
||||
import {
|
||||
EV,
|
||||
EVENTS,
|
||||
Plan,
|
||||
SKUResponse,
|
||||
SubscriptionPlan,
|
||||
User
|
||||
} from "@notesnook/core";
|
||||
import { strings } from "@notesnook/intl";
|
||||
import { useThemeColors } from "@notesnook/theme";
|
||||
import React, { useEffect, useState } from "react";
|
||||
@@ -924,22 +931,14 @@ const PricingPlanCard = ({
|
||||
setStep: (step: number) => void;
|
||||
}) => {
|
||||
const { colors } = useThemeColors();
|
||||
const isSelected = pricingPlans?.currentPlan?.id === plan.id;
|
||||
const isFreePlan = plan.id === "free";
|
||||
const [regionalDiscount, setRegionaDiscount] = useState<SKUResponse>();
|
||||
|
||||
const product =
|
||||
plan.subscriptions?.[
|
||||
`notesnook.${plan.id}.${annualBilling ? "yearly" : "monthly"}`
|
||||
];
|
||||
|
||||
const discountPercentage = annualBilling
|
||||
? pricingPlans?.compareProductPrice(
|
||||
plan.id,
|
||||
`notesnook.${plan.id}.yearly`,
|
||||
`notesnook.${plan.id}.monthly`
|
||||
)
|
||||
: null;
|
||||
|
||||
const price = pricingPlans?.getPrice(
|
||||
product as RNIap.Subscription,
|
||||
pricingPlans.hasTrialOffer(plan.id, product?.productId) ? 1 : 0,
|
||||
@@ -951,6 +950,19 @@ const PricingPlanCard = ({
|
||||
annualBilling ? "yearly" : "monthly"
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
pricingPlans
|
||||
?.getRegionalDiscount(
|
||||
plan.id,
|
||||
pricingPlans.isGithubRelease
|
||||
? (WebPlan?.period as string)
|
||||
: (product?.productId as string)
|
||||
)
|
||||
.then((value) => {
|
||||
setRegionaDiscount(value);
|
||||
});
|
||||
}, [pricingPlans, plan, product, WebPlan]);
|
||||
|
||||
return (
|
||||
<TouchableOpacity
|
||||
activeOpacity={0.8}
|
||||
@@ -972,7 +984,7 @@ const PricingPlanCard = ({
|
||||
gap: 6
|
||||
}}
|
||||
>
|
||||
{/* {discountPercentage ? (
|
||||
{regionalDiscount?.discount ? (
|
||||
<View
|
||||
style={{
|
||||
backgroundColor: colors.static.red,
|
||||
@@ -985,10 +997,10 @@ const PricingPlanCard = ({
|
||||
}}
|
||||
>
|
||||
<Heading color={colors.static.white} size={AppFontSize.xs}>
|
||||
{discountPercentage}% Off
|
||||
{regionalDiscount?.discount}% Off
|
||||
</Heading>
|
||||
</View>
|
||||
) : null} */}
|
||||
) : null}
|
||||
|
||||
<View>
|
||||
<Heading size={AppFontSize.md}>
|
||||
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
export const FeaturesList = {
|
||||
// Monthly: ["$0/mo", "$1.99/mo", "$5.99/mo", "$9.99/mo"],
|
||||
// Yearly: ["$0/yr", "$14.99/yr", "$59.99/yr", "$109.99/yr"],
|
||||
// "5 year": [null, null, "$249.99/5yr", "$449.99/5yr"],
|
||||
Plans: ["Free", "Essential", "Pro", "Believer"]
|
||||
};
|
||||
@@ -16,7 +16,7 @@ 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 { Plan } from "@notesnook/core";
|
||||
import { Plan, SKUResponse, SubscriptionPlanId } from "@notesnook/core";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Platform } from "react-native";
|
||||
import Config from "react-native-config";
|
||||
@@ -160,6 +160,7 @@ const usePricingPlans = (options?: PricingPlansOptions) => {
|
||||
const [cancelPromo, setCancelPromo] = useState(false);
|
||||
const [userCanRequestTrial, setUserCanRequestTrial] = useState(false);
|
||||
const [webPricingPlans, setWebPricingPlans] = useState<Plan[]>([]);
|
||||
const [regionalDiscount, setRegionalDiscount] = useState<SKUResponse>();
|
||||
|
||||
const getProduct = (planId: string, skuId: string) => {
|
||||
if (isGithubRelease)
|
||||
@@ -189,6 +190,17 @@ const usePricingPlans = (options?: PricingPlansOptions) => {
|
||||
if (!selectedProductSku && !productId) return false;
|
||||
|
||||
if (productId?.includes("5year")) return false;
|
||||
if (isGithubRelease) {
|
||||
if (
|
||||
user?.subscription.trialsAvailed?.some(
|
||||
(plan) => plan === planIdToIndex(planId || currentPlan)
|
||||
)
|
||||
) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return Platform.OS === "ios"
|
||||
? (
|
||||
@@ -652,6 +664,43 @@ const usePricingPlans = (options?: PricingPlansOptions) => {
|
||||
|
||||
// }
|
||||
|
||||
useEffect(() => {
|
||||
db.pricing
|
||||
.sku(
|
||||
isGithubRelease
|
||||
? "paddle"
|
||||
: Platform.OS === "android"
|
||||
? "google"
|
||||
: "apple",
|
||||
selectedProductSku.includes("5")
|
||||
? "5-year"
|
||||
: selectedProductSku.includes("year")
|
||||
? "yearly"
|
||||
: "monthly",
|
||||
currentPlan as SubscriptionPlanId
|
||||
)
|
||||
.then((sku) => setRegionalDiscount(sku))
|
||||
.catch((e) => console.log(e));
|
||||
}, [currentPlan, selectedProductSku]);
|
||||
|
||||
async function getRegionalDiscount(plan: string, productId: string) {
|
||||
try {
|
||||
return await db.pricing.sku(
|
||||
isGithubRelease
|
||||
? "paddle"
|
||||
: Platform.OS === "android"
|
||||
? "google"
|
||||
: "apple",
|
||||
productId.includes("5")
|
||||
? "5-year"
|
||||
: productId.includes("year")
|
||||
? "yearly"
|
||||
: "monthly",
|
||||
plan as SubscriptionPlanId
|
||||
);
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
return {
|
||||
currentPlan: pricingPlans.find((p) => p.id === currentPlan),
|
||||
pricingPlans: plans,
|
||||
@@ -700,7 +749,10 @@ const usePricingPlans = (options?: PricingPlansOptions) => {
|
||||
return webPricingPlans.find(
|
||||
(plan) => plan.plan === planIndex && plan.period === period
|
||||
);
|
||||
}
|
||||
},
|
||||
regionalDiscount,
|
||||
getRegionalDiscount,
|
||||
isGithubRelease: isGithubRelease
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -358,8 +358,7 @@ export const RootNavigation = () => {
|
||||
<RootStack.Screen
|
||||
name="PayWall"
|
||||
getComponent={() => {
|
||||
PayWall =
|
||||
PayWall || require("../components/premium/paywall").default;
|
||||
PayWall = PayWall || require("../components/paywall").default;
|
||||
return PayWall;
|
||||
}}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user