Skip to content

Commit

Permalink
skip basic details step (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
juancwu authored Dec 11, 2024
2 parents 5a83003 + 384f7a2 commit 305d1b8
Show file tree
Hide file tree
Showing 4 changed files with 222 additions and 161 deletions.
26 changes: 8 additions & 18 deletions frontend/src/components/layout/RegistrationGuard.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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 };
export { RegistrationGuard };

39 changes: 13 additions & 26 deletions frontend/src/pages/Register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,7 @@ const FormDetails = ({

const RegistrationComplete = ({ onComplete }: RegistrationCompleteProps) => {
useEffect(() => {
const timer = setTimeout(() => {
onComplete();
}, 2000);

return () => clearTimeout(timer);
setTimeout(onComplete, 1000);
}, [onComplete]);

return (
Expand Down Expand Up @@ -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<FormData>({
firstName: user?.firstName || '',
lastName: user?.lastName || '',
firstName: user?.first_name || '',
lastName: user?.last_name || '',
position: '',
bio: '',
linkedIn: '',
Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -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');
};
Expand Down Expand Up @@ -528,7 +515,9 @@ const Register = () => {
case 'signing-in':
return (
<SigningIn
onComplete={() => setCurrentStep('form-details')}
onComplete={() =>
setCurrentStep('registration-complete')
}
/>
);
case 'form-details':
Expand All @@ -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') {
Expand All @@ -567,7 +554,7 @@ const Register = () => {
}
}
}
}, [user, currentStep, navigate]);
}, [user, currentStep]);

return (
<div className="min-h-screen bg-gray-50">
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/types/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading

0 comments on commit 305d1b8

Please sign in to comment.