@akinon/pz-otp 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/Otp.tsx +19 -9
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
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 (
|
|
88
|
-
data.code = otp;
|
|
89
|
-
data.phone = phone;
|
|
90
|
-
const res = await submitAction(data);
|
|
88
|
+
if (isSubmitting) return;
|
|
91
89
|
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
97
|
-
|
|
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
|