Skip to content

Commit

Permalink
remove page
Browse files Browse the repository at this point in the history
  • Loading branch information
ob6160 committed Jul 26, 2021
1 parent 4a32ca0 commit d61cb49
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
6 changes: 2 additions & 4 deletions src/pages/loos/[id]/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ const EditPage = (props: { match: { params: { id: any; }; }; }) => {

if (saveData) {
// redirect to updated toilet entry page
return (
<Redirect to={`/loos/${saveData.submitReport.loo.id}?message=updated`} />
);
router.push(`/loos/${saveData.submitReport.loo.id}?message=updated`)
}

if (loadingLooData || !looData || !initialData || looError) {
Expand All @@ -139,7 +137,7 @@ const EditPage = (props: { match: { params: { id: any; }; }; }) => {

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

const getLoosToDisplay = () => {
Expand Down
32 changes: 16 additions & 16 deletions src/pages/RemovePage.tsx → src/pages/loos/[id]/remove.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
import React, { useState } from 'react';
import { Helmet } from 'react-helmet';
import useSWR from 'swr';
import { Redirect, useParams, useHistory } from 'next/link';
// import { loader } from 'graphql.macro';
import { print } from 'graphql/language/printer';

import config from '../config';
import { useMutation } from '../graphql/fetcher';
import config from '../../../config';
import { useMutation } from '../../../graphql/fetcher';

import PageLayout from '../components/PageLayout';
import Container from '../components/Container';
import Spacer from '../components/Spacer';
import Text from '../components/Text';
import Button from '../components/Button';
import Notification from '../components/Notification';
import PageLayout from '../../../components/PageLayout';
import Container from '../../../components/Container';
import Spacer from '../../../components/Spacer';
import Text from '../../../components/Text';
import Button from '../../../components/Button';
import Notification from '../../../components/Notification';

// const REMOVE_LOO_MUTATION = print(loader('../graphql/removeLoo.graphql'));
import REMOVE_LOO_MUTATION from '../graphql/removeLoo.graphql';
import REMOVE_LOO_MUTATION from '../../../graphql/removeLoo.graphql';

// const GET_LOO_BY_ID_QUERY = print(loader('../graphql/findLooById.graphql'));

import GET_LOO_BY_ID_QUERY from '../graphql/findLooById.graphql';
import GET_LOO_BY_ID_QUERY from '../../../graphql/findLooById.graphql';
import { useRouter } from 'next/router';

const RemovePage = function (props: { match: { params: { id: any; }; }; }) {
const [reason, setReason] = useState('');
const params = useParams();
const history = useHistory();
const router = useRouter();
const {id: selectedLooId} = router.query;

const {
isValidating: loadingLooData,
data: looData,
error: looError,
} = useSWR([GET_LOO_BY_ID_QUERY, JSON.stringify({ id: params.id })]);
} = useSWR([GET_LOO_BY_ID_QUERY, JSON.stringify({ id: selectedLooId })]);

const [doRemove, { loading: loadingRemove, error: removeError }] =
useMutation(REMOVE_LOO_MUTATION);
Expand All @@ -48,7 +48,7 @@ const RemovePage = function (props: { match: { params: { id: any; }; }; }) {
reason,
});

history.push(`/loos/${props.match.params.id}?message=removed`);
router.push(`/loos/${selectedLooId}?message=removed`);
};

if (removeError || looError) {
Expand All @@ -66,7 +66,7 @@ const RemovePage = function (props: { match: { params: { id: any; }; }; }) {
}

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

return (
Expand Down

0 comments on commit d61cb49

Please sign in to comment.