This guide offers a systematic view of how to create the application screens on DIGIT.
Developer code: Download the UI code from the link here Sanitation.
UI Development Pre-requisites
Technical pre-requisites
Knowledge of the DIGIT UI framework
Prior knowledge of React JS
Prior knowledge of Redux/Hooks
Prior knowledge of SCSS/React StoryBook
Prior knowledge of Git
Prior knowledge of Queries and Mutations
Citizen Module Setup
This section of the guide enables developers to create their own front-end citizen module from scratch which they can deploy on top of DIGIT UI. The new module will be visible as a ‘card’ in the DIGIT citizen portal.
Steps to build a citizen portal for a module:
Create Project Structure:
Project Structure
Front-end module project structure
Download the UI code from the link here Sanitation.
Follow the steps detailed in this doc.
Create Project Structure
Go to micro-ui--internals → packages → modules.
Inside the module, create a folder and provide a name for the service. For instance, the service name here is birth registration.
Create folder fsm (you can give any name).
Add the package.json to the created folder. Mention the module name and other dependencies here.
The FSM UI module needs to be registered in three places so that it will be available for the developer at run-time as well as at the time of deployment.
Below are the three places where the module needs to be registered:
In the example/package.json, add the following line:
"@egovernments/digit-ui-module-fsm":”1.6.1”,
In the web/package.json, add the following line:
"@egovernments/digit-ui-module-fsm":”1.6.1”,
Import Required Components:
DIGIT comes with common re-usable libraries that can be imported for use in a new module. CSS , libraries , common , react components can be imported by adding into package.json.
Common components live in micro-ui/web/micro-ui-internals/packages/react-components micro-ui/web/micro-ui-internals/packages/css. DIGIT components that we are reusing:
FormComposer
ActionBar
Banner
Card
CardText
Loader
SubmitBar
AppContainer
BackButton
PrivateRoute
Icons
CitizenHomecard
Write Citizen Module Code
This section will walk you through the code that needs to be developed for the application. Detailed user screen wireframes should be available at this point for development.
Following are the steps:
1. Create Application Form:
We need to create a form where users can enter all required information and submit the form. Create a file called index.js in the path below:
index.js will import the Formcomposer. Inside that, add the heading, label, and form components. The configuration file that will contain the actual form schema is mapped below in the following two lines. The newConfig.json file details are mentioned in the below sections:
import { newConfig } from "../../../components/config/config";
This file defines the form meta-data and structure. The form heading goes into the "head" field. Components inside the form go into the body field. This form config has already been mapped in the index.js file, and therefore, will be rendered onto the screen:
After adding the config.js and create/index.js, add routing for the birth registration form. Create the index.js into fsm/src/pages/citizen/index.js, where the private route will be added. In index.js, mention the path and component name, the component one needs to show or render when one hits that route.
Once the backend is set up, the hooks or service will be used to send the data to the backend after submitting the form. Add the onSubmit function in this file: (fsm/src/pages/citizen/create/index.js) and in that function, pass the user’s entered data to the BRService that has been created.
import { FormComposer, Loader } from "@egovernments/digit-ui-react-components";
import React, { useState } from "react";
import { useTranslation } from "react-i18next";
import { useHistory } from "react-router-dom";
import { newConfig } from "../../../components/config/config";
const Create = () => {
const tenantId = Digit.ULBService.getCurrentTenantId();
const { t } = useTranslation();
const history = useHistory();
const onSubmit = (data) => {
let Users = [
{
user: {
firstName: data?.FSMSelectName?.firstName,
lastName: data?.FSMSelectName?.lastName,
tenantId: tenantId,
},
},
];
/* use customiseCreateFormData hook to make some chnages to the Employee object */
Digit.FSMService.create(Users, tenantId).then((result,err)=>{
let getdata = {...data , get: result }
onSelect("", getdata, "", true);
console.log("daaaa",getdata);
})
.catch((e) => {
console.log("err");
});
history.push("/digit-ui/citizen/fsm/response");
console.log("getting data",Users)
};
/* use newConfig instead of commonFields for local development in case needed */
const configs = newConfig?newConfig:newConfig;
return (
<FormComposer
heading={t("FSM Registration")}
label={t("ES_COMMON_APPLICATION_SUBMIT")}
config={configs.map((config) => {
return {
...config,
body: config.body.filter((a) => !a.hideInEmployee),
};
})}
onSubmit={onSubmit}
fieldStyle={{ marginRight: 0 }}
/>
);
};
export default Create;
Once the integration is done, the data will be saved into the database.
Local Development Setup
The following tools have to be installed before development. Make sure to install the specific versions provided below. If no version is provided, it is assumed that the latest version can be installed.
Install Visual Studio Code. VS Code Extensions to be installed from the marketplace:
Install NodeJS 14.20.0
version 1.22.19
Clone the DIGIT-OSS repository locally from your organization's umbrella. This contains the frontend code under the frontend folder.
Build & Deploy
Go to the Jenkins build page. Click on SANITATION under the folder path mentioned below. frontend/sanitation-ui
Click on Build with parameter. Select the feature branch name by searching for it in the search box on the right side of the screen. Click on Build.
Once the build is successful, open the console output and find the docker image that has been built. Copy the docker image ID.
Copy the docker image IDs from the previous step and paste in the above box. Click on ‘Build’. Once the image is deployed, you will see a message as shown below:
Run the Application
After the application is built and deployed, run and test it in the local environment.
Configure Environment File - Citizen
To run the application in the local environment, add the .env file in the example folder - If the user is a citizen, configure the .env file as shown below:
Open Terminal in micro-UI-internals and run the following command:
yarn start
The application will start after you run the command.
Login
There are two types of login:
Employee:
Homepage Employee: After the login is successful for employees, users are redirected to the employee home page.
On the homepage, users can see the cards for FSM. These cards need to be added. Go through the link to create an employee card.
Homepage Citizen: After the login is successful for citizens, users are redirected to the citizen homepage.