2023-01-16 09:45:12 +00:00
|
|
|
import { SingleAutocompleteChoiceType } from "@dashboard/components/SingleAutocompleteSelectField";
|
|
|
|
import { FormChange } from "@dashboard/hooks/useForm";
|
2019-08-09 10:17:04 +00:00
|
|
|
|
2021-08-16 13:44:00 +00:00
|
|
|
export interface SingleAutocompleteSelectedChangeHandlerProps {
|
|
|
|
change: FormChange;
|
|
|
|
setSelected: (value: string) => void;
|
|
|
|
choices: SingleAutocompleteChoiceType[];
|
|
|
|
}
|
|
|
|
|
2019-08-09 10:17:04 +00:00
|
|
|
function createSingleAutocompleteSelectHandler(
|
|
|
|
change: FormChange,
|
|
|
|
setSelected: (value: string) => void,
|
2022-06-21 09:36:55 +00:00
|
|
|
choices: SingleAutocompleteChoiceType[],
|
2019-08-09 10:17:04 +00:00
|
|
|
): FormChange {
|
|
|
|
return (event: React.ChangeEvent<any>) => {
|
|
|
|
change(event);
|
|
|
|
|
|
|
|
const value = event.target.value;
|
2019-10-30 14:34:24 +00:00
|
|
|
const choice = choices.find(category => category.value === value);
|
2019-10-15 10:33:14 +00:00
|
|
|
setSelected(choice ? choice.label : value);
|
2019-08-09 10:17:04 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default createSingleAutocompleteSelectHandler;
|