Skip to content

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

feat: implement signup flow

thecodrrd666636b26ad
diff --git a/apps/web/src/components/dialogs/signupdialog.js b/apps/web/src/components/dialogs/signupdialog.js
index aa14ffbcc..93c08e4ba 100644
--- a/apps/web/src/components/dialogs/signupdialog.js
+++ b/apps/web/src/components/dialogs/signupdialog.js
@@ -7,10 +7,13 @@ import Dialog, { showDialog } from "./dialog";
import EmailInput from "../inputs/email";
import PasswordInput from "../inputs/password";
import Dropper from "../dropper";
+import { useStore } from "../../stores/user-store";
function SignUpDialog(props) {
const { onClose } = props;
const [error, setError] = useState();
+ const isSigningIn = useStore((store) => store.isSigningIn);
+ const signup = useStore((store) => store.signup);
const form = { error: true };
return (
@@ -22,14 +25,15 @@ function SignUpDialog(props) {
negativeButton={{ onClick: onClose }}
positiveButton={{
text: "Sign Up",
+ loading: isSigningIn,
+ disabled: isSigningIn,
onClick: () => {
setError();
if (form.error) return;
- /* db.user
- .signup(form)
+ signup(form)
.then(onClose)
- .catch(error => setError(`Couldn't signup. Error: ${error}`)); */
- }
+ .catch((e) => setError(e.message));
+ },
}}
>
<Box mt={1}>
@@ -45,5 +49,5 @@ function SignUpDialog(props) {
}
export function showSignUpDialog() {
- return showDialog(perform => <SignUpDialog onClose={() => perform()} />);
+ return showDialog((perform) => <SignUpDialog onClose={() => perform()} />);
}
diff --git a/apps/web/src/stores/user-store.js b/apps/web/src/stores/user-store.js
index ace68d959..b8b6adfce 100644
--- a/apps/web/src/stores/user-store.js
+++ b/apps/web/src/stores/user-store.js
@@ -6,13 +6,14 @@ import BaseStore from "./index";
class UserStore extends BaseStore {
isLoggedIn = false;
isLoggingIn = false;
+ isSigningIn = false;
isSyncing = false;
user = undefined;
init = () => {
- return db.user.get().then(user => {
+ return db.user.get().then((user) => {
if (!user) return false;
- this.set(state => {
+ this.set((state) => {
state.user = user;
state.isLoggedIn = true;
});
@@ -21,36 +22,48 @@ class UserStore extends BaseStore {
});
};
- login = form => {
- this.set(state => (state.isLoggingIn = true));
+ login = (form) => {
+ this.set((state) => (state.isLoggingIn = true));
return db.user
.login(form.username, form.password)
.then(() => {
return this.init();
})
.finally(() => {
- this.set(state => (state.isLoggingIn = false));
+ this.set((state) => (state.isLoggingIn = false));
+ });
+ };
+
+ signup = (form) => {
+ this.set((state) => (state.isSigningIn = true));
+ return db.user
+ .signup(form.username, form.email, form.password)
+ .then(() => {
+ return this.init();
+ })
+ .finally(() => {
+ this.set((state) => (state.isSigningIn = false));
});
};
sync = () => {
- this.set(state => (state.isSyncing = true));
+ this.set((state) => (state.isSyncing = true));
db.sync()
.then(() => {
appStore.refresh();
})
- .catch(err => {
+ .catch((err) => {
if (err.code === "MERGE_CONFLICT") appStore.refresh();
else console.error(err);
})
.finally(() => {
- this.set(state => (state.isSyncing = false));
+ this.set((state) => (state.isSyncing = false));
});
};
logout = () => {
db.user.logout().then(() => {
- this.set(state => {
+ this.set((state) => {
state.user = undefined;
state.isLoggedIn = false;
});