Skip to content

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

complete new settings migration

ammarahm-ed0df57ff4cd4d
diff --git a/apps/mobile/src/screens/settings/home.tsx b/apps/mobile/src/screens/settings/home.tsx
index bb364e44f..6730c8507 100644
--- a/apps/mobile/src/screens/settings/home.tsx
+++ b/apps/mobile/src/screens/settings/home.tsx
@@ -33,10 +33,16 @@ import AppLock from './app-lock';
import { verifyUser } from './functions';
import { SectionGroup } from './section-group';
import { RouteParams, SettingSection } from './types';
-import SettingsUserSection from './user-section';
+import SettingsUserSection, { getTimeLeft } from './user-section';
import Sync from '../../services/sync';
import { MFARecoveryCodes, MFASheet } from './2fa';
import { db } from '../../utils/database';
+import { SUBSCRIPTION_STATUS } from '../../utils/constants';
+import dayjs from 'dayjs';
+import BiometicService from '../../services/biometrics';
+import { presentDialog } from '../../components/dialog/functions';
+import { checkVersion } from 'react-native-check-version';
+import { Update } from '../../components/sheets/update';
const format = (ver: number) => {
let parts = ver.toString().split('');
return `v${parts[0]}.${parts[1]}.${parts[2]?.startsWith('0') ? '' : parts[2]}${
@@ -48,6 +54,42 @@ const groups: SettingSection[] = [
{
name: 'account',
sections: [
+ {
+ useHook: () => useUserStore(state => state.user),
+ name: current => {
+ const user = current;
+ const isBasic = user.subscription?.type === SUBSCRIPTION_STATUS.BASIC;
+ const isTrial = user.subscription?.type === SUBSCRIPTION_STATUS.TRIAL;
+ return isBasic
+ ? 'Subscribe to Pro'
+ : isTrial
+ ? 'Your free trial has started'
+ : 'Subscription details';
+ },
+ type: 'component',
+ component: 'subscription',
+ icon: 'crown',
+ description: current => {
+ const user = current;
+ const subscriptionDaysLeft = user && getTimeLeft(parseInt(user.subscription?.expiry));
+ const expiryDate = dayjs(user?.subscription?.expiry).format('MMMM D, YYYY');
+ const startDate = dayjs(user?.subscription?.start).format('MMMM D, YYYY');
+
+ return user.subscription?.type === 2
+ ? 'You signed up on ' + startDate
+ : user.subscription?.type === 1
+ ? 'Your free trial will end on ' + expiryDate
+ : user.subscription?.type === 6
+ ? subscriptionDaysLeft.time < -3
+ ? 'Your subscription has ended'
+ : 'Your account will be downgraded to Basic in 3 days'
+ : user.subscription?.type === 7
+ ? `Your subscription will end on ${expiryDate}.`
+ : user.subscription?.type === 5
+ ? `Your subscription will renew on ${expiryDate}.`
+ : 'Never hesitate to choose privacy';
+ }
+ },
{
type: 'screen',
name: 'Account Settings',
@@ -187,6 +229,56 @@ const groups: SettingSection[] = [
});
},
description: 'Verify your subscription to Notesnook Pro'
+ },
+ {
+ name: 'Log out',
+ description: 'Clear all your data and reset the app.',
+ icon: 'logout'
+ },
+ {
+ type: 'danger',
+ name: 'Delete account',
+ icon: 'alert',
+ description: `All your data will be removed permanantly. Make sure you have saved backup of your notes. This action is IRREVERSIBLE.`,
+ modifer: () => {
+ presentDialog({
+ title: 'Delete account',
+ paragraphColor: 'red',
+ paragraph:
+ 'All your data will be removed permanantly. Make sure you have saved backup of your notes. This action is IRREVERSIBLE.',
+ positiveType: 'errorShade',
+ input: true,
+ inputPlaceholder: 'Enter account password',
+ positiveText: 'Delete',
+ positivePress: async value => {
+ try {
+ let verified = await db.user?.verifyPassword(value);
+ if (verified) {
+ await db.user?.deleteUser(value);
+ await BiometicService.resetCredentials();
+ SettingsService.set({
+ introCompleted: true
+ });
+ } else {
+ ToastEvent.show({
+ heading: 'Incorrect password',
+ message: 'The account password you entered is incorrect',
+ type: 'error',
+ context: 'global'
+ });
+ }
+ } catch (e) {
+ console.log(e);
+ ToastEvent.show({
+ heading: 'Failed to delete account',
+ message: e.message,
+ type: 'error',
+ context: 'global'
+ });
+ }
+ }
+ });
+ }
}
]
},
@@ -542,7 +634,14 @@ const groups: SettingSection[] = [
modifer: async () => {
Linking.openURL('https://docs.notesnook.com');
},
- description: 'Learn about every feature and how it works.'
+ description: 'Learn about every feature and how it works.',
+ icon: 'file-document'
+ },
+ {
+ type: 'switch',
+ name: 'Debug mode',
+ description: 'Show debug options on items',
+ property: 'devMode'
}
]
},
@@ -619,7 +718,7 @@ const groups: SettingSection[] = [
await Linking.openURL('https://notesnook.com');
} catch (e) {}
},
- description: 'Notesnook app can be downloaded on all platforms'
+ description: 'Get Notesnook app on your desktop and access all notes'
},
{
name: 'Roadmap',
@@ -632,7 +731,20 @@ const groups: SettingSection[] = [
description: 'See what the future of Notesnook is going to be like.'
},
{
- name: 'About Notesnook',
+ name: 'Check for updates',
+ icon: 'cellphone-arrow-down',
+ description: 'Check for new version of Notesnook',
+ modifer: async () => {
+ const version = await checkVersion();
+ if (!version.needsUpdate) return false;
+ presentSheet({
+ component: ref => <Update version={version} fwdRef={ref} />
+ });
+ }
+ },
+ {
+ name: 'App version',
+ icon: 'alpha-v',
modifer: async () => {
try {
await Linking.openURL('https://notesnook.com');
diff --git a/apps/mobile/src/screens/settings/sectionitem.tsx b/apps/mobile/src/screens/settings/sectionitem.tsx
index fd1bbad5b..868941756 100644
--- a/apps/mobile/src/screens/settings/sectionitem.tsx
+++ b/apps/mobile/src/screens/settings/sectionitem.tsx
@@ -1,23 +1,127 @@
import { NavigationProp, StackActions, useNavigation } from '@react-navigation/native';
+import dayjs from 'dayjs';
import React, { ReactElement } from 'react';
-import { View } from 'react-native';
+import { Linking, Platform, View } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import ToggleSwitch from 'toggle-switch-react-native';
+import { Button } from '../../components/ui/button';
import { PressableButton } from '../../components/ui/pressable';
import Seperator from '../../components/ui/seperator';
import Paragraph from '../../components/ui/typography/paragraph';
+import { eSendEvent, presentSheet, ToastEvent } from '../../services/event-manager';
+import PremiumService from '../../services/premium';
import SettingsService from '../../services/settings';
-import { useSettingStore } from '../../stores/stores';
+import { useSettingStore, useUserStore } from '../../stores/stores';
import { useThemeStore } from '../../stores/theme';
+import { SUBSCRIPTION_PROVIDER, SUBSCRIPTION_STATUS } from '../../utils/constants';
+import { eOpenPremiumDialog } from '../../utils/events';
+import { usePricing } from '../../utils/hooks/use-pricing';
import { SIZE } from '../../utils/size';
import { AccentColorPicker, HomagePageSelector } from './appearance';
import { AutomaticBackupsSelector } from './backup-restore';
import { RouteParams, SettingSection } from './types';
+import { getTimeLeft } from './user-section';
+
+const Subscription = () => {
+ const user: any = useUserStore(state => state.user);
+ const monthlyPlan = usePricing('monthly');
+ const colors = useThemeStore(state => state.colors);
+ const isNotPro =
+ user.subscription?.type !== SUBSCRIPTION_STATUS.PREMIUM &&
+ user.subscription?.type !== SUBSCRIPTION_STATUS.BETA;
+
+ const manageSubscription = () => {
+ if (!user.isEmailConfirmed) {
+ PremiumService.showVerifyEmailDialog();
+ return;
+ }
+ if (
+ user.subscription?.type === SUBSCRIPTION_STATUS.PREMIUM_CANCELLED &&
+ Platform.OS === 'android'
+ ) {
+ if (user.subscription?.provider === 3) {
+ ToastEvent.show({
+ heading: 'Subscribed on web',
+ message: 'Open your web browser to manage your subscription.',
+ type: 'success'
+ });
+ return;
+ }
+ Linking.openURL('https://play.google.com/store/account/subscriptions');
+
+ /**
+ *
+ * Platform.OS === 'ios'
+ ? 'https://apps.apple.com/account/subscriptions'
+ : 'https://play.google.com/store/account/subscriptions'
+ */
+ } else {
+ eSendEvent(eOpenPremiumDialog);
+ }
+ };
+
+ return (
+ <View>
+ {isNotPro ? (
+ <Button
+ height={35}
+ style={{
+ borderRadius: 100,
+ paddingHorizontal: 16,
+ alignSelf: 'flex-start'
+ }}
+ fontSize={SIZE.sm}
+ type="accent"
+ onPress={manageSubscription}
+ title={
+ !user.isEmailConfirmed
+ ? 'Confirm your email'
+ : user.subscription?.provider === 3 &&
+ user.subscription?.type === SUBSCRIPTION_STATUS.PREMIUM_CANCELLED
+ ? 'Manage subscription from desktop app'
+ : user.subscription?.type === SUBSCRIPTION_STATUS.PREMIUM_CANCELLED &&
+ Platform.OS === 'android'
+ ? `Resubscribe from Google Playstore`
+ : user.subscription?.type === SUBSCRIPTION_STATUS.PREMIUM_EXPIRED
+ ? `Resubscribe to Pro (${monthlyPlan?.product?.localizedPrice} / mo)`
+ : `Get Pro (${monthlyPlan?.product?.localizedPrice} / mo)`
+ }
+ />
+ ) : null}
+
+ {user?.subscription?.provider &&
+ user.subscription?.type !== SUBSCRIPTION_STATUS.PREMIUM_EXPIRED &&
+ user.subscription?.type !== SUBSCRIPTION_STATUS.BASIC &&
+ SUBSCRIPTION_PROVIDER[user?.subscription?.provider] ? (
+ <Button
+ title={SUBSCRIPTION_PROVIDER[user?.subscription?.provider]?.title}
+ onPress={() => {
+ presentSheet({
+ title: SUBSCRIPTION_PROVIDER[user?.subscription?.provider].title,
+ paragraph: SUBSCRIPTION_PROVIDER[user?.subscription?.provider].desc
+ });
+ }}
+ style={{
+ alignSelf: 'flex-start',
+ paddingHorizontal: 0
+ }}
+ fontSize={SIZE.sm}
+ textStyle={{
+ fontWeight: 'normal'
+ }}
+ height={30}
+ type="transparent"
+ />
+ ) : null}
+ </View>
+ );
+};
const components: { [name: string]: ReactElement } = {
colorpicker: <AccentColorPicker wrap={true} />,
homeselector: <HomagePageSelector />,
- autobackups: <AutomaticBackupsSelector />
+ autobackups: <AutomaticBackupsSelector />,
+ subscription: <Subscription />
};
export const SectionItem = ({ item }: { item: SettingSection }) => {
@@ -37,9 +141,16 @@ export const SectionItem = ({ item }: { item: SettingSection }) => {
[item.property]: !settings[item.property]
});
};
+
+ const styles =
+ item.type === 'danger'
+ ? {
+ backgroundColor: colors.errorBg
+ }
+ : {};
+
return isHidden ? null : (
<PressableButton
- key={item.name}
disabled={item.type === 'component'}
customStyle={{
width: '100%',
@@ -47,7 +158,8 @@ export const SectionItem = ({ item }: { item: SettingSection }) => {
padding: 12,
flexDirection: 'row',
justifyContent: 'space-between',
- paddingVertical: 20
+ paddingVertical: 20,
+ ...styles
}}
onPress={() => {
switch (item.type) {
@@ -66,8 +178,7 @@ export const SectionItem = ({ item }: { item: SettingSection }) => {
<View
style={{
flexDirection: 'row',
- flexShrink: 1,
- alignItems: 'center'
+ flexShrink: 1
}}
>
<View
@@ -81,7 +192,13 @@ export const SectionItem = ({ item }: { item: SettingSection }) => {
borderRadius: 100
}}
>
- {!!item.icon && <Icon color={colors.icon} name={item.icon} size={30} />}
+ {!!item.icon && (
+ <Icon
+ color={item.type === 'danger' ? colors.errorText : colors.icon}
+ name={item.icon}
+ size={30}
+ />
+ )}
</View>
<View
@@ -90,18 +207,26 @@ export const SectionItem = ({ item }: { item: SettingSection }) => {
paddingRight: item.type === 'switch' ? 10 : 0
}}
>
- <Paragraph color={colors.heading} size={SIZE.md + 1}>
- {item.name}
+ <Paragraph
+ color={item.type === 'danger' ? colors.errorText : colors.heading}
+ size={SIZE.md + 1}
+ >
+ {typeof item.name === 'function' ? item.name(current) : item.name}
</Paragraph>
{!!item.description && (
- <Paragraph size={SIZE.sm}>
- {typeof item.description === 'function' ? item.description() : item.description}
+ <Paragraph
+ color={item.type === 'danger' ? colors.errorText : colors.pri}
+ size={SIZE.sm}
+ >
+ {typeof item.description === 'function'
+ ? item.description(current)
+ : item.description}
</Paragraph>
)}
{!!item.component && (
<>
- <Seperator />
+ <Seperator half />
{components[item.component]}
</>
)}
diff --git a/apps/mobile/src/screens/settings/types.ts b/apps/mobile/src/screens/settings/types.ts
index 0771817c6..e1d503a2d 100644
--- a/apps/mobile/src/screens/settings/types.ts
+++ b/apps/mobile/src/screens/settings/types.ts
@@ -1,9 +1,9 @@
import { Settings } from '../../stores/interfaces';
export type SettingSection = {
- type?: 'screen' | 'switch' | 'component';
- name?: string;
- description?: string | (() => string);
+ type?: 'screen' | 'switch' | 'component' | 'danger';
+ name?: string | ((current: any) => string);
+ description?: string | ((current: any) => string);
icon?: string;
property?: keyof Settings;
sections?: SettingSection[];
diff --git a/apps/mobile/src/screens/settings/usersection.js b/apps/mobile/src/screens/settings/usersection.js
index dcdfcb6f1..c233e5830 100644
--- a/apps/mobile/src/screens/settings/usersection.js
+++ b/apps/mobile/src/screens/settings/usersection.js
@@ -35,7 +35,7 @@ import { CustomButton } from './button';
import { verifyUser } from './functions';
import { TimeSince } from '../../components/ui/time-since';
-const getTimeLeft = t2 => {
+export const getTimeLeft = t2 => {
let daysRemaining = dayjs(t2).diff(dayjs(), 'days');
return {
time: dayjs(t2).diff(dayjs(), daysRemaining === 0 ? 'hours' : 'days'),
@@ -52,6 +52,12 @@ const SettingsUserSection = ({ item }) => {
const expiryDate = dayjs(user?.subscription?.expiry).format('MMMM D, YYYY');
const startDate = dayjs(user?.subscription?.start).format('MMMM D, YYYY');
const monthlyPlan = usePricing('monthly');
+ const isBasic = user.subscription?.type === SUBSCRIPTION_STATUS.BASIC;
+ const isTrial = user.subscription?.type === SUBSCRIPTION_STATUS.TRIAL;
+ const isPro = user.subscription?.type === SUBSCRIPTION_STATUS.PREMIUM;
+ const isNotPro =
+ user.subscription?.type !== SUBSCRIPTION_STATUS.PREMIUM &&
+ user.subscription?.type !== SUBSCRIPTION_STATUS.BETA;
const lastSynced = useUserStore(state => state.lastSynced);
@@ -141,7 +147,8 @@ const SettingsUserSection = ({ item }) => {
<View
style={{
- marginLeft: 10
+ marginLeft: 10,
+ flexGrow: 1
}}
>
<Heading color={colors.accent} size={SIZE.xs + 1}>
@@ -160,19 +167,22 @@ const SettingsUserSection = ({ item }) => {
</Paragraph>
</View>
</View>
-
- <Button
- height={35}
- style={{
- borderRadius: 100,
- paddingHorizontal: 12
- }}
- fontSize={SIZE.xs}
- type="accent"
- title="GET PRO"
- />
</View>
</View>
+
+ {/* {isNotPro ? (
+ <Button
+ height={30}
+ style={{
+ borderRadius: 100,
+ paddingHorizontal: 12
+ }}
+ fontSize={SIZE.xs}
+ type="accent"
+ title={`GET PRO (${monthlyPlan?.product?.localizedPrice} / mo)`}
+ />
+ ) : null} */}
+
<View>
{user.subscription?.type !== SUBSCRIPTION_STATUS.BASIC ? (
<View>
@@ -217,38 +227,6 @@ const SettingsUserSection = ({ item }) => {
</Paragraph>
</View>
) : null}
-
- {/* {user.subscription?.type !== SUBSCRIPTION_STATUS.PREMIUM &&
- user.subscription?.type !== SUBSCRIPTION_STATUS.BETA && (
- <>
- <Seperator />
- <Button
- onPress={manageSubscription}
- style={{
- paddingHorizontal: 24,
- borderRadius: 100,
- height: 40,
- alignSelf: 'flex-end'
- }}
- fontSize={SIZE.sm}
- title={
- !user.isEmailConfirmed
- ? 'Confirm your email'
- : user.subscription?.provider === 3 &&
- user.subscription?.type === SUBSCRIPTION_STATUS.PREMIUM_CANCELLED
- ? 'Manage subscription from desktop app'
- : user.subscription?.type === SUBSCRIPTION_STATUS.PREMIUM_CANCELLED &&
- Platform.OS === 'android'
- ? `Resubscribe from Google Playstore`
- : user.subscription?.type === SUBSCRIPTION_STATUS.PREMIUM_EXPIRED
- ? `Resubscribe to Pro (${monthlyPlan?.product?.localizedPrice} / mo)`
- : `Get Pro (${monthlyPlan?.product?.localizedPrice} / mo)`
- }
- height={50}
- type="accent"
- />
- </>
- )} */}
</View>
{user?.subscription?.provider &&