Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions src/components/pages/AdminPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import React from 'react';
import PropTypes from 'prop-types';
import { defineMessages, FormattedMessage } from 'react-intl';
import { Redirect, Route, Switch } from 'react-router';
import Immutable from 'immutable';
import { useSelector } from 'react-redux';
import AccountPageContainer from '../../containers/pages/AccountPageContainer';
import AuthRolePageContainer from '../../containers/pages/AuthRolePageContainer';
import AdminNavBar from '../admin/AdminNavBar';
import TitleBar from '../sections/TitleBar';
import { canList } from '../../helpers/permissionHelpers';
import styles from '../../../styles/cspace-ui/AdminPage.css';
import { getAdminTab, getUserPerms } from '../../reducers';

const messages = defineMessages({
title: {
Expand All @@ -26,17 +27,16 @@ const propTypes = {
match: PropTypes.shape({
url: PropTypes.string,
}),
perms: PropTypes.instanceOf(Immutable.Map),
preferredTab: PropTypes.string,
};

export default function AdminPage(props) {
const {
match,
perms,
preferredTab,
} = props;

const perms = useSelector(getUserPerms);
const preferredTab = useSelector(getAdminTab);

const basename = match.url;
const title = <FormattedMessage {...messages.title} />;
const permittedTabs = tabs.filter((tab) => canList(tab, perms));
Expand Down
7 changes: 4 additions & 3 deletions src/components/pages/AuthorizePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import { useEffect } from 'react';
import PropTypes from 'prop-types';
import get from 'lodash/get';
import { useDispatch } from 'react-redux';
import { createAuthCodeUrl } from '../../actions/login';

const propTypes = {
config: PropTypes.shape({
serverUrl: PropTypes.string,
}),
createAuthCodeUrl: PropTypes.func.isRequired,
location: PropTypes.shape({
state: PropTypes.object,
}).isRequired,
Expand All @@ -21,8 +22,8 @@ const contextTypes = {
};

export default function AuthorizePage(props, context) {
const dispatch = useDispatch();
const {
createAuthCodeUrl,
location,
} = props;

Expand All @@ -33,7 +34,7 @@ export default function AuthorizePage(props, context) {
const landingPath = get(location, ['state', 'continuation']) || '';

useEffect(() => {
createAuthCodeUrl(config, landingPath).then((url) => {
dispatch(createAuthCodeUrl(config, landingPath)).then((url) => {
window.location.replace(url);
});
}, []);
Expand Down
28 changes: 16 additions & 12 deletions src/components/pages/AuthorizedPage.jsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import React, { useEffect } from 'react';
import PropTypes from 'prop-types';
import Immutable from 'immutable';
import { useDispatch, useSelector } from 'react-redux';
import LoginForm from '../login/LoginForm';
import styles from '../../../styles/cspace-ui/AuthorizedPage.css';
import {
getLoginError,
getLoginLandingPath,
isLoginPending as isLoginPendingSelector,
isLoginSuccess as isLoginSuccessSelector,
} from '../../reducers';
import { receiveAuthCode } from '../../actions/login';

const propTypes = {
history: PropTypes.shape({
replace: PropTypes.func.isRequired,
}).isRequired,
isLoginPending: PropTypes.bool,
isLoginSuccess: PropTypes.bool,
landingPath: PropTypes.string,
location: PropTypes.shape({
search: PropTypes.string,
}).isRequired,
loginError: PropTypes.instanceOf(Immutable.Map),
receiveAuthCode: PropTypes.func.isRequired,
};

const contextTypes = {
Expand All @@ -30,13 +32,16 @@ export default function AuthorizedPage(props, context = {}) {
} = context;

const {
isLoginPending,
isLoginSuccess,
location,
loginError,
receiveAuthCode,
} = props;

const isLoginPending = useSelector(isLoginPendingSelector);
const isLoginSuccess = useSelector(isLoginSuccessSelector);
const landingPath = useSelector(getLoginLandingPath);
const loginError = useSelector(getLoginError);

const dispatch = useDispatch();

useEffect(() => {
const {
search,
Expand All @@ -46,14 +51,13 @@ export default function AuthorizedPage(props, context = {}) {
const authCodeRequestId = params.get('state');
const authCode = params.get('code');

receiveAuthCode(config, authCodeRequestId, authCode);
dispatch(receiveAuthCode(config, authCodeRequestId, authCode));
}, []);

useEffect(() => {
if (isLoginSuccess) {
const {
history,
landingPath,
} = props;

history.replace(landingPath);
Expand Down
12 changes: 6 additions & 6 deletions src/components/pages/RootPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import { Helmet } from 'react-helmet';
import classNames from 'classnames';
import ProtectedRouteContainer from '../../containers/routes/ProtectedRouteContainer';
import PublicRoute from '../routes/PublicRoute';
import AdminPageContainer from '../../containers/pages/AdminPageContainer';
import AuthorizePageContainer from '../../containers/pages/AuthorizePageContainer';
import AuthorizedPageContainer from '../../containers/pages/AuthorizedPageContainer';
import ConfigPage from './ConfigPage';
import ContentViewerPageContainer from '../../containers/pages/ContentViewerPageContainer';
import CreatePageContainer from '../../containers/pages/CreatePageContainer';
Expand All @@ -24,6 +21,9 @@ import SearchResultPageContainer from '../../containers/pages/SearchResultPageCo
import NotificationBarContainer from '../../containers/notification/NotificationBarContainer';
import styles from '../../../styles/cspace-ui/RootPage.css';
import favicon from '../../../images/favicon.png';
import AdminPage from './AdminPage';
import AuthorizedPage from './AuthorizedPage';
import AuthorizePage from './AuthorizePage';

const messages = defineMessages({
title: {
Expand Down Expand Up @@ -66,13 +66,13 @@ function RootPage(props) {
<PublicRoute path="/welcome" component={WelcomePage} />
<PublicRoute path="/logout" component={LogoutPageContainer} decorated={false} />
<PublicRoute path="/config" component={ConfigPage} />
<PublicRoute path="/authorize" component={AuthorizePageContainer} decorated={false} />
<PublicRoute path="/authorized" component={AuthorizedPageContainer} decorated={false} />
<PublicRoute path="/authorize" component={AuthorizePage} decorated={false} />
<PublicRoute path="/authorized" component={AuthorizedPage} decorated={false} />

<ProtectedRouteContainer path="/dashboard" component={DashboardPage} />
<ProtectedRouteContainer path="/create" component={injectIntl(CreatePageContainer)} />
<ProtectedRouteContainer path="/tool" component={ToolPageContainer} />
<ProtectedRouteContainer path="/admin" component={AdminPageContainer} />
<ProtectedRouteContainer path="/admin" component={AdminPage} />

<ProtectedRouteContainer
path="/search/:recordType?/:vocabulary?"
Expand Down
16 changes: 0 additions & 16 deletions src/containers/pages/AdminPageContainer.js

This file was deleted.

15 changes: 0 additions & 15 deletions src/containers/pages/AuthorizePageContainer.js

This file was deleted.

26 changes: 0 additions & 26 deletions src/containers/pages/AuthorizedPageContainer.js

This file was deleted.

46 changes: 0 additions & 46 deletions test/specs/containers/pages/AdminPageContainer.spec.jsx

This file was deleted.