Skip to content

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

feat: add user upgrading

thecodrr04e94b1d74e8
diff --git a/apps/web/public/index.html b/apps/web/public/index.html
index 5f2d249d5..552f17151 100644
--- a/apps/web/public/index.html
+++ b/apps/web/public/index.html
@@ -45,5 +45,34 @@
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
+ <script>
+ (function (document, src, libName, config) {
+ var script = document.createElement("script");
+ script.src = src;
+ script.async = true;
+ var firstScriptElement = document.getElementsByTagName("script")[0];
+ script.onload = function () {
+ for (var namespace in config) {
+ if (config.hasOwnProperty(namespace)) {
+ window[libName].setup.setConfig(namespace, config[namespace]);
+ }
+ }
+ window[libName].register();
+ };
+
+ firstScriptElement.parentNode.insertBefore(script, firstScriptElement);
+ })(
+ document,
+ "https://secure.avangate.com/checkout/client/twoCoInlineCart.js",
+ "TwoCoInlineCart",
+ {
+ app: { merchant: "250327951921", iframeLoad: "checkout" },
+ cart: {
+ host: "https:\/\/secure.2checkout.com",
+ customization: "inline",
+ },
+ }
+ );
+ </script>
</body>
</html>
diff --git a/apps/web/src/common/upgrade.js b/apps/web/src/common/upgrade.js
new file mode 100644
index 000000000..23cf66a16
--- /dev/null
+++ b/apps/web/src/common/upgrade.js
@@ -0,0 +1,40 @@
+import { db } from "./index";
+
+window.onload = async function (e) {
+ const refno = getParameterByName("refno");
+ if (refno) {
+ console.log(refno);
+ await db.user.upgrade(refno);
+ window.location.hash = "#";
+ }
+};
+
+function upgrade(user) {
+ const { TwoCoInlineCart: cart } = window;
+ if (!cart) return;
+ cart.setup.setMerchant("250327951921"); // your Merchant code
+ cart.billing.setEmail(user.email); // customer email address
+ cart.shipping.setEmail(user.email); // customer Delivery email
+ cart.cart.setTest(true);
+
+ cart.products.add({
+ code: "notesnook",
+ quantity: 1,
+ });
+
+ cart.cart.setCartLockedFlag(true);
+ cart.cart.checkout().then(console.log); // start checkout process
+}
+//http://localhost:3000/#/?refno=121822593&total=6.99&total-currency=USD&signature=06b250570afca7ccd6cb54d4d1dc63a7c4c3e1adf28be4cdb57a9f4569bfbbce
+
+function getParameterByName(name, url) {
+ if (!url) url = window.location.href;
+ name = name.replace(/[[\]]/g, "\\$&");
+ var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
+ results = regex.exec(url);
+ if (!results) return null;
+ if (!results[2]) return "";
+ return decodeURIComponent(results[2].replace(/\+/g, " "));
+}
+
+export { upgrade };
diff --git a/apps/web/src/components/dialogs/signupdialog.js b/apps/web/src/components/dialogs/signupdialog.js
index 28b376497..37d015379 100644
--- a/apps/web/src/components/dialogs/signupdialog.js
+++ b/apps/web/src/components/dialogs/signupdialog.js
@@ -62,3 +62,7 @@ function submit(setError, form, signup, onClose) {
export function showSignUpDialog() {
return showDialog((perform) => <SignUpDialog onClose={() => perform()} />);
}
+
+/**
+
+ */
diff --git a/apps/web/src/components/editor/index.js b/apps/web/src/components/editor/index.js
index 336dee3f3..c6b7c98bc 100644
--- a/apps/web/src/components/editor/index.js
+++ b/apps/web/src/components/editor/index.js
@@ -16,7 +16,7 @@ function Editor() {
const setSession = useStore((store) => store.setSession);
const saveSession = useStore((store) => store.saveSession);
const isFocusMode = useAppStore((store) => store.isFocusMode);
- const isPremium = useUserStore((store) => store.isPremium);
+ const isPremium = useUserStore((store) => store.user.isPremium);
const quillRef = useRef();
useEffect(() => {
diff --git a/apps/web/src/components/menu/index.js b/apps/web/src/components/menu/index.js
index a0375124f..282c3469a 100644
--- a/apps/web/src/components/menu/index.js
+++ b/apps/web/src/components/menu/index.js
@@ -3,7 +3,8 @@ import { Flex, Box, Text } from "rebass";
import { useStore as useUserStore } from "../../stores/user-store";
function Menu(props) {
- const isPremium = useUserStore((store) => store.isPremium);
+ const isPremium = useUserStore((store) => store.user.isPremium);
+ const isTrialExpired = useUserStore((store) => store.isTrialExpired);
return (
<Flex
@@ -41,7 +42,7 @@ function Menu(props) {
if (props.closeMenu) {
props.closeMenu();
}
- const onlyPro = item.onlyPro && !isPremium;
+ const onlyPro = item.onlyPro && !isPremium && isTrialExpired;
if (onlyPro) {
// TODO
} else if (item.onClick) {
diff --git a/apps/web/src/stores/user-store.js b/apps/web/src/stores/user-store.js
index 90d4f8f6b..6b5e4d9ea 100644
--- a/apps/web/src/stores/user-store.js
+++ b/apps/web/src/stores/user-store.js
@@ -10,17 +10,16 @@ class UserStore extends BaseStore {
isLoggingIn = false;
isSigningIn = false;
isSyncing = false;
- user = undefined;
- isPremium = false;
+ isTrialExpired = false;
+ user = {};
init = () => {
return db.user.get().then(async (user) => {
if (!user) return false;
- const isPremium = await db.user.isPremium();
this.set((state) => {
state.user = user;
+ state.isTrialExpired = user.trialExpiryDate > Date.now() * 1000;
state.isLoggedIn = true;
- state.isPremium = isPremium;
});
db.ev.subscribe("sync", () => {
this.sync();
@@ -72,7 +71,7 @@ class UserStore extends BaseStore {
logout = () => {
return db.user.logout().then(async () => {
this.set((state) => {
- state.user = undefined;
+ state.user = {};
state.isLoggedIn = false;
});
config.clear();
diff --git a/apps/web/src/theme/font/fontsize.js b/apps/web/src/theme/font/fontsize.js
index 6bf484270..ab38affc1 100644
--- a/apps/web/src/theme/font/fontsize.js
+++ b/apps/web/src/theme/font/fontsize.js
@@ -3,7 +3,7 @@ class FontSizeFactory {
return {
heading: 28 * scaleFactor,
input: 16 * scaleFactor,
- title: 14 * scaleFactor,
+ title: 18 * scaleFactor,
subtitle: 16 * scaleFactor,
body: 16 * scaleFactor,
menu: 14 * scaleFactor,
diff --git a/apps/web/src/theme/variants/text.js b/apps/web/src/theme/variants/text.js
index 97f7220e9..b62c4ed18 100644
--- a/apps/web/src/theme/variants/text.js
+++ b/apps/web/src/theme/variants/text.js
@@ -4,6 +4,7 @@ class TextFactory {
default: new Default(),
heading: new Heading(),
title: new Title(),
+ subtitle: new Subtitle(),
body: new Body(),
subBody: new SubBody(),
error: new Error(),
@@ -40,6 +41,14 @@ class Title {
};
}
}
+class Subtitle {
+ constructor() {
+ return {
+ variant: "text.heading",
+ fontSize: "subtitle",
+ };
+ }
+}
class Body {
constructor() {
diff --git a/apps/web/src/views/Settings.js b/apps/web/src/views/Settings.js
index 02900345d..58f110afe 100644
--- a/apps/web/src/views/Settings.js
+++ b/apps/web/src/views/Settings.js
@@ -6,19 +6,21 @@ import { useStore as useThemeStore } from "../stores/theme-store";
import AccentItem from "../components/accent-item";
import accents from "../theme/accents";
import { showLogInDialog } from "../components/dialogs/logindialog";
+import { upgrade } from "../common/upgrade";
function Settings(props) {
const theme = useThemeStore((store) => store.theme);
const toggleNightMode = useThemeStore((store) => store.toggleNightMode);
const user = useUserStore((store) => store.user);
const isLoggedIn = useUserStore((store) => store.isLoggedIn);
- const isPremium = useUserStore((store) => store.isPremium);
+ const isPremium = useUserStore((store) => store.user.isPremium);
+ const isTrialExpired = useUserStore((store) => store.isTrialExpired);
const logout = useUserStore((store) => store.logout);
return (
<Flex variant="columnFill" mx={2}>
{isLoggedIn && (
- <Text mb={2} variant="title" color="primary">
+ <Text mb={2} variant="subtitle" color="primary">
Account Settings
</Text>
)}
@@ -29,6 +31,8 @@ function Settings(props) {
onClick={async () => {
if (!isLoggedIn) {
await showLogInDialog();
+ } else {
+ upgrade(user);
}
// TODO open buy premium dialog
}}
@@ -53,7 +57,7 @@ function Settings(props) {
<Flex variant="columnCenter" alignItems="flex-start">
{isLoggedIn ? (
<>
- <Text variant="title">{user.username}</Text>
+ <Text variant="subtitle">{user.username}</Text>
<Text variant="subBody">{user.email}</Text>
</>
) : (
@@ -66,26 +70,31 @@ function Settings(props) {
)}
</Flex>
</Flex>
- <Text
- bg="primary"
- sx={{ borderRadius: "default" }}
- color="static"
- fontSize="title"
- px={1}
- >
- {isPremium ? "Pro" : "Trial"}
- </Text>
+ {isLoggedIn && (
+ <Text
+ bg="primary"
+ sx={{ borderRadius: "default" }}
+ color="static"
+ fontSize="body"
+ px={1}
+ py={1 / 2}
+ >
+ {isPremium || isTrialExpired ? "Pro" : "Trial"}
+ </Text>
+ )}
</Flex>
</Flex>
- <Button
- variant="list"
- onClick={async () => {
- await logout();
- }}
- >
- Logout
- </Button>
- <Text my={2} variant="title" color="primary">
+ {isLoggedIn && (
+ <Button
+ variant="list"
+ onClick={async () => {
+ await logout();
+ }}
+ >
+ Logout
+ </Button>
+ )}
+ <Text my={2} variant="subtitle" color="primary">
Appearance
</Text>
<Box
@@ -125,7 +134,7 @@ function Settings(props) {
{theme === "dark" ? <Icon.Check /> : <Icon.CircleEmpty />}
</Flex>
</Box>
- <Text my={2} variant="title" color="primary">
+ <Text my={2} variant="subtitle" color="primary">
Other
</Text>
{["Terms of Service", "Privacy Policy", "About"].map((title) => (
diff --git a/apps/web/yarn.lock b/apps/web/yarn.lock
index 7d470db61..88f319223 100644
--- a/apps/web/yarn.lock
+++ b/apps/web/yarn.lock
@@ -7191,6 +7191,13 @@ no-case@^3.0.3:
lower-case "^2.0.1"
tslib "^1.10.0"
+no-internet@^1.5.2:
+ version "1.5.2"
+ resolved "https://registry.yarnpkg.com/no-internet/-/no-internet-1.5.2.tgz#a51e8c314fd4d005c8239eda7e6c4aad7c0cadfb"
+ integrity sha512-4GnJQsc/BCwcOG+8acwAsm9bYVdgh0V5ORQTAnB+7u9hoKdR4WqSqw6Bhjo3DO/tvhad4wbrw4l07/CG6C+wDg==
+ dependencies:
+ set-interval "^2.0.1"
+
version "0.9.0"
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.9.0.tgz#d624050edbb44874adca12bb9a52ec63cb782579"
@@ -7295,10 +7302,11 @@ normalize-url@^3.0.0, normalize-url@^3.0.1:
"notes-core@git+ssh://[email protected]:streetwriters/notesnook-core.git":
version "1.5.0"
- resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#57f6e79aa1f0ec5b861ea93cc3c0026c478deb53"
+ resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#ccddf7870901639d82a1998701b1aa3a50742091"
dependencies:
fast-sort "^2.0.1"
fuzzysearch "^1.0.3"
+ no-internet "^1.5.2"
qclone "^1.0.4"
transfun "^1.0.2"
@@ -9609,6 +9617,11 @@ set-blocking@^2.0.0:
resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7"
integrity sha1-BF+XgtARrppoA93TgrJDkrPYkPc=
+set-interval@^2.0.1:
+ version "2.0.4"
+ resolved "https://registry.yarnpkg.com/set-interval/-/set-interval-2.0.4.tgz#419266c0a2b05d5fd5bde6e7896b57a27d060a5a"
+ integrity sha512-Srlnjq2O84WQxv2DkTyf7S0nRebiNE+uD5nd2Iy4ISOtiZbxglSfup88vegIAYRpCn/ITS1rYmjCPuAhn/hdmg==
+
set-value@^2.0.0, set-value@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/set-value/-/set-value-2.0.1.tgz#a18d40530e6f07de4228c7defe4227af8cad005b"