Skip to content

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

feat: add trial expiry reminder dialogs

thecodrr8a3efcb98a10
diff --git a/apps/web/src/common/dialogcontroller.js b/apps/web/src/common/dialogcontroller.js
index 66aa9f783..2ca5a9e7b 100644
--- a/apps/web/src/common/dialogcontroller.js
+++ b/apps/web/src/common/dialogcontroller.js
@@ -528,6 +528,20 @@ export function showFeatureDialog(featureName) {
));
}
+export function showReminderDialog(reminderKey) {
+ if (Config.get(reminderKey, false)) return;
+
+ return showDialog((Dialogs, perform) => (
+ <Dialogs.ReminderDialog
+ reminderKey={reminderKey}
+ onClose={(res) => {
+ Config.set(reminderKey, true);
+ perform(res);
+ }}
+ />
+ ));
+}
+
export function showTrackingDetailsDialog() {
return showDialog((Dialogs, perform) => (
<Dialogs.TrackingDetailsDialog onClose={(res) => perform(res)} />
diff --git a/apps/web/src/common/index.js b/apps/web/src/common/index.js
index 46b2adce5..601426721 100644
--- a/apps/web/src/common/index.js
+++ b/apps/web/src/common/index.js
@@ -7,6 +7,7 @@ import {
showFeatureDialog,
showLoadingDialog,
showPasswordDialog,
+ showReminderDialog,
} from "../common/dialog-controller";
import Config from "../utils/config";
import { hashNavigate, getCurrentHash } from "../navigation";
@@ -141,3 +142,26 @@ export const AppEventManager = new EventManager();
export const AppEvents = {
UPDATE_ATTACHMENT_PROGRESS: "updateAttachmentProgress",
};
+
+export function totalSubscriptionConsumed(user) {
+ if (!user) return 0;
+ const start = user.subscription?.start;
+ const end = user.subscription?.expiry;
+ if (!start || !end) return 0;
+
+ const total = end - start;
+ const consumed = Date.now() - start;
+
+ return Math.round((consumed / total) * 100);
+}
+
+export async function showUpgradeReminderDialogs(user) {
+ const consumed = totalSubscriptionConsumed(user);
+ const isTrial = user?.subscription?.type === SUBSCRIPTION_STATUS.TRIAL;
+ const isBasic = user?.subscription?.type === SUBSCRIPTION_STATUS.BASIC;
+ if (isBasic && consumed >= 100) {
+ await showReminderDialog("trialexpired");
+ } else if (isTrial && consumed >= 75) {
+ await showReminderDialog("trialexpiring");
+ }
+}
diff --git a/apps/web/src/components/dialogs/dialog.js b/apps/web/src/components/dialogs/dialog.js
index 67d3252eb..7c3d7c8b6 100644
--- a/apps/web/src/components/dialogs/dialog.js
+++ b/apps/web/src/components/dialogs/dialog.js
@@ -52,7 +52,7 @@ function Dialog(props) {
>
<Flex
flexDirection="column"
- width={["100%", "90%", props.width || "25%"]}
+ width={["100%", "90%", props.width || "380px"]}
maxHeight={["100%", "80%", "70%"]}
height={["100%", "auto", "auto"]}
bg="background"
@@ -72,11 +72,11 @@ function Dialog(props) {
position: "absolute",
cursor: "pointer",
top: 0,
- right: 30,
- mt: 38,
+ right: 20,
+ mt: 26,
zIndex: 999,
}}
- size={26}
+ size={20}
onClick={props.onClose}
/>
)}
@@ -84,13 +84,17 @@ function Dialog(props) {
<Text
variant="heading"
fontSize="subheading"
- textAlign="left"
+ textAlign={props.alignment || "left"}
color="text"
>
{props.title}
</Text>
{props.description && (
- <Text variant="body" textAlign="left" color="fontTertiary">
+ <Text
+ variant="body"
+ textAlign={props.alignment || "left"}
+ color="fontTertiary"
+ >
{props.description}
</Text>
)}
@@ -100,7 +104,7 @@ function Dialog(props) {
</Flex>
{(props.positiveButton || props.negativeButton) && (
<Flex
- sx={{ justifyContent: props.buttonsAlignment || "flex-end" }}
+ sx={{ justifyContent: props.alignment || "flex-end" }}
bg="bgSecondary"
p={1}
px={2}
diff --git a/apps/web/src/components/dialogs/index.js b/apps/web/src/components/dialogs/index.js
index f01179bee..e8e8d12fa 100644
--- a/apps/web/src/components/dialogs/index.js
+++ b/apps/web/src/components/dialogs/index.js
@@ -12,6 +12,7 @@ import ItemDialog from "./itemdialog";
import SessionExpiredDialog from "./sessionexpireddialog";
import FeatureDialog from "./feature-dialog";
import TrackingDetailsDialog from "./trackingdetailsdialog";
+import ReminderDialog from "./reminderdialog";
const Dialogs = {
AddNotebookDialog,
@@ -28,5 +29,6 @@ const Dialogs = {
SessionExpiredDialog,
FeatureDialog,
ProgressDialog,
+ ReminderDialog,
};
export default Dialogs;
diff --git a/apps/web/src/components/dialogs/reminder-dialog.js b/apps/web/src/components/dialogs/reminder-dialog.js
new file mode 100644
index 000000000..7bf760eb8
--- /dev/null
+++ b/apps/web/src/components/dialogs/reminder-dialog.js
@@ -0,0 +1,135 @@
+import { Text, Flex, Box, Button } from "rebass";
+import Dialog from "./dialog";
+import * as Icon from "../icons";
+import { showBuyDialog } from "../../common/dialog-controller";
+
+const features = [
+ { icon: Icon.Sync, title: "Instant private sync" },
+ { icon: Icon.Notebook, title: "Unlimited notebooks" },
+ { icon: Icon.Tag2, title: "Unlimited tags" },
+ { icon: Icon.Attachment, title: "Encrypted attachments" },
+ { icon: Icon.Backup, title: "Encrypted backups" },
+ { icon: Icon.Vault, title: "Secure private vault" },
+ { icon: Icon.PDF, title: "Export to PDF" },
+ { icon: Icon.Edit, title: "Rich text editor" },
+];
+// TODO create trial expiry coupon codes
+const reminders = {
+ trialexpired: {
+ title: "Your free trial has expired",
+ description: "But we have a special offer just for you!",
+ offer: {
+ title: (
+ <>
+ Subscribe now to{" "}
+ <Text as="span" fontWeight="bold" color="primary">
+ get 30% off
+ </Text>
+ </>
+ ),
+ subtitle: "on monthly & yearly plans",
+ },
+ features,
+ footer: (
+ <Flex bg="bgSecondary" pb={2} justifyContent="center">
+ <Button variant="anchor" color="text">
+ Can't decide yet? Extend your trial!
+ </Button>
+ </Flex>
+ ),
+ cta: {
+ title: "Subscribe now",
+ action: () => showBuyDialog("monthly"),
+ },
+ },
+ trialexpiring: {
+ title: "Your free trial is ending soon",
+ description: "But your privacy doesn't have to...",
+ offer: {
+ title: (
+ <>
+ Upgrade now to continue using all the pro features without
+ interruption.
+ </>
+ ),
+ },
+ features,
+ cta: {
+ title: "Upgrade now",
+ action: () => showBuyDialog("monthly"),
+ },
+ },
+};
+
+function ReminderDialog(props) {
+ const { reminderKey } = props;
+ const reminder = reminders[reminderKey];
+ if (!reminder) return;
+
+ return (
+ <Dialog
+ isOpen={true}
+ title={reminder.title}
+ onClose={props.onClose}
+ showClose
+ scrollable
+ description={reminder.description}
+ alignment="center"
+ positiveButton={{
+ text: <Flex>{reminder.cta.title}</Flex>,
+ onClick: () => {
+ if (reminder.cta.action) reminder.cta.action();
+ props.onClose(true);
+ },
+ }}
+ footer={reminder.footer}
+ >
+ <Flex
+ flexDirection="column"
+ overflowY="auto"
+ justifyContent="center"
+ alignItems="center"
+ mt={2}
+ overflow="hidden"
+ >
+ {reminder.offer && (
+ <>
+ <Text textAlign="center" variant="body" fontSize="title">
+ {reminder.offer.title}
+ </Text>
+ <Text textAlign="center" variant="body" opacity="0.8">
+ {reminder.offer.subtitle}
+ </Text>
+ </>
+ )}
+ {reminder.features && (
+ <Box
+ mt={2}
+ sx={{
+ display: "grid",
+ gridTemplateColumns: "1fr 1fr",
+ columnGap: 1,
+ rowGap: 1,
+ }}
+ >
+ {reminder.features.map((feature) => (
+ <Flex
+ p={1}
+ sx={{
+ borderRadius: "default",
+ border: "1px solid var(--border)",
+ }}
+ >
+ <feature.icon size={16} sx={{ alignSelf: "start" }} />
+ <Text variant="body" ml={1}>
+ {feature.title}
+ </Text>
+ </Flex>
+ ))}
+ </Box>
+ )}
+ </Flex>
+ </Dialog>
+ );
+}
+export default ReminderDialog;
diff --git a/apps/web/src/stores/user-store.js b/apps/web/src/stores/user-store.js
index 2310a400d..eaf075eb3 100644
--- a/apps/web/src/stores/user-store.js
+++ b/apps/web/src/stores/user-store.js
@@ -8,7 +8,8 @@ import { showSessionExpiredDialog } from "../common/dialog-controller";
import { showAccountLoggedOutNotice } from "../common/dialog-controller";
import Config from "../utils/config";
import { onPageVisibilityChanged } from "../utils/page-visibility";
-import { extendHomeRoute, hardNavigate, hashNavigate } from "../navigation";
+import { hashNavigate } from "../navigation";
+import { showUpgradeReminderDialogs } from "../common";
class UserStore extends BaseStore {
isLoggedIn = false;
@@ -45,6 +46,7 @@ class UserStore extends BaseStore {
return db.user.fetchUser().then(async (user) => {
if (!user) return false;
+
EV.remove(
EVENTS.userSubscriptionUpdated,
EVENTS.userEmailConfirmed,
@@ -55,9 +57,11 @@ class UserStore extends BaseStore {
state.user = user;
state.isLoggedIn = true;
});
+
EV.subscribe(EVENTS.userSubscriptionUpdated, (subscription) => {
this.set((state) => (state.user.subscription = subscription));
});
+
EV.subscribe(EVENTS.userEmailConfirmed, () => {
hashNavigate("/confirmed");
});
@@ -84,6 +88,8 @@ class UserStore extends BaseStore {
await db.connectSSE();
}
});
+
+ await showUpgradeReminderDialogs(user);
await appStore.sync();
return true;
});