@akinon/pz-bkm 2.0.0-beta.13 → 2.0.0-beta.15

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,13 @@
1
1
  # @akinon/pz-bkm
2
2
 
3
+ ## 2.0.0-beta.15
4
+
5
+ ## 2.0.0-beta.14
6
+
7
+ ### Minor Changes
8
+
9
+ - 6ad72e8d: ZERO-4032: Add loading state management for payment submissions across multiple components and add safe guarding
10
+
3
11
  ## 2.0.0-beta.13
4
12
 
5
13
  ## 1.118.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akinon/pz-bkm",
3
- "version": "2.0.0-beta.13",
3
+ "version": "2.0.0-beta.15",
4
4
  "license": "MIT",
5
5
  "main": "src/index.tsx",
6
6
  "peerDependencies": {
@@ -1,4 +1,4 @@
1
- import React, { ReactElement, useId } from 'react';
1
+ import React, { ReactElement, useId, useState } from 'react';
2
2
  import Script from 'next/script';
3
3
  import * as yup from 'yup';
4
4
  import { yupResolver } from '@hookform/resolvers/yup';
@@ -53,56 +53,68 @@ const BKMOption = ({
53
53
  customUIRender
54
54
  }: BKMOptionProps) => {
55
55
  const id = useId();
56
+ const [isProcessing, setIsProcessing] = useState(false);
56
57
  const {
57
58
  handleSubmit,
58
59
  control,
59
- formState: { errors },
60
+ formState: { errors, isSubmitting },
60
61
  getValues
61
62
  } = useForm<BKMOptionForm>({
62
63
  resolver: yupResolver(formSchema(translations?.required)) as any
63
64
  });
64
- const [setBkm] = useSetBkmMutation();
65
+ const [setBkm, { isLoading: isSettingBkm }] = useSetBkmMutation();
65
66
  const [completeBkm] = useCompleteBkmMutation();
66
67
 
68
+ const isButtonDisabled = isSubmitting || isSettingBkm || isProcessing;
69
+
67
70
  const onSubmit: SubmitHandler<BKMOptionForm> = async () => {
68
- const response = await setBkm(getValues('agreement')).unwrap();
71
+ if (isButtonDisabled) return;
69
72
 
70
- const bexContext = response.context_list.find(
71
- (context) => context.page_name === 'BexBinNumberPage'
72
- );
73
+ setIsProcessing(true);
73
74
 
74
- if (!bexContext) {
75
- return;
76
- }
75
+ try {
76
+ const response = await setBkm(getValues('agreement')).unwrap();
77
77
 
78
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
79
- // @ts-ignore
80
- window.Bex.init(
81
- {
82
- id: bexContext.page_context.transaction_id,
83
- path: bexContext.page_context.path,
84
- token: bexContext.page_context.token
85
- },
86
- 'modal',
87
- {
88
- container: `js-bkm-frame-${id}`,
89
- buttonSize: [500, 500],
90
- skipButton: true,
91
- onComplete: async (status) => {
92
- if (status == 'success') {
93
- const data = await completeBkm().unwrap();
94
- const redirectUrl =
95
- data.context_list?.[0]?.page_context?.redirect_url;
96
-
97
- if (!redirectUrl) {
98
- return;
99
- }
78
+ const bexContext = response.context_list.find(
79
+ (context) => context.page_name === 'BexBinNumberPage'
80
+ );
81
+
82
+ if (!bexContext) {
83
+ setIsProcessing(false);
84
+ return;
85
+ }
100
86
 
101
- window.location.href = redirectUrl;
87
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
88
+ // @ts-ignore
89
+ window.Bex.init(
90
+ {
91
+ id: bexContext.page_context.transaction_id,
92
+ path: bexContext.page_context.path,
93
+ token: bexContext.page_context.token
94
+ },
95
+ 'modal',
96
+ {
97
+ container: `js-bkm-frame-${id}`,
98
+ buttonSize: [500, 500],
99
+ skipButton: true,
100
+ onComplete: async (status) => {
101
+ if (status == 'success') {
102
+ const data = await completeBkm().unwrap();
103
+ const redirectUrl =
104
+ data.context_list?.[0]?.page_context?.redirect_url;
105
+
106
+ if (!redirectUrl) {
107
+ return;
108
+ }
109
+
110
+ window.location.href = redirectUrl;
111
+ }
102
112
  }
103
113
  }
104
- }
105
- );
114
+ );
115
+ } catch (error) {
116
+ setIsProcessing(false);
117
+ }
106
118
  };
107
119
 
108
120
  if (customUIRender) {
@@ -166,6 +178,7 @@ const BKMOption = ({
166
178
  classes?.button
167
179
  )}
168
180
  type="submit"
181
+ disabled={isButtonDisabled}
169
182
  data-testid="checkout-bank-account-place-order"
170
183
  >
171
184
  <span>{translations?.button ?? 'Pay with BKM Express'}</span>