Skip to content

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

feat: add redirect in login dialog

thecodrr0fea07cba0ec
diff --git a/apps/web/src/common/upgrade.js b/apps/web/src/common/upgrade.js
index 9c0020fc2..0778d2908 100644
--- a/apps/web/src/common/upgrade.js
+++ b/apps/web/src/common/upgrade.js
@@ -17,7 +17,7 @@ function loadPaddle() {
});
}
-async function upgrade(user) {
+async function upgrade(user, coupon) {
if (!window.Paddle) {
await loadPaddle();
}
@@ -28,6 +28,7 @@ async function upgrade(user) {
Paddle.Checkout.open({
product: PRODUCT_ID,
email: user.email,
+ coupon,
passthrough: JSON.stringify({
userId: user.id,
}),
diff --git a/apps/web/src/components/dialogs/logindialog.js b/apps/web/src/components/dialogs/logindialog.js
index 384c2931a..631db1d63 100644
--- a/apps/web/src/components/dialogs/logindialog.js
+++ b/apps/web/src/components/dialogs/logindialog.js
@@ -7,15 +7,25 @@ import Field from "../field";
import { Checkbox, Label } from "@rebass/forms";
import { showForgotPasswordDialog } from "../../common/dialog-controller";
import { hashNavigate } from "../../navigation";
+import useHashLocation from "../../utils/use-hash-location";
const requiredValues = ["email", "password", "remember"];
function LoginDialog(props) {
const { onClose } = props;
+ const [, queryParams] = useHashLocation();
const [error, setError] = useState();
const [credential, setCredential] = useState();
const [email, setEmail] = useState();
const isLoggingIn = useStore((store) => store.isLoggingIn);
const login = useStore((store) => store.login);
+ const isLoggedIn = useStore((store) => store.isLoggedIn);
+
+ useEffect(() => {
+ if (isLoggedIn) {
+ onClose();
+ if (queryParams.redirect) hashNavigate(queryParams.redirect);
+ }
+ }, [isLoggedIn, queryParams, onClose]);
useEffect(() => {
if (!window.PasswordCredential) return;
@@ -97,6 +107,7 @@ function LoginDialog(props) {
id="loginForm"
as="form"
onSubmit={(e) => {
+ console.log("SUBMIT", e);
e.preventDefault();
const form = new FormData(e.target);
const data = requiredValues.reduce((prev, curr) => {
@@ -121,6 +132,9 @@ function LoginDialog(props) {
} else {
onClose();
}
+ if (queryParams.redirect) {
+ hashNavigate(queryParams.redirect);
+ }
})
.catch((e) => setError(e.message));
}}
diff --git a/apps/web/src/navigation/hash-routes.js b/apps/web/src/navigation/hash-routes.js
index 8b0c59565..cc7e17e6d 100644
--- a/apps/web/src/navigation/hash-routes.js
+++ b/apps/web/src/navigation/hash-routes.js
@@ -22,6 +22,9 @@ import { hashNavigate } from ".";
import { Suspense } from "react";
import EditorLoading from "../components/editor/loading";
import EditorPlaceholder from "../components/editor/-placeholder";
+import { store as userStore } from "../stores/user-store";
+import { upgrade } from "../common/upgrade";
+import { isUserPremium } from "../common";
const Editor = React.lazy(() => import("../components/editor"));
const hashroutes = {
@@ -99,6 +102,12 @@ const hashroutes = {
"/login": () => {
showLogInDialog();
},
+ "/buy/:code": ({ code }) => {
+ hashNavigate("/", { notify: false });
+ const user = userStore.get().user;
+ if (!user || isUserPremium()) return;
+ upgrade(user, code);
+ },
};
export default hashroutes;
diff --git a/apps/web/src/navigation/index.js b/apps/web/src/navigation/index.js
index 2d72ce1bc..ca5b7b32b 100644
--- a/apps/web/src/navigation/index.js
+++ b/apps/web/src/navigation/index.js
@@ -53,27 +53,8 @@ export function hashNavigate(
// dispatchEvent(new PopStateEvent("popstate", null));
}
-export function useQueryParams(
- parseFn = parseQuery
- //serializeFn = serializeQuery
-) {
+export function useQueryParams(parseFn = parseQuery) {
const [querystring] = useState(getQueryString());
- // const setQueryParams = useCallback(
- // (params, { replace = true } = {}) => {
- // let path = getCurrentPath();
- // params = replace ? params : { ...parseFn(querystring), ...params };
- // const serialized = serializeFn(params).toString();
- // if (serialized) path += "?" + serialized;
- // if (!replace) path += getCurrentHash();
- // navigate(path);
- // },
- // [querystring]
- // );
- // Update state when route changes
- // const updateQuery = useCallback(() => setQuerystring(getQueryString()), [
- // setQueryParams,
- // ]);
- //useLocationChange(updateQuery);
return [parseFn(querystring)];
}
@@ -81,12 +62,6 @@ function parseQuery(querystring) {
return Object.fromEntries(new URLSearchParams(querystring).entries());
}
-// function serializeQuery(queryParams) {
-// return new URLSearchParams(
-// Object.entries(queryParams).filter(([, v]) => v !== null)
-// );
-// }
-
export function getQueryString() {
return window.location.search;
}
diff --git a/apps/web/src/utils/useHashLocation.js b/apps/web/src/utils/useHashLocation.js
index 3a533338c..5de311772 100644
--- a/apps/web/src/utils/useHashLocation.js
+++ b/apps/web/src/utils/useHashLocation.js
@@ -4,22 +4,33 @@ import { hashNavigate } from "../navigation";
// returns the current hash location in a normalized form
// (excluding the leading '#' symbol)
const currentLocation = () => {
- return window.location.hash.replace(/^#/, "") || "/";
+ const location = window.location.hash.replace(/^#/, "") || "/";
+ let end = location.indexOf("?");
+ if (end <= -1) end = undefined;
+ return location.substring(0, end);
+};
+
+const currentQuery = () => {
+ const location = window.location.hash.replace(/^#/, "") || "/";
+ return Object.fromEntries(
+ new URLSearchParams(location.substring(location.indexOf("?"))).entries()
+ );
};
export default function useHashLocation() {
const [loc, setLoc] = useState(currentLocation());
+ const [queryParams, setQueryParams] = useState(currentQuery());
useEffect(() => {
// this function is called whenever the hash changes
const handler = () => {
setLoc(currentLocation());
+ setQueryParams(currentQuery());
};
// subscribe to hash changes
window.addEventListener("hashchange", handler);
return () => window.removeEventListener("hashchange", handler);
}, []);
-
- return [loc, hashNavigate];
+ return [loc, queryParams, hashNavigate];
}
diff --git a/apps/web/src/views/email-confirmed.js b/apps/web/src/views/email-confirmed.js
index a771014cb..fdc8a1ac7 100644
--- a/apps/web/src/views/email-confirmed.js
+++ b/apps/web/src/views/email-confirmed.js
@@ -1,8 +1,9 @@
import React, { useEffect } from "react";
-import { Button, Flex, Text } from "rebass";
+import { Button, Flex, Text, Image } from "rebass";
import ThemeProvider from "../components/theme-provider";
import * as Icon from "../components/icons";
import { useQueryParams } from "../navigation";
+import Logo from "../assets/logo.svg";
function EmailConfirmed() {
const [{ userId }] = useQueryParams();
@@ -14,30 +15,109 @@ function EmailConfirmed() {
<ThemeProvider>
<Flex
flexDirection="column"
+ bg="background"
height="100%"
justifyContent="center"
alignItems="center"
>
+ <Image src={Logo} height={30} mt={2} />
+ <Text variant="title" textAlign="center">
+ Notesnook
+ </Text>
<Flex
+ flex="1"
flexDirection="column"
justifyContent="center"
alignItems="center"
- p={2}
>
- <Text variant="heading" color="primary">
- Notesnook
- </Text>
-
- <Text display="flex" variant="heading" fontSize={32}>
+ <Text
+ display="flex"
+ variant="heading"
+ fontSize={32}
+ justifyContent="center"
+ alignItems="center"
+ >
<Icon.Success color="primary" size={32} sx={{ mr: 2 }} /> Email
confirmed!
</Text>
<Text variant="body" mt={2}>
You can safely close this window and return to Notesnook.
</Text>
+ <SaleBanner discount={80} promoCode="EARLYBIRD" daysRemaining="2" />
</Flex>
</Flex>
</ThemeProvider>
);
}
export default EmailConfirmed;
+
+function SaleBanner(props) {
+ const { discount, promoCode, daysRemaining } = props;
+ return (
+ <Flex
+ bg="shade"
+ flexDirection="column"
+ mt={5}
+ justifyContent="center"
+ alignItems="center"
+ p={2}
+ maxWidth={["80%", "auto", "auto"]}
+ sx={{
+ borderRadius: "default",
+ border: "1px solid",
+ borderColor: "primary",
+ }}
+ >
+ <Text variant="title" textAlign="center">
+ Notesnook Pro Early Bird Offer!
+ </Text>
+ <Text
+ variant="heading"
+ fontSize={32}
+ color="primary"
+ textAlign="center"
+ fontWeight="bold"
+ >
+ {discount}% OFF
+ </Text>
+ <Text variant="body" fontSize="title" textAlign="center">
+ *Use code{" "}
+ <Text as="b" color="primary">
+ {promoCode}
+ </Text>{" "}
+ at checkout to get{" "}
+ <Text as="b" color="primary">
+ {discount}% off your first month.
+ </Text>
+ </Text>
+ <Button
+ mt={1}
+ fontSize="title"
+ width="100%"
+ onClick={() => {
+ if (window.umami)
+ window.umami(`Email verified offer [${promoCode}] click`, "offers");
+ window.location.href = `/#/login?redirect=/buy/${promoCode}`;
+ }}
+ >
+ Subscribe now before offer ends!
+ </Button>
+ <Text as="em" variant="body" mt={1} color="error">
+ (Only {daysRemaining} days remaining.)
+ </Text>
+
+ <Text variant="body" fontSize="subBody" mt={1}>
+ *This offer only works if you purchase through our web app.
+ </Text>
+ {/* <Text variant="body" textAlign="center">
+ Unlimited storage &amp; attachments
+ <br />
+ Unlimited notebooks &amp; tags
+ <br />
+ Automatic syncing &amp; backups
+ <br />
+ <a href="https://notesnook.com/">AND SO MUCH MORE!</a>
+ </Text> */}
+ </Flex>
+ );
+}
diff --git a/apps/web/src/views/recovery.js b/apps/web/src/views/recovery.js
index d344b7b55..a7517c346 100644
--- a/apps/web/src/views/recovery.js
+++ b/apps/web/src/views/recovery.js
@@ -81,36 +81,42 @@ function AccountRecovery() {
<ThemeProvider>
<Flex
flexDirection="column"
+ bg="background"
height="100%"
- overflowY="auto"
- alignItems="center"
justifyContent="center"
- p={2}
+ alignItems="center"
>
- <Image src={Logo} height={50} sx={{ position: "absolute", top: 2 }} />
- <Text variant="heading" color="primary">
+ <Image src={Logo} height={30} mt={2} />
+ <Text variant="title" textAlign="center">
Notesnook
</Text>
- {loading.isLoading ? (
- <Flex flexDirection="column" mt={2}>
- <Icon.Loading rotate color="primary" />
- <Text variant="body" mt={2} fontSize={"title"}>
- {loading.message}
- </Text>
- </Flex>
- ) : (
- <>
- <Step
- performAction={performAction}
- onFinished={() => {
- setStep((s) => ++s);
- }}
- onRestart={() => {
- setStep(0);
- }}
- />
- </>
- )}
+ <Flex
+ flex="1"
+ flexDirection="column"
+ justifyContent="center"
+ alignItems="center"
+ >
+ {loading.isLoading ? (
+ <Flex flexDirection="column" mt={2}>
+ <Icon.Loading rotate color="primary" />
+ <Text variant="body" mt={2} fontSize={"title"}>
+ {loading.message}
+ </Text>
+ </Flex>
+ ) : (
+ <>
+ <Step
+ performAction={performAction}
+ onFinished={() => {
+ setStep((s) => ++s);
+ }}
+ onRestart={() => {
+ setStep(0);
+ }}
+ />
+ </>
+ )}
+ </Flex>
</Flex>
</ThemeProvider>
);
@@ -119,12 +125,7 @@ export default AccountRecovery;
function Step({ heading, children }) {
return (
- <Flex
- flexDirection="column"
- justifyContent="center"
- alignItems="center"
- sx={{ width: ["90%", "50%", "20%"] }}
- >
+ <Flex flexDirection="column" justifyContent="center" alignItems="center">
<Text variant="heading" fontSize={24} mb={25} textAlign="center">
{heading}
</Text>