Skip to content
Merged
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: 8 additions & 2 deletions src/lib/api/banners/banner.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { http } from '@api/base';
import { getSearchTotal } from '@api/utils';

const bannerURL = '/banners/';

const getActive = async () => {
const URLPath = window.location.pathname;
return await http.get(`${bannerURL}active`, {
params: { url_path: URLPath },
const response = await http.get(`${bannerURL}`, {
params: { url_path: URLPath, active: true },
});

response.data.total = getSearchTotal(response.data.hits);
response.data.hits = response.data.hits.hits;

return response;
};

export const bannerApi = {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/authentication/pages/Login/Login.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { parseParams } from '@authentication/utils';
import { EnvironmentLabel } from '@components/EnvironmentLabel';
import { Media } from '@components/Media';
import { Banner } from '@components/Banner';
import { Banners } from '@components/Banners';
import { Notifications } from '@components/Notifications';
import { invenioConfig } from '@config';
import { goTo } from '@history';
Expand Down Expand Up @@ -248,7 +248,7 @@ class Login extends Component {
return (
<>
<Overridable id="Login.extras">
<Banner />
<Banners />
</Overridable>
<LoginLayout
hasError={hasError}
Expand Down
18 changes: 0 additions & 18 deletions src/lib/components/Banner/index.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ const BannerCmp = ({ message, category }) => {
default:
break;
}

return (
<Overridable
id="Banner.layout"
id="Banners.layout"
message={message}
category={category}
colorProp={colorProp}
Expand All @@ -37,45 +38,56 @@ BannerCmp.propTypes = {
category: PropTypes.string.isRequired,
};

class Banner extends Component {
class Banners extends Component {
componentDidMount() {
const { fetchBanner, resetBanner } = this.props;
resetBanner();
fetchBanner();
this.intervalFetchBannerId = setInterval(
fetchBanner,
const { fetchBanners, resetBanners } = this.props;
resetBanners();
fetchBanners();
this.intervalfetchBannersId = setInterval(
fetchBanners,
FETCH_BANNER_EVERY_SECS * 1000
);
}

componentWillUnmount() {
this.intervalFetchBannerId && clearInterval(this.intervalFetchBannerId);
this.intervalfetchBannersId && clearInterval(this.intervalfetchBannersId);
}

render() {
const { banner, children } = this.props;
const { banners, children } = this.props;

return (
<>
{!_isEmpty(banner) ? <BannerCmp {...banner} /> : null} {children}
{!_isEmpty(banners)
? banners.hits.map((banner) => (
<BannerCmp key={banner.id} {...banner} />
))
: null}{' '}
{children}
</>
);
}
}

Banner.propTypes = {
Banners.propTypes = {
children: PropTypes.node,
/* REDUX */
banner: PropTypes.shape({
message: PropTypes.string,
category: PropTypes.string,
banners: PropTypes.shape({
hits: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string.isRequired,
message: PropTypes.string.isRequired,
category: PropTypes.string.isRequired,
})
),
}),
fetchBanner: PropTypes.func.isRequired,
resetBanner: PropTypes.func.isRequired,
fetchBanners: PropTypes.func.isRequired,
resetBanners: PropTypes.func.isRequired,
};

Banner.defaultProps = {
banner: null,
Banners.defaultProps = {
banners: null,
children: null,
};

export default Overridable.component('Banner', Banner);
export default Overridable.component('Banners', Banners);
18 changes: 18 additions & 0 deletions src/lib/components/Banners/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { connect } from 'react-redux';
import BannerComponent from './Banners';
import { fetchBanners, resetBanners } from './state/actions';

const mapStateToProps = (state) => ({
banners: state.banners.data,
error: state.banners.error,
});

const mapDispatchToProps = (dispatch) => ({
fetchBanners: () => dispatch(fetchBanners()),
resetBanners: () => dispatch(resetBanners()),
});

export const Banners = connect(
mapStateToProps,
mapDispatchToProps
)(BannerComponent);
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { bannerApi } from '@api/banners';

export const BANNER_RESET = 'fetchBanner/RESET';
export const BANNER_SUCCESS = 'fetchBanner/SUCCESS';
export const BANNER_HAS_ERROR = 'fetchBanner/HAS_ERROR';
export const BANNER_RESET = 'fetchBanners/RESET';
export const BANNER_SUCCESS = 'fetchBanners/SUCCESS';
export const BANNER_HAS_ERROR = 'fetchBanners/HAS_ERROR';

export const resetBanner = () => {
export const resetBanners = () => {
return async (dispatch) =>
dispatch({
type: BANNER_RESET,
});
};

export const fetchBanner = () => {
export const fetchBanners = () => {
return async (dispatch) => {
try {
const response = await bannerApi.getActive();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const initialState = {
error: {},
};

export const fetchBannerReducer = (state = initialState, action) => {
export const fetchBannersReducer = (state = initialState, action) => {
switch (action.type) {
case BANNER_RESET:
return {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/backoffice/Sidebar/AdminMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export default class AdminMenu extends Component {
<Menu.Menu>
<Menu.Item
as="a"
href={`${invenioConfig.APP.INVENIO_UI_URL}/admin`}
href={`${invenioConfig.APP.INVENIO_UI_URL}/administration`}
target="_blank"
>
Admin panel
</Menu.Item>
<Menu.Item
as="a"
href={`${invenioConfig.APP.INVENIO_UI_URL}/admin/page`}
href={`${invenioConfig.APP.INVENIO_UI_URL}/administration/pages`}
target="_blank"
>
Static pages
Expand Down
4 changes: 2 additions & 2 deletions src/lib/reducers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { authenticationReducer } from '@authentication/reducer';
import { deleteRecordModalReducer } from '@components/backoffice/DeleteRecordModal/reducer';
import { fetchBannerReducer } from '@components/Banner/state/reducer';
import { fetchBannersReducer } from '@components/Banners/state/reducer';
import { notificationsReducer } from '@components/Notifications/reducer';
import { overdueLoanSendNotificationModalReducer } from '@modules/Loan/backoffice/OverdueLoanSendNotificationModal/reducer';
import { loanActionReducer, loanDetailsReducer } from '@modules/Loan/reducer';
Expand Down Expand Up @@ -123,7 +123,7 @@ export default function createILSReducer(asyncReducers) {
borrowingRequestLoanExtension: borrowingRequestLoanExtensionReducer,
itemsCheckIn: itemsCheckInReducer,
checkOut: checkOutReducer,
banner: fetchBannerReducer,
banners: fetchBannersReducer,
bulkLoanExtend: patronBulkExtendLoans,
...asyncReducers,
});
Expand Down
4 changes: 2 additions & 2 deletions src/lib/routes/backoffice/BackOffice.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Sidebar } from '@components/backoffice/Sidebar';
import { Banner } from '@components/Banner';
import { Banners } from '@components/Banners';
import { Notifications } from '@components/Notifications';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
Expand All @@ -12,7 +12,7 @@ export class BackOffice extends Component {
return (
<>
<Overridable id="BackOffice.extras">
<Banner />
<Banners />
</Overridable>
<div className="backoffice">
<div className="bo-sidebar">
Expand Down
4 changes: 2 additions & 2 deletions src/lib/routes/frontsite/Frontsite.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Banner } from '@components/Banner';
import { Banners } from '@components/Banners';
import { NotFound } from '@components/HttpErrors';
import { ILSFooter } from '@components/ILSFooter';
import { ILSMenu } from '@components/ILSMenu';
Expand Down Expand Up @@ -38,7 +38,7 @@ export default class FrontSite extends Component {
<Notifications className="compact" />
<Container fluid className="fs-content">
<Overridable id="FrontSite.extras">
<Banner />
<Banners />
</Overridable>
<Switch>
<Route
Expand Down
Loading