Skip to content

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

feat: add email verification dialog

thecodrracc1e7929cb2
diff --git a/apps/web/src/common/reminders.js b/apps/web/src/common/reminders.js
index bba45b8b0..d22378a7a 100644
--- a/apps/web/src/common/reminders.js
+++ b/apps/web/src/common/reminders.js
@@ -3,7 +3,6 @@ import { createBackup, db } from "./index";
import { store as appStore } from "../stores/app-store";
import * as Icon from "../components/icons";
import dayjs from "dayjs";
-import { showToast } from "../utils/toast";
import { showRecoveryKeyDialog } from "../components/dialogs/recoverykeydialog";
import { hashNavigate } from "../navigation";
@@ -47,10 +46,7 @@ export const Reminders = {
},
email: {
title: "Please confirm your email",
- action: async () => {
- await db.user.sendVerificationEmail();
- showToast("success", "Confirmation email sent. Please check your inbox!");
- },
+ action: () => hashNavigate("/email/verify"),
icon: Icon.Email,
},
recoverykey: {
diff --git a/apps/web/src/components/dialogs/email-verification-dialog.js b/apps/web/src/components/dialogs/email-verification-dialog.js
new file mode 100644
index 000000000..295a244cc
--- /dev/null
+++ b/apps/web/src/components/dialogs/email-verification-dialog.js
@@ -0,0 +1,63 @@
+import React from "react";
+import { Flex, Button, Text } from "rebass";
+import Dialog, { showDialog } from "./dialog";
+import { useStore as useUserStore } from "../../stores/user-store";
+import { db } from "../../common";
+import { useState } from "react";
+
+function EmailVerificationDialog(props) {
+ const user = useUserStore((store) => store.user);
+ const [error, setError] = useState();
+ if (!user) {
+ props.onCancel();
+ return;
+ }
+ return (
+ <Dialog
+ isOpen={true}
+ title={"Verify your email"}
+ description={"Please check your inbox for the confirmation email."}
+ onClose={props.onCancel}
+ negativeButton={{ text: "Done", onClick: props.onCancel }}
+ >
+ <Flex flexDirection="column" alignItems="flex-start">
+ <Text
+ as="span"
+ variant="body"
+ bg="shade"
+ color="primary"
+ p={1}
+ alignSelf="stretch"
+ sx={{ borderRadius: "default" }}
+ >
+ We have sent the email with the confirmation link to{" "}
+ <b>{user.email}</b>.
+ </Text>
+ <Button
+ mt={2}
+ variant="anchor"
+ onClick={async () => {
+ try {
+ await db.user.sendVerificationEmail();
+ } catch (e) {
+ setError(e.message);
+ }
+ }}
+ >
+ Resend confirmation email
+ </Button>
+ {error && (
+ <Text variant="error" mt={2}>
+ {error}
+ </Text>
+ )}
+ </Flex>
+ </Dialog>
+ );
+}
+
+export function showEmailVerificationDialog() {
+ return showDialog((perform) => (
+ <EmailVerificationDialog onCancel={() => perform(false)} />
+ ));
+}
diff --git a/apps/web/src/components/status-bar/index.js b/apps/web/src/components/status-bar/index.js
index a6cea3621..24b4e54d1 100644
--- a/apps/web/src/components/status-bar/index.js
+++ b/apps/web/src/components/status-bar/index.js
@@ -5,7 +5,7 @@ import * as Icon from "../icons";
import { useStore as useUserStore } from "../../stores/user-store";
import { showLogInDialog } from "../dialogs/logindialog";
import TimeAgo from "timeago-react";
-import { navigate } from "../../navigation";
+import { hashNavigate, navigate } from "../../navigation";
function StatusBar() {
const user = useUserStore((state) => state.user);
@@ -24,7 +24,11 @@ function StatusBar() {
{isLoggedIn ? (
<Flex>
<Button
- onClick={() => navigate("/settings")}
+ onClick={() =>
+ user.isEmailConfirmed
+ ? navigate("/settings")
+ : hashNavigate("/email/verify")
+ }
variant="statusitem"
display="flex"
sx={{ alignItems: "center", justifyContent: "center" }}
diff --git a/apps/web/src/navigation/hash-routes.js b/apps/web/src/navigation/hash-routes.js
index 861ceeb31..a908fa04d 100644
--- a/apps/web/src/navigation/hash-routes.js
+++ b/apps/web/src/navigation/hash-routes.js
@@ -1,5 +1,6 @@
import React from "react";
import Vault from "../common/vault";
+import { showEmailVerificationDialog } from "../components/dialogs/emailverificationdialog";
import {
showAddNotebookDialog,
showEditNotebookDialog,
@@ -19,6 +20,9 @@ const hashroutes = {
"/": () => {
closeOpenedDialog();
},
+ "/email/verify": () => {
+ showEmailVerificationDialog();
+ },
"/notebooks/create": () => {
showAddNotebookDialog();
},
diff --git a/apps/web/src/views/settings.js b/apps/web/src/views/settings.js
index cdba3b5ea..2cec50bb6 100644
--- a/apps/web/src/views/settings.js
+++ b/apps/web/src/views/settings.js
@@ -172,7 +172,11 @@ function Settings(props) {
</>
) : null
) : (
- <Button mt={2} bg="error">
+ <Button
+ mt={2}
+ bg="error"
+ onClick={() => hashNavigate("/email/verify")}
+ >
<Flex alignItems="center">
<Icon.Warn color="static" size={13} />
<Text color="static" ml={1}>