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 registeringall 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
Reference for the Index.js file is available here: Index.js
Create Form - Create Screen
Introduction
The guide walks you through the steps required to create and integrate a form within a micro-frontend architecture using the DIGIT framework. You will learn how to set up the form configuration, create a custom component, and integrate the form with backend APIs.
Steps
Create Application Form
Create a form where users can enter all required information and submit the form.
Update the Index.js file with routes.
Index.js will import FormcomposerV2. Add the heading, label, and form components inside it. Import the configuration file containing the form schema mapping detail (refer to the code below) into the create screen.
import { newConfig } from "../../configs/IndividualCreateConfig";
const configs = newConfig?newConfig:newConfig;
An example of a Create Screen is given below. Create a page IndividualCreate.js under the following path:
The configuration file outlines the form's meta-data and structure. The "head" field contains the form heading, while the form's components are placed in the "body" field.
This configuration file is imported into the Create screen.
To meet unique requirements, we can design custom components in our application.
Begin by creating a custom component featuring the necessary specifications. The Panel component displays responsive messages, similar to informational cards. This enables users to display dynamic text.
To include the Panel Component in your configuration file, specify the component name and type as "component". Refer to the code below to find how to do it:
Access the create form screen by navigating to the URL below.
/sample/create-individual
The screen is similar to the image below, illustrating the Create Form.
Integration with Backend API
We have completed the UI for the Employee module. Now, let's integrate it with the backend API.
Hooks
We will implement custom hooks in our code to handle data transfers to the backend. These hooks will make API calls and format the responses accordingly.
Refer to the link - Common Hooks
After setting up the backend service, we will use hooks or a service to send data to the backend upon form submission.
This On Submit function is added to the Create screen.
Refer to the file here - IndividualCreate.js
Once the integration is complete the data is saved into the database.
Employee Module Setup
Employee view of the module
Now that we are done with setting up the citizen module, the next step is to build the employee portal on top of the DIGIT UI for the Birth Registration module. The employee portal is designed to support multiple workflows like verifying the information and approving or rejecting the registered details of citizens.
Build the employee portal for a module - Steps
The guide provides examples and illustrations on how to set up and integrate the most commonly used DIGIT UI libraries.