@akinon/pz-otp 1.23.0 → 1.24.0-rc.0

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-otp
2
2
 
3
+ ## 1.24.0-rc.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 0181251: ZERO-2440: move otp popup state to redux
8
+
3
9
  ## 1.23.0
4
10
 
5
11
  ## 1.22.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akinon/pz-otp",
3
- "version": "1.23.0",
3
+ "version": "1.24.0-rc.0",
4
4
  "license": "MIT",
5
5
  "main": "src/index.tsx",
6
6
  "peerDependencies": {
package/src/index.tsx CHANGED
@@ -1 +1,4 @@
1
+ import otpReducer from './redux/reducer';
2
+
1
3
  export * from './views/Otp';
4
+ export { otpReducer };
@@ -0,0 +1,26 @@
1
+ import { createSlice } from '@reduxjs/toolkit';
2
+
3
+ export interface OtpState {
4
+ isPopupVisible: boolean;
5
+ }
6
+
7
+ const initialState: OtpState = {
8
+ isPopupVisible: false
9
+ };
10
+
11
+ const otpSlice = createSlice({
12
+ name: 'otp',
13
+ initialState,
14
+ reducers: {
15
+ showPopup(state) {
16
+ state.isPopupVisible = true;
17
+ },
18
+ hidePopup(state) {
19
+ state.isPopupVisible = false;
20
+ }
21
+ }
22
+ });
23
+
24
+ export const { showPopup, hidePopup } = otpSlice.actions;
25
+
26
+ export default otpSlice.reducer;
package/src/views/Otp.tsx CHANGED
@@ -1,9 +1,10 @@
1
1
  import { FormEvent, ReactNode, useEffect, useState } from 'react';
2
- import { useRouter } from '@akinon/next/hooks';
3
2
  import { Button } from '@akinon/next/components/button';
4
3
  import OtpInput from 'react-otp-input';
5
4
  import { SubmitHandler } from 'react-hook-form';
6
5
  import { twMerge } from 'tailwind-merge';
6
+ import { useAppDispatch } from '@akinon/next/redux/hooks';
7
+ import { hidePopup } from '../redux/reducer';
7
8
 
8
9
  enum Component {
9
10
  Title = 'title',
@@ -21,15 +22,14 @@ enum ComponentWrapper {
21
22
  Otp = 'otp'
22
23
  }
23
24
 
24
- type ComponentClassKey = (typeof Component)[keyof typeof Component];
25
+ type ComponentClassKey = typeof Component[keyof typeof Component];
25
26
  type ComponentWrapperClassKey =
26
- `${(typeof ComponentWrapper)[keyof typeof ComponentWrapper]}Wrapper`;
27
+ `${typeof ComponentWrapper[keyof typeof ComponentWrapper]}Wrapper`;
27
28
  type ComponentClasses = ComponentClassKey | ComponentWrapperClassKey;
28
29
 
29
30
  type OtpProps = {
30
31
  codeLength?: number;
31
32
  timer?: number;
32
- setShowPopup: any;
33
33
  submitAction: SubmitHandler<{
34
34
  [key: string]: any;
35
35
  }>;
@@ -49,16 +49,14 @@ export const Otp = ({
49
49
  data,
50
50
  codeLength = 6,
51
51
  timer = 60,
52
- setShowPopup,
53
52
  texts,
54
53
  classes
55
54
  }: OtpProps) => {
56
- const router = useRouter();
57
-
58
55
  const [otp, setOtp] = useState('');
59
56
  const [canResend, setCanResend] = useState(false);
60
57
  const [time, setTime] = useState(timer);
61
58
  const [hasError, setHasError] = useState(false);
59
+ const dispatch = useAppDispatch();
62
60
 
63
61
  const resetTimer = () => {
64
62
  setTime(timer);
@@ -79,9 +77,7 @@ export const Otp = ({
79
77
  };
80
78
 
81
79
  const closeHandler = () => {
82
- if (setShowPopup) {
83
- setShowPopup(false);
84
- }
80
+ dispatch(hidePopup());
85
81
  };
86
82
 
87
83
  const resendHandler = async () => {
@@ -105,9 +101,9 @@ export const Otp = ({
105
101
  }, 1000);
106
102
 
107
103
  return () => clearInterval(timerId);
108
- } else {
109
- onTimerEnd();
110
104
  }
105
+
106
+ onTimerEnd();
111
107
  }, [time, onTimerEnd]);
112
108
 
113
109
  useEffect(() => {
@@ -117,7 +113,7 @@ export const Otp = ({
117
113
  return () => {
118
114
  document.body.style.overflow = 'auto';
119
115
  };
120
- });
116
+ }, []);
121
117
 
122
118
  return (
123
119
  <div className="fixed left-0 top-0 z-50 flex h-screen w-screen items-end md:items-center md:justify-center md:bg-black/10">