Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolving redirection on go-back button #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 62 additions & 10 deletions src/components/error-dart.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,71 @@
import React from 'react'
import axios from 'axios'
import { Header, Button } from 'semantic-ui-react'

import { getTheme, urlErrorAssets } from 'formula_one'
import { getTheme, urlErrorAssets, urlWhoAmI } from 'formula_one'

import blocks from '../css/error-dart.css'
import { element } from 'prop-types'

export default class ErrorDart extends React.PureComponent {
state = {
isFacultyOrGuest: false
}

isFacultyOrGuest = (roles) => {
let isFacultyOrGuest = false
roles.forEach(element => {
geekvert marked this conversation as resolved.
Show resolved Hide resolved
if (element.role === 'FacultyMember' || element.role === 'Guest') {
geekvert marked this conversation as resolved.
Show resolved Hide resolved
isFacultyOrGuest = true
}
})
return isFacultyOrGuest
}

fetchUserRoles = () => {
geekvert marked this conversation as resolved.
Show resolved Hide resolved
axios
.get(urlWhoAmI())
.then(res => {
this.setState({
isFacultyOrGuest: this.isFacultyOrGuest(res.data.roles)
})
})
.catch(() => {
this.setState({
isFacultyOrGuest: true
})
})
}

getGoBackButton = () => {
if (this.state.isFacultyOrGuest) {
return (
<Button
basic
onClick = {() => this.props.history.goBack()}
color={getTheme()}
>
Go back?
</Button>
)
}
return (
<Button
basic
as='a'
href='https://youtu.be/dQw4w9WgXcQ?t=43&lc=Ugx5eioe8QbJJGWVZ0x4AaABAg'
target='_blank'
color={getTheme()}
>
Go back?
</Button>
)
}

componentDidMount() {
this.fetchUserRoles()
}

render () {
return (
<div>
Expand All @@ -15,15 +75,7 @@ export default class ErrorDart extends React.PureComponent {
404: Foundn't
<Header.Subheader>Content not found</Header.Subheader>
</Header>
<Button
basic
as='a'
href='https://youtu.be/dQw4w9WgXcQ?t=43&lc=Ugx5eioe8QbJJGWVZ0x4AaABAg'
target='_blank'
color={getTheme()}
>
Go back?
</Button>
{this.getGoBackButton()}
</div>
<div styleName='blocks.board-container'>
<img
Expand Down
71 changes: 61 additions & 10 deletions src/components/error-rabbit.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,70 @@
import React from 'react'
import axios from 'axios'
import { Header, Button } from 'semantic-ui-react'

import { getTheme, urlErrorAssets } from 'formula_one'
import { getTheme, urlErrorAssets, urlWhoAmI } from 'formula_one'

import blocks from '../css/error-rabbit.css'

export default class ErrorRabbit extends React.PureComponent {
state = {
isFacultyOrGuest: false
}

isFacultyOrGuest = (roles) => {
let isFacultyOrGuest = false
roles.forEach(element => {
if (element.role === 'FacultyMember' || element.role === 'Guest') {
isFacultyOrGuest = true
}
})
return isFacultyOrGuest
}

fetchUserRoles = () => {
axios
.get(urlWhoAmI())
.then(res => {
this.setState({
isFacultyOrGuest: this.isFacultyOrGuest(res.data.roles)
})
})
.catch(() => {
this.setState({
isFacultyOrGuest: true
})
})
}

getGoBackButton = () => {
if (this.state.isFacultyOrGuest) {
return (
<Button
basic
onClick = {() => this.props.history.goBack()}
color={getTheme()}
>
Go back?
</Button>
)
}
return (
<Button
basic
as='a'
href='https://youtu.be/dQw4w9WgXcQ?t=43&lc=Ugx5eioe8QbJJGWVZ0x4AaABAg'
target='_blank'
color={getTheme()}
>
Go back?
</Button>
)
}

componentDidMount() {
this.fetchUserRoles()
}

render () {
return (
<div>
Expand All @@ -15,15 +74,7 @@ export default class ErrorRabbit extends React.PureComponent {
404: Foundn't
<Header.Subheader>Content not found</Header.Subheader>
</Header>
<Button
basic
as='a'
href='https://youtu.be/dQw4w9WgXcQ?t=43&lc=Ugx5eioe8QbJJGWVZ0x4AaABAg'
target='_blank'
color={getTheme()}
>
Go back?
</Button>
{this.getGoBackButton()}
</div>
<div styleName='blocks.confetti-container'>
<img
Expand Down
3 changes: 2 additions & 1 deletion src/components/no-match.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import blocks from '../css/no-match.css'

export default class NoMatch extends React.PureComponent {
render () {
const { history } = this.props
const creators = [
{
name: 'Dhruv Bhanushali',
Expand All @@ -42,7 +43,7 @@ export default class NoMatch extends React.PureComponent {
<Scrollbars autoHide>
<div styleName='blocks.app-wrapper'>
<Container styleName='blocks.main'>
{isBrowser ? <ErrorDart /> : <ErrorRabbit />}
{isBrowser ? <ErrorDart history={history} /> : <ErrorRabbit history={history} />}
</Container>
</div>
</Scrollbars>
Expand Down