Skip to content

Commit

Permalink
fix: revert changes
Browse files Browse the repository at this point in the history
  • Loading branch information
naman114 committed Dec 21, 2022
1 parent 9729f85 commit 0fd7948
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
21 changes: 10 additions & 11 deletions src/Components/Facility/FacilityFilter/LocalBodySelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ interface LocalBodySelectProps {
district?: string;
isLoading?: (loading: boolean) => void;
setSelected: (selected: string) => void;
selectedLocalBodyObject: any;
setSelectedLocalBodyObject: (local_body: any) => void;
}

function LocalBodySelect(props: LocalBodySelectProps) {
Expand All @@ -28,15 +26,19 @@ function LocalBodySelect(props: LocalBodySelectProps) {
setSelected,
margin,
district,
selectedLocalBodyObject,
setSelectedLocalBodyObject,
} = props;
const [loadBodyLoading, isLocalBodyLoading] = useState(false);
const [selectedObject, setSelectedObject] = useState(null);
const [hasSearchText, setHasSearchText] = useState(false);
const [districtLocalBodies, setDistrictLocalBodies] = useState([]);
const [localBodyList, setLocalBodyList] = useState([]);
const dispatchAction: any = useDispatch();

const handleValueChange = (local_body: any) => {
setSelectedObject(local_body);
setSelected(local_body?.id);
};

const handleSearch = (e: any) => {
const searchTerm = e.target.value;
isLocalBodyLoading(true);
Expand All @@ -61,7 +63,7 @@ function LocalBodySelect(props: LocalBodySelectProps) {
setLocalBodyList(res.data);

if (selected) {
setSelectedLocalBodyObject(
setSelectedObject(
res.data.find((local_body: any) => local_body.id == selected) ||
null
);
Expand All @@ -76,21 +78,18 @@ function LocalBodySelect(props: LocalBodySelectProps) {
isLocalBodyLoading(true);
fetchLocalbodies();
isLocalBodyLoading(false);
}, [dispatchAction, district, selected, setSelectedLocalBodyObject]);
}, [dispatchAction, district, selected]);

return (
<AutoCompleteAsyncField
name={name}
multiple={multiple}
variant="outlined"
margin={margin}
value={selectedLocalBodyObject}
value={selectedObject}
options={localBodyList}
onSearch={handleSearch}
onChange={(e: any, selected: any) => {
setSelectedLocalBodyObject(selected);
setSelected(selected?.id);
}}
onChange={(e: any, selected: any) => handleValueChange(selected)}
loading={loadBodyLoading}
placeholder="Enter local body name"
noOptionsText={
Expand Down
12 changes: 1 addition & 11 deletions src/Components/Facility/FacilityFilter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ function FacilityFilter(props: any) {
const [isDistrictLoading, setIsDistrictLoading] = useState(false);
const [states, setStates] = useState(initialStates);
const [districts, setDistricts] = useState(selectStates);
const [selectedLocalBodyObject, setSelectedLocalBodyObject] = useState(null);
const [filterState, setFilterState] = useMergeState({
state: filter.state || "",
district: filter.district || "",
Expand Down Expand Up @@ -113,14 +112,7 @@ function FacilityFilter(props: any) {
<button
className="btn btn-default mt-1"
onClick={(_) => {
setFilterState({
state: "",
district: "",
local_body: "",
facility_type: "",
kasp_empanelled: "",
});
setSelectedLocalBodyObject(null);
closeFilter();
navigate("/facility");
}}
>
Expand Down Expand Up @@ -182,8 +174,6 @@ function FacilityFilter(props: any) {
selected={filterState.local_body}
setSelected={handleLocalBodyChange}
margin="dense"
selectedLocalBodyObject={selectedLocalBodyObject}
setSelectedLocalBodyObject={setSelectedLocalBodyObject}
/>
</div>
</div>
Expand Down

0 comments on commit 0fd7948

Please sign in to comment.