Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyleye committed Dec 1, 2021
1 parent e70a644 commit 4457249
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 61 deletions.
78 changes: 49 additions & 29 deletions client/src/components/Auth/Field.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,52 @@
import React from 'react';
import { TextField, Grid, InputAdornment, IconButton } from '@material-ui/core';
import React, { useState } from "react";
import { TextField, Grid, InputAdornment, IconButton } from "@material-ui/core";

import Visibility from '@material-ui/icons/Visibility';
import VisibilityOff from '@material-ui/icons/VisibilityOff';
import Visibility from "@material-ui/icons/Visibility";
import VisibilityOff from "@material-ui/icons/VisibilityOff";

const Field = ({ name, handleChange, label, half, autoFocus, type, handleShowPassword, placeholder }) => (
<Grid item xs={12} sm={half ? 6 : 12}>
<TextField
name={name}
onChange={handleChange}
placeholder={placeholder}
variant="outlined"
required
fullWidth
label={label}
autoFocus={autoFocus}
type={type}
InputProps={name === 'password' ? {
endAdornment: (
<InputAdornment position="end">
<IconButton onClick={handleShowPassword}>
{type === 'password' ? <Visibility /> : <VisibilityOff />}
</IconButton>
</InputAdornment>
),
} : null}
/>
</Grid>
);
const Field = ({
name,
handleChange,
label,
half,
autoFocus,
type,
placeholder,
}) => {
const [showPass, setShowPass] = useState(false);

export default Field
const togglePasswordVisibility = () => {
setShowPass((show) => !show);
};

return (
<Grid item xs={12} sm={half ? 6 : 12}>
<TextField
name={name}
onChange={handleChange}
placeholder={placeholder}
variant="outlined"
required
fullWidth
label={label}
autoFocus={autoFocus}
type={showPass ? "text" : type}
InputProps={
name === "password"
? {
endAdornment: (
<InputAdornment position="end">
<IconButton onClick={togglePasswordVisibility}>
{!showPass ? <Visibility /> : <VisibilityOff />}
</IconButton>
</InputAdornment>
),
}
: null
}
/>
</Grid>
);
};

export default Field;
2 changes: 1 addition & 1 deletion client/src/components/Auth/auth-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const AuthForm = ({ isSignup = false, onSubmit }) => {
type="submit"
className={styles.submitBtn}
>
{isSignup ? "Sign In" : "Sign Up"}
{isSignup ? "Sign Up" : "Sign In"}
</button>
)}
</div>
Expand Down
15 changes: 11 additions & 4 deletions client/src/components/Auth/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from "react";
import { Container } from "@material-ui/core";
import { Switch, Route, useHistory } from "react-router-dom";
import SignupForm from "./signup-form";
import LoginForm from "./login-form";
import AuthForm from "./auth-form";
import { useDispatch } from "react-redux";
import { signin, signup } from "../../actions/auth";

const Auth = () => {
const history = useHistory();
Expand All @@ -13,11 +14,17 @@ const Auth = () => {
history.push("/dashboard");
}

const dispatch = useDispatch();

return (
<Container component="main" maxWidth="xs">
<Switch>
<Route path="/login" component={LoginForm} />
<Route path="/signup" component={SignupForm} />
<Route path="/login">
<AuthForm onSubmit={() => dispatch(signin())} />
</Route>
<Route path="/signup">
<AuthForm isSignup onSubmit={() => dispatch(signup())} />
</Route>
</Switch>
</Container>
);
Expand Down
14 changes: 0 additions & 14 deletions client/src/components/Auth/login-form.js

This file was deleted.

13 changes: 0 additions & 13 deletions client/src/components/Auth/signup-form.js

This file was deleted.

0 comments on commit 4457249

Please sign in to comment.