@akinon/pz-otp 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-otp
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-otp",
3
- "version": "2.0.0-beta.13",
3
+ "version": "2.0.0-beta.15",
4
4
  "license": "MIT",
5
5
  "main": "./src/index.ts",
6
6
  "module": "./src/index.ts",
package/src/views/Otp.tsx CHANGED
@@ -73,6 +73,7 @@ export const Otp = ({
73
73
  const [canResend, setCanResend] = useState(false);
74
74
  const [time, setTime] = useState(timer);
75
75
  const [hasError, setHasError] = useState(false);
76
+ const [isSubmitting, setIsSubmitting] = useState(false);
76
77
  const dispatch = useAppDispatch();
77
78
  const { isPopupVisible } = useAppSelector((state) => state.otp);
78
79
 
@@ -84,18 +85,26 @@ export const Otp = ({
84
85
  const onSubmit = async (event: FormEvent<HTMLFormElement>) => {
85
86
  event.preventDefault();
86
87
 
87
- if (submitAction) {
88
- data.code = otp;
89
- data.phone = phone;
90
- const res = await submitAction(data);
88
+ if (isSubmitting) return;
91
89
 
92
- if (res?.status !== 200 || error) {
93
- setHasError(true);
94
- }
90
+ setIsSubmitting(true);
91
+
92
+ try {
93
+ if (submitAction) {
94
+ data.code = otp;
95
+ data.phone = phone;
96
+ const res = await submitAction(data);
97
+
98
+ if (res?.status !== 200 || error) {
99
+ setHasError(true);
100
+ }
95
101
 
96
- if (res?.status === 200) {
97
- dispatch(hidePopup());
102
+ if (res?.status === 200) {
103
+ dispatch(hidePopup());
104
+ }
98
105
  }
106
+ } finally {
107
+ setIsSubmitting(false);
99
108
  }
100
109
  };
101
110
 
@@ -225,6 +234,7 @@ export const Otp = ({
225
234
  {error && <p className="text-xs text-error mt-2">{error}</p>}
226
235
  <Button
227
236
  type="submit"
237
+ disabled={isSubmitting}
228
238
  className={twMerge(
229
239
  'mt-5 h-auto w-full py-4 text-lg font-medium uppercase',
230
240
  classes?.submitButton