mirror of
https://codeberg.org/MarkusThielker/finances.git
synced 2025-04-12 05:08:43 +00:00
N-FIN-42: set default category when payee is selected
This commit is contained in:
parent
715ce17e1f
commit
3c19d8b639
2 changed files with 22 additions and 3 deletions
|
@ -166,7 +166,17 @@ export default function PaymentForm({value, entities, categories, onSubmit, clas
|
||||||
placeholder="Select payee"
|
placeholder="Select payee"
|
||||||
items={entitiesMapped}
|
items={entitiesMapped}
|
||||||
next={categoryRef}
|
next={categoryRef}
|
||||||
{...field} />
|
{...field}
|
||||||
|
onChange={(e) => {
|
||||||
|
field.onChange(e);
|
||||||
|
if (e && e.target.value) {
|
||||||
|
const entity = entities.find((entity) => entity.id === Number(e.target.value));
|
||||||
|
console.log(entity?.defaultCategoryId);
|
||||||
|
if (entity?.defaultCategoryId !== null) {
|
||||||
|
form.setValue('categoryId', entity?.defaultCategoryId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage/>
|
<FormMessage/>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|
|
@ -13,12 +13,12 @@ export interface AutoCompleteInputProps
|
||||||
const AutoCompleteInput = React.forwardRef<HTMLInputElement, AutoCompleteInputProps>(
|
const AutoCompleteInput = React.forwardRef<HTMLInputElement, AutoCompleteInputProps>(
|
||||||
({className, type, ...props}, ref) => {
|
({className, type, ...props}, ref) => {
|
||||||
|
|
||||||
const [value, setValue] = useState(getInitialValue());
|
const [value, setValue] = useState(getNameOfPropValue());
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [lastKey, setLastKey] = useState('');
|
const [lastKey, setLastKey] = useState('');
|
||||||
const [filteredItems, setFilteredItems] = useState(props.items);
|
const [filteredItems, setFilteredItems] = useState(props.items);
|
||||||
|
|
||||||
function getInitialValue() {
|
function getNameOfPropValue() {
|
||||||
|
|
||||||
if (!props.items) {
|
if (!props.items) {
|
||||||
return '';
|
return '';
|
||||||
|
@ -50,6 +50,15 @@ const AutoCompleteInput = React.forwardRef<HTMLInputElement, AutoCompleteInputPr
|
||||||
}
|
}
|
||||||
}, [filteredItems]);
|
}, [filteredItems]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log('Prop value changed', value, props.value);
|
||||||
|
if (props.value) {
|
||||||
|
setValue(getNameOfPropValue());
|
||||||
|
} else {
|
||||||
|
setValue('');
|
||||||
|
}
|
||||||
|
}, [props.value]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<input
|
<input
|
||||||
|
|
Loading…
Add table
Reference in a new issue