Skip to content

Commit

Permalink
FSM select address modified for citizen
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmoy-eGov committed Jun 20, 2024
1 parent bb527a2 commit ef7d46b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@egovernments/digit-ui-module-bills": "1.7.24",
"@egovernments/digit-ui-module-common": "1.7.24",
"@egovernments/digit-ui-module-engagement": "1.7.24",
"@egovernments/digit-ui-module-fsm": "1.7.27",
"@egovernments/digit-ui-module-fsm": "1.7.28",
"@egovernments/digit-ui-module-mcollect": "1.7.24",
"@egovernments/digit-ui-module-noc": "1.7.24",
"@egovernments/digit-ui-module-obps": "1.7.25",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@egovernments/digit-ui-module-fsm",
"version": "1.7.27",
"version": "1.7.28",
"license": "MIT",
"main": "dist/index.js",
"description": "Digit FSM Module",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@ import { FormStep, CardLabel, Dropdown, RadioButtons, LabelFieldPair, RadioOrSel
import Timeline from "../components/TLTimelineInFSM";
import { useLocation } from "react-router-dom";

// const Digit = window.Digit;

const FSMSelectAddress = ({ t, config, onSelect, userType, formData }) => {
const allCities = Digit.Hooks.fsm.useTenants();
let tenantId = Digit.ULBService.getCurrentTenantId();

if (userType !== "employee") {
tenantId = Digit.SessionStorage.get("CITIZEN.COMMON.HOME.CITY")?.code;
}
const location = useLocation();
const isNewVendor = location.pathname.includes("new-vendor");
const isEditVendor = location.pathname.includes("modify-vendor");

const inputs = [
{
active: true,
Expand Down Expand Up @@ -48,13 +45,9 @@ const FSMSelectAddress = ({ t, config, onSelect, userType, formData }) => {
: allCities;

const [selectedCity, setSelectedCity] = useState(
() =>
formData?.address?.city ||
Digit.SessionStorage.get("fsm.file.address.city") ||
Digit.SessionStorage.get("CITIZEN.COMMON.HOME.CITY")
() => formData?.address?.city || Digit.SessionStorage.get("fsm.file.address.city") || Digit.SessionStorage.get("CITIZEN.COMMON.HOME.CITY")
);
const [newLocality, setNewLocality] = useState();

const { data: fetchedLocalities } = Digit.Hooks.useBoundaryLocalities(
selectedCity?.code,
"revenue",
Expand All @@ -63,18 +56,17 @@ const FSMSelectAddress = ({ t, config, onSelect, userType, formData }) => {
},
t
);

const { data: urcConfig } = Digit.Hooks.fsm.useMDMS(tenantId, "FSM", "UrcConfig");
const isUrcEnable =
urcConfig && urcConfig.length > 0 && urcConfig[0].URCEnable;
const isUrcEnable = urcConfig && urcConfig.length > 0 && urcConfig[0].URCEnable;
const [selectLocation, setSelectLocation] = useState(() =>
formData?.address?.propertyLocation
? formData?.address?.propertyLocation
: Digit.SessionStorage.get("locationType")
? Digit.SessionStorage.get("locationType")
: inputs[0]
);

const [selectLocation, setSelectLocation] = useState(() =>
formData?.address?.propertyLocation
? formData?.address?.propertyLocation
: Digit.SessionStorage.get("locationType")
? Digit.SessionStorage.get("locationType")
: inputs[0]
);

const [localities, setLocalities] = useState();
const [selectedLocality, setSelectedLocality] = useState();

Expand All @@ -85,7 +77,7 @@ const FSMSelectAddress = ({ t, config, onSelect, userType, formData }) => {
}
}
}, [cities]);

useEffect(() => {
if (selectedCity && selectLocation) {
if (userType === "employee") {
Expand All @@ -96,11 +88,7 @@ const FSMSelectAddress = ({ t, config, onSelect, userType, formData }) => {
});
}
}
if (
(!isUrcEnable || isNewVendor || isEditVendor) &&
selectedCity &&
fetchedLocalities
) {
if ((!isUrcEnable || isNewVendor || isEditVendor) && selectedCity && fetchedLocalities) {
let __localityList = fetchedLocalities;
let filteredLocalityList = [];

Expand All @@ -109,25 +97,18 @@ const FSMSelectAddress = ({ t, config, onSelect, userType, formData }) => {
}

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

if (userType === "employee") {
onSelect(config.key, { ...formData[config.key], city: selectedCity });
}
setLocalities(() =>
filteredLocalityList.length > 0 ? filteredLocalityList : __localityList
);
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],
});
onSelect(config.key, { ...formData[config.key], locality: filteredLocalityList[0] });
}
}
}
Expand Down Expand Up @@ -180,9 +161,7 @@ const FSMSelectAddress = ({ t, config, onSelect, userType, formData }) => {
function onSubmit() {
onSelect(config.key, {
city: selectedCity,
propertyLocation: Digit.SessionStorage.get("locationType")
? Digit.SessionStorage.get("locationType")
: selectLocation,
propertyLocation: Digit.SessionStorage.get("locationType") ? Digit.SessionStorage.get("locationType") : selectLocation,
});
}

Expand All @@ -199,7 +178,7 @@ const FSMSelectAddress = ({ t, config, onSelect, userType, formData }) => {
isMandatory
selected={cities?.length === 1 ? cities[0] : selectedCity}
disable={cities?.length === 1}
option={cities?.sort((a, b) => a.name.localeCompare(b.name))}
option={cities}
select={selectCity}
optionKey="code"
t={t}
Expand All @@ -209,36 +188,27 @@ const FSMSelectAddress = ({ t, config, onSelect, userType, formData }) => {
<div>
<LabelFieldPair>
<CardLabel className="card-label-smaller">
{`${t("CS_CREATECOMPLAINT_MOHALLA")} *`}
{/* {config.isMandatory ? " * " : null} */}
{t("ES_NEW_APPLICATION_LOCATION_MOHALLA")}
{config.isMandatory ? " * " : null}
</CardLabel>
<Dropdown
className="form-field"
isMandatory
selected={selectedLocality}
option={localities?.sort((a, b) =>
a.name.localeCompare(b.name)
)}
option={localities}
select={selectLocality}
optionKey="i18nkey"
t={t}
/>
</LabelFieldPair>
{!isNewVendor && !isEditVendor && !isUrcEnable && formData?.address?.locality?.name === "Other" && (
<LabelFieldPair>
<CardLabel className="card-label-smaller">{`${t(
"ES_INBOX_PLEASE_SPECIFY_LOCALITY"
)} *`}</CardLabel>
<div className="field">
<TextInput
id="newLocality"
key="newLocality"
value={newLocality}
onChange={(e) => onNewLocality(e.target.value)}
/>
</div>
</LabelFieldPair>
)}
<LabelFieldPair>
<CardLabel className="card-label-smaller">{`${t("ES_INBOX_PLEASE_SPECIFY_LOCALITY")} *`}</CardLabel>
<div className="field">
<TextInput id="newLocality" key="newLocality" value={newLocality} onChange={(e) => onNewLocality(e.target.value)} />
</div>
</LabelFieldPair>
)}
</div>
) : (
<LabelFieldPair>
Expand All @@ -264,26 +234,20 @@ const FSMSelectAddress = ({ t, config, onSelect, userType, formData }) => {
<Timeline currentStep={1} flow="APPLY" />
<FormStep config={config} onSelect={onSubmit} t={t} isDisabled={selectLocation ? false : true}>
{isUrcEnable && (
<>
<React.Fragment>
<CardLabel>{`${t("CS_PROPERTY_LOCATION")} *`}</CardLabel>
<RadioOrSelect
isMandatory={config.isMandatory}
options={inputs}
selectedOption={Digit.SessionStorage.get("locationType")? Digit.SessionStorage.get("locationType"): selectLocation}
selectedOption={Digit.SessionStorage.get("locationType") ? Digit.SessionStorage.get("locationType") : selectLocation}
optionKey="i18nKey"
onSelect={selectedValue}
t={t}
/>
</>
</React.Fragment>
)}
<CardLabel>{`${t("MYCITY_CODE_LABEL")} *`}</CardLabel>
<RadioOrSelect
options={cities?.sort((a, b) => a.name.localeCompare(b.name))}
selectedOption={cities?.length === 1 ? cities[0] : selectedCity}
optionKey="i18nKey"
onSelect={selectCity}
t={t}
/>
<RadioOrSelect options={cities} selectedOption={selectedCity} optionKey="i18nKey" onSelect={selectCity} t={t} />
</FormStep>
</React.Fragment>
);
Expand Down
2 changes: 1 addition & 1 deletion frontend/micro-ui/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@egovernments/digit-ui-module-core": "1.7.24",
"@egovernments/digit-ui-module-engagement": "1.7.24",
"@egovernments/digit-ui-module-dss": "1.7.24",
"@egovernments/digit-ui-module-fsm": "1.7.27",
"@egovernments/digit-ui-module-fsm": "1.7.28",
"@egovernments/digit-ui-module-hrms": "1.7.24",
"@egovernments/digit-ui-module-mcollect": "1.7.24",
"@egovernments/digit-ui-module-commonpt":"1.7.24",
Expand Down

0 comments on commit ef7d46b

Please sign in to comment.