Skip to content

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

show correct premium status message

ammarahm-ed00bfa7a55933
diff --git a/apps/mobile/src/services/Message.js b/apps/mobile/src/services/Message.js
index 6bef5f722..a1404ebb9 100644
--- a/apps/mobile/src/services/Message.js
+++ b/apps/mobile/src/services/Message.js
@@ -6,6 +6,7 @@ import {
} from '../utils/Events';
import { MMKV } from '../utils/mmkv';
import { eSendEvent, ToastEvent } from './EventManager';
+import PremiumService from './PremiumService';
export function setLoginMessage(dispatch) {
dispatch({
@@ -32,37 +33,7 @@ export function setEmailVerifyMessage(dispatch) {
message: 'Email not verified',
actionText: 'Please verify your email to sync.',
onPress: () => {
- eSendEvent(eOpenProgressDialog, {
- title: 'Email not verified',
- icon: 'email',
- paragraph:
- 'We have sent you an email confirmation link. Please check your email to verify your account.',
- action: async () => {
- try {
- let lastEmailTime = await MMKV.getItem('lastEmailTime');
- if (
- lastEmailTime &&
- Date.now() - JSON.parse(lastEmailTime) < 60000 * 10
- ) {
- ToastEvent.show(
- 'Please wait before requesting another email',
- 'error',
- 'local',
- );
- console.log('error');
- return;
- }
- await db.user.sendVerificationEmail();
- await MMKV.setItem('lastEmailTime', JSON.stringify(Date.now()));
- ToastEvent.show('Verification email sent!', 'success', 'local');
- } catch (e) {
- ToastEvent.show(e.message, 'error', 'local');
- await MMKV.removeItem('lastEmailTime');
- }
- },
- actionText: 'Resend Confirmation Link',
- noProgress: true,
- });
+ PremiumService.showVerifyEmailDialog();
},
data: {},
icon: 'alert',
diff --git a/apps/mobile/src/services/PremiumService.js b/apps/mobile/src/services/PremiumService.js
index 7f805e997..930180151 100644
--- a/apps/mobile/src/services/PremiumService.js
+++ b/apps/mobile/src/services/PremiumService.js
@@ -1,9 +1,10 @@
import {CHECK_IDS} from 'notes-core/common';
import {db} from '../utils/DB';
import {eOpenPremiumDialog, eShowGetPremium} from '../utils/Events';
-import {eSendEvent} from './EventManager';
+import {MMKV} from '../utils/mmkv';
+import {eSendEvent, ToastEvent} from './EventManager';
-let premiumStatus = true;
+let premiumStatus = 0;
async function setPremiumStatus() {
try {
@@ -19,7 +20,7 @@ async function setPremiumStatus() {
}
function get() {
- return premiumStatus && premiumStatus !== 0 && premiumStatus !== 4;
+ return premiumStatus === 1 || premiumStatus === 2;
}
async function verify(callback, error) {
@@ -91,9 +92,44 @@ const onUserStatusCheck = async (type) => {
return {type, result: status};
};
+const showVerifyEmailDialog = () => {
+ eSendEvent(eOpenProgressDialog, {
+ title: 'Email not verified',
+ icon: 'email',
+ paragraph:
+ 'We have sent you an email confirmation link. Please check your email to verify your account.',
+ action: async () => {
+ try {
+ let lastEmailTime = await MMKV.getItem('lastEmailTime');
+ if (
+ lastEmailTime &&
+ Date.now() - JSON.parse(lastEmailTime) < 60000 * 10
+ ) {
+ ToastEvent.show(
+ 'Please wait before requesting another email',
+ 'error',
+ 'local',
+ );
+ console.log('error');
+ return;
+ }
+ await db.user.sendVerificationEmail();
+ await MMKV.setItem('lastEmailTime', JSON.stringify(Date.now()));
+ ToastEvent.show('Verification email sent!', 'success', 'local');
+ } catch (e) {
+ ToastEvent.show(e.message, 'error', 'local');
+ await MMKV.removeItem('lastEmailTime');
+ }
+ },
+ actionText: 'Resend Confirmation Link',
+ noProgress: true,
+ });
+};
+
export default {
verify,
setPremiumStatus,
get,
onUserStatusCheck,
+ showVerifyEmailDialog,
};
diff --git a/apps/mobile/src/utils/index.js b/apps/mobile/src/utils/index.js
index b09dc1259..10b06a19b 100755
--- a/apps/mobile/src/utils/index.js
+++ b/apps/mobile/src/utils/index.js
@@ -137,11 +137,11 @@ export const MenuItemsList = [
];
export const SUBSCRIPTION_STATUS = {
- EXPIRED: 0,
+ BASIC: 0,
TRIAL: 1,
- ACTIVE: 2,
- ACTIVE_RENEWING: 3,
- CANCELLED: 4,
+ BETA: 2,
+ TRIAL_EXPIRED: 3,
+ BETA_EXPIRED: 4,
};
export const SUBSCRIPTION_STATUS_STRINGS = {
diff --git a/apps/mobile/src/views/Editor/Functions.js b/apps/mobile/src/views/Editor/Functions.js
index ae78a82d3..d6abd7bc4 100644
--- a/apps/mobile/src/views/Editor/Functions.js
+++ b/apps/mobile/src/views/Editor/Functions.js
@@ -150,14 +150,14 @@ function clearNote() {
};
}
-let currentEditingTimer = null;
+let currentEditingTimer = null;
export const loadNote = async (item) => {
editing.currentlyEditing = true;
post('blur');
if (item && item.type === 'new') {
- await clearEditor();
+ await clearEditor();
clearNote();
noteEdited = false;
id = null;
@@ -232,12 +232,16 @@ export const _onMessage = async (evt) => {
eSendEvent('editorScroll', message);
break;
case 'premium':
- eSendEvent(eShowGetPremium, {
- context: 'editor',
- title: 'Get Notesnook Pro',
- desc: 'Enjoy Full Rich Text Editor with Markdown Support!',
- });
-
+ let user = await db.user.getUser();
+ if (!user.isEmailConfirmed) {
+ PremiumService.showVerifyEmailDialog();
+ } else {
+ eSendEvent(eShowGetPremium, {
+ context: 'editor',
+ title: 'Get Notesnook Pro',
+ desc: 'Enjoy Full Rich Text Editor with Markdown Support!',
+ });
+ }
break;
case 'status':
webviewInit = true;
@@ -269,14 +273,14 @@ export async function clearEditor() {
updateEvent({type: Actions.CURRENT_EDITING_NOTE, id: null});
sendNoteEditedEvent({
id: id,
- forced:true
+ forced: true,
});
eSendEvent('historyEvent', {
undo: 0,
redo: 0,
});
saveCounter = 0;
- post('dateEdited', "");
+ post('dateEdited', '');
post('saving', '');
clearNote();
//intent = false;
diff --git a/apps/mobile/src/views/Editor/index.js b/apps/mobile/src/views/Editor/index.js
index 270cd2e36..e1ceee06e 100755
--- a/apps/mobile/src/views/Editor/index.js
+++ b/apps/mobile/src/views/Editor/index.js
@@ -3,6 +3,7 @@ import { Platform, TextInput, View } from 'react-native';
import WebView from 'react-native-webview';
import { notesnook } from '../../../e2e/test.ids';
import { useTracked } from '../../provider';
+import PremiumService from '../../services/PremiumService';
import EditorHeader from './EditorHeader';
import {
EditorWebView,
@@ -16,7 +17,7 @@ import {
const Editor = () => {
const [state] = useTracked();
- const {colors, premiumUser} = state;
+ const {colors} = state;
return (
<>
@@ -31,7 +32,7 @@ const Editor = () => {
ref={EditorWebView}
onError={(error) => console.log(error)}
onLoad={async (event) =>
- await onWebViewLoad(premiumUser, colors, event)
+ await onWebViewLoad(PremiumService.get(), colors, event)
}
javaScriptEnabled={true}
focusable={true}