Skip to content

Commit

Permalink
Fix incorrect url of login modal when authorization expires.
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-lee committed Dec 5, 2023
1 parent 66503d8 commit 28215f1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cspace-ui",
"version": "9.0.0-dev.4",
"version": "9.0.0-dev.5",
"description": "CollectionSpace user interface for browsers",
"author": "Ray Lee <ray.lee@lyrasis.org>",
"license": "ECL-2.0",
Expand Down
5 changes: 2 additions & 3 deletions src/actions/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
} from '../constants/actionCodes';

export const LOGIN_WINDOW_NAME = 'cspace-login';
export const AUTHORIZE_PAGE_URL = '/authorize';

const renewAuth = (config, authCode, authCodeRequestData = {}) => (dispatch) => {
const {
Expand Down Expand Up @@ -266,7 +265,7 @@ export const receiveAuthCode = (
return dispatch(login(config, authCode, authCodeRequestData));
};

export const openLoginWindow = () => {
export const openLoginWindow = (url) => {
const popupWidth = 550;
const popupHeight = 800;

Expand All @@ -277,7 +276,7 @@ export const openLoginWindow = () => {
const top = (screenHeight - popupHeight) / 2;

const popup = window.open(
AUTHORIZE_PAGE_URL,
url,
LOGIN_WINDOW_NAME,
`width=${popupWidth},height=${popupHeight},left=${left},top=${top}`,
);
Expand Down
24 changes: 20 additions & 4 deletions src/components/login/LoginLink.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import PropTypes from 'prop-types';
import { defineMessages, FormattedMessage } from 'react-intl';
import { Link } from 'react-router-dom';
import { AUTHORIZE_PAGE_URL } from '../../actions/login';
import styles from '../../../styles/cspace-ui/LoginLink.css';

const propTypes = {
Expand All @@ -13,6 +12,12 @@ const defaultProps = {
openLoginWindow: null,
};

const contextTypes = {
config: PropTypes.shape({
recordTypes: PropTypes.object,
}),
};

const messages = defineMessages({
label: {
id: 'loginLink.label',
Expand All @@ -26,29 +31,40 @@ const messages = defineMessages({
},
});

export default function LoginLink(props) {
export default function LoginLink(props, context) {
const {
openLoginWindow,
} = props;

const authorizePath = '/authorize';

let handleClick;

if (openLoginWindow) {
const {
config,
} = context;

const {
basename,
} = config;

handleClick = (event) => {
event.preventDefault();

openLoginWindow();
openLoginWindow(`${basename}${authorizePath}`);
};
}

const message = openLoginWindow ? messages.openLabel : messages.label;

return (
<Link className={styles.common} to={AUTHORIZE_PAGE_URL} onClick={handleClick}>
<Link className={styles.common} to={authorizePath} onClick={handleClick}>
<FormattedMessage {...message} />
</Link>
);
}

LoginLink.propTypes = propTypes;
LoginLink.defaultProps = defaultProps;
LoginLink.contextTypes = contextTypes;

0 comments on commit 28215f1

Please sign in to comment.