From a3254544e75ece6bec594a955d36c767fba0bec0 Mon Sep 17 00:00:00 2001 From: Tom Russell Date: Wed, 14 Aug 2019 16:03:47 +0100 Subject: [PATCH] Pull BuildingNotFound out of view/edit --- app/src/frontend/building/building-edit.tsx | 12 +++------ .../frontend/building/building-not-found.tsx | 26 +++++++++++++++++++ app/src/frontend/building/building-view.tsx | 11 ++------ 3 files changed, 31 insertions(+), 18 deletions(-) create mode 100644 app/src/frontend/building/building-not-found.tsx diff --git a/app/src/frontend/building/building-edit.tsx b/app/src/frontend/building/building-edit.tsx index b669d3e0..5af6c1fd 100644 --- a/app/src/frontend/building/building-edit.tsx +++ b/app/src/frontend/building/building-edit.tsx @@ -2,9 +2,10 @@ import React, { Component, Fragment } from 'react'; import { Link, NavLink, Redirect } from 'react-router-dom'; import PropTypes from 'prop-types'; +import Sidebar from './sidebar'; +import BuildingNotFound from './building-not-found'; import ErrorBox from '../components/error-box'; import InfoBox from '../components/info-box'; -import Sidebar from './sidebar'; import Tooltip from '../components/tooltip'; import { BackIcon, SaveIcon } from '../components/icons'; @@ -18,14 +19,7 @@ const BuildingEdit = (props) => { const sections = CONFIG.filter((d) => d.slug === cat) if (!props.building_id || sections.length !== 1){ - return ( - - -
- Back to categories -
-
- ); + return (); } const section = sections[0]; diff --git a/app/src/frontend/building/building-not-found.tsx b/app/src/frontend/building/building-not-found.tsx new file mode 100644 index 00000000..a1b8510a --- /dev/null +++ b/app/src/frontend/building/building-not-found.tsx @@ -0,0 +1,26 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { Link } from 'react-router-dom'; + +import Sidebar from './sidebar'; +import InfoBox from '../components/info-box'; + + +interface BuildingNotFoundProps { + mode: string +} + +const BuildingNotFound: React.FunctionComponent = (props) => ( + + +
+ Back to categories +
+
+); + +BuildingNotFound.propTypes = { + mode: PropTypes.string +} + +export default BuildingNotFound; diff --git a/app/src/frontend/building/building-view.tsx b/app/src/frontend/building/building-view.tsx index 672e9482..9f9dcc98 100644 --- a/app/src/frontend/building/building-view.tsx +++ b/app/src/frontend/building/building-view.tsx @@ -2,9 +2,9 @@ import React, { Fragment } from 'react'; import { Link, NavLink } from 'react-router-dom'; import PropTypes from 'prop-types'; +import BuildingNotFound from './building-not-found'; import Sidebar from './sidebar'; import Tooltip from '../components/tooltip'; -import InfoBox from '../components/info-box'; import { BackIcon, EditIcon } from '../components/icons'; import { sanitiseURL } from '../helpers'; @@ -15,14 +15,7 @@ const BuildingView = (props) => { const sections = CONFIG.filter((d) => d.slug === cat) if (!props.building_id || sections.length !== 1){ - return ( - - -
- Back to categories -
-
- ); + return (); } const section = sections[0];