Skip to content

Commit

Permalink
discard changes in userAutoComp and rm FacilityId
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaJ2305 committed Feb 1, 2025
1 parent d655e6f commit 2906b3a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
38 changes: 17 additions & 21 deletions src/components/Common/UserAutocompleteFormField.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useQuery } from "@tanstack/react-query";
import { useEffect, useState } from "react";

import { Autocomplete } from "@/components/Form/FormFields/Autocomplete";
Expand All @@ -11,7 +10,7 @@ import { UserType } from "@/components/Users/UserFormValidations";
import { UserBareMinimum } from "@/components/Users/models";

import routes from "@/Utils/request/api";
import query from "@/Utils/request/query";
import useTanStackQueryInstead from "@/Utils/request/useQuery";
import {
classNames,
formatName,
Expand All @@ -34,38 +33,35 @@ type UserSearchProps = BaseProps & {

export default function UserAutocomplete(props: UserSearchProps) {
const field = useFormFieldPropsResolver(props);
const [queryParam, setQueryParam] = useState("");
const [query, setQuery] = useState("");
const [disabled, setDisabled] = useState(false);

const { data, isLoading } = useQuery({
queryKey: ["user", props.homeFacility, props.facilityId],
queryFn: query(routes.userList, {
queryParams: {
home_facility: props.homeFacility,
user_type: props.userType,
search_text: queryParam,
limit: 50,
offset: 0,
},
}),
const { data, loading } = useTanStackQueryInstead(routes.userList, {
query: {
home_facility: props.homeFacility,
user_type: props.userType,
search_text: query,
limit: 50,
offset: 0,
},
});

useEffect(() => {
if (
isLoading ||
queryParam ||
loading ||
query ||
!field.required ||
!props.noResultsError ||
!data
!data?.results
) {
return;
}

if (data.count === 0) {
if (data.results.length === 0) {
setDisabled(true);
field.handleChange(undefined as unknown as UserBareMinimum);
}
}, [isLoading, field.required, data?.results, props.noResultsError]);
}, [loading, field.required, data?.results, props.noResultsError]);

const getAvatar = (option: UserBareMinimum) => {
return (
Expand Down Expand Up @@ -98,8 +94,8 @@ export default function UserAutocomplete(props: UserSearchProps) {
`${option.user_type} - ${option.username}`
}
optionValue={(option) => option}
onQuery={setQueryParam}
isLoading={isLoading}
onQuery={setQuery}
isLoading={loading}
/>
</FormField>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Patient/FileUploadPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function FileUploadPage(props: {
const { facilityId, patientId, encounterId, type } = props;

const { data: patient } = useQuery({
queryKey: ["patient", facilityId, patientId],
queryKey: ["patient", patientId],
queryFn: query(routes.getPatient, {
pathParams: { id: patientId },
}),
Expand Down

0 comments on commit 2906b3a

Please sign in to comment.