SignUp.hooks.ts 983 B

1234567891011121314151617181920212223242526272829303132
  1. import { useState } from 'react';
  2. import { useAppDispatch, useAppSelector } from '../../../store';
  3. import { currentUserActions } from '../../../redux/current-user/slice';
  4. import { useNavigate } from 'react-router-dom';
  5. export const useSignUp = () => {
  6. const [showPassword, setShowPassword] = useState(false);
  7. const [showConfirmPassword, setShowConfirmPassword] = useState(false);
  8. const appDispatch = useAppDispatch();
  9. const currentUser = useAppSelector((state) => state.currentUser);
  10. const navigate = useNavigate();
  11. function onTogglePassword() {
  12. setShowPassword(!showPassword);
  13. }
  14. function onToggleConfirmPassword() {
  15. setShowConfirmPassword(!showConfirmPassword);
  16. }
  17. function onSignUpClick() {
  18. appDispatch(
  19. currentUserActions.updateUser({
  20. ...currentUser,
  21. isAuthenticated: true,
  22. })
  23. );
  24. navigate('/');
  25. }
  26. return { showPassword, onTogglePassword, showConfirmPassword, onToggleConfirmPassword, onSignUpClick };
  27. };