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

178 lines
5.3 KiB
JavaScript
Raw Normal View History

2021-11-11 13:05:55 +05:00
import React, { useEffect, useState } from 'react';
2021-11-15 15:24:37 +05:00
import { View } from 'react-native';
2022-02-28 23:25:18 +05:00
import { useThemeStore } from '../../stores/theme';
import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
import PremiumService from '../../services/premium';
2022-02-28 13:48:59 +05:00
import { eOpenPremiumDialog, eOpenResultDialog, eOpenTrialEndingDialog } from '../../utils/events';
import { SIZE } from '../../utils/size';
import { sleep } from '../../utils/time';
import { Button } from '../ui/button';
import BaseDialog from '../dialog/base-dialog';
import DialogContainer from '../dialog/dialog-container';
import Seperator from '../ui/seperator';
import Heading from '../ui/typography/heading';
import Paragraph from '../ui/typography/paragraph';
2021-11-15 15:24:37 +05:00
import { CompactFeatures } from './compact-features';
2021-11-11 13:05:55 +05:00
import { Offer } from './offer';
export const Expiring = () => {
2022-02-28 23:25:18 +05:00
const colors = useThemeStore(state => state.colors);
2021-11-11 13:05:55 +05:00
const [visible, setVisible] = useState(false);
const [status, setStatus] = useState({
2021-11-15 15:24:37 +05:00
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
});
2022-01-22 12:57:05 +05:00
const promo = status.offer
? {
promoCode: 'com.streetwriters.notesnook.sub.yr.trialoffer',
text: 'GET 30% OFF on yearly'
}
: null;
2021-11-11 13:05:55 +05:00
useEffect(() => {
eSubscribeEvent(eOpenTrialEndingDialog, open);
return () => {
eUnSubscribeEvent(eOpenTrialEndingDialog, open);
};
}, []);
const open = status => {
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',
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={status.offer} />
</>
) : (
<>
<Paragraph
textBreakStrategy="balanced"
style={{
textAlign: 'center',
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',
color: colors.icon,
marginTop: 10
2022-01-22 12:57:05 +05:00
}}
>
2021-11-11 13:05:55 +05:00
See what's included in Basic & Pro plans
</Paragraph>
<Seperator />
</View>
</View>
<View
style={{
backgroundColor: colors.nav,
width: '100%',
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);
2022-01-22 12:57:05 +05:00
PremiumService.sheet(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'
}}
onPress={async () => {
setVisible(false);
await sleep(300);
eSendEvent(eOpenResultDialog, {
title: 'Your trial has been extended',
paragraph:
'Try out all features of Notesnook free for 7 more days. No limitations. No commitments.',
button: 'Continue'
});
}}
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>
)
);
};