Files
notesnook/apps/mobile/src/components/Announcements/cta.js

97 lines
2.8 KiB
JavaScript
Raw Normal View History

2021-11-22 15:12:26 +05:00
import React from 'react';
import {View} from 'react-native';
import {useTracked} from '../../provider';
import {eSendEvent, presentSheet} from '../../services/EventManager';
import {eCloseAnnouncementDialog} from '../../utils/Events';
import {openLinkInBrowser} from '../../utils/functions';
import {SIZE} from '../../utils/SizeUtils';
import {sleep} from '../../utils/TimeUtils';
2021-11-24 10:13:42 +05:00
import SettingsBackupAndRestore from '../../views/Settings/backup-restore';
import {Button} from '../Button';
import GeneralSheet from '../GeneralSheet';
import {PricingPlans} from '../Premium/pricing-plans';
import {allowedOnPlatform, getStyle} from './functions';
2021-11-22 15:12:26 +05:00
export const Cta = ({actions, style = {}, color, inline}) => {
2021-11-22 15:12:26 +05:00
const [state] = useTracked();
const colors = state.colors;
let buttons = actions.filter(item => allowedOnPlatform(item.platforms)) || [];
2021-11-23 15:06:35 +05:00
const onPress = async item => {
2021-11-23 19:24:53 +05:00
if (!inline) {
eSendEvent(eCloseAnnouncementDialog);
await sleep(500);
}
2021-11-23 15:06:35 +05:00
if (item.type === 'link') {
try {
await openLinkInBrowser(item.data, colors);
} catch (e) {}
} else if (item.type === 'promo') {
presentSheet({
component: (
<PricingPlans
marginTop={1}
promo={{
promoCode: item.data,
text: item.title
}}
/>
2022-01-07 23:42:58 +05:00
)
2021-11-23 15:06:35 +05:00
});
} else if (item.type === 'backup') {
presentSheet({
title: 'Backup & restore',
paragraph: 'Please enable automatic backups to keep your data safe',
component: <SettingsBackupAndRestore isSheet={true} />
});
}
};
2021-11-22 15:12:26 +05:00
return (
<View
style={{
paddingHorizontal: 12,
...getStyle(style)
}}>
<GeneralSheet context="premium_cta" />
2021-11-23 15:06:35 +05:00
{buttons.length > 0 &&
buttons.slice(0, 1).map(item => (
<Button
key={item.title}
title={item.title}
fontSize={SIZE.md}
buttonType={{
color: color ? color : colors.accent,
text: colors.light,
selected: color ? color : colors.accent,
opacity: 1
}}
onPress={() => onPress(item)}
width={'100%'}
style={{
marginBottom: 5
}}
/>
))}
{buttons.length > 1 &&
buttons.slice(1, 2).map((item, index) => (
<Button
key={item.title}
title={item.title}
2021-12-16 10:20:34 +05:00
fontSize={SIZE.xs}
2021-11-23 15:06:35 +05:00
type="gray"
onPress={() => onPress(item)}
width={null}
height={20}
style={{
minWidth: '50%'
}}
textStyle={{
textDecorationLine: 'underline'
}}
/>
))}
2021-11-22 15:12:26 +05:00
</View>
);
};