feat: async autocomplete on individual discounts

This commit is contained in:
Rafael Taranto 2025-06-23 10:15:42 +01:00
parent d0aaf6c170
commit f1e5edd4ac
5 changed files with 146 additions and 103 deletions

View file

@ -0,0 +1,29 @@
import React, { useState } from 'react'
import { AsyncAutocomplete as BaseAsyncAutocomplete } from '../base/AsyncAutocomplete'
const AsyncAutocompleteFormik = ({ field, form, ...props }) => {
const { name } = field
const { touched, errors, setFieldValue } = form
const [selectedOption, setSelectedOption] = useState(null)
const error = touched[name] && errors[name]
const getOptionId = props.getOptionId || (opt => opt.id)
const handleChange = (event, newValue) => {
setSelectedOption(newValue)
setFieldValue(name, newValue ? getOptionId(newValue) : '')
}
return (
<BaseAsyncAutocomplete
{...props}
name={name}
value={selectedOption}
onChange={handleChange}
error={!!error}
helperText={error || ''}
/>
)
}
export const AsyncAutocomplete = AsyncAutocompleteFormik

View file

@ -1,4 +1,5 @@
import Autocomplete from './Autocomplete'
import { AsyncAutocomplete } from './AsyncAutocomplete'
import CashCassetteInput from './CashCassetteInput'
import Checkbox from './Checkbox'
import Dropdown from './Dropdown'
@ -9,6 +10,7 @@ import TextInput from './TextInput'
export {
Autocomplete,
AsyncAutocomplete,
Checkbox,
TextInput,
NumberInput,