LogoLogo
Join our community
  • AdminJS
  • Contribute
  • Demo
  • Addons Marketplace
  • Installation
    • Getting started
    • Plugins
      • Adonis
      • Express
      • Nest
      • Fastify
      • Hapi
      • Koa
      • Community Plugins
        • FeathersJS
        • AdonisJS
      • Matrix
    • Adapters
      • TypeORM
      • Sequelize
      • Prisma
      • MikroORM
      • Objection
      • SQL
      • Mongoose
      • Community Adapters
        • AdonisJS
    • What's new in v7?
    • Migration Guide v7
  • Basics
    • Resource
    • Action
    • Property
    • Features
      • Relations
      • Upload
      • Logger
      • Import & Export
      • Password
      • Leaflet Maps
      • Writing your own features
    • API
      • List
      • New
      • Search
      • Show
      • Edit
      • Delete
      • Bulk Delete
    • Themes
    • Authentication
      • FirebaseAuthProvider
      • MatrixAuthProvider
  • How to write an addon?
  • UI Customization
    • Writing your own Components
    • Overwriting CSS styles
    • Dashboard customization
    • Changing the form view
    • Storybook
  • Tutorials
    • Role-Based Access Control
    • Internationalization (i18n)
    • Content Management System
    • Custom components library
    • Custom component internationalization
  • FAQ
    • PDF Generator
    • Charts
    • Forgot Password
  • ⚠️Legacy documentation
Powered by GitBook
On this page
  • Creating a React component for your dashboard
  • Configuring the dashboard to use your component
  • (Optional) Creating a handler for your dashboard to access server data
  1. UI Customization

Dashboard customization

PreviousOverwriting CSS stylesNextChanging the form view

Last updated 1 year ago

By default, AdminJS comes with a simple dashboard which you may want to customize in most cases.

The customization of the dashboard consists of two required and one optional steps:

  1. Creating a React component for your dashboard

  2. Configuring the dashboard to use your component

  3. (Optional) Creating a handler for your dashboard to access server data

Creating a React component for your dashboard

useTranslation hook can be imported from adminjs library:

import { useTranslation } from 'adminjs'

The rest of the code can be copied as is and worked on.

Configuring the dashboard to use your component

Assuming that this is your ComponentLoader:

import { ComponentLoader } from 'adminjs'

const componentLoader = new ComponentLoader()

const Components = {
  Dashboard: componentLoader.add('Dashboard', './dashboard'),
  // other custom components
}

This would be how you override the dashboard:

const admin = new AdminJS({
  dashboard: {
    component: Components.Dashboard,
  },
  componentLoader
})

Restart your server and you should see your new, customized dashboard.

(Optional) Creating a handler for your dashboard to access server data

In some cases you might want to access backend data in your dashboard, for example when you would like to display charts or statistics in general. To do this, you have to create a handler for you dashboard.

const dashboardHandler = async () => {
  // Asynchronous code where you, e. g. fetch data from your database
  
  return { message: 'Hello World' }
}

The handler your create has to be assigned to dashboard option in your AdminJS instance:

const admin = new AdminJS({
  dashboard: {
    component: Components.Dashboard,
    handler: dashboardHandler,
  },
  componentLoader
})

You now have the logic for returning the data to the frontend, the last part is accessing it in your dashboard component. To do this, you can use AdminJS's ApiClient in your React component:

import { ApiClient } from 'adminjs'
import React, { useEffect, useState } from 'react'

// ...
const [data, setData] = useState(null)
const api = new ApiClient()

useEffect(() => {
  api.getDashboard()
    .then((response) => {
      setData(response.data) // { message: 'Hello World' }
    })
    .catch((error) => {
      // handle any errors
    });
}, [])

// ...

console.log(data.message) // "Hello World"

Save your component, restart your server and you're good to go.

This step requires you to create a React component which is pretty much straightforward. Please refer to the to get started.

Now you will have to tell AdminJS to use your dashboard. This can be achieved by configuring the dashboard option when instantiating AdminJS. Please refer to tutorial to find out how you can bundle your dashboard component.

source code of default dashboard
"Writing your own Components"
Default Dashboard