Skip to content

Commit

Permalink
Added URC for citizrn and employee in create flow (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
rakesh-wt-egov committed Apr 1, 2023
1 parent 8ffaef6 commit bec377c
Show file tree
Hide file tree
Showing 11 changed files with 770 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const Urls = {
location: {
localities: `/egov-location/location/v11/boundarys/_search?hierarchyTypeCode=ADMIN&boundaryType=Locality`,
revenue_localities: `/egov-location/location/v11/boundarys/_search?hierarchyTypeCode=REVENUE&boundaryType=Locality`,
gramPanchayats: `/egov-location/location/v11/boundarys/_search?hierarchyTypeCode=REVENUE&boundaryType=GramPanchayat`,
},

pgr_search: `/pgr-services/v2/request/_search`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,13 @@ export const LocationService = {
});
return response;
},
getGramPanchayats: async (tenantId) => {
const response = await ServiceRequest({
serviceName: "getGramPanchayats",
url: Urls.location.gramPanchayats,
params: { tenantId: tenantId },
useCache: true,
});
return response;
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ export const getLocalities = {
await StoreService.defaultData(tenant, tenant, Digit.StoreData.getCurrentLanguage());
return (await LocationService.getRevenueLocalities(tenant)).TenantBoundary[0];
},
grampanchayats: async (tenant) => {
await StoreService.defaultData(tenant, tenant, Digit.StoreData.getCurrentLanguage());
return (await LocationService.getGramPanchayats(tenant)).TenantBoundary[0];
},
};
2 changes: 2 additions & 0 deletions web/micro-ui-internals/packages/modules/fsm/src/Module.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import AdvanceCollection from "./pageComponents/AdvanceCollection";
import SelectTrips from "./pageComponents/SelectTrips";
import PlusMinusInput from "./pageComponents/PlusMinusInput";
import ConfirmationBox from "./components/Confirmation";
import SelectLocalityOrGramPanchayat from "./pageComponents/SelectLocalityOrGramPanchayat";

const FSMModule = ({ stateCode, userType, tenants }) => {
const moduleCode = "FSM";
Expand Down Expand Up @@ -203,6 +204,7 @@ const componentsToRegister = {
SelectTrips,
PlusMinusInput,
ConfirmationBox,
SelectLocalityOrGramPanchayat,
};

export const initFSMComponents = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
import { CardLabel, Dropdown, FormStep, LabelFieldPair } from "@egovernments/digit-ui-react-components";
import _ from "lodash";
import React, { useEffect, useState } from "react";
import { useForm } from "react-hook-form";
import Timeline from "../components/TLTimelineInFSM";

const SelectLocalityOrGramPanchayat = ({ t, config, onSelect, userType, formData, formState }) => {
const allCities = Digit.Hooks.fsm.useTenants();
let tenantId = Digit.ULBService.getCurrentTenantId();
const { pincode, city, propertyLocation } = formData?.address || "";
const cities =
userType === "employee"
? allCities.filter((city) => city.code === tenantId)
: pincode
? allCities.filter((city) => city?.pincode?.some((pin) => pin == pincode))
: allCities;
const [selectedLocality, setSelectedLocality] = useState();
const [localities, setLocalities] = useState();
const [gramPanchayats, setGramPanchayats] = useState();
const [selectedGp, setSelectedGp] = useState();
const [villages, setVillages] = useState();
const [selectedVillage, setSelectedVillage] = useState();

const [selectedCity, setSelectedCity] = useState(() => formData?.address?.city || Digit.SessionStorage.get("fsm.file.address.city") || null);
useEffect(() => {
if (cities) {
if (cities.length === 1) {
setSelectedCity(cities[0]);
}
}
}, [cities]);
var { data: fetchedGramPanchayats } = Digit.Hooks.useBoundaryLocalities(
selectedCity?.code,
"gramPanchayats",
{
enabled: !!selectedCity,
},
t
);

var { data: fetchedLocalities } = Digit.Hooks.useBoundaryLocalities(
selectedCity?.code,
"revenue",
{
enabled: !!selectedCity,
},
t
);

useEffect(() => {
if (selectedCity && fetchedLocalities) {
let __localityList = fetchedLocalities;
let filteredLocalityList = [];

if (formData?.address?.locality) {
setSelectedLocality(formData.address.locality);
}

if (formData?.address?.pincode) {
filteredLocalityList = __localityList.filter((obj) => obj.pincode?.find((item) => item == formData.address.pincode));
if (!formData?.address?.locality) setSelectedLocality();
}
setLocalities(() => (filteredLocalityList.length > 0 ? filteredLocalityList : __localityList));

if (filteredLocalityList.length === 1) {
setSelectedLocality(filteredLocalityList[0]);
if (userType === "employee") {
onSelect(config.key, { ...formData[config.key], locality: filteredLocalityList[0] });
}
}
}
}, [selectedCity, fetchedLocalities, formData]);

useEffect(() => {
if (fetchedGramPanchayats) {
if (fetchedGramPanchayats && fetchedGramPanchayats.length > 0) {
setGramPanchayats(fetchedGramPanchayats);
}
}
}, [fetchedGramPanchayats]);
if (userType !== "employee" && propertyLocation?.code === "FROM_GRAM_PANCHAYAT") {
config.texts.cardText = "CS_FILE_APPLICATION_PROPERTY_LOCATION_GRAM_PANCHAYAT_TEXT";
}

function selectLocality(locality) {
setSelectedLocality(locality);
if (userType === "employee") {
onSelect(config.key, { ...formData[config.key], locality: locality });
}
}

function selectGramPanchayat(value) {
setSelectedGp(value);
const filteredVillages = fetchedGramPanchayats.filter((items) => items.code === value.code)[0].children;
const localitiesWithLocalizationKeys = filteredVillages.map((obj) => ({
...obj,
i18nkey: tenantId.replace(".", "_").toUpperCase() + "_" + obj.code,
}));
if (localitiesWithLocalizationKeys.length > 0) {
setVillages(localitiesWithLocalizationKeys);
}
if (userType === "employee") {
onSelect(config.key, { ...formData[config.key], gramPanchayat: value });
}
}

function selectVillage(value) {
setSelectedVillage(value);
if (userType === "employee") {
onSelect(config.key, { ...formData[config.key], village: value });
}
}

function onSubmit() {
if (propertyLocation?.code === "FROM_GRAM_PANCHAYAT") {
onSelect(config.key, { gramPanchayat: selectedGp, village: selectedVillage });
} else {
onSelect(config.key, { locality: selectedLocality });
}
}
if (userType === "employee") {
return (
<div>
{propertyLocation?.code === "FROM_GRAM_PANCHAYAT" ? (
<div>
<LabelFieldPair>
<CardLabel className="card-label-smaller">
{t("CS_GRAM_PANCHAYAT")}
{config.isMandatory ? " * " : null}
</CardLabel>
<Dropdown
className="form-field"
isMandatory
selected={selectedGp}
option={gramPanchayats}
select={selectGramPanchayat}
optionKey="i18nkey"
t={t}
/>
</LabelFieldPair>
<LabelFieldPair>
<CardLabel className="card-label-smaller">
{t("CS_VILLAGE_NAME")}
{config.isMandatory ? " * " : null}
</CardLabel>
<Dropdown
className="form-field"
isMandatory
selected={selectedVillage}
option={villages}
select={selectVillage}
optionKey="i18nkey"
t={t}
/>
</LabelFieldPair>
</div>
) : (
<LabelFieldPair>
<CardLabel className="card-label-smaller">
{t("CS_CREATECOMPLAINT_MOHALLA")}
{config.isMandatory ? " * " : null}
</CardLabel>
<Dropdown
className="form-field"
isMandatory
selected={selectedLocality}
option={fetchedLocalities}
select={selectLocality}
optionKey="i18nkey"
t={t}
/>
</LabelFieldPair>
)}
</div>
);
}
return (
<React.Fragment>
<Timeline currentStep={1} flow="APPLY" />
<FormStep config={config} onSelect={onSubmit} isDisabled={!selectedGp} t={t}>
{propertyLocation?.code === "WITHIN_ULB_LIMITS" ? (
<LabelFieldPair>
<CardLabel className="card-label-smaller">
{`${t("CS_CREATECOMPLAINT_MOHALLA")} *`}
{/* {config.isMandatory ? " * " : null} */}
</CardLabel>
<Dropdown
className="form-field"
isMandatory
selected={selectedLocality}
option={fetchedLocalities}
select={selectLocality}
optionKey="i18nkey"
t={t}
/>
</LabelFieldPair>
) : (
<div>
<LabelFieldPair>
<CardLabel className="card-label-smaller">
{`${t("CS_GRAM_PANCHAYAT")} *`}
{/* {config.isMandatory ? " * " : null} */}
</CardLabel>
<Dropdown
className="form-field"
isMandatory
selected={selectedGp}
option={gramPanchayats}
select={selectGramPanchayat}
optionKey="i18nkey"
t={t}
/>
</LabelFieldPair>
<LabelFieldPair>
<CardLabel className="card-label-smaller">
{`${t("CS_VILLAGE_NAME")} *`}
{/* {config.isMandatory ? " * " : null} */}
</CardLabel>
<Dropdown
className="form-field"
isMandatory
selected={selectedVillage}
option={villages}
select={selectVillage}
optionKey="i18nkey"
t={t}
/>
</LabelFieldPair>
</div>
)}
</FormStep>
</React.Fragment>
);
};

export default SelectLocalityOrGramPanchayat;
2 changes: 2 additions & 0 deletions web/src/Customisations/fsm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import SelectChannel from "./pageComponents/SelectChannel";
import Inbox from "./pages/employee/Inbox";
import SelectTankSize from "./pageComponents/SelectTankSize";
import NewApplicationCitizen from "./pages/citizen/NewApplication/index";
import SelectAddress from "./pageComponents/SelectAddress";

export const fsmComponents = {
FSMResponse: Response,
Expand All @@ -28,4 +29,5 @@ export const fsmComponents = {
SelectChannel: SelectChannel,
SelectTankSize,
FSMNewApplicationCitizen: NewApplicationCitizen,
SelectAddress,
};

0 comments on commit bec377c

Please sign in to comment.