Skip to content

Commit

Permalink
User redirect after Signup
Browse files Browse the repository at this point in the history
  • Loading branch information
dssudake committed Jun 5, 2020
1 parent d6655f1 commit 9b29415
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 8 deletions.
8 changes: 4 additions & 4 deletions eda-frontend/src/components/SchematicEditor/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function Header () {
noWrap
className={classes.toolbarTitle}
>
<Link color="inherit" target='blank' component={RouterLink} to="/">
<Link color="inherit" target='_blank' component={RouterLink} to="/">
eSim
</Link>
</Typography>
Expand Down Expand Up @@ -153,23 +153,23 @@ function Header () {
style={{ marginTop: '25px' }}
>
<MenuItem
target='blank'
target='_blank'
component={RouterLink}
to="/dashboard"
onClick={handleClose}
>
<ListItemText primary={auth.user.username} secondary={auth.user.email} />
</MenuItem>
<MenuItem
target='blank'
target='_blank'
component={RouterLink}
to="/dashboard/profile"
onClick={handleClose}
>
My Profile
</MenuItem>
<MenuItem
target='blank'
target='_blank'
component={RouterLink}
to="/dashboard/schematics"
onClick={handleClose}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ export default function SchematicToolbar ({ mobileClose }) {
var title = schSave.title
var description = schSave.description
dispatch(saveSchematic(title, description, xml))
setMessage('Saved Successfully')
handleSnacClick()
}
}

Expand Down
2 changes: 1 addition & 1 deletion eda-frontend/src/components/SchematicEditor/SideComp.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default function SideComp ({ component }) {
</ListItemText>

<ListItemText>
<b>Datasheet:</b> <a href={component.data_link} target='blank' >{component.data_link}</a>
<b>Datasheet:</b> <a href={component.data_link} rel="noreferrer" target='_blank' >{component.data_link}</a>
</ListItemText>

<ListItemText>
Expand Down
9 changes: 7 additions & 2 deletions eda-frontend/src/pages/signUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
} from '@material-ui/core'
import { makeStyles } from '@material-ui/core/styles'
import LockOutlinedIcon from '@material-ui/icons/LockOutlined'
import { Link as RouterLink } from 'react-router-dom'
import { useDispatch } from 'react-redux'
import { Link as RouterLink, Redirect } from 'react-router-dom'
import { useSelector, useDispatch } from 'react-redux'
import { signUp } from '../redux/actions/index'

const useStyles = makeStyles((theme) => ({
Expand All @@ -41,6 +41,8 @@ const useStyles = makeStyles((theme) => ({
export default function SignUp () {
const classes = useStyles()

const auth = useSelector(state => state.authReducer)

useEffect(() => {
document.title = 'Sign Up - eSim '
})
Expand All @@ -50,6 +52,9 @@ export default function SignUp () {
const [email, setEmail] = useState('')
const dispatch = useDispatch()

if (auth.isRegistered) {
return <Redirect to="/login" />
}
return (
<Container component="main" maxWidth="xs">
<Card className={classes.paper}>
Expand Down
1 change: 1 addition & 0 deletions eda-frontend/src/redux/actions/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const AUTHENTICATION_ERROR = 'AUTHENTICATION_ERROR'
export const LOGIN_FAILED = 'LOGIN_FAILED'
export const LOGOUT_SUCCESSFUL = 'LOGOUT_SUCCESSFUL'
export const LOADING_FAILED = 'LOADING_FAILED'
export const SIGNUP_SUCCESSFUL = 'SIGNUP_SUCCESSFUL'

export const SAVE_SCHEMATICS = 'SAVE_SCHEMATICS'
export const SET_SCH_SAVED = 'SET_SCH_SAVED'
Expand Down
3 changes: 2 additions & 1 deletion eda-frontend/src/redux/actions/authActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ export const signUp = (email, username, password) => (dispatch) => {

api.post('auth/users/', body, config)
.then((res) => {
console.log(res)
// console.log(res)
dispatch({ type: actions.SIGNUP_SUCCESSFUL })
})
.catch((err) => { console.error(err) })
}
Expand Down
8 changes: 8 additions & 0 deletions eda-frontend/src/redux/reducers/authReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as actions from '../actions/actions'
const initialState = {
token: localStorage.getItem('esim_token'),
isAuthenticated: null,
isRegistered: null,
isLoading: false,
user: null,
errors: {}
Expand All @@ -17,6 +18,13 @@ export default function (state = initialState, action) {
}
}

case actions.SIGNUP_SUCCESSFUL: {
return {
...state,
isRegistered: true
}
}

case actions.USER_LOADED: {
return {
...state,
Expand Down

0 comments on commit 9b29415

Please sign in to comment.