Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consultation Form Enhancement: No home facility docs #7914

Merged
Merged
2 changes: 2 additions & 0 deletions src/Components/Common/UserAutocompleteFormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Props = FormFieldBaseProps<UserModel> & {
homeFacility?: string;
userType?: UserRole;
showActiveStatus?: boolean;
noResultsLabel?: string;
};

export default function UserAutocompleteFormField(props: Props) {
Expand Down Expand Up @@ -83,6 +84,7 @@ export default function UserAutocompleteFormField(props: Props) {
: getUserList({ ...search_filter, search_text: query }),
)
}
noResultsLabel={props.noResultsLabel ?? "No options found"}
isLoading={isLoading}
/>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/Components/Facility/ConsultationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,7 @@ export const ConsultationForm = ({ facilityId, patientId, id }: Props) => {
userType={"Doctor"}
homeFacility={facilityId}
error={state.errors.treating_physician}
noResultsLabel="No home facility doctors available"
/>
</div>

Expand Down
21 changes: 19 additions & 2 deletions src/Components/Form/FormFields/Autocomplete.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from "react";
import { useEffect, useRef, useState } from "react";
import { Combobox } from "@headlessui/react";
import { DropdownTransition } from "../../Common/components/HelperComponents";
import CareIcon from "../../../CAREUI/icons/CareIcon";
Expand All @@ -7,6 +7,7 @@ import { FormFieldBaseProps, useFormFieldPropsResolver } from "./Utils";
import FormField from "./FormField";
import { classNames } from "../../../Utils/utils";
import { useTranslation } from "react-i18next";
import * as Notifications from "../../../Utils/Notifications.js";

type OptionCallback<T, R> = (option: T) => R;

Expand Down Expand Up @@ -71,6 +72,7 @@ type AutocompleteProps<T, V = T> = {
isLoading?: boolean;
allowRawInput?: boolean;
error?: string;
noResultsLabel?: string;
} & (
| {
required?: false;
Expand Down Expand Up @@ -136,6 +138,21 @@ export const Autocomplete = <T, V>(props: AutocompleteProps<T, V>) => {
? options.filter((o) => o.search.includes(query))
: options;

const prevQuery = useRef("");
useEffect(() => {
if (
query &&
prevQuery.current !== query &&
filteredOptions.length === 0 &&
props.noResultsLabel
) {
Notifications.Error({
msg: props.noResultsLabel,
});
}
prevQuery.current = query;
}, [query, filteredOptions, props.noResultsLabel]);

return (
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved
<div
className={
Expand Down Expand Up @@ -195,7 +212,7 @@ export const Autocomplete = <T, V>(props: AutocompleteProps<T, V>) => {
<Combobox.Options className="cui-dropdown-base absolute z-10 mt-0.5 origin-top-right">
{filteredOptions.length === 0 && (
<div className="p-2 text-sm text-gray-500">
No options found
{props.noResultsLabel ?? "No options found"}
</div>
)}
{filteredOptions.map((option, index) => (
Expand Down
Loading