@akinon/pz-bkm 2.0.0-beta.13 → 2.0.0-beta.14
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 +6 -0
- package/package.json +1 -1
- package/src/views/bkm-option.tsx +48 -35
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/views/bkm-option.tsx
CHANGED
|
@@ -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
|
-
|
|
71
|
+
if (isButtonDisabled) return;
|
|
69
72
|
|
|
70
|
-
|
|
71
|
-
(context) => context.page_name === 'BexBinNumberPage'
|
|
72
|
-
);
|
|
73
|
+
setIsProcessing(true);
|
|
73
74
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
75
|
+
try {
|
|
76
|
+
const response = await setBkm(getValues('agreement')).unwrap();
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
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>
|