@truworth/twc-auth 3.0.2 → 3.0.3

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.
@@ -4,12 +4,17 @@ import { defaultPolicy } from "../../../../constants/defaultPolicy";
4
4
  * @internal
5
5
  * Internal hook for managing CreatePassword screen state and auth context integration.
6
6
  * Not exposed to package consumers.
7
+ *
8
+ * Both web and native use the same pattern:
9
+ * - Hook manages password state internally
10
+ * - Use handlePassword/handleConfirmPassword to update state
11
+ * - Optional initial values for preserving state when navigating back
7
12
  */
8
- const useCreatePassword = () => {
13
+ const useCreatePassword = (props) => {
9
14
  const [passwordVisible, setPasswordVisible] = useState(false);
10
15
  const [confirmPasswordVisible, setConfirmPasswordVisible] = useState(false);
11
- const [password, setPassword] = useState('');
12
- const [confirmPassword, setConfirmPassword] = useState('');
16
+ const [password, setPassword] = useState(props?.initialPassword || '');
17
+ const [confirmPassword, setConfirmPassword] = useState(props?.initialConfirmPassword || '');
13
18
  const [maxLength, setMaxLength] = useState(defaultPolicy.maxLength);
14
19
  const [criteria, setCriteria] = useState({});
15
20
  const handlePassword = (text) => {
@@ -23,7 +28,9 @@ const useCreatePassword = () => {
23
28
  setConfirmPassword('');
24
29
  onResult();
25
30
  };
26
- const isContinueDisabled = !Object.keys(criteria).every(c => criteria[c]) || (password !== confirmPassword);
31
+ const allCriteriaMet = Object.keys(criteria).length > 0 && Object.keys(criteria).every(c => criteria[c]);
32
+ const passwordsMatch = password.length > 0 && password === confirmPassword;
33
+ const isContinueDisabled = !allCriteriaMet || !passwordsMatch;
27
34
  return {
28
35
  password, setPassword,
29
36
  confirmPassword, setConfirmPassword,
@@ -1,43 +1,16 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Button, Flex, Form, PasswordInput, Typography, useForm } from "@truworth/twc-web-design";
2
+ import { Button, Flex, PasswordInput, Typography } from "@truworth/twc-web-design";
3
3
  import { useCreatePassword } from "./hooks/internal/useCreatePassword";
4
4
  import { ScreenLayout } from "../../components/ScreenLayout";
5
5
  import { PasswordCriteria } from "../../components/PasswordCriteria";
6
6
  const CreatePassword = ({ userDetails, handleBack, onContinue }) => {
7
7
  const { countryCode, email } = userDetails;
8
- const form = useForm({
9
- defaultValues: {
10
- password: userDetails.password || '',
11
- confirmPassword: userDetails.confirmPassword || '',
12
- }
13
- });
14
- const { password, confirmPassword } = form.watch();
15
- const { criteria, setCriteria, maxLength, setMaxLength, handleSkip, isContinueDisabled } = useCreatePassword();
8
+ const { password, confirmPassword, handlePassword, handleConfirmPassword, passwordVisible, setPasswordVisible, confirmPasswordVisible, setConfirmPasswordVisible, criteria, setCriteria, maxLength, setMaxLength, handleSkip, isContinueDisabled } = useCreatePassword();
16
9
  return (_jsx(ScreenLayout, { title: _jsxs(Flex, { justify: "between", align: "center", children: [_jsx(Typography, { type: "heading", size: "h5", children: "Create your Password" }), countryCode == '91' &&
17
- _jsx(Button, { label: "Skip Now", variant: "link", onClick: () => handleSkip({ onResult: onContinue }) })] }), subTitle: "Use a password that's easy to remember and fulfills all the requirements listed below.", buttonProps: {
10
+ _jsx(Button, { label: "Skip Now", variant: "link", onClick: () => handleSkip({ onResult: () => onContinue('', '') }) })] }), subTitle: "Use a password that's easy to remember and fulfills all the requirements listed below.", buttonProps: {
18
11
  label: 'Continue',
19
12
  onClick: () => onContinue(password, confirmPassword),
20
13
  disabled: isContinueDisabled
21
- }, onPressBack: handleBack, children: _jsxs(Form, { form: form, className: 'w-full', children: [_jsx(Form.Item, { name: "password", label: "Enter Password", normalize: (value) => value.replace(/\s/g, ''), rules: [
22
- {
23
- required: true,
24
- message: 'Please enter your password'
25
- }
26
- ], children: _jsx(PasswordInput, { placeholder: "Enter password", value: password, maxLength: maxLength, showStrengthIndicator: false }) }), _jsx(PasswordCriteria, { email: email, password: password, criteria: criteria, onCriteriaChange: setCriteria, onMaxLengthChange: setMaxLength }), _jsx(Form.Item, { name: "confirmPassword", label: "Confirm Password", className: "mt-6", normalize: (value) => value.replace(/\s/g, ''), rules: [
27
- {
28
- required: true,
29
- message: 'Please confirm your password',
30
- },
31
- {
32
- validator: async (_, value) => {
33
- const password = form.getValues('password');
34
- if (!value)
35
- return;
36
- if (!value || password !== value) {
37
- throw new Error('Passwords don’t match');
38
- }
39
- },
40
- },
41
- ], children: _jsx(PasswordInput, { className: "mb-6", value: confirmPassword, placeholder: "Re-enter password", maxLength: maxLength, showStrengthIndicator: false }) })] }) }));
14
+ }, onPressBack: handleBack, children: _jsxs("div", { style: { width: '100%' }, children: [_jsxs("div", { style: { marginBottom: '8px', width: '100%' }, children: [_jsx(Typography, { type: "body", size: "small", className: "mb-1 font-medium", children: "Enter Password" }), _jsx("div", { style: { width: '100%' }, children: _jsx(PasswordInput, { placeholder: "Enter password", value: password, onChange: (value) => handlePassword(value), maxLength: maxLength, showStrengthIndicator: false, style: { width: '100%' } }) })] }), _jsx(PasswordCriteria, { email: email, password: password, criteria: criteria, onCriteriaChange: setCriteria, onMaxLengthChange: setMaxLength }), _jsxs("div", { style: { marginTop: '24px', marginBottom: '24px', width: '100%' }, children: [_jsx(Typography, { type: "body", size: "small", className: "mb-1 font-medium", children: "Confirm Password" }), _jsx("div", { style: { width: '100%' }, children: _jsx(PasswordInput, { placeholder: "Re-enter password", value: confirmPassword, onChange: (value) => handleConfirmPassword(value), maxLength: maxLength, showStrengthIndicator: false, style: { width: '100%' } }) }), confirmPassword && password !== confirmPassword && (_jsx(Typography, { type: "body", size: "tiny", className: "text-red-500 mt-1", children: "Passwords don't match" }))] })] }) }));
42
15
  };
43
16
  export default CreatePassword;
@@ -7,7 +7,6 @@ import { useAuthPackageContext } from '../../hooks/internal/useAuthPackageContex
7
7
  import { CDN_IMAGES_URL } from '../../constants/cdn-url';
8
8
  import { useConsent } from './hooks/internal/useConsent';
9
9
  import { ScreenLayout } from "../../components/ScreenLayout";
10
- import { useNavigator } from '../../hooks/useNavigator';
11
10
  import VerifyMobile from "../VerifyMobile";
12
11
  import VerifyEmail from "../VerifyEmail";
13
12
  import redirectHome from '../../../assets/animation/redirect-home.json';
@@ -20,7 +19,6 @@ const UserConsent = ({ userDetails, handleBack }) => {
20
19
  const [sessionToken, setSessionToken] = useState('');
21
20
  const { onLogin, appConfig: { appName, privacyPolicyUrl }, LogoComponent, onTokenChange } = useAuthPackageContext();
22
21
  const { loading, onAgree } = useConsent();
23
- const navigator = useNavigator();
24
22
  const onAgreeHandler = (res) => {
25
23
  const { token, member, emailVerificationRequired, mobileVerificationRequired, sessionToken } = res;
26
24
  if (token && member) {
@@ -58,18 +56,25 @@ const UserConsent = ({ userDetails, handleBack }) => {
58
56
  source: 'web',
59
57
  onResult: onAgreeHandler
60
58
  }), className: "w-full lg:!w-auto lg:!mt-0" }), _jsx(Button, { label: "Not Now, I Will Register Later", variant: "link", onClick: () => setRedirectModal(true), className: "w-full lg:!w-auto lg:!mt-0" })] })] }) })] }), subTitle: "", onPressBack: handleBack }), redirectModal &&
61
- _jsx(RedirectToHomeModal, { redirectModal: redirectModal, navigator: navigator }), showVerifyMobileModal &&
59
+ _jsx(RedirectToHomeModal, { redirectModal: redirectModal }), showVerifyMobileModal &&
62
60
  _jsx(VerifyMobileModal, { phone: phone, visible: showVerifyMobileModal, hide: () => setShowVerifyMobileModal(false), sessionToken: sessionToken }), showVerifyEmailModal &&
63
61
  _jsx(VerifyEmailModal, { email: email, visible: showVerifyEmailModal, hide: () => setShowVerifyEmailModal(false), sessionToken: sessionToken, onVerifiedOTP: () => {
64
62
  setShowVerifyEmailModal(false);
65
63
  setShowVerifyMobileModal(true);
66
64
  } })] }));
67
65
  };
68
- const RedirectToHomeModal = ({ redirectModal, navigator }) => {
66
+ const RedirectToHomeModal = ({ redirectModal }) => {
67
+ const [isMounted, setIsMounted] = useState(false);
69
68
  useEffect(() => {
70
- navigator.pushAbsolute('/login');
69
+ setIsMounted(true);
70
+ // Redirect after a short delay to show the modal
71
+ const timer = setTimeout(() => {
72
+ // Use window.location for full page navigation to avoid context issues
73
+ window.location.href = '/login';
74
+ }, 2000);
75
+ return () => clearTimeout(timer);
71
76
  }, []);
72
- return (_jsxs(Modal, { title: "", open: redirectModal, showCloseButton: false, footer: null, children: [_jsx(Suspense, { fallback: _jsx("div", { className: "h-[150px] w-[250px]" }), children: _jsx(Lottie
77
+ return (_jsxs(Modal, { title: "", open: redirectModal, showCloseButton: false, footer: null, children: [isMounted && (_jsx(Suspense, { fallback: _jsx("div", { className: "h-[150px] w-[250px]" }), children: _jsx(Lottie
73
78
  /* @ts-ignore */
74
79
  , {
75
80
  /* @ts-ignore */
@@ -77,7 +82,7 @@ const RedirectToHomeModal = ({ redirectModal, navigator }) => {
77
82
  animationData: redirectHome,
78
83
  loop: true,
79
84
  autoplay: true
80
- }, height: 150, width: 250 }) }), _jsxs(Flex, { direction: 'column', style: { marginTop: "-30px" }, children: [_jsx(Typography, { type: 'heading', size: 'h5', className: 'text-center mb-6', color: "text-gray-800", children: "Redirecting to the website homepage" }), _jsxs(Flex, { children: [_jsx(Info, { color: 'blue' }), _jsx(Typography, { type: 'body', size: 'small', className: 'text-center mb-6', color: "text-gray-800", children: "We have not stored any information you shared during registration." })] })] })] }));
85
+ }, height: 150, width: 250 }) })), _jsxs(Flex, { direction: 'column', style: { marginTop: isMounted ? "-30px" : "0" }, children: [_jsx(Typography, { type: 'heading', size: 'h5', className: 'text-center mb-6', color: "text-gray-800", children: "Redirecting to the website homepage" }), _jsxs(Flex, { children: [_jsx(Info, { color: 'blue' }), _jsx(Typography, { type: 'body', size: 'small', className: 'text-center mb-6', color: "text-gray-800", children: "We have not stored any information you shared during registration." })] })] })] }));
81
86
  };
82
87
  const VerifyMobileModal = ({ visible, hide, sessionToken, phone }) => {
83
88
  return (_jsx(ResponsiveModal, { title: 'Verify Mobile', open: visible, onClose: hide, onOpenChange: hide, maskClosable: false, showCloseButton: false, children: _jsx(VerifyMobile, { sessionToken: sessionToken, phone: phone }) }));
@@ -1,9 +1,20 @@
1
+ interface UseCreatePasswordProps {
2
+ /** Initial password value (for preserving state when navigating back) */
3
+ initialPassword?: string;
4
+ /** Initial confirm password value (for preserving state when navigating back) */
5
+ initialConfirmPassword?: string;
6
+ }
1
7
  /**
2
8
  * @internal
3
9
  * Internal hook for managing CreatePassword screen state and auth context integration.
4
10
  * Not exposed to package consumers.
11
+ *
12
+ * Both web and native use the same pattern:
13
+ * - Hook manages password state internally
14
+ * - Use handlePassword/handleConfirmPassword to update state
15
+ * - Optional initial values for preserving state when navigating back
5
16
  */
6
- declare const useCreatePassword: () => {
17
+ declare const useCreatePassword: (props?: UseCreatePasswordProps) => {
7
18
  password: string;
8
19
  setPassword: import("react").Dispatch<import("react").SetStateAction<string>>;
9
20
  confirmPassword: string;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "description": "Truworth Auth Package for React Native and Web",
7
- "version": "3.0.2",
7
+ "version": "3.0.3",
8
8
  "main": "build/src/index.js",
9
9
  "types": "build/types/index.d.ts",
10
10
  "files": [