From 384f7a2ed0f3066d4d014d3fda5d9fb2ae444391 Mon Sep 17 00:00:00 2001 From: jc <46619361+juancwu@users.noreply.github.com> Date: Wed, 11 Dec 2024 12:57:15 -0500 Subject: [PATCH] skip basic details step --- .../components/layout/RegistrationGuard.tsx | 26 +- frontend/src/pages/Register.tsx | 39 +-- frontend/src/types/auth.ts | 8 +- frontend/src/utils/Router.tsx | 310 +++++++++++------- 4 files changed, 222 insertions(+), 161 deletions(-) diff --git a/frontend/src/components/layout/RegistrationGuard.tsx b/frontend/src/components/layout/RegistrationGuard.tsx index c91dd42b..322e6f7c 100644 --- a/frontend/src/components/layout/RegistrationGuard.tsx +++ b/frontend/src/components/layout/RegistrationGuard.tsx @@ -1,4 +1,4 @@ -import { useNavigate } from "react-router-dom"; +import { useNavigate } from 'react-router-dom'; import { useAuth } from '@/contexts/AuthContext'; import { useEffect } from 'react'; @@ -8,31 +8,21 @@ const RegistrationGuard = ({ children }: { children: React.ReactNode }) => { useEffect(() => { if (user) { - if (!user.isEmailVerified) { + if (!user.email_verified) { navigate('/register', { state: { step: 'verify-email', - email: user.email + email: user.email, }, - replace: true - }); - return; - } - - if (!user.firstName || !user.lastName) { - navigate('/register', { - state: { - step: 'form-details', - email: user.email - }, - replace: true + replace: true, }); return; } } - }, [user, navigate]); + }, [user]); - return <>{ children } + return <>{children}; }; -export { RegistrationGuard }; \ No newline at end of file +export { RegistrationGuard }; + diff --git a/frontend/src/pages/Register.tsx b/frontend/src/pages/Register.tsx index 553be477..47a7af83 100644 --- a/frontend/src/pages/Register.tsx +++ b/frontend/src/pages/Register.tsx @@ -309,11 +309,7 @@ const FormDetails = ({ const RegistrationComplete = ({ onComplete }: RegistrationCompleteProps) => { useEffect(() => { - const timer = setTimeout(() => { - onComplete(); - }, 2000); - - return () => clearTimeout(timer); + setTimeout(onComplete, 1000); }, [onComplete]); return ( @@ -341,21 +337,17 @@ const Register = () => { } if (user) { - if (!user.isEmailVerified) { + if (!user.email_verified) { return 'verify-email'; } - - if (!user.firstName || !user.lastName) { - return 'form-details'; - } } return 'login-register'; }); const [formData, setFormData] = useState({ - firstName: user?.firstName || '', - lastName: user?.lastName || '', + firstName: user?.first_name || '', + lastName: user?.last_name || '', position: '', bio: '', linkedIn: '', @@ -448,16 +440,11 @@ const Register = () => { company ? company.ID : null ); - if (!signinResp.user.isEmailVerified) { + if (!signinResp.user.email_verified) { setCurrentStep('verify-email'); return; } - if (!signinResp.user.firstName || !signinResp.user.lastName) { - setCurrentStep('form-details'); - return; - } - // Redirect based on user role if (signinResp.user.role === 'admin') { navigate('/admin/projects', { replace: true }); @@ -488,8 +475,8 @@ const Register = () => { const handleFormSubmit = (e: FormEvent) => { e.preventDefault(); if (!user) return; - user.firstName = formData.firstName; - user.lastName = formData.lastName; + user.first_name = formData.firstName; + user.last_name = formData.lastName; setAuth(user, accessToken, companyId); setCurrentStep('registration-complete'); }; @@ -528,7 +515,9 @@ const Register = () => { case 'signing-in': return ( setCurrentStep('form-details')} + onComplete={() => + setCurrentStep('registration-complete') + } /> ); case 'form-details': @@ -553,11 +542,9 @@ const Register = () => { useEffect(() => { if (user && currentStep === 'login-register') { - if (!user.isEmailVerified) { + if (!user.email_verified) { setCurrentStep('verify-email'); - } else if (!user.firstName || !user.lastName) { - setCurrentStep('form-details'); - } else { + } else if (user) { if (user.role === 'admin') { navigate('/admin/dashboard', { replace: true }); } else if (user.role === 'startup_owner') { @@ -567,7 +554,7 @@ const Register = () => { } } } - }, [user, currentStep, navigate]); + }, [user, currentStep]); return (
diff --git a/frontend/src/types/auth.ts b/frontend/src/types/auth.ts index 7deb5863..51443662 100644 --- a/frontend/src/types/auth.ts +++ b/frontend/src/types/auth.ts @@ -3,9 +3,9 @@ export type UserRole = 'startup_owner' | 'admin' | 'investor'; export interface User { id: string; email: string; - firstName: string; - lastName: string; + first_name: string; + last_name: string; role: string; - walletAddress: string; - isEmailVerified: boolean; + wallet_address: string; + email_verified: boolean; } diff --git a/frontend/src/utils/Router.tsx b/frontend/src/utils/Router.tsx index ed355def..4e415485 100644 --- a/frontend/src/utils/Router.tsx +++ b/frontend/src/utils/Router.tsx @@ -23,13 +23,22 @@ const Router = () => ( } /> {/* User routes */} - - - - - - } /> + + + + + + } + /> ( } /> - - - - - - } /> - - - - - - } /> - - - - - - } /> - - - - - - } /> - - - - - - } /> - - - - - - } /> - + + + + + + } + /> + + + + + + } + /> + + + + + + } + /> + + + + + + } + /> + + + + + + } + /> + + + + + + } + /> + {/* Admin routes */} - - - - - - } /> - - - - - - } /> - - - - - - } /> - - - - - - } /> - - - - - - } /> - - - - - - } /> - - - - - - } /> - - - - - - } /> - - - - - - } /> + + + + + + } + /> + + + + + + } + /> + + + + + + } + /> + + + + + + } + /> + + + + + + } + /> + + + + + + } + /> + + + + + + } + /> + + + + + + } + /> + + + + + + } + />