@akinon/next 1.63.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,19 @@
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
+
10
+ ## 1.64.0
11
+
12
+ ### Minor Changes
13
+
14
+ - c53ea3e: ZERO-2609: Reset additional form fields when selectedFormType is not company
15
+ - d3474c6: ZERO-2655: Add data source shipping option
16
+
3
17
  ## 1.63.0
4
18
 
5
19
  ### 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
  );
@@ -380,6 +380,22 @@ export const checkoutApi = api.injectEndpoints({
380
380
  dispatch(setShippingStepBusy(false));
381
381
  }
382
382
  }),
383
+ setDataSourceShippingOptions: build.mutation<CheckoutResponse, number[]>({
384
+ query: (pks) => ({
385
+ url: buildClientRequestUrl(checkout.setDataSourceShippingOption, {
386
+ useFormData: true
387
+ }),
388
+ method: 'POST',
389
+ body: {
390
+ data_source_shipping_options: JSON.stringify(pks)
391
+ }
392
+ }),
393
+ async onQueryStarted(arg, { dispatch, queryFulfilled }) {
394
+ dispatch(setShippingStepBusy(true));
395
+ await queryFulfilled;
396
+ dispatch(setShippingStepBusy(false));
397
+ }
398
+ }),
383
399
  setRetailStore: build.mutation<CheckoutResponse, SetRetailStoreParams>({
384
400
  query: ({ retailStorePk, billingAddressPk }) => ({
385
401
  url: buildClientRequestUrl(
@@ -712,6 +728,7 @@ export const {
712
728
  useSetDeliveryOptionMutation,
713
729
  useSetAddressesMutation,
714
730
  useSetShippingOptionMutation,
731
+ useSetDataSourceShippingOptionsMutation,
715
732
  useSetPaymentOptionMutation,
716
733
  useSetBinNumberMutation,
717
734
  useSetInstallmentOptionMutation,
package/data/urls.ts CHANGED
@@ -83,6 +83,8 @@ export const checkout = {
83
83
  setDeliveryOption: '/orders/checkout/?page=DeliveryOptionSelectionPage',
84
84
  setAddresses: '/orders/checkout/?page=AddressSelectionPage',
85
85
  setShippingOption: '/orders/checkout/?page=ShippingOptionSelectionPage',
86
+ setDataSourceShippingOption:
87
+ '/orders/checkout/?page=DataSourceShippingOptionSelectionPage',
86
88
  setPaymentOption: '/orders/checkout/?page=PaymentOptionSelectionPage',
87
89
  setBinNumber: '/orders/checkout/?page=BinNumberPage',
88
90
  setMasterpassBinNumber: '/orders/checkout/?page=MasterpassBinNumberPage',
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.63.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.63.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
  }
@@ -16,6 +16,7 @@ import {
16
16
  setPreOrder,
17
17
  setRetailStores,
18
18
  setShippingOptions,
19
+ setDataSourceShippingOptions,
19
20
  setShippingStepCompleted,
20
21
  setCreditPaymentOptions
21
22
  } from '../../redux/reducers/checkout';
@@ -73,6 +74,7 @@ export const preOrderMiddleware: Middleware = ({
73
74
  deliveryOptions,
74
75
  addressList: addresses,
75
76
  shippingOptions,
77
+ dataSourceShippingOptions,
76
78
  paymentOptions,
77
79
  installmentOptions
78
80
  } = getState().checkout;
@@ -126,6 +128,22 @@ export const preOrderMiddleware: Middleware = ({
126
128
  dispatch(apiEndpoints.setShippingOption.initiate(shippingOptions[0].pk));
127
129
  }
128
130
 
131
+ if (
132
+ dataSourceShippingOptions.length > 0 &&
133
+ !preOrder.data_source_shipping_options
134
+ ) {
135
+ const selectedDataSourceShippingOptionsPks =
136
+ dataSourceShippingOptions.map(
137
+ (opt) => opt.data_source_shipping_options[0].pk
138
+ );
139
+
140
+ dispatch(
141
+ apiEndpoints.setDataSourceShippingOptions.initiate(
142
+ selectedDataSourceShippingOptionsPks
143
+ )
144
+ );
145
+ }
146
+
129
147
  if (!preOrder.payment_option && paymentOptions.length > 0) {
130
148
  dispatch(apiEndpoints.setPaymentOption.initiate(paymentOptions[0].pk));
131
149
  }
@@ -164,7 +182,6 @@ export const contextListMiddleware: Middleware = ({
164
182
  if (result?.payload?.context_list) {
165
183
  result.payload.context_list.forEach((context) => {
166
184
  const redirectUrl = context.page_context.redirect_url;
167
-
168
185
  if (redirectUrl) {
169
186
  const currentLocale = getCookie('pz-locale');
170
187
 
@@ -221,6 +238,12 @@ export const contextListMiddleware: Middleware = ({
221
238
  dispatch(setShippingOptions(context.page_context.shipping_options));
222
239
  }
223
240
 
241
+ if (context.page_context.data_sources) {
242
+ dispatch(
243
+ setDataSourceShippingOptions(context.page_context.data_sources)
244
+ );
245
+ }
246
+
224
247
  if (context.page_context.payment_options) {
225
248
  dispatch(setPaymentOptions(context.page_context.payment_options));
226
249
  }
@@ -14,7 +14,8 @@ import {
14
14
  CheckoutCreditPaymentOption,
15
15
  PreOrder,
16
16
  RetailStore,
17
- ShippingOption
17
+ ShippingOption,
18
+ DataSource
18
19
  } from '../../types';
19
20
 
20
21
  export interface CheckoutState {
@@ -36,6 +37,7 @@ export interface CheckoutState {
36
37
  addressList: Address[];
37
38
  deliveryOptions: DeliveryOption[];
38
39
  shippingOptions: ShippingOption[];
40
+ dataSourceShippingOptions: DataSource[];
39
41
  paymentOptions: PaymentOption[];
40
42
  creditPaymentOptions: CheckoutCreditPaymentOption[];
41
43
  selectedCreditPaymentPk: number;
@@ -67,6 +69,7 @@ const initialState: CheckoutState = {
67
69
  addressList: [],
68
70
  deliveryOptions: [],
69
71
  shippingOptions: [],
72
+ dataSourceShippingOptions: [],
70
73
  paymentOptions: [],
71
74
  creditPaymentOptions: [],
72
75
  selectedCreditPaymentPk: null,
@@ -121,6 +124,9 @@ const checkoutSlice = createSlice({
121
124
  setShippingOptions(state, { payload }) {
122
125
  state.shippingOptions = payload;
123
126
  },
127
+ setDataSourceShippingOptions(state, { payload }) {
128
+ state.dataSourceShippingOptions = payload;
129
+ },
124
130
  setPaymentOptions(state, { payload }) {
125
131
  state.paymentOptions = payload;
126
132
  },
@@ -168,6 +174,7 @@ export const {
168
174
  setAddressList,
169
175
  setDeliveryOptions,
170
176
  setShippingOptions,
177
+ setDataSourceShippingOptions,
171
178
  setPaymentOptions,
172
179
  setCreditPaymentOptions,
173
180
  setSelectedCreditPaymentPk,
@@ -17,7 +17,7 @@ export type AddressFormType = {
17
17
  line: string;
18
18
  postcode: string;
19
19
  company_name?: string;
20
- tax_no?: number;
20
+ tax_no?: string;
21
21
  tax_office?: string;
22
22
  e_bill_taxpayer?: boolean;
23
23
  country_code?: string;
@@ -34,6 +34,23 @@ export interface ShippingOption {
34
34
  slug: string;
35
35
  }
36
36
 
37
+ export interface DataSource {
38
+ pk: number;
39
+ name: string;
40
+ data_source_shipping_options: DataSourceShippingOption[];
41
+ }
42
+
43
+ export interface DataSourceShippingOption {
44
+ pk: number;
45
+ shipping_amount: string;
46
+ shipping_option_name: string;
47
+ shipping_option_logo: string | null;
48
+ data_source: {
49
+ pk: number;
50
+ title: string | null;
51
+ };
52
+ }
53
+
37
54
  export interface CheckoutAddressType {
38
55
  label: string;
39
56
  text: string;
@@ -79,6 +96,7 @@ export interface PreOrder {
79
96
  retail_store?: RetailStore;
80
97
  gift_box?: GiftBox;
81
98
  credit_payment_option?: CheckoutCreditPaymentOption;
99
+ data_source_shipping_options: any;
82
100
  bags?: Product[];
83
101
  bags_fee?: string;
84
102
  extra_field?: ExtraField;