show correct premium status message

This commit is contained in:
ammarahm-ed
2021-01-03 11:21:36 +05:00
parent 4dfba5e047
commit 00bfa7a559
5 changed files with 62 additions and 50 deletions

View File

@@ -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',

View File

@@ -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,
};

View File

@@ -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 = {

View File

@@ -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;

View File

@@ -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}