Skip to content

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

feat: add subscription info in setting

thecodrr13c736e2e4f0
diff --git a/apps/web/src/common/index.js b/apps/web/src/common/index.js
index 58ab5c588..896e138c1 100644
--- a/apps/web/src/common/index.js
+++ b/apps/web/src/common/index.js
@@ -5,7 +5,7 @@ import EventSource from "eventsource";
import { navigate } from "hookrouter";
export const db = new Database(StorageInterface, EventSource);
-db.host("https://api.notesnook.com");
+db.host("http://localhost:4100");
export const COLORS = {
red: "#f44336",
diff --git a/apps/web/src/components/dialogs/buydialog.js b/apps/web/src/components/dialogs/buydialog.js
index eb6883fb3..92b97f18e 100644
--- a/apps/web/src/components/dialogs/buydialog.js
+++ b/apps/web/src/components/dialogs/buydialog.js
@@ -82,7 +82,7 @@ function BuyDialog(props) {
: "Start your 14 Day Trial (no credit card required)"}
</Text>
</Text>
- <Text as="span" variant="body" fontSize="heading" color="text" mt={3}>
+ <Text as="span" variant="body" fontSize={30} color="text" mt={3}>
$6.99
<Text as="span" variant="body" color="primary" fontSize="subBody">
/mo
diff --git a/apps/web/src/components/dialogs/recovery-key-dialog.js b/apps/web/src/components/dialogs/recovery-key-dialog.js
index d5d809481..8d72f8dab 100644
--- a/apps/web/src/components/dialogs/recovery-key-dialog.js
+++ b/apps/web/src/components/dialogs/recovery-key-dialog.js
@@ -23,12 +23,7 @@ function RecoveryKeyDialog(props) {
})();
}, []);
return (
- <Dialog
- isOpen={true}
- title="Backup Recovery Key"
- onClose={props.onCancel}
- showClose
- >
+ <Dialog isOpen={true} title="Backup Recovery Key" onClose={props.onDone}>
<Flex flexDirection="column" flex={1} sx={{ overflow: "hidden" }}>
<Flex flexDirection="column" sx={{ overflowY: "auto" }}>
<Text
diff --git a/apps/web/src/views/settings.js b/apps/web/src/views/settings.js
index 754e58cba..7f626d300 100644
--- a/apps/web/src/views/settings.js
+++ b/apps/web/src/views/settings.js
@@ -1,4 +1,4 @@
-import React, { useEffect } from "react";
+import React, { useEffect, useMemo } from "react";
import { Button, Flex, Text } from "rebass";
import * as Icon from "../components/icons";
import { useStore as useUserStore } from "../stores/user-store";
@@ -12,6 +12,9 @@ import useSystemTheme from "../utils/use-system-theme";
import download from "../utils/download";
import { db, SUBSCRIPTION_STATUS } from "../common";
import { usePersistentState } from "../utils/hooks";
+import dayjs from "dayjs";
+import { showRecoveryKeyDialog } from "../components/dialogs/recoverykeydialog";
+import { showBuyDialog } from "../components/dialogs/buy-dialog";
function importBackup() {
return new Promise((resolve, reject) => {
@@ -45,6 +48,7 @@ function importBackup() {
}
function Settings(props) {
+ const isSystemThemeDark = useSystemTheme();
const theme = useThemeStore((store) => store.theme);
const toggleNightMode = useThemeStore((store) => store.toggleNightMode);
const setTheme = useThemeStore((store) => store.setTheme);
@@ -58,16 +62,21 @@ function Settings(props) {
);
const user = useUserStore((store) => store.user);
const isLoggedIn = useUserStore((store) => store.isLoggedIn);
- const isTrial = useUserStore(
- (store) => store?.user?.subscription?.status === SUBSCRIPTION_STATUS.TRIAL
- );
const logout = useUserStore((store) => store.logout);
const [backupReminderOffset, setBackupReminderOffset] = usePersistentState(
"backupReminderOffset",
0
);
- const isSystemThemeDark = useSystemTheme();
+ const subscriptionDaysRemaining = useMemo(
+ () => dayjs(user?.subscription?.expiry).diff(dayjs(), "day") + 1,
+ [user]
+ );
+ const isTrial = useMemo(
+ () => user?.subscription?.status === SUBSCRIPTION_STATUS.TRIAL,
+ [user]
+ );
+
useEffect(() => {
if (!followSystemTheme) return;
setTheme(isSystemThemeDark ? "dark" : "light");
@@ -75,82 +84,106 @@ function Settings(props) {
return (
<Flex variant="columnFill" px={2} sx={{ overflowY: "auto" }}>
- {isLoggedIn && (
- <Text mb={2} variant="subtitle" color="primary">
- Account Settings
- </Text>
- )}
- <Flex
- bg="shade"
- p={2}
- sx={{ borderRadius: "default", cursor: "pointer" }}
- onClick={async () => {
- if (!isLoggedIn) {
- await showLogInDialog();
- } else {
- upgrade(user);
- }
- // TODO open buy premium dialog
- }}
- >
+ {isLoggedIn ? (
<Flex
- flex="1 1 auto"
- justifyContent="space-between"
- alignItems="center"
+ bg="shade"
+ flexDirection="column"
+ p={2}
+ sx={{ borderRadius: "default" }}
>
- <Flex>
- <Flex
- variant="columnCenter"
- bg="primary"
- mr={2}
- size={35}
- sx={{
- borderRadius: 80,
- }}
- >
- <Icon.User size={20} color="static" />
+ <Flex flex="1" justifyContent="space-between">
+ <Flex>
+ <Icon.User size={15} color="primary" />
+ <Text variant="body" color="text" ml={1}>
+ {user.username}
+ </Text>
</Flex>
- <Flex variant="columnCenter" alignItems="flex-start">
- {isLoggedIn ? (
- <>
- <Text variant="subtitle">{user.username}</Text>
- <Text variant="subBody">{user.email}</Text>
- </>
- ) : (
- <>
- <Text variant="subBody">You are not logged in</Text>
- <Text variant="body" color="primary" fontSize={14}>
- Login to sync your notes
- </Text>
- </>
- )}
- </Flex>
- </Flex>
- {isLoggedIn ? (
<Text
- bg="primary"
+ variant="subBody"
+ px={"2px"}
+ py={"1px"}
sx={{ borderRadius: "default" }}
- color="static"
- fontSize="body"
- px={1}
- py={1 / 2}
+ bg="static"
+ color="primary"
>
- {!isTrial ? "Pro" : "Trial"}
+ {isTrial ? "Trial" : "Pro"}
</Text>
- ) : (
- <Icon.ChevronRight size={20} color="primary" />
+ </Flex>
+ <Text
+ color={subscriptionDaysRemaining <= 5 ? "error" : "primary"}
+ variant="body"
+ fontSize={26}
+ mt={2}
+ >
+ {subscriptionDaysRemaining} Days Remaining
+ </Text>
+ <Text variant="subBody">
+ Your trial period started on{" "}
+ {dayjs(user.subscription.start).format("MMMM D, YYYY")}
+ </Text>
+ {isTrial && (
+ <Button mt={2} onClick={showBuyDialog}>
+ Upgrade to Notesnook Pro
+ </Button>
)}
</Flex>
- </Flex>
- {isLoggedIn && (
- <Button
- variant="list"
+ ) : (
+ <Flex
+ bg="shade"
+ p={2}
+ sx={{ borderRadius: "default", cursor: "pointer" }}
onClick={async () => {
- await logout();
+ await showLogInDialog();
}}
>
- Logout
- </Button>
+ <Flex
+ flex="1 1 auto"
+ justifyContent="space-between"
+ alignItems="center"
+ >
+ <Flex>
+ <Flex
+ variant="columnCenter"
+ bg="primary"
+ mr={2}
+ size={35}
+ sx={{
+ borderRadius: 80,
+ }}
+ >
+ <Icon.User size={20} color="static" />
+ </Flex>
+ <Flex variant="columnCenter" alignItems="flex-start">
+ <Text variant="subBody">You are not logged in</Text>
+ <Text variant="body" color="primary" fontSize={14}>
+ Login to sync your notes
+ </Text>
+ </Flex>
+ </Flex>
+ <Icon.ChevronRight size={20} color="primary" />
+ </Flex>
+ </Flex>
+ )}
+ {isLoggedIn && (
+ <>
+ <Button variant="list" onClick={showRecoveryKeyDialog}>
+ <TextWithTip
+ text="Backup data recovery key"
+ tip="In case you lose your password, you can recover your data using your recovery key."
+ />
+ </Button>
+ <Button
+ variant="list"
+ onClick={async () => {
+ await logout();
+ }}
+ >
+ <TextWithTip
+ text="Logout"
+ tip="Log out of your account and clear all data."
+ />
+ </Button>
+ </>
)}
<Text
variant="subtitle"
diff --git a/apps/web/yarn.lock b/apps/web/yarn.lock
index 1d52b5a17..8188779af 100644
--- a/apps/web/yarn.lock
+++ b/apps/web/yarn.lock
@@ -6354,6 +6354,10 @@ https-proxy-agent@^5.0.0:
agent-base "6"
debug "4"
+"hypersearch@https://github.com/streetwriters/hypersearch":
+ version "0.1.0"
+ resolved "https://github.com/streetwriters/hypersearch#fa5d2b8435c1b7bca4b5f8059054da848fe1631f"
+
[email protected], iconv-lite@^0.4.24:
version "0.4.24"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
@@ -8860,11 +8864,12 @@ normalize-url@^3.0.0, normalize-url@^3.0.1:
integrity sha512-U+JJi7duF1o+u2pynbp2zXDW2/PADgC30f0GsHZtRh+HOcXHnw137TrNlyxxRvWW5fjKd3bcLHPxofWuCjaeZg==
"notes-core@git+ssh://[email protected]:streetwriters/notesnook-core.git":
- version "1.5.0"
- resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#abeb8f7a5a4ae52cb6409d930e13238b96941e6f"
+ version "2.1.0"
+ resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#b7d94074f19261cd0efc6c60c1720e82981b49a2"
dependencies:
fast-sort "^2.0.1"
fuzzysearch "^1.0.3"
+ hypersearch "https://github.com/streetwriters/hypersearch"
jshashes "^1.0.8"
no-internet "^1.5.2"
qclone "^1.0.4"