-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add login/registration forms #284
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { z } from 'zod'; | ||
import { registerSchema } from '../register/register-schema'; | ||
|
||
export const loginSchema = registerSchema.pick({ | ||
email: true, | ||
password: true, | ||
}); | ||
|
||
export type LoginSchemaType = z.infer<typeof loginSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { useForm } from 'react-hook-form'; | ||
import { Link, useNavigate } from 'react-router-dom'; | ||
import { zodResolver } from '@hookform/resolvers/zod'; | ||
|
||
import { Input } from '@/components/ui/input'; | ||
import { Button } from '@/components/ui/button'; | ||
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form'; | ||
import { LoadingSpinner } from '@/components/connections/components/LoadingSpinner'; | ||
|
||
import useLoginMutation from '@/hooks/mutations/useLoginMutation'; | ||
import { type LoginSchemaType, loginSchema } from './login-schema'; | ||
import { toast } from 'sonner'; | ||
|
||
export const LoginUserForm = () => { | ||
const navigate = useNavigate(); | ||
const { mutate: login, isPending: loginPending } = useLoginMutation(); | ||
|
||
const form = useForm<LoginSchemaType>({ | ||
resolver: zodResolver(loginSchema), | ||
}); | ||
|
||
const onSubmit = async (data: LoginSchemaType) => { | ||
login(data, { | ||
onSuccess: () => { | ||
navigate('/'); | ||
}, | ||
onError: () => { | ||
toast.error("Failed to log in. Please verify your email and password and try again."); | ||
}, | ||
}); | ||
}; | ||
|
||
return ( | ||
<div className='mx-auto w-full max-w-sm lg:w-96'> | ||
<div className='text-center'> | ||
<Link to='/'> | ||
<img src='/logo.png' className='w-14 mx-auto' /> | ||
</Link> | ||
<h2 className='mt-6 text-3xl font-extrabold'>Login</h2> | ||
<p className='mt-2 text-sm'> | ||
Don't have an account?{' '} | ||
<Link to='/auth/register' className='font-medium text-primary hover:text-primary/80'> | ||
Register | ||
</Link> | ||
</p> | ||
</div> | ||
|
||
<Form {...form}> | ||
<form className='space-y-6 mt-8' onSubmit={form.handleSubmit(onSubmit)}> | ||
<FormField | ||
control={form.control} | ||
name='email' | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel htmlFor='email'>Email</FormLabel> | ||
<FormControl> | ||
<Input placeholder='[email protected]' autoComplete='email' {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
|
||
<FormField | ||
control={form.control} | ||
name='password' | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel htmlFor='password'>Password</FormLabel> | ||
<FormControl> | ||
<Input placeholder='********' type='password' autoComplete='current-password' {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
|
||
<Link to='/auth/forgot-password' className='font-medium block text-sm text-primary hover:text-primary/80'> | ||
Forgot your password? | ||
</Link> | ||
|
||
<Button type='submit' className='w-full' disabled={loginPending}> | ||
{loginPending ? <LoadingSpinner className='' /> : 'Login'} | ||
</Button> | ||
</form> | ||
</Form> | ||
</div> | ||
); | ||
}; |
81 changes: 81 additions & 0 deletions
81
apps/webapp/src/components/auth/register/create-organization-form.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { useForm } from "react-hook-form"; | ||
import { Link, useNavigate } from "react-router-dom"; | ||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
|
||
import { | ||
Form, | ||
FormControl, | ||
FormField, | ||
FormItem, | ||
FormLabel, | ||
FormMessage, | ||
} from "@/components/ui/form"; | ||
import { Input } from "@/components/ui/input"; | ||
import { Button } from "@/components/ui/button"; | ||
import { LoadingSpinner } from "@/components/connections/components/LoadingSpinner"; | ||
|
||
import useOrganisationMutation from "@/hooks/mutations/useOrganisationMutation"; | ||
import { | ||
type OrganizationFormSchemaType, | ||
organizationFormSchema, | ||
} from "./create-organization-schema"; | ||
|
||
export const CreateOrganizationForm = () => { | ||
const navigate = useNavigate(); | ||
const { mutate, isPending } = useOrganisationMutation(); | ||
|
||
const form = useForm<OrganizationFormSchemaType>({ | ||
resolver: zodResolver(organizationFormSchema), | ||
}); | ||
|
||
const onSubmit = (data: OrganizationFormSchemaType) => { | ||
mutate( | ||
{ ...data, stripe_customer_id: "stripe-customer-76" }, | ||
{ | ||
onSuccess: () => navigate("/"), | ||
} | ||
); | ||
}; | ||
|
||
return ( | ||
<div className="mx-auto w-full max-w-sm lg:w-96"> | ||
<div className="text-center"> | ||
<Link to="/"> | ||
<img src="/logo.png" className="w-14 mx-auto" /> | ||
</Link> | ||
<h2 className="mt-6 text-3xl font-extrabold">Create Organization</h2> | ||
</div> | ||
|
||
<Form {...form}> | ||
<form className="space-y-6 mt-8" onSubmit={form.handleSubmit(onSubmit)}> | ||
<FormField | ||
control={form.control} | ||
name="name" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel htmlFor="name">Name</FormLabel> | ||
<FormControl> | ||
<Input | ||
placeholder="organization" | ||
autoComplete="given-name" | ||
{...field} | ||
/> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<Button className="w-full" type="submit"> | ||
{isPending ? <LoadingSpinner className="" /> : "Create"} | ||
</Button> | ||
</form> | ||
</Form> | ||
<Link | ||
to="/" | ||
className="mt-4 text-sm font-medium text-primary hover:text-primary/80 text-center block mx-auto" | ||
> | ||
Skip For Now | ||
</Link> | ||
</div> | ||
); | ||
}; |
8 changes: 8 additions & 0 deletions
8
apps/webapp/src/components/auth/register/create-organization-schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { z } from 'zod'; | ||
|
||
export const organizationFormSchema = z.object({ | ||
name: z.string().min(1, 'Name is required').max(100, 'Name must be less than 100 characters'), | ||
stripe_customer_id: z.string().min(1, 'stripe customer id is required'), | ||
}); | ||
|
||
export type OrganizationFormSchemaType = z.infer<typeof organizationFormSchema>; |
12 changes: 12 additions & 0 deletions
12
apps/webapp/src/components/auth/register/register-form.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { useState } from 'react'; | ||
|
||
import { RegisterUserForm } from './register-user-form'; | ||
import { CreateOrganizationForm } from './create-organization-form'; | ||
|
||
export const RegisterForm = () => { | ||
const [registered, setIsRegistered] = useState(false); | ||
|
||
if (!registered) return <RegisterUserForm onSuccess={() => setIsRegistered(true)} />; | ||
|
||
return <CreateOrganizationForm />; | ||
}; |
10 changes: 10 additions & 0 deletions
10
apps/webapp/src/components/auth/register/register-schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { z } from 'zod'; | ||
|
||
export const registerSchema = z.object({ | ||
firstName: z.string().min(1, 'First name is required'), | ||
lastName: z.string().min(1, 'Last name is required'), | ||
email: z.string().min(1, 'Email is required').email('Email is invalid'), | ||
password: z.string().min(8, 'Password must be at least 8 characters'), | ||
}); | ||
|
||
export type RegisterSchemaType = z.infer<typeof registerSchema>; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
registerSchema
includes basic validation forfirstName
,lastName
,email
, andpassword
. Consider adding more comprehensive validation rules foremail
andpassword
to enhance security, such as regex patterns for email format and password complexity requirements.Committable suggestion