"use client" /* * File: ResetPasswordScreen.tsx * Description: Password reset screen with gradient background and shared components. * Design & Developed by Tech4Biz Solutions * Copyright (c) Spurrin Innovations. All rights reserved. */ import type React from "react" import { useState, useEffect } from "react" import { View, Text, StyleSheet, TextInput, TouchableOpacity } from "react-native" import { Button } from "../../../../shared/src/components/Button" import OnboardingContainer from "../components/OnboardingContainer" import IconContainer from "../components/IconContainer" import { Colors, Spacing, Typography } from "../../../../shared/src/theme" import { showError, showSuccess } from "../../../../shared/src/utils/helpers/Toast" import Icon from "react-native-vector-icons/Feather" import { PasswordIconSVG } from "../../../../shared/src/components/Icons/SvgIcons" import { authAPI } from "../services/authAPI" import { useDispatch, useSelector } from "react-redux" import { selectUser } from "../redux" import { updateOnboarded } from "../redux/authSlice" interface PasswordScreenProps { onContinue: (password: string) => void onBack: () => void } interface PasswordRule { id: string label: string validator: (password: string) => boolean isValid: boolean } const ResetPasswordScreen: React.FC = () => { const [password, setPassword] = useState("") const [confirmPassword, setConfirmPassword] = useState("") const [isPasswordVisible, setPasswordVisible] = useState(false) const [isConfirmPasswordVisible, setConfirmPasswordVisible] = useState(false) const [loading, setLoading] = useState(false); const user=useSelector(selectUser); const dispatch=useDispatch() const [passwordRules, setPasswordRules] = useState([ { id: 'length', label: 'At least 8 characters', validator: (pwd: string) => pwd.length >= 8, isValid: false }, { id: 'uppercase', label: 'One uppercase letter', validator: (pwd: string) => /[A-Z]/.test(pwd), isValid: false }, { id: 'lowercase', label: 'One lowercase letter', validator: (pwd: string) => /[a-z]/.test(pwd), isValid: false }, { id: 'number', label: 'One number', validator: (pwd: string) => /\d/.test(pwd), isValid: false }, { id: 'special', label: 'One special character', validator: (pwd: string) => /[!@#$%^&*(),.?":{}|<>]/.test(pwd), isValid: false }, { id: 'match', label: 'Passwords match', validator: (pwd:string) => {if(pwd.length > 0 && confirmPassword.length > 0 && pwd === confirmPassword){ return true }else{ return false } }, // This will be handled separately isValid: false } ]) console.log('password rules',passwordRules) const validatePassword = (pwd: string): boolean => { return passwordRules.every(rule => rule.isValid) } const updatePasswordRules = (pwd: string) => { setPasswordRules(prevRules => prevRules.map(rule => { if (rule.id === 'match') { return { ...rule, isValid: pwd.length > 0 && confirmPassword.length > 0 && pwd === confirmPassword } } return { ...rule, isValid: rule.validator(pwd) } }) ) } const updatePasswordMatchRule = () => { setPasswordRules(prevRules => prevRules.map(rule => { // if (rule.id === 'match') { // return { // ...rule, // isValid: password.length > 0 && confirmPassword.length > 0 && password === confirmPassword // } // } return rule }) ) } useEffect(() => { updatePasswordRules(password) }, [password,confirmPassword]) // useEffect(() => { // updatePasswordMatchRule() // }, [password, confirmPassword]) const handlePasswordChange = (pwd: string) => { setPassword(pwd) } const handleConfirmPasswordChange = (pwd: string) => { setConfirmPassword(pwd) } const handleContinue = () => { if (!password.trim() || !confirmPassword.trim()) { showError("Validation Error", "Both password fields are required.") return } console.log('Validation',validatePassword(password)) if (!validatePassword(password)) { showError("Validation Error", "Please meet all password requirements.") return } if (password !== confirmPassword) { showError("Validation Error", "Passwords do not match.") return } setLoading(true) setTimeout(() => { setLoading(false) onReset(password) }, 1000) } const onBack=()=>{} const onReset=async (password:string)=>{ const response :any=await authAPI.changepassword({password,token:user?.access_token}); console.log('reset response',response); if(response.data&&response.data.message){ if(response.data.success){ showSuccess(response.data.message); dispatch(updateOnboarded(true)) }else{ showError(response.data.message) } }else{ showError('eeror while changing password') } } const renderPasswordRule = (rule: PasswordRule) => ( {rule.isValid && ( )} {rule.label} ) return ( } /> Reset your password Create a strong password with the following requirements setPasswordVisible(!isPasswordVisible)} style={styles.eyeIcon}> setConfirmPasswordVisible(!isConfirmPasswordVisible)} style={styles.eyeIcon}> {/* Password Rules Section */} Password Requirements: {passwordRules.map(renderPasswordRule)}