diff --git a/src/Components/Users/UserAdd.tsx b/src/Components/Users/UserAdd.tsx index b4d9e9fbca6..40e4e3af093 100644 --- a/src/Components/Users/UserAdd.tsx +++ b/src/Components/Users/UserAdd.tsx @@ -41,6 +41,7 @@ import routes from "../../Redux/api"; import request from "../../Utils/request/request"; import useQuery from "../../Utils/request/useQuery"; import CareIcon from "../../CAREUI/icons/CareIcon"; +import AutocompleteFormField from "../Form/FormFields/Autocomplete"; const Loading = lazy(() => import("../Common/Loading")); @@ -266,6 +267,20 @@ export const UserAdd = (props: UserProps) => { }, }); + const { loading: isStateLoading } = useQuery(routes.statesList, { + onResponse: ({ data }) => { + if (!data) { + return; + } + + if (userIndex <= USER_TYPES.indexOf("StateAdmin")) { + setStates([authUser.state_object!]); + } else { + setStates(data.results); + } + }, + }); + const { loading: isLocalbodyLoading } = useQuery( routes.getAllLocalBodyByDistrict, { @@ -282,17 +297,6 @@ export const UserAdd = (props: UserProps) => { } ); - const { loading: isStateLoading } = useQuery(routes.statesList, { - onResponse: (result) => { - if (!result || !result.res || !result.data) return; - if (userIndex <= USER_TYPES.indexOf("StateAdmin")) { - setStates([authUser.state_object!]); - } else { - setStates(result.data.results); - } - }, - }); - const handleDateChange = (e: FieldChangeEvent) => { if (dayjs(e.value).isValid()) { dispatch({ @@ -328,7 +332,7 @@ export const UserAdd = (props: UserProps) => { setSelectedFacility(selected as FacilityModel[]); const form = { ...state.form }; form.facilities = selected - ? (selected as FacilityModel[]).map((i) => i.id ?? -1) + ? (selected as FacilityModel[]).map((i) => parseInt(i.id as string) ?? -1) : []; dispatch({ type: "set_form", form }); }; @@ -583,10 +587,6 @@ export const UserAdd = (props: UserProps) => { } }; - if (isLoading) { - return ; - } - const field = (name: string) => { return { id: name, @@ -597,14 +597,18 @@ export const UserAdd = (props: UserProps) => { }; }; + if (isLoading) { + return ; + } + return (  Need Help? @@ -631,13 +635,15 @@ export const UserAdd = (props: UserProps) => { showAll={false} /> - o.role + (o.readOnly ? " (Read Only)" : "")} optionValue={(o) => o.id} + required /> {state.form.user_type === "Doctor" && (