-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate
useDispatch
with useQuery/request
in `src/Components/Comm…
…on/**` (#6889) * Migrate to `useQuery` in `AssetSelect` * Migrate `useQuery` in `BedSelect` * Migrate `useQuery` in `DistrictAutocompleteFormField` * Migrate `useQuery` in `StateAutocompleteFormField` * Migrate `useQuery` in `LocalBodyAutocompleteFormField` * Migrate `useQuery` in `FacilitySelect` * Migrate `useQuery` in `LocationSelect` * Migrate `useQuery` in `SkillSelect` * Migrate `useQuery` in `InvestigationBuilder` * Migrate `useQuery` in `Uptime` (Asset) * fix location select not working for single select * uptime: fix issue with reverse
- v25.1.0
- v24.52.0
- v24.51.0
- v24.50.0
- v24.49.0
- v24.48.1
- v24.48.0
- v24.47.0
- v24.46.0
- v24.45.1
- v24.45.0
- v24.44.0
- v24.43.0
- v24.42.0
- v24.41.0
- v24.40.0
- v24.39.0
- v24.38.0
- v24.37.0
- v24.35.0
- v24.34.1
- v24.34.0
- v24.33.0
- v24.32.0
- v24.31.0
- v24.30.1
- v24.30.0
- v24.29.0
- v24.28.0
- v24.27.0
- v24.26.0
- v24.25.1
- v24.25.0
- v24.24.0
- v24.23.0
- v24.22.0
- v24.21.0
- v24.20.0
- v24.19.0
- v24.18.0
- v24.17.0
- v24.15.0
- v24.14.0
- v24.13.0
- v24.12.0
- v24.11.0
- v24.10.0
- v24.09.0
- v24.08.0
- v24.07.0
- v24.06.0
- v24.05.0
- v24.04.0
- v24.03.0
1 parent
cc38860
commit 197cb39
Showing
18 changed files
with
156 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,23 @@ | ||
import { useCallback, useState } from "react"; | ||
import AutocompleteFormField from "../Form/FormFields/Autocomplete"; | ||
import { FormFieldBaseProps } from "../Form/FormFields/Utils"; | ||
import { statusType, useAbortableEffect } from "../../Common/utils"; | ||
import { useDispatch } from "react-redux"; | ||
import { getStates } from "../../Redux/actions"; | ||
import { StateModel } from "../Facility/models"; | ||
import useQuery from "../../Utils/request/useQuery"; | ||
import routes from "../../Redux/api"; | ||
|
||
export type IState = { | ||
id: number; | ||
name: string; | ||
}; | ||
|
||
type Props = FormFieldBaseProps<IState["id"]> & { | ||
type Props = FormFieldBaseProps<StateModel["id"]> & { | ||
placeholder?: string; | ||
}; | ||
|
||
export default function StateAutocompleteFormField(props: Props) { | ||
const dispatch = useDispatch<any>(); | ||
const [states, setStates] = useState<IState[]>(); | ||
|
||
const fetchStates = useCallback( | ||
async (status: any) => { | ||
setStates(undefined); | ||
const res = await dispatch(getStates()); | ||
if (!status.aborted && res && res.data) { | ||
setStates(res.data.results); | ||
} | ||
}, | ||
[dispatch] | ||
); | ||
|
||
useAbortableEffect((status: statusType) => { | ||
fetchStates(status); | ||
}, []); | ||
const { data, loading } = useQuery(routes.statesList); | ||
|
||
return ( | ||
<AutocompleteFormField | ||
{...props} | ||
options={states ?? []} | ||
options={data?.results ?? []} | ||
optionLabel={(option) => option.name} | ||
optionValue={(option) => option.id} | ||
isLoading={states === undefined} | ||
isLoading={loading} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters