This guide provides a step-by-step approach to creating an employee module screen with essential functionality. Learn how to set up the module, create a sample card, and integrate links for individual search and create pages. Following these steps ensures modularity and reusability in your code, making it easier to manage and scale.
Steps
Create a Sample card within the Sample module. This card will display links to pages within the module, such as Individual Create and Individual Search.
Create a SampleCard.js file under the following path:
Hurray! Now you can see the Sample Card with 2 links on the screen as visible in the below screenshot:
Nothing is rendered when clicking on the label. We need to set up the routes to fix this.
Set Up Routes
Routing in an application is essential for navigation and managing different views or pages based on the URL.
Utilize a new file, index.js, to add all the routes for navigation. In the index.js file, we can create an App component where all the routes are defined. Then, in the module.js file, we import this App component as EmployeeApp and use it to render the screens within the module. This approach helps to organize the routing logic effectively, keeping the module.js file focused on the module's specific functionality.
Create the index.js under the following path:
micro-ui-internals/packages/modules/sample/src/pages/employee/index.js
In index.js, add the private route specifying the path and component name to render upon accessing that route. Ensure all components are correctly imported into this file.
Reference for Routing and index.js file is available here: Index.js
After adding routes in index.js, call them from module.js. The module.js file acts as the entry point, initializing components, hooks, and configurations. It renders the EmployeeApp component, which contains the routes and ensures the correct page is displayed.
In the Module.js add the following:
import { default as EmployeeApp } from "./pages/employee";
if (isLoading) {
return <Loader />;
}
return <EmployeeApp path={path} stateCode={stateCode} userType={userType} tenants={tenants} />;
};
The Sample Card is now visible with routes to the Respective Pages.
One link is for the Create Individual screen, and the other is for the Individual Search. You can view the code for the Create screen or set up the Create page by referring to the link here - Create-Screen
Registering Components
After registering all components, links and module code we need to enable it in two places:
In micro-ui/web/src/App.js, import the SampleModule, initSampleComponents, and enable the Sample module. Add App.js file under the following path: micro-ui/web/src/App.js
The reference for the App.js file is available here: App.js
In index.js, import SampleModule, initialize initSampleComponents, and enable the Sample module.
Create the index.js file under the following path:
micro-ui-internals/example/src/index.js