Files
notesnook/apps/mobile/app/components/premium/expiring.js

218 lines
6.6 KiB
JavaScript
Raw Normal View History

2022-08-30 16:13:11 +05:00
/* This file is part of the Notesnook project (https://notesnook.com/)
*
* Copyright (C) 2022 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/>.
*/
2022-08-29 16:19:17 +05:00
import React, { useEffect, useState } from "react";
import { View } from "react-native";
2022-08-29 16:19:17 +05:00
import { usePricing } from "../../hooks/use-pricing";
import {
eSendEvent,
eSubscribeEvent,
eUnSubscribeEvent
} from "../../services/event-manager";
import PremiumService from "../../services/premium";
2022-08-29 16:19:17 +05:00
import { useThemeStore } from "../../stores/use-theme-store";
import {
eOpenPremiumDialog,
eOpenResultDialog,
eOpenTrialEndingDialog
} from "../../utils/events";
import { SIZE } from "../../utils/size";
import { sleep } from "../../utils/time";
import BaseDialog from "../dialog/base-dialog";
import DialogContainer from "../dialog/dialog-container";
2022-08-29 16:19:17 +05:00
import { Button } from "../ui/button";
import Seperator from "../ui/seperator";
import Heading from "../ui/typography/heading";
import Paragraph from "../ui/typography/paragraph";
import { CompactFeatures } from "./compact-features";
import { Offer } from "./offer";
2021-11-11 13:05:55 +05:00
export const Expiring = () => {
const colors = useThemeStore((state) => state.colors);
2021-11-11 13:05:55 +05:00
const [visible, setVisible] = useState(false);
const [status, setStatus] = useState({
title: "Your trial is ending soon",
2021-11-11 13:05:55 +05:00
offer: null,
2021-11-15 15:24:37 +05:00
extend: true
2021-11-11 13:05:55 +05:00
});
const pricing = usePricing("yearly");
console.log(pricing?.info?.discount);
2022-01-22 12:57:05 +05:00
const promo = status.offer
? {
promoCode:
pricing?.info?.discount > 30
? pricing.info.sku
: "com.streetwriters.notesnook.sub.yr.trialoffer",
text: `GET ${
pricing?.info?.discount > 30 ? pricing?.info?.discount : 30
}% OFF on yearly`,
discount: pricing?.info?.discount > 30 ? pricing?.info?.discount : 30
2022-01-22 12:57:05 +05:00
}
: null;
2021-11-11 13:05:55 +05:00
useEffect(() => {
eSubscribeEvent(eOpenTrialEndingDialog, open);
return () => {
eUnSubscribeEvent(eOpenTrialEndingDialog, open);
};
}, []);
const open = (status) => {
2021-11-11 13:05:55 +05:00
setStatus(status);
setVisible(true);
};
return (
visible && (
<BaseDialog
onRequestClose={() => {
setVisible(false);
2022-01-22 12:57:05 +05:00
}}
>
2021-11-11 13:05:55 +05:00
<DialogContainer>
<View
style={{
width: "100%",
alignItems: "center"
2022-01-22 12:57:05 +05:00
}}
>
2021-11-11 13:05:55 +05:00
<View
style={{
paddingHorizontal: 12,
width: "100%"
2022-01-22 12:57:05 +05:00
}}
>
2021-11-11 13:05:55 +05:00
<Heading
textBreakStrategy="balanced"
style={{
textAlign: "center",
2021-11-11 13:05:55 +05:00
paddingTop: 18
2022-01-22 12:57:05 +05:00
}}
>
2021-11-11 13:05:55 +05:00
{status.title}
</Heading>
<Seperator />
<View
style={{
width: "100%",
alignItems: "center"
2022-01-22 12:57:05 +05:00
}}
>
2021-11-11 13:05:55 +05:00
{status.offer ? (
<>
<Offer padding={20} off={promo?.discount || 30} />
2021-11-11 13:05:55 +05:00
</>
) : (
<>
<Paragraph
textBreakStrategy="balanced"
style={{
textAlign: "center",
2021-11-11 13:05:55 +05:00
paddingTop: 0,
paddingBottom: 20
}}
2022-01-22 12:57:05 +05:00
size={SIZE.md + 2}
>
Upgrade now to continue using all the pro features after
your trial ends
2021-11-11 13:05:55 +05:00
</Paragraph>
</>
)}
2022-01-22 12:57:05 +05:00
<CompactFeatures />
2021-11-11 13:05:55 +05:00
<Paragraph
onPress={async () => {
setVisible(false);
await sleep(300);
2021-11-19 15:34:19 +05:00
eSendEvent(eOpenPremiumDialog, promo);
2021-11-11 13:05:55 +05:00
}}
2021-12-16 10:20:34 +05:00
size={SIZE.xs + 1}
2021-11-11 13:05:55 +05:00
style={{
textDecorationLine: "underline",
2021-11-11 13:05:55 +05:00
color: colors.icon,
marginTop: 10
2022-01-22 12:57:05 +05:00
}}
>
{"See what's included in Basic & Pro plans"}
2021-11-11 13:05:55 +05:00
</Paragraph>
<Seperator />
</View>
</View>
<View
style={{
backgroundColor: colors.nav,
width: "100%",
2021-11-11 13:05:55 +05:00
borderBottomRightRadius: 10,
borderBottomLeftRadius: 10
2022-01-22 12:57:05 +05:00
}}
>
2021-11-11 13:05:55 +05:00
<Button
type="transparent"
title="Subscribe now"
onPress={async () => {
setVisible(false);
await sleep(300);
PremiumService.sheet(
null,
promo?.discount > 30 ? null : promo
);
2021-11-11 13:05:55 +05:00
}}
2021-11-15 15:24:37 +05:00
fontSize={SIZE.md + 2}
2021-11-11 13:05:55 +05:00
style={{
2021-11-15 15:24:37 +05:00
marginBottom: status.extend ? 0 : 10,
marginTop: 10,
2021-11-11 13:05:55 +05:00
paddingHorizontal: 24
}}
/>
{status.extend && (
<Button
type="gray"
title="Not sure yet? Extend trial for 7 days"
textStyle={{
textDecorationLine: "underline"
2021-11-11 13:05:55 +05:00
}}
onPress={async () => {
setVisible(false);
await sleep(300);
eSendEvent(eOpenResultDialog, {
title: "Your trial has been extended",
2021-11-11 13:05:55 +05:00
paragraph:
"Try out all features of Notesnook free for 7 more days. No limitations. No commitments.",
button: "Continue"
2021-11-11 13:05:55 +05:00
});
}}
2021-12-16 10:20:34 +05:00
fontSize={SIZE.xs}
2021-11-11 13:05:55 +05:00
height={30}
style={{
2021-11-15 15:24:37 +05:00
marginBottom: 10
2021-11-11 13:05:55 +05:00
}}
/>
)}
</View>
</View>
</DialogContainer>
</BaseDialog>
)
);
};