feat(webapp): invoice tax rate

This commit is contained in:
Ahmed Bouhuolia
2023-09-11 23:17:27 +02:00
parent 6abae43c6f
commit b98b73ad98
21 changed files with 615 additions and 126 deletions

View File

@@ -0,0 +1,36 @@
import React, { useState } from 'react';
interface UseUncontrolledInput<T> {
/** Value for controlled state */
value?: T;
/** Initial value for uncontrolled state */
initialValue?: T;
/** Final value for uncontrolled state when value and initialValue are not provided */
finalValue?: T;
/** Controlled state onChange handler */
onChange?(value: T): void;
}
export function useUncontrolled<T>({
value,
initialValue,
finalValue,
onChange = () => {},
}: UseUncontrolledInput<T>) {
const [uncontrolledValue, setUncontrolledValue] = useState(
initialValue !== undefined ? initialValue : finalValue,
);
const handleUncontrolledChange = (val: T) => {
setUncontrolledValue(val);
onChange?.(val);
};
if (value !== undefined) {
return [value as T, onChange, true];
}
return [uncontrolledValue as T, handleUncontrolledChange, false];
}