feat: async autocomplete on individual discounts
This commit is contained in:
parent
d0aaf6c170
commit
f1e5edd4ac
5 changed files with 146 additions and 103 deletions
|
|
@ -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
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue