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

Enable clearing 'referred to' in discharge modal #6337

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/Components/Facility/DischargeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const DischargeModal = ({
const [latestClaim, setLatestClaim] = useState<HCXClaimModel>();
const [isCreateClaimLoading, setIsCreateClaimLoading] = useState(false);
const [isSendingDischargeApi, setIsSendingDischargeApi] = useState(false);
const [facility, setFacility] = useState<FacilityModel>({ id: 0, name: "" }); // for referred to external
const [facility, setFacility] = useState<FacilityModel>();
const [errors, setErrors] = useState<any>({});

const fetchLatestClaim = useCallback(async () => {
Expand Down Expand Up @@ -186,12 +186,13 @@ const DischargeModal = ({
const prescriptionActions = PrescriptionActions(consultationData.id ?? "");

const handleFacilitySelect = (selected: FacilityModel) => {
setFacility(selected ? selected : facility);
const { id, name } = selected;
setFacility(selected);
const { id, name } = selected || {};
const isExternal = id === -1;
setPreDischargeForm((prev) => ({
...prev,
...(isExternal ? { referred_to_external: name } : { referred_to: id }),
referred_to: isExternal ? null : id,
referred_to_external: isExternal ? name : null,
}));
};

Expand Down Expand Up @@ -238,8 +239,8 @@ const DischargeModal = ({
handleFacilitySelect(selected as FacilityModel)
}
selected={facility}
showAll={true}
freeText={true}
showAll
freeText
multiple={false}
errors={errors?.referred_to}
className="mb-4"
Expand Down
22 changes: 19 additions & 3 deletions src/Components/Form/AutoCompleteAsync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
MultiSelectOptionChip,
dropdownOptionClassNames,
} from "./MultiSelectMenuV2";
import { useTranslation } from "react-i18next";

interface Props {
name?: string;
Expand All @@ -23,6 +24,7 @@ interface Props {
placeholder?: string;
disabled?: boolean;
error?: string;
required?: boolean;
onBlur?: () => void;
onFocus?: () => void;
}
Expand All @@ -42,11 +44,13 @@ const AutoCompleteAsync = (props: Props) => {
className = "",
placeholder,
disabled = false,
required = false,
error,
} = props;
const [data, setData] = useState([]);
const [query, setQuery] = useState("");
const [loading, setLoading] = useState(false);
const { t } = useTranslation();

const hasSelection =
(!multiple && selected) || (multiple && selected?.length > 0);
Expand Down Expand Up @@ -86,9 +90,7 @@ const AutoCompleteAsync = (props: Props) => {
: placeholder || "Start typing to search..."
}
displayValue={() =>
hasSelection && !multiple
? optionLabel && optionLabel(selected)
: ""
hasSelection && !multiple ? optionLabel?.(selected) : ""
}
onChange={({ target }) => setQuery(target.value)}
onFocus={props.onFocus}
Expand All @@ -100,6 +102,20 @@ const AutoCompleteAsync = (props: Props) => {
/>
<Combobox.Button className="absolute inset-y-0 right-0 flex items-center pr-2">
<div className="absolute right-0 top-1 mr-2 flex items-center text-lg text-secondary-900">
{hasSelection && !loading && !required && (
<div className="tooltip">
<CareIcon
className="care-l-times-circle mb-[-5px] h-4 w-4 text-gray-800 transition-colors duration-200 ease-in-out hover:text-gray-500"
onClick={(e) => {
e.preventDefault();
onChange(null);
}}
/>
<span className="tooltip-text tooltip-bottom -translate-x-1/2 text-xs">
{t("clear_selection")}
</span>
</div>
)}
{loading ? (
<CareIcon className="care-l-spinner -mb-1.5 animate-spin" />
) : (
Expand Down
Loading