Skip to content

Commit

Permalink
Use AutoCompleteMultiSelectFormField for Symptom selrction
Browse files Browse the repository at this point in the history
  • Loading branch information
Omkar76 committed Jan 2, 2024
1 parent 9f6c733 commit e88771d
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions src/Components/Common/SymptomsSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import CareIcon from "../../CAREUI/icons/CareIcon";
import { SYMPTOM_CHOICES } from "../../Common/constants";
import FormField from "../Form/FormFields/FormField";
import {
FieldChangeEvent,
FormFieldBaseProps,
useFormFieldPropsResolver,
} from "../Form/FormFields/Utils";
import MultiSelectMenuV2 from "../Form/MultiSelectMenuV2";
import AutocompleteMultiSelectFormField from "../Form/FormFields/AutocompleteMultiselect";

const ASYMPTOMATIC_ID = 1;

Expand All @@ -20,7 +20,7 @@ const ASYMPTOMATIC_ID = 1;
export const SymptomsSelect = (props: FormFieldBaseProps<number[]>) => {
const field = useFormFieldPropsResolver(props);

const updateSelection = (value: number[]) => {
const updateSelection = ({ value }: FieldChangeEvent<number[]>) => {
// Skip the complexities if no initial value was present
if (!props.value?.length) return field.handleChange(value);

Expand All @@ -44,39 +44,41 @@ export const SymptomsSelect = (props: FormFieldBaseProps<number[]>) => {
field.handleChange(value);
};

const getDescription = ({ id }: { id: number }) => {
const value = props.value || [];
if (!value.length) return;
// TODO : uncomment this whenn `AutocompleteMultiSelectFormField` can accept
// `optionDescription` prop
// const getDescription = ({ id }: { id: number }) => {
// const value = props.value || [];
// if (!value.length) return;

if (value.includes(ASYMPTOMATIC_ID) && id !== ASYMPTOMATIC_ID)
return (
<div className="items-center">
<CareIcon className="care-l-exclamation-triangle mr-2" />
<span>
also unselects <b className="font-medium">Asymptomatic</b>
</span>
</div>
);
// if (value.includes(ASYMPTOMATIC_ID) && id !== ASYMPTOMATIC_ID)
// return (
// <div className="items-center">
// <CareIcon className="care-l-exclamation-triangle mr-2" />
// <span>
// also unselects <b className="font-medium">Asymptomatic</b>
// </span>
// </div>
// );

if (!value.includes(ASYMPTOMATIC_ID) && id === ASYMPTOMATIC_ID)
return (
<span>
<CareIcon className="care-l-exclamation-triangle mr-2" />
{`also unselects the other ${value.length} option(s)`}
</span>
);
};
// if (!value.includes(ASYMPTOMATIC_ID) && id === ASYMPTOMATIC_ID)
// return (
// <span>
// <CareIcon className="care-l-exclamation-triangle mr-2" />
// {`also unselects the other ${value.length} option(s)`}
// </span>
// );
// };

return (
<FormField field={field}>
<MultiSelectMenuV2
<AutocompleteMultiSelectFormField
id={field.id}
name={field.name}
options={SYMPTOM_CHOICES}
disabled={props.disabled}
placeholder="Select symptoms"
optionLabel={(option) => option.text}
optionValue={(option) => option.id}
optionDescription={getDescription}
value={props.value}
onChange={updateSelection}
/>
Expand Down

0 comments on commit e88771d

Please sign in to comment.