@akinon/pz-hepsipay 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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @akinon/pz-hepsipay
2
2
 
3
+ ## 2.0.0-beta.14
4
+
5
+ ### Minor Changes
6
+
7
+ - 6ad72e8d: ZERO-4032: Add loading state management for payment submissions across multiple components and add safe guarding
8
+
3
9
  ## 2.0.0-beta.13
4
10
 
5
11
  ## 1.118.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akinon/pz-hepsipay",
3
- "version": "2.0.0-beta.13",
3
+ "version": "2.0.0-beta.14",
4
4
  "license": "MIT",
5
5
  "main": "src/index.tsx",
6
6
  "peerDependencies": {
package/src/index.tsx CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Button, Icon } from '@akinon/next/components';
2
+ import { checkPaymentWillRedirect } from '@akinon/next/utils';
2
3
  import Script from 'next/script';
3
4
  import { useEffect, useCallback, useState } from 'react';
4
5
  import { RootState } from 'redux/store';
@@ -70,12 +71,13 @@ export const Hepsipay = ({
70
71
  const {
71
72
  handleSubmit,
72
73
  control,
73
- formState: { errors }
74
+ formState: { errors, isSubmitting }
74
75
  } = useForm({
75
76
  resolver: yupResolver(hepsiPayFormSchema()) as any
76
77
  });
77
78
 
78
79
  const [isPaymentSuccessful, setIsPaymentSuccessful] = useState(false);
80
+ const [isProcessing, setIsProcessing] = useState(false);
79
81
 
80
82
  const context_extras = useAppSelector(
81
83
  (state: RootState) => state.checkout.preOrder?.context_extras
@@ -125,11 +127,18 @@ export const Hepsipay = ({
125
127
  }
126
128
  }, [initHepsipay]);
127
129
 
130
+ const isButtonDisabled = isSubmitting || isProcessing;
131
+
128
132
  const onSubmit: SubmitHandler<null> = async () => {
133
+ if (isButtonDisabled) return;
134
+
135
+ setIsProcessing(true);
136
+
129
137
  if (window.HepsipaySdk) {
130
138
  window.HepsipaySdk.initPayment();
131
139
  } else {
132
140
  console.error('Hepsipay SDK is not available');
141
+ setIsProcessing(false);
133
142
  }
134
143
  };
135
144
 
@@ -159,6 +168,7 @@ export const Hepsipay = ({
159
168
  <Button
160
169
  className="group uppercase mt-4 inline-flex items-center justify-center w-full"
161
170
  type="submit"
171
+ disabled={isButtonDisabled}
162
172
  data-testid="checkout-bank-account-place-order"
163
173
  >
164
174
  <span>{_translations.placeholderInput}</span>