@akinon/next 1.64.0 → 1.65.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @akinon/next
2
2
 
3
+ ## 1.65.0
4
+
5
+ ### Minor Changes
6
+
7
+ - d13fd36: ZERO-2614: Refactor Price component to remove unnecessary code and improve readability also fix the decimal scale
8
+ - 86d2531: ZERO-2693: resolve dependency collision warning for eslint-config-next
9
+
3
10
  ## 1.64.0
4
11
 
5
12
  ### Minor Changes
@@ -1,13 +1,11 @@
1
1
  import { useMemo } from 'react';
2
- // @ts-ignore
3
- import { NumericFormat, NumericFormatProps } from 'react-number-format';
2
+ import NumberFormat, { NumberFormatProps } from 'react-number-format';
4
3
  import { getCurrency } from '@akinon/next/utils';
5
-
6
4
  import { useLocalization } from '@akinon/next/hooks';
7
5
  import { PriceProps } from '../types';
8
6
  import Settings from 'settings';
9
7
 
10
- export const Price = (props: NumericFormatProps & PriceProps) => {
8
+ export const Price = (props: NumberFormatProps & PriceProps) => {
11
9
  const {
12
10
  value,
13
11
  currencyCode,
@@ -23,16 +21,10 @@ export const Price = (props: NumericFormatProps & PriceProps) => {
23
21
  fixedDecimalScale = true,
24
22
  ...rest
25
23
  } = props;
24
+
26
25
  const { currency: selectedCurrencyCode } = useLocalization();
27
26
  const currencyCode_ = currencyCode || selectedCurrencyCode;
28
27
 
29
- // TODO: This is very bad practice. It broke decimalScale.
30
- const _value = value?.toString().replace('.', ',');
31
-
32
- const currentCurrencyDecimalScale = Settings.localization.currencies.find(
33
- (currency) => currency.code === currencyCode_
34
- ).decimalScale;
35
-
36
28
  const currency = useMemo(
37
29
  () =>
38
30
  getCurrency({
@@ -44,17 +36,39 @@ export const Price = (props: NumericFormatProps & PriceProps) => {
44
36
  [currencyCode_, useCurrencySymbol, useCurrencyAfterPrice, useCurrencySpace]
45
37
  );
46
38
 
39
+ const numericValue =
40
+ typeof value === 'string'
41
+ ? parseFloat(value)
42
+ : typeof value === 'number'
43
+ ? value
44
+ : 0;
45
+
46
+ const formattedValue = Number.isFinite(numericValue)
47
+ ? numericValue.toFixed(decimalScale)
48
+ : '0';
49
+
50
+ const displayValue =
51
+ useNegative && numericValue < 0
52
+ ? `-${useNegativeSpace ? ' ' : ''}${Math.abs(numericValue).toFixed(
53
+ decimalScale
54
+ )}`
55
+ : formattedValue;
56
+
57
+ const currentCurrencyDecimalScale = Settings.localization.currencies.find(
58
+ (currency) => currency.code === currencyCode_
59
+ ).decimalScale;
60
+
47
61
  return (
48
- <NumericFormat
49
- value={useNegative ? `-${useNegativeSpace}${_value}` : _value}
50
- {...{
51
- [useCurrencyAfterPrice ? 'suffix' : 'prefix']: currency
52
- }}
62
+ <NumberFormat
63
+ value={displayValue}
53
64
  displayType={displayType}
54
65
  thousandSeparator={thousandSeparator}
55
66
  decimalScale={currentCurrencyDecimalScale ?? decimalScale}
56
67
  decimalSeparator={decimalSeparator}
57
68
  fixedDecimalScale={fixedDecimalScale}
69
+ prefix={!useCurrencyAfterPrice ? currency : undefined}
70
+ suffix={useCurrencyAfterPrice ? currency : undefined}
71
+ isNumericString={true}
58
72
  {...rest}
59
73
  />
60
74
  );
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@akinon/next",
3
3
  "description": "Core package for Project Zero Next",
4
- "version": "1.64.0",
4
+ "version": "1.65.0",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -30,12 +30,13 @@
30
30
  "set-cookie-parser": "2.6.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@akinon/eslint-plugin-projectzero": "1.64.0",
33
+ "@akinon/eslint-plugin-projectzero": "1.65.0",
34
34
  "@types/react-redux": "7.1.30",
35
35
  "@types/set-cookie-parser": "2.4.7",
36
36
  "@typescript-eslint/eslint-plugin": "6.7.4",
37
37
  "@typescript-eslint/parser": "6.7.4",
38
- "eslint": "^8.14.0",
38
+ "eslint": "8.56.0",
39
+ "eslint-config-next": "14.2.3",
39
40
  "eslint-config-prettier": "8.5.0"
40
41
  }
41
42
  }