Use defaultValue in currency input (#4911)
- Fix default value sent to backend, using single quotes by default - Use default value in field definition and column definition so that field inputs can access it - Used currency default value in CurrencyFieldInput --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -7,7 +7,6 @@ import { SETTINGS_FIELD_CURRENCY_CODES } from '@/settings/data-model/constants/S
|
||||
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
|
||||
import { CurrencyPickerDropdownButton } from '@/ui/input/components/internal/currency/components/CurrencyPickerDropdownButton';
|
||||
import { TEXT_INPUT_STYLE } from '@/ui/theme/constants/TextInputStyle';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
|
||||
export const StyledInput = styled.input`
|
||||
margin: 0;
|
||||
@ -77,9 +76,6 @@ export const CurrencyInput = ({
|
||||
const theme = useTheme();
|
||||
|
||||
const [internalText, setInternalText] = useState(value);
|
||||
const [internalCurrency, setInternalCurrency] = useState<Currency | null>(
|
||||
null,
|
||||
);
|
||||
|
||||
const wrapperRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
@ -89,7 +85,6 @@ export const CurrencyInput = ({
|
||||
};
|
||||
|
||||
const handleCurrencyChange = (currency: Currency) => {
|
||||
setInternalCurrency(currency);
|
||||
onSelect?.(currency.value);
|
||||
};
|
||||
|
||||
@ -116,23 +111,18 @@ export const CurrencyInput = ({
|
||||
[],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const currency = currencies.find(({ value }) => value === currencyCode);
|
||||
if (isDefined(currency)) {
|
||||
setInternalCurrency(currency);
|
||||
}
|
||||
}, [currencies, currencyCode]);
|
||||
const currency = currencies.find(({ value }) => value === currencyCode);
|
||||
|
||||
useEffect(() => {
|
||||
setInternalText(value);
|
||||
}, [value]);
|
||||
|
||||
const Icon: IconComponent = internalCurrency?.Icon;
|
||||
const Icon: IconComponent = currency?.Icon;
|
||||
|
||||
return (
|
||||
<StyledContainer ref={wrapperRef}>
|
||||
<CurrencyPickerDropdownButton
|
||||
valueCode={internalCurrency?.value ?? ''}
|
||||
valueCode={currency?.value ?? ''}
|
||||
onChange={handleCurrencyChange}
|
||||
currencies={currencies}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user