Skip to content

Commit

Permalink
Pgr sandbox (#1360)
Browse files Browse the repository at this point in the history
* pgr

* pgr (#1357)

* fix (#1358)

* Update index.html

---------

Co-authored-by: nabeelmd-eGov <[email protected]>
  • Loading branch information
aaradhya-egov and nabeelmd-eGov authored Sep 5, 2024
1 parent 742f502 commit fedc0cd
Show file tree
Hide file tree
Showing 15 changed files with 242 additions and 70 deletions.
2 changes: 1 addition & 1 deletion micro-ui/web/micro-ui-internals/example/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
<div id="root"></div>
</body>

</html>
</html>
4 changes: 3 additions & 1 deletion micro-ui/web/micro-ui-internals/example/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ const initDigitUI = () => {
const pathname = window.location.pathname;
const context = window?.globalConfigs?.getConfig("CONTEXT_PATH");
const start = pathname.indexOf(context) + context.length + 1;
const end = pathname.indexOf("employee");
const employeeIndex = pathname.indexOf("employee");
const citizenIndex = pathname.indexOf("citizen");
const end = (employeeIndex !== -1) ? employeeIndex : (citizenIndex !== -1) ? citizenIndex : -1;
const tenant = end > start ? pathname.substring(start, end).replace(/\/$/, "") : "";
window.contextPath = window?.globalConfigs?.getConfig("CONTEXT_PATH") + `${tenant ? `/${tenant}` : ""}` || "digit-ui";
window.globalPath = window?.globalConfigs?.getConfig("CONTEXT_PATH") || "digit-ui";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,25 @@ export const ULBService = {
*/
getCurrentTenantId: () => {
// TODO: change when setter is done.

const user = UserService.getUser();
const isMultiRootTenant = window?.globalConfigs?.getConfig("MULTI_ROOT_TENANT") || false;
const pathname = window.location.pathname;
const context = window?.globalConfigs?.getConfig("CONTEXT_PATH");
const start = pathname.indexOf(context) + context.length + 1;
const employeeIndex = pathname.indexOf("employee");
const citizenIndex = pathname.indexOf("citizen");
const end = (employeeIndex !== -1) ? employeeIndex : (citizenIndex !== -1) ? citizenIndex : -1;
const tenant = end > start ? pathname.substring(start, end).replace(/\/$/, "") : "";
if (user?.extraRoleInfo) {
const isDsoRoute = Digit.Utils.detectDsoRoute(window.location.pathname);
if (isDsoRoute) {
return user.extraRoleInfo?.tenantId;
}
}

//TODO: fix tenant id from userinfo
const tenantId =
const tenantId = user?.info?.type !== "EMPLOYEE" && isMultiRootTenant && tenant ? tenant :
user?.info?.type === "EMPLOYEE" && user?.info?.tenantId ? user?.info?.tenantId : window?.globalConfigs.getConfig("STATE_LEVEL_TENANT_ID");
return tenantId;
},
Expand All @@ -56,7 +66,9 @@ export const ULBService = {
const pathname = window.location.pathname;
const context = window?.globalConfigs?.getConfig("CONTEXT_PATH");
const start = pathname.indexOf(context) + context.length + 1;
const end = pathname.indexOf("employee");
const employeeIndex = pathname.indexOf("employee");
const citizenIndex = pathname.indexOf("citizen");
const end = (employeeIndex !== -1) ? employeeIndex : (citizenIndex !== -1) ? citizenIndex : -1;
const tenant = end > start ? pathname.substring(start, end).replace(/\/$/, "") : "";

return isMultiRootTenant && tenant ? tenant : window?.globalConfigs?.getConfig("STATE_LEVEL_TENANT_ID");
Expand All @@ -74,7 +86,7 @@ export const ULBService = {
getCurrentUlb: () => {
const initData = StoreService.getInitData();
const tenantId = ULBService.getCurrentTenantId();
return initData?.tenants?.find((tenant) => tenant?.code === tenantId)||ULBService.getStateId();
return initData?.tenants?.find((tenant) => tenant?.code === tenantId) || ULBService.getStateId();
}
/**
* Custom method to get citizen's current selected city
Expand All @@ -88,12 +100,12 @@ export const ULBService = {
*
* @returns {String}
*/,
getCitizenCurrentTenant: (selectedCity=false) => {
const homeCity=Digit.SessionStorage.get("CITIZEN.COMMON.HOME.CITY")?.code;
if(selectedCity){
getCitizenCurrentTenant: (selectedCity = false) => {
const homeCity = Digit.SessionStorage.get("CITIZEN.COMMON.HOME.CITY")?.code;
if (selectedCity) {
return homeCity;
}
return homeCity|| Digit.UserService.getUser()?.info?.permanentCity || ULBService.getStateId();
return homeCity || Digit.UserService.getUser()?.info?.permanentCity || ULBService.getStateId();
},
/**
* Custom method to get all ulb's which the loggedin employee has access to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ const pgrAccess = () => {
const userInfo = Digit.UserService.getUser();
const userRoles = userInfo?.info?.roles?.map((roleData) => roleData?.code);
const pgrRoles = ["PGR_LME", "PGR-ADMIN", "CSR", "CEMP", "FEMP", "DGRO", "ULB Operator", "GRO", "GO", "RO", "GA"];

if (window.globalPath === "sandbox-ui") {
pgrRoles.push("SUPERUSER");
}
const PGR_ACCESS = userRoles?.filter((role) => pgrRoles.includes(role));

return PGR_ACCESS?.length > 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import {
BackButton,
BackLink,
CitizenHomeCard,
CitizenInfoLabel,
Loader,
FSMIcon,
MCollectIcon,
BillsIcon
} from "@egovernments/digit-ui-components";
import { CustomSVG } from "@egovernments/digit-ui-components";

import React, { Fragment } from "react";
import { useTranslation } from "react-i18next";
Expand All @@ -18,7 +16,12 @@ export const processLinkData = (newData, code, t) => {
const obj = newData?.[`${code}`];
if (obj) {
obj.map((link) => {
(link.link = link["navigationURL"]), (link.i18nKey = t(link["name"]));
if (window.globalPath === "sandbox-ui") {
link["navigationURL"] = link["navigationURL"].replace("/sandbox-ui/citizen", `/sandbox-ui/${Digit.ULBService.getCurrentTenantId()}/citizen`);
}
link.link = link["navigationURL"];
link.i18nKey = t(link["name"]);

});
}
const newObj = {
Expand Down Expand Up @@ -56,23 +59,23 @@ export const processLinkData = (newData, code, t) => {
const iconSelector = (code) => {
switch (code) {
case "PT":
return <PTIcon className="fill-path-primary-main" />;
return <CustomSVG.PTIcon className="fill-path-primary-main" />;
case "WS":
return <WSICon className="fill-path-primary-main" />;
return <CustomSVG.WSICon className="fill-path-primary-main" />;
case "FSM":
return <FSMIcon className="fill-path-primary-main" />;
return <CustomSVG.FSMIcon className="fill-path-primary-main" />;
case "MCollect":
return <MCollectIcon className="fill-path-primary-main" />;
return <CustomSVG.MCollectIcon className="fill-path-primary-main" />;
case "PGR":
return <PGRIcon className="fill-path-primary-main" />;
return <CustomSVG.PGRIcon className="fill-path-primary-main" />;
case "TL":
return <TLIcon className="fill-path-primary-main" />;
return <CustomSVG.TLIcon className="fill-path-primary-main" />;
case "OBPS":
return <OBPSIcon className="fill-path-primary-main" />;
return <CustomSVG.OBPSIcon className="fill-path-primary-main" />;
case "Bills":
return <BillsIcon className="fill-path-primary-main" />;
return <CustomSVG.BillsIcon className="fill-path-primary-main" />;
default:
return <PTIcon className="fill-path-primary-main" />;
return <CustomSVG.PTIcon className="fill-path-primary-main" />;
}
};
const CitizenHome = ({
Expand All @@ -88,14 +91,14 @@ const CitizenHome = ({
if (isLoading) {
return <Loader />;
}

return (
<React.Fragment>
<div className="citizen-all-services-wrapper">
{location.pathname.includes(
"sanitation-ui/citizen/all-services"
) ? null : (
<BackButton />
<BackLink />
)}
<div className="citizenAllServiceGrid">
{moduleArray
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
DeathIcon,
FirenocIcon,
Loader
} from "@egovernments/digit-ui-components";
} from "@egovernments/digit-ui-react-components";
import { Link, useLocation } from "react-router-dom";
import SideBarMenu from "../../../config/sidebar-menu";
import { useTranslation } from "react-i18next";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BackButton, CardHeader, CardLabelError, PageBasedInput, SearchOnRadioButtons } from "@egovernments/digit-ui-components";
import { BackLink, CardHeader, CardLabelError, PageBasedInput, SearchOnRadioButtons } from "@egovernments/digit-ui-components";
import React, { useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { useHistory, useLocation } from "react-router-dom";
Expand All @@ -7,7 +7,49 @@ const LocationSelection = () => {
const { t } = useTranslation();
const history = useHistory();
const location = useLocation();
const { data: cities, isLoading } = Digit.Hooks.useTenants();
let hookResult = { data: null, isLoading: false };

// Check the value of window.globalPath
if (window?.globalPath === 'sandbox-ui') {
// Call the useTenants hook only if the condition is met
hookResult = Digit.Hooks.useTenants();
}

// Destructure the result
const { data: cities, isLoading } = hookResult;
// Define the requestCriteria
let requestCriteria = null;

// Check the value of window.globalPath
if (window?.globalPath === 'sandbox-ui') {
requestCriteria = {
url: "/tenant-management/tenant/_search",
params: {
code: Digit.ULBService.getCurrentTenantId(),
includeSubTenants: true
},
body: {
"inbox": {
"limit": 10,
"offset": 0
},
apiOperation: "SEARCH",
},
config: {
select: (data) => {
return data?.Tenants;
},
},
};
}

// Use the requestCriteria only if it's not null
const { data: subTenants, refetch, isLoading: isLoadingSubTenants } = requestCriteria
? Digit.Hooks.useCustomAPIHook(requestCriteria)
: { data: null, refetch: () => {}, isLoading: false };

// Now you can use subTenants, refetch, and isLoadingSubTenants


const [selectedCity, setSelectedCity] = useState(() => ({ code: Digit.ULBService.getCitizenCurrentTenant(true) }));
const [showError, setShowError] = useState(false);
Expand All @@ -27,18 +69,21 @@ const LocationSelection = () => {

const RadioButtonProps = useMemo(() => {
return {
options: cities,
optionsKey: "i18nKey",
options: window?.globalPath === "sandbox-ui" ? subTenants : cities,
optionsKey: window?.globalPath === "sandbox-ui"? "name" :"i18nKey",
additionalWrapperClass: "digit-reverse-radio-selection-wrapper",
onSelect: selectCity,
selectedOption: selectedCity,
};
}, [cities, t, selectedCity]);
}, [subTenants,cities, t, selectedCity]);

function onSubmit() {
if (selectedCity) {
Digit.SessionStorage.set("CITIZEN.COMMON.HOME.CITY", selectedCity);
const redirectBackTo = location.state?.redirectBackTo;
if(window?.globalPath === "sandbox-ui"){
history.push(`/${window?.contextPath}/citizen/all-services`);
}
if (redirectBackTo) {
history.replace(redirectBackTo);
} else history.push(`/${window?.contextPath}/citizen`);
Expand All @@ -51,7 +96,7 @@ const LocationSelection = () => {
<loader />
) : (
<div className="selection-card-wrapper">
<BackButton />
<BackLink />
<PageBasedInput texts={texts} onSubmit={onSubmit} className="location-selection-container">
<CardHeader>{t("CS_COMMON_CHOOSE_LOCATION")}</CardHeader>
<SearchOnRadioButtons {...RadioButtonProps} placeholder={t("COMMON_TABLE_SEARCH")} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const Home = () => {
history.push(`/${window?.contextPath}/citizen/${redirectURL}`);
}
/* fix for sanitation ui */
if (window?.location?.href?.includes?.("sanitation-ui")) {
if (window?.location?.href?.includes?.("sanitation-ui")|| window?.location?.href?.includes?.("sandbox-ui")) {
history.push(`/${window?.contextPath}/citizen/all-services`);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CardText, CardLabelError, FormStep, OTPInput } from "@egovernments/digit-ui-components";
import { CardText, CardLabelError, FormStep } from "@egovernments/digit-ui-components";
import React, { Fragment, useState } from "react";
import useInterval from "../../../hooks/useInterval";
import { OTPInput } from "@egovernments/digit-ui-react-components";

const SelectOtp = ({ config, otp, onOtpChange, onResend, onSelect, t, error, userType = "citizen", canSubmit }) => {
const [timeLeft, setTimeLeft] = useState(30);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AppContainer, BackButton ,Toast} from "@egovernments/digit-ui-components";
import { AppContainer, BackLink ,Toast} from "@egovernments/digit-ui-components";
import React, { useEffect, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { Route, Switch, useHistory, useLocation, useRouteMatch } from "react-router-dom";
Expand Down Expand Up @@ -233,7 +233,7 @@ const Login = ({ stateCode, isUserRegistered = true }) => {
<div className="citizen-form-wrapper">
<Switch>
<AppContainer>
<BackButton />
<BackLink />
<Route path={`${path}`} exact>
<SelectMobileNumber
onSelect={selectMobileNumber}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BackButton, CitizenHomeCard, CitizenInfoLabel } from "@egovernments/digit-ui-components";
import { BackLink, CitizenHomeCard, CitizenInfoLabel } from "@egovernments/digit-ui-components";
import React from "react";
import { useTranslation } from "react-i18next";
import { Route, Switch, useHistory, useRouteMatch } from "react-router-dom";
Expand Down Expand Up @@ -51,7 +51,7 @@ const Home = ({
[
{
name: "actions-test",
filter: `[?(@.url == '${window.contextPath}-card')]`,
filter: `[?(@.url == '${window.globalPath === "sandbox-ui" ? window.globalPath : window.contextPath}-card')]`,
},
],
{
Expand All @@ -66,7 +66,6 @@ const Home = ({
},
}
);

const classname = Digit.Hooks.useRouteSubscription(pathname);
const { t } = useTranslation();
const { path } = useRouteMatch();
Expand Down Expand Up @@ -99,7 +98,7 @@ const Home = ({
<Route key={index} path={`${path}/${code.toLowerCase()}-home`}>
<div className="moduleLinkHomePage">
<img src={bannerImage || stateInfo?.bannerUrl} alt="noimagefound" />
<BackButton className="moduleLinkHomePageBackButton" />
<BackLink className="moduleLinkHomePageBackButton" />
<h1>{t("MODULE_" + code.toUpperCase())}</h1>
<div className="moduleLinkHomePageModuleLinks">
{mdmsDataObj && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@ const PGRCard = () => {
<path d="M20 2H4c-1.1 0-1.99.9-1.99 2L2 22l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-7 9h-2V5h2v6zm0 4h-2v-2h2v2z" fill="white"></path>
</svg>

let propsForCSR =[
{
label: t("ES_PGR_NEW_COMPLAINT"),
link: `/${window?.contextPath}/employee/pgr/complaint/create`,
role: "CSR"
}
]
let role = "CSR";

if (window.globalPath === "sandbox-ui") {
role = "SUPERUSER";
}

let propsForCSR = [
{
label: t("ES_PGR_NEW_COMPLAINT"),
link: `/${window?.contextPath}/employee/pgr/complaint/create`,
role: role
}
];

propsForCSR = propsForCSR.filter(link => link.role && Digit.Utils.didEmployeeHasRole(link.role) );

Expand Down
Loading

0 comments on commit fedc0cd

Please sign in to comment.