ui: fix login/signup dialogs

This commit is contained in:
thecodrr
2020-04-14 11:08:56 +05:00
parent 28cf586c26
commit 401b68f28b
3 changed files with 11 additions and 3 deletions

View File

@@ -8,12 +8,12 @@ import { useStore } from "../../stores/user-store";
import PasswordInput from "../inputs/password";
import Dropper from "../dropper";
const form = { error: true };
function LoginDialog(props) {
const { onClose } = props;
const [error, setError] = useState();
const isLoggingIn = useStore((store) => store.isLoggingIn);
const login = useStore((store) => store.login);
const form = { error: true };
return (
<Dialog
@@ -51,6 +51,7 @@ function LoginDialog(props) {
function submit(setError, form, login, onClose) {
setError();
if (form.error) return;
login(form)
.then(onClose)
.catch((e) => setError(e.message));

View File

@@ -9,12 +9,12 @@ import PasswordInput from "../inputs/password";
import Dropper from "../dropper";
import { useStore } from "../../stores/user-store";
const form = { error: true };
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 (
<Dialog
@@ -49,6 +49,10 @@ function SignUpDialog(props) {
function submit(setError, form, signup, onClose) {
setError();
if (form.password !== form.confirm) {
form.error = true;
setError("Passwords do not match.");
}
if (form.error) return;
signup(form)
.then(onClose)

View File

@@ -12,7 +12,10 @@ function PasswordInput(props) {
title="Confirm Password"
type="password"
error="Passwords do not match"
validate={(password, form) => form.password === password}
name="confirm"
validate={(password, form) =>
!form.password || form.password === password
}
/>
)}
</Dropper>