Skip to content

Commit

Permalink
🏷️ [#445] Convert Price component to TS
Browse files Browse the repository at this point in the history
And immediately there is a type issue where strings are passed down
to FormattedNumber, which is invalid.
  • Loading branch information
sergei-maertens committed Mar 6, 2025
1 parent 7ba1be0 commit fa08946
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/components/Price.jsx → src/components/Price.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import PropTypes from 'prop-types';
import {FormattedMessage, FormattedNumber} from 'react-intl';

import {getBEMClassName} from 'utils';

const Price = ({price = ''}) => {
export interface PriceProps {
price?: string | number; // the API serializes decimals to strings to not lose precision
}

const Price: React.FC<PriceProps> = ({price = '0'}) => {
return (
<div className={getBEMClassName('price')}>
<div className={getBEMClassName('price__label')}>
<FormattedMessage description="Label for the total price to pay" defaultMessage="Total" />:
</div>
<div className={getBEMClassName('price__amount')}>
<FormattedNumber
value={price}
value={typeof price === 'number' ? price : parseFloat(price)}
style="currency"
currency="EUR"
minimumFractionDigits={2}
Expand All @@ -22,8 +25,4 @@ const Price = ({price = ''}) => {
);
};

Price.propTypes = {
price: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
};

export default Price;

0 comments on commit fa08946

Please sign in to comment.