Skip to content

Commit

Permalink
Add option to change the logo of the login page
Browse files Browse the repository at this point in the history
  • Loading branch information
soupette committed Aug 9, 2019
1 parent 668dac6 commit 25d7fad
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/strapi-admin/admin/src/config.js
@@ -1 +1,2 @@
export const LOGIN_LOGO = null;
export const SHOW_TUTORIALS = true;
Expand Up @@ -10,6 +10,8 @@ import { get } from 'lodash';

import Helmet from 'react-helmet';
import { BlockerComponent } from 'strapi-helper-plugin';

import { LOGIN_LOGO } from '../../config';
import ErrorBoundary from '../ErrorBoundary';

export function PluginDispatcher(props) {
Expand Down Expand Up @@ -46,7 +48,11 @@ export function PluginDispatcher(props) {
<div>
<Helmet title={`Strapi - ${name}`} />
<ErrorBoundary>
<PluginEntryComponent {...props} {...blockerComponentProps} />
<PluginEntryComponent
{...props}
{...blockerComponentProps}
assets={{ loginLogo: LOGIN_LOGO }}
/>
</ErrorBoundary>
</div>
);
Expand Down
28 changes: 28 additions & 0 deletions packages/strapi-admin/doc/change-the-login-page-logo.md
@@ -0,0 +1,28 @@
# Change the logo of the login page

In order to change the logo of the login page follow these steps:

### 1 Add your new logo in your `./my-project/admin/src/<mylogo>.png`'s folder project (the location doesn't matter)

### 2 Create a configuration file:

**`Path: ./my-project/admin/src/config.js`**

```js
import MyLogo from './<mylogo>.png';

export const LOGIN_LOGO = MyLogo;
export const SHOW_TUTORIALS = true;
```

### 3 Rebuild your app

```js
# Using yarn

yarn build

# Using npm

npm run build
```
Expand Up @@ -29,13 +29,15 @@ class App extends React.Component {
}
}

renderRoute = props => <AuthPage {...this.props} {...props} />;

render() {
return (
<div className={pluginId}>
<Switch>
<Route
path={`/plugins/${pluginId}/auth/:authType/:id?`}
component={AuthPage}
render={this.renderRoute}
exact
/>
<Route
Expand Down
Expand Up @@ -83,6 +83,14 @@ export class AuthPage extends React.Component {
return get(formErrors, ['0', 'errors', '0', 'id']);
};

getLogo = () => {
const {
assets: { loginLogo },
} = this.props;

return loginLogo || LogoStrapi;
};

setForm = () => {
const {
location: { search },
Expand Down Expand Up @@ -202,7 +210,7 @@ export class AuthPage extends React.Component {
renderLogo = () =>
this.isAuthType('register') && (
<div className={styles.logoContainer}>
<img src={LogoStrapi} alt="logo" />
<img src={this.getLogo()} alt="logo" />
</div>
);

Expand Down Expand Up @@ -248,9 +256,9 @@ export class AuthPage extends React.Component {
return map(inputs, (input, key) => {
const label = isForgotEmailSent
? {
id:
id:
'users-permissions.Auth.form.forgot-password.email.label.success',
}
}
: get(input, 'label');

return (
Expand Down Expand Up @@ -278,6 +286,7 @@ export class AuthPage extends React.Component {

render() {
const { modifiedData, noErrorsDescription, submitSuccess } = this.props;

let divStyle = this.isAuthType('register')
? { marginTop: '3.2rem' }
: { marginTop: '.9rem' };
Expand All @@ -293,7 +302,7 @@ export class AuthPage extends React.Component {
{this.isAuthType('register') ? (
<FormattedMessage id="users-permissions.Auth.form.header.register" />
) : (
<img src={LogoStrapi} alt="logo" />
<img src={this.getLogo()} alt="logo" />
)}
</div>
<div className={styles.headerDescription}>
Expand All @@ -307,7 +316,7 @@ export class AuthPage extends React.Component {
styles.formContainer,
this.isAuthType('forgot-password') && submitSuccess
? styles.borderedSuccess
: styles.bordered,
: styles.bordered
)}
style={divStyle}
>
Expand Down Expand Up @@ -346,7 +355,12 @@ AuthPage.contextTypes = {
updatePlugin: PropTypes.func,
};

AuthPage.defaultProps = {
assets: { loginLogo: null },
};

AuthPage.propTypes = {
assets: PropTypes.object,
didCheckErrors: PropTypes.bool.isRequired,
formErrors: PropTypes.array.isRequired,
hideLoginErrorsInput: PropTypes.func.isRequired,
Expand All @@ -373,13 +387,13 @@ function mapDispatchToProps(dispatch) {
setForm,
submit,
},
dispatch,
dispatch
);
}

const withConnect = connect(
mapStateToProps,
mapDispatchToProps,
mapDispatchToProps
);
const withReducer = window.strapi.injectReducer({
key: 'authPage',
Expand All @@ -391,5 +405,5 @@ const withSaga = window.strapi.injectSaga({ key: 'authPage', saga, pluginId });
export default compose(
withReducer,
withSaga,
withConnect,
withConnect
)(AuthPage);

0 comments on commit 25d7fad

Please sign in to comment.