157 lines
5.6 KiB
TypeScript
157 lines
5.6 KiB
TypeScript
'use client';
|
|
|
|
import { useForm } from "react-hook-form";
|
|
import { Button } from "@/components/ui/button";
|
|
import InputField from "@/components/forms/InputField";
|
|
import SelectField from "@/components/forms/SelectField";
|
|
import PasswordRequirements from "@/components/forms/PasswordRequirements";
|
|
import { INVESTMENT_GOALS, PASSWORD_VALIDATION, PREFERRED_INDUSTRIES, RISK_TOLERANCE_OPTIONS } from "@/lib/constants";
|
|
import { CountrySelectField } from "@/components/forms/CountrySelectField";
|
|
import FooterLink from "@/components/forms/FooterLink";
|
|
import { signUpWithEmail } from "@/lib/actions/auth.actions";
|
|
import { useRouter } from "next/navigation";
|
|
import { toast } from "sonner";
|
|
import OpenDevSocietyBranding from "@/components/OpenDevSocietyBranding";
|
|
import React from "react";
|
|
|
|
const SignUp = () => {
|
|
const router = useRouter()
|
|
const {
|
|
register,
|
|
handleSubmit,
|
|
control,
|
|
watch,
|
|
formState: { errors, isSubmitting },
|
|
} = useForm<SignUpFormData>({
|
|
defaultValues: {
|
|
fullName: '',
|
|
email: '',
|
|
password: '',
|
|
country: 'IN',
|
|
investmentGoals: 'Growth',
|
|
riskTolerance: 'Medium',
|
|
preferredIndustry: 'Technology'
|
|
},
|
|
mode: 'onBlur'
|
|
},);
|
|
|
|
const passwordValue = watch('password');
|
|
|
|
const onSubmit = async (data: SignUpFormData) => {
|
|
try {
|
|
const result = await signUpWithEmail(data);
|
|
if (result.success) {
|
|
router.push('/');
|
|
return;
|
|
}
|
|
toast.error('Sign up failed', {
|
|
description: result.error ?? 'We could not create your account.',
|
|
});
|
|
} catch (e) {
|
|
console.error(e);
|
|
toast.error('Sign up failed', {
|
|
description: e instanceof Error ? e.message : 'Failed to create an account.'
|
|
})
|
|
}
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<h1 className="form-title">Sign Up & Personalize</h1>
|
|
|
|
<form onSubmit={handleSubmit(onSubmit)} className="space-y-5">
|
|
<InputField
|
|
name="fullName"
|
|
label="Full Name"
|
|
placeholder="Enter full name"
|
|
register={register}
|
|
error={errors.fullName}
|
|
validation={{ required: 'Full name is required', minLength: 2 }}
|
|
/>
|
|
|
|
<InputField
|
|
name="email"
|
|
label="Email"
|
|
placeholder="opendevsociety@cc.cc"
|
|
register={register}
|
|
error={errors.email}
|
|
validation={{
|
|
required: 'Email is required',
|
|
pattern: {
|
|
value: /^[\w-.]+@([\w-]+\.)+[\w-]{2,}$/,
|
|
message: 'Please enter a valid email address'
|
|
}
|
|
}}
|
|
/>
|
|
|
|
<InputField
|
|
name="password"
|
|
label="Password"
|
|
placeholder="Enter a strong password"
|
|
type="password"
|
|
register={register}
|
|
error={errors.password}
|
|
validation={PASSWORD_VALIDATION}
|
|
/>
|
|
<PasswordRequirements password={passwordValue ?? ''} />
|
|
|
|
<CountrySelectField
|
|
name="country"
|
|
label="Country"
|
|
control={control}
|
|
error={errors.country}
|
|
required
|
|
/>
|
|
|
|
<SelectField
|
|
name="investmentGoals"
|
|
label="Investment Goals"
|
|
placeholder="Select your investment goal"
|
|
options={INVESTMENT_GOALS}
|
|
control={control}
|
|
error={errors.investmentGoals}
|
|
required
|
|
/>
|
|
|
|
<SelectField
|
|
name="riskTolerance"
|
|
label="Risk Tolerance"
|
|
placeholder="Select your risk level"
|
|
options={RISK_TOLERANCE_OPTIONS}
|
|
control={control}
|
|
error={errors.riskTolerance}
|
|
required
|
|
/>
|
|
|
|
<SelectField
|
|
name="preferredIndustry"
|
|
label="Preferred Industry"
|
|
placeholder="Select your preferred industry"
|
|
options={PREFERRED_INDUSTRIES}
|
|
control={control}
|
|
error={errors.preferredIndustry}
|
|
required
|
|
/>
|
|
|
|
<Button type="submit" disabled={isSubmitting} className="yellow-btn w-full mt-5">
|
|
{isSubmitting ? 'Creating Account' : 'Start Your Investing Journey'}
|
|
</Button>
|
|
|
|
<FooterLink text="Already have an account?" linkText="Sign in" href="/sign-in" />
|
|
|
|
<OpenDevSocietyBranding outerClassName="mt-10 flex justify-center" />
|
|
<div className="mt-5 flex justify-center">
|
|
<a href="https://peerlist.io/ravixalgorithm/project/openstock" target="_blank" rel="noreferrer">
|
|
<img
|
|
src="https://peerlist.io/api/v1/projects/embed/PRJH8OED7MBL9MGB9HRMKAKLM66KNN?showUpvote=true&theme=light"
|
|
alt="OpenStock"
|
|
style={{ width: 'auto', height: '72px' }}
|
|
/>
|
|
</a>
|
|
</div>
|
|
</form>
|
|
</>
|
|
)
|
|
}
|
|
export default SignUp;
|