Skip to content

Commit

Permalink
Merge pull request #758 from neontribe/page-transition-warning
Browse files Browse the repository at this point in the history
fix: avoid page transition warning
  • Loading branch information
falconx authored Jun 4, 2020
2 parents f069548 + a45bc0a commit 35463d9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/pages/AddPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Helmet } from 'react-helmet';
import queryString from 'query-string';
import { useMutation } from '@apollo/client';
import { loader } from 'graphql.macro';
import { Redirect } from 'react-router-dom';

import PageLayout from '../components/PageLayout';
import LooMap from '../components/LooMap';
Expand All @@ -16,7 +17,6 @@ import useMapPosition from '../components/useMapPosition';
import useNearbyLoos from '../components/useNearbyLoos';

import config from '../config';
import history from '../history';

const UPDATE_LOO = loader('./updateLoo.graphql');

Expand Down Expand Up @@ -61,7 +61,11 @@ const AddPage = (props) => {

// redirect to new toilet entry page on successful addition
if (saveResponse && saveResponse.submitReport.code === '200') {
history.push(`/loos/${saveResponse.submitReport.loo.id}?message=created`);
return (
<Redirect
to={`/loos/${saveResponse.submitReport.loo.id}?message=created`}
/>
);
}

const save = (data) => {
Expand Down
12 changes: 8 additions & 4 deletions src/pages/EditPage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useEffect } from 'react';
import { Helmet } from 'react-helmet';
import { Link } from 'react-router-dom';
import { Link, Redirect } from 'react-router-dom';
import merge from 'lodash/merge';
import cloneDeep from 'lodash/cloneDeep';
import uniqBy from 'lodash/uniqBy';
Expand All @@ -20,7 +20,7 @@ import useNearbyLoos from '../components/useNearbyLoos';
import useMapPosition from '../components/useMapPosition';

import config from '../config';
import history from '../history';
// import history from '../history';

const FIND_BY_ID = loader('./findLooById.graphql');
const UPDATE_LOO = loader('./updateLoo.graphql');
Expand Down Expand Up @@ -119,12 +119,16 @@ const EditPage = (props) => {

// redirect to index if loo is not active (i.e. removed)
if (looData && !looData.loo.active) {
history.push('/');
return <Redirect to="/" />;
}

// redirect to new toilet entry page on successful addition
if (saveResponse && saveResponse.submitReport.code === '200') {
history.push(`/loos/${saveResponse.submitReport.loo.id}?message=updated`);
return (
<Redirect
to={`/loos/${saveResponse.submitReport.loo.id}?message=updated`}
/>
);
}

const getLoosToDisplay = () => {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/RemovePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React, { useState } from 'react';
import { Helmet } from 'react-helmet';
import { useQuery, useMutation } from '@apollo/client';
import { loader } from 'graphql.macro';
import { Redirect } from 'react-router-dom';

import config from '../config';
import history from '../history';

import PageLayout from '../components/PageLayout';
import Container from '../components/Container';
Expand Down Expand Up @@ -67,7 +67,7 @@ const RemovePage = function (props) {
}

if (!looData.loo.active) {
history.push('/');
return <Redirect to="/" />;
}

return (
Expand Down

1 comment on commit 35463d9

@vercel
Copy link

@vercel vercel bot commented on 35463d9 Jun 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.