Skip to content

Commit

Permalink
bg(refactoring): improve existing logical operation checking
Browse files Browse the repository at this point in the history
- refactor code
- add style
- [Finishes #171403437]
  • Loading branch information
NiyongaboEric committed Feb 25, 2020
1 parent 167aa97 commit a559d8b
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 34 deletions.
1 change: 1 addition & 0 deletions src/assets/css/authentication.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
margin: 0 auto;
}
input {
padding-left: 10px;
width: 435px;
height: 45px;
margin-top: 10px;
Expand Down
6 changes: 3 additions & 3 deletions src/components/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ export class Profile extends Component {

const token = localStorage.getItem('token');
this.decode = jwtDecode(token);
const { getProfile, updateSpinnerStatus, getManagers } = this.props;
const { getProfile, updateSpinnerStatus, getManagers, profileError } = this.props;
await getManagers();
await getProfile();
if (this.props.profileError.error
|| this.props.profileError.message === 'You have provided an invalid token') {
if (profileError.error
|| profileError.message === 'You have provided an invalid token') {
return this.props.history.push('/signin');
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/containers/Trips/MulticityTrip.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ export class MulticityTrip extends Component {
componentDidUpdate(prevProps) {
const { history } = this.props;
const { multicityTripData } = this.props;
if (prevProps.multicityTripData !== multicityTripData) {
if (multicityTripData.message === 'Trip requested successfully') {
return history.push('/requests');
}
if (
(prevProps.multicityTripData !== multicityTripData) &&
(multicityTripData.message === 'Trip requested successfully')
) {
return history.push('/requests');
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/containers/TripsContainer/Requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class Requests extends Component {
}

async componentDidMount() {
const { fetchRequestsAction, searchResults } = this.props;
const { fetchRequestsAction, searchResults, profileError } = this.props;
await searchResults();
await fetchRequestsAction();
if (this.props.profileError.error
|| this.props.profileError.message === 'You have provided an invalid token') {
if (profileError.error
|| profileError.message === 'You have provided an invalid token') {
return this.props.history.push('/signin');
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/containers/TripsContainer/oneway.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ export class Oneway extends Component {
}

componentDidUpdate(prevProps) {
const { payload: incomingData } = this.props.tripState.trips.tripRequests;
const { payload: incomingData } = this.props.tripState.trips.tripRequests;
const { payload: oldData } = prevProps.tripState.trips.tripRequests;
const { history } = this.props;
if (incomingData !== oldData) {
if (incomingData.message === 'Trip requested successfully') {
return history.push(`/requests/${incomingData.data.id}`);
}
if (
(incomingData !== oldData)
&& (incomingData.message === 'Trip requested successfully')
) {
return history.push(`/requests/${incomingData.data.id}`);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/containers/trips/SearchStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export class Requests extends Component {
if (!verifyToken(tokenExist)) {
return this.props.history.push('/signin');
}
const { getStatsAction } = this.props;
const { getStatsAction, profileError } = this.props;
getStatsAction({ tripType: '1', from: '2020-01-22', to: '2020-01-26' });


if (this.props.profileError.error
|| this.props.profileError.message === 'You have provided an invalid token') {
if (profileError.error
|| profileError.message === 'You have provided an invalid token') {
return this.props.history.push('/signin');
}
}
Expand Down
31 changes: 16 additions & 15 deletions src/views/Dashboard/sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,27 @@ export class Sidebar extends Component {
render() {
let backdrop;
const { sideDrawerOpen } = this.state;
const { children } = this.props;
const { children, profileError, profile } = this.props;
const { tokenValid } = this.state;

if (sideDrawerOpen) {
backdrop = <Backdrop click={this.backdropClickHandler} />;
}

if(this.state.tokenValid) {
if (this.props.profileError) {
if(this.props.profileError.error) {
return <Redirect to="/verify-email"/>;
}
if(this.props.profileError.message) {
localStorage.removeItem('token')
return <Redirect to="/signin"/>;
}
}}
if (this.props.profile.data) {
if (!this.props.profile.data.managerId) {
return <Redirect to="/profile"/>;
}

if(tokenValid && profileError && profileError.error) {
return <Redirect to="/verify-email"/>;
}

if(tokenValid && profileError && profileError.message) {
localStorage.removeItem('token')
return <Redirect to="/signin"/>;
}

if (profile.data && !profile.data.managerId) {
return <Redirect to="/profile"/>;
}

return (
<>
<TopSide drawerClickHandler={this.drawerToggleClickHandler} />
Expand Down
1 change: 0 additions & 1 deletion src/views/accommodation/ViewAccomodation.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export class viewAllAccomodation extends Component {
this.refs.mytrips &&
this.refs.mytrips.children.length > 0 &&
PaginationStyle(this.refs.mytrips.children, pageNo)
console.log('ooooooooooooo')

return (
<Dashboard>
Expand Down
Empty file.

0 comments on commit a559d8b

Please sign in to comment.