This commit is contained in:
soupette 2019-04-16 18:05:12 +02:00
parent c7b7fddaba
commit d6e8ff0807
4 changed files with 117 additions and 29 deletions

View File

@ -11,14 +11,14 @@ import { Switch, Route } from 'react-router-dom';
import pluginId from '../../pluginId'; import pluginId from '../../pluginId';
// Containers // Containers
import HomePage from '../HomePage'; import HomePage from '../HomePage';
import NotFoundPage from '../NotFoundPage'; import { NotFound } from 'strapi-helper-plugin';
function App() { function App() {
return ( return (
<div className={pluginId}> <div className={pluginId}>
<Switch> <Switch>
<Route path={`/plugins/${pluginId}`} component={HomePage} exact /> <Route path={`/plugins/${pluginId}`} component={HomePage} exact />
<Route component={NotFoundPage} /> <Route component={NotFound} />
</Switch> </Switch>
</div> </div>
); );

View File

@ -1,14 +1,24 @@
// import { LOCATION_CHANGE } from 'react-router-redux';
import { cloneDeep, isArray } from 'lodash'; import { cloneDeep, isArray } from 'lodash';
import { all, takeLatest, put, fork, call, select } from 'redux-saga/effects'; import { all, takeLatest, put, fork, call, select } from 'redux-saga/effects';
import request from 'utils/request'; import { request } from 'strapi-helper-plugin';
import { GET_DOC_INFOS, ON_CONFIRM_DELETE_DOC, ON_UPDATE_DOC, ON_SUBMIT } from './constants'; import {
GET_DOC_INFOS,
ON_CONFIRM_DELETE_DOC,
ON_UPDATE_DOC,
ON_SUBMIT,
} from './constants';
import { getDocInfosSucceeded, setFormErrors } from './actions'; import { getDocInfosSucceeded, setFormErrors } from './actions';
import { makeSelectVersionToDelete, makeSelectPrefix, makeSelectForm } from './selectors'; import {
makeSelectVersionToDelete,
makeSelectPrefix,
makeSelectForm,
} from './selectors';
function* getData() { function* getData() {
try { try {
const response = yield call(request, '/documentation/getInfos', { method: 'GET' }); const response = yield call(request, '/documentation/getInfos', {
method: 'GET',
});
yield put(getDocInfosSucceeded(response)); yield put(getDocInfosSucceeded(response));
} catch (err) { } catch (err) {
strapi.notification.error('An error occurred'); strapi.notification.error('An error occurred');
@ -50,7 +60,9 @@ function* submit() {
if (body.restrictedAccess && body.password === '') { if (body.restrictedAccess && body.password === '') {
return yield put( return yield put(
setFormErrors({ password: [{ id: 'components.Input.error.validation.required' }] }), setFormErrors({
password: [{ id: 'components.Input.error.validation.required' }],
}),
); );
} }
@ -67,7 +79,10 @@ function* updateDoc(action) {
try { try {
const body = { version: action.version }; const body = { version: action.version };
const prefix = yield select(makeSelectPrefix()); const prefix = yield select(makeSelectPrefix());
const response = yield call(request, `${prefix}/regenerateDoc`, { method: 'POST', body }); const response = yield call(request, `${prefix}/regenerateDoc`, {
method: 'POST',
body,
});
if (response.ok) { if (response.ok) {
yield call(getData); yield call(getData);

View File

@ -1,20 +0,0 @@
/**
* NotFoundPage
*
* This is the page we show when the user visits a url that doesn't have a route
*
* NOTE: while this component should technically be a stateless functional
* component (SFC), hot reloading does not currently support SFCs. If hot
* reloading is not a neccessity for you then you can refactor it and remove
* the linting exception.
*/
import React from 'react';
import NotFound from 'components/NotFound';
export default class NotFoundPage extends React.Component {
render() {
return <NotFound {...this.props} />;
}
}

View File

@ -0,0 +1,93 @@
import React from 'react';
import { reduce } from 'lodash';
import pluginPkg from '../../package.json';
import pluginId from './pluginId';
import App from './containers/App';
const pluginDescription = pluginPkg.strapi.description || pluginPkg.description;
const formatMessages = messages =>
reduce(
messages,
(result, value, key) => {
result[`${pluginId}.${key}`] = value;
return result;
},
{},
);
const requireTranslations = language => {
try {
return require(`./translations/${language}.json`); // eslint-disable-line global-require
} catch (error) {
console.error(
`Unable to load "${language}" translation for the plugin ${pluginId}. Please make sure "${language}.json" file exists in "pluginPath/admin/src/translations" folder.`,
);
return;
}
};
const translationMessages = reduce(
strapi.languages,
(result, language) => {
result[language] = formatMessages(requireTranslations(language));
return result;
},
{},
);
// const layout = (() => {
// try {
// return require('../../config/layout.js'); // eslint-disable-line import/no-unresolved
// } catch (err) {
// return null;
// }
// })();
const injectedComponents = (() => {
try {
return require('./injectedComponents').default; // eslint-disable-line import/no-unresolved
} catch (err) {
return [];
}
})();
const initializer = (() => {
try {
return require('./initializer');
} catch (err) {
return null;
}
})();
const lifecycles = (() => {
try {
return require('./lifecycles');
} catch (err) {
return null;
}
})();
function Comp(props) {
return <App {...props} />;
}
const plugin = {
blockerComponent: null,
blockerComponentProps: {},
description: pluginDescription,
icon: pluginPkg.strapi.icon,
id: pluginId,
initializer,
injectedComponents,
layout: null,
lifecycles,
leftMenuLinks: [],
leftMenuSections: [],
mainComponent: Comp,
name: pluginPkg.strapi.name,
preventComponentRendering: false,
translationMessages,
};
export default plugin;