-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor: Use Named Exports for Form Components and Import Types from Schema #28
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
Merged
Merged
Changes from all commits
Commits
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 hidden or 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 hidden or 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,112 @@ | ||
"use client"; | ||
|
||
import Link from "next/link"; | ||
import { useRouter } from "next/navigation"; | ||
import { | ||
Card, | ||
CardContent, | ||
CardDescription, | ||
CardFooter, | ||
CardHeader, | ||
CardTitle, | ||
} from "@/components/ui/card"; | ||
import { signinAction } from "@/actions/auth/signin/action"; | ||
import { useForm } from "react-hook-form"; | ||
import { useAction } from "next-safe-action/hooks"; | ||
import { Form } from "@/components/ui/form"; | ||
import { FormInput } from "@/components/shared/Form/FormInput"; | ||
import { signinSchema, SigninInput } from "@/actions/auth/signin/schema"; | ||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
import { toast } from "sonner"; | ||
import { FormButton } from "@/components/shared/Form/FormButton"; | ||
|
||
export function SigninForm() { | ||
const form = useForm<SigninInput>({ | ||
mode: "onChange", | ||
resolver: zodResolver(signinSchema), | ||
defaultValues: { | ||
email: "", | ||
password: "", | ||
}, | ||
}); | ||
const router = useRouter(); | ||
|
||
const { execute, isExecuting } = useAction(signinAction, { | ||
onSuccess: () => { | ||
toast.success("Signed in successfully!"); | ||
router.push("/"); | ||
}, | ||
onError: (error) => { | ||
const fieldErrors = error.error.validationErrors?.fieldErrors; | ||
const errorMessage = | ||
error.error.serverError ?? | ||
(fieldErrors | ||
? Object.entries(fieldErrors) | ||
.map(([key, value]) => `${key}: ${value}`) | ||
.join(", ") | ||
: "An unknown error occurred"); | ||
toast.error(errorMessage); | ||
}, | ||
}); | ||
|
||
return ( | ||
<div className="min-h-screen flex items-center justify-center bg-gray-50 py-12 px-4 sm:px-6 lg:px-8"> | ||
<Card className="w-full max-w-md"> | ||
<CardHeader className="space-y-1"> | ||
<CardTitle className="text-2xl font-bold text-center"> | ||
Sign in to Sentiopulse | ||
</CardTitle> | ||
<CardDescription className="text-center"> | ||
Enter your credentials to access your account | ||
</CardDescription> | ||
</CardHeader> | ||
|
||
<Form {...form}> | ||
<form onSubmit={form.handleSubmit(execute)}> | ||
<CardContent className="space-y-4"> | ||
<FormInput | ||
control={form.control} | ||
name="email" | ||
label="Email" | ||
placeholder="john@example.com" | ||
type="email" | ||
required | ||
/> | ||
<FormInput | ||
control={form.control} | ||
name="password" | ||
label="Password" | ||
placeholder="Enter your password" | ||
type="password" | ||
required | ||
/> | ||
</CardContent> | ||
|
||
<CardFooter className="flex flex-col space-y-4"> | ||
<FormButton | ||
className="w-full" | ||
loading={isExecuting} | ||
disabled={ | ||
!form.formState.isValid || | ||
!form.formState.isDirty || | ||
isExecuting | ||
} | ||
> | ||
Sign in | ||
</FormButton> | ||
<p className="text-center text-sm text-gray-600"> | ||
Don't have an account?{" "} | ||
<Link | ||
href="/signup" | ||
className="text-blue-600 hover:underline font-medium" | ||
> | ||
Sign up | ||
</Link> | ||
</p> | ||
</CardFooter> | ||
</form> | ||
</Form> | ||
</Card> | ||
</div> | ||
); | ||
} |
This file contains hidden or 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,151 @@ | ||
"use client"; | ||
|
||
import Link from "next/link"; | ||
import { useRouter } from "next/navigation"; | ||
import { | ||
Card, | ||
CardContent, | ||
CardFooter, | ||
CardHeader, | ||
CardTitle, | ||
} from "@/components/ui/card"; | ||
import { signupAction } from "@/actions/auth/signup/action"; | ||
import { useForm } from "react-hook-form"; | ||
import { useAction } from "next-safe-action/hooks"; | ||
import { Form } from "@/components/ui/form"; | ||
import { FormInput } from "@/components/shared/Form/FormInput"; | ||
import { FormCheckbox } from "@/components/shared/Form/FormCheckbox"; | ||
import { signupSchema, SignupInput } from "@/actions/auth/signup/schema"; | ||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
import { toast } from "sonner"; | ||
import { FormButton } from "@/components/shared/Form/FormButton"; | ||
|
||
export function SignupForm() { | ||
const form = useForm<SignupInput>({ | ||
mode: "onChange", | ||
resolver: zodResolver(signupSchema), | ||
defaultValues: { | ||
name: "", | ||
email: "", | ||
password: "", | ||
confirmPassword: "", | ||
terms: false, | ||
}, | ||
}); | ||
const router = useRouter(); | ||
|
||
const { execute, isExecuting } = useAction(signupAction, { | ||
onSuccess: () => { | ||
toast.success("Account created successfully!"); | ||
form.reset(); | ||
router.push("/"); | ||
}, | ||
onError: (error) => { | ||
const fieldErrors = error.error.validationErrors?.fieldErrors; | ||
const errorMessage = | ||
error.error.serverError ?? | ||
(fieldErrors | ||
? Object.entries(fieldErrors) | ||
.map(([key, value]) => `${key}: ${value}`) | ||
.join(", ") | ||
: "An unknown error occurred"); | ||
toast.error(errorMessage); | ||
}, | ||
}); | ||
|
||
return ( | ||
<div className="min-h-screen flex items-center justify-center bg-gray-50 py-12 px-4 sm:px-6 lg:px-8"> | ||
<Card className="w-full max-w-md"> | ||
<CardHeader className="space-y-1"> | ||
<CardTitle className="text-2xl font-bold text-center"> | ||
Create your account | ||
</CardTitle> | ||
</CardHeader> | ||
|
||
<Form {...form}> | ||
<form onSubmit={form.handleSubmit(execute)}> | ||
<CardContent className="space-y-4"> | ||
<FormInput | ||
control={form.control} | ||
name="name" | ||
label="Full Name" | ||
placeholder="John Doe" | ||
required | ||
/> | ||
<FormInput | ||
control={form.control} | ||
name="email" | ||
label="Email" | ||
placeholder="john@example.com" | ||
type="email" | ||
required | ||
/> | ||
<FormInput | ||
control={form.control} | ||
name="password" | ||
label="Password" | ||
placeholder="Create a strong password" | ||
type="password" | ||
required | ||
/> | ||
<FormInput | ||
control={form.control} | ||
name="confirmPassword" | ||
label="Confirm Password" | ||
placeholder="Confirm your password" | ||
type="password" | ||
required | ||
/> | ||
<FormCheckbox | ||
control={form.control} | ||
name="terms" | ||
label={ | ||
<span> | ||
I agree to the{" "} | ||
<Link | ||
href="/terms" | ||
className="text-blue-600 hover:underline" | ||
> | ||
Terms of Service | ||
</Link>{" "} | ||
and{" "} | ||
<Link | ||
href="/privacy" | ||
className="text-blue-600 hover:underline" | ||
> | ||
Privacy Policy | ||
</Link> | ||
</span> | ||
} | ||
required | ||
/> | ||
</CardContent> | ||
|
||
<CardFooter className="flex flex-col space-y-4"> | ||
<FormButton | ||
className="w-full" | ||
loading={isExecuting} | ||
disabled={ | ||
!form.formState.isValid || | ||
!form.formState.isDirty || | ||
isExecuting | ||
} | ||
> | ||
Create account | ||
</FormButton> | ||
<p className="text-center text-sm text-gray-600"> | ||
Already have an account?{" "} | ||
<Link | ||
href="/signin" | ||
className="text-blue-600 hover:underline font-medium" | ||
> | ||
Sign in | ||
</Link> | ||
</p> | ||
</CardFooter> | ||
</form> | ||
</Form> | ||
</Card> | ||
</div> | ||
); | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -1,115 +1,5 @@ | ||
"use client"; | ||
import { SigninForm } from "@/components/models/auth/SigninForm"; | ||
|
||
import Link from "next/link"; | ||
import { useRouter } from "next/navigation"; | ||
import { | ||
Card, | ||
CardContent, | ||
CardDescription, | ||
CardFooter, | ||
CardHeader, | ||
CardTitle, | ||
} from "@/components/ui/card"; | ||
import { signinAction } from "@/actions/auth/signin/action"; | ||
import { useForm } from "react-hook-form"; | ||
import { useAction } from "next-safe-action/hooks"; | ||
import { Form } from "@/components/ui/form"; | ||
import FormInput from "@/components/shared/Form/FormInput"; | ||
import { signinSchema } from "@/actions/auth/signin/schema"; | ||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
import { z } from "zod"; | ||
import { toast } from "sonner"; | ||
import { FormButton } from "@/components/shared/Form/FormButton"; | ||
|
||
type SignInFormValues = z.infer<typeof signinSchema>; | ||
|
||
export function SigninPageContainer() { | ||
const form = useForm<SignInFormValues>({ | ||
mode: "onChange", | ||
resolver: zodResolver(signinSchema), | ||
defaultValues: { | ||
email: "", | ||
password: "", | ||
}, | ||
}); | ||
const router = useRouter(); | ||
|
||
const { execute, isExecuting } = useAction(signinAction, { | ||
onSuccess: () => { | ||
toast.success("Signed in successfully!"); | ||
router.push("/"); | ||
}, | ||
onError: (error) => { | ||
const fieldErrors = error.error.validationErrors?.fieldErrors; | ||
const errorMessage = | ||
error.error.serverError ?? | ||
(fieldErrors | ||
? Object.entries(fieldErrors) | ||
.map(([key, value]) => `${key}: ${value}`) | ||
.join(", ") | ||
: "An unknown error occurred"); | ||
toast.error(errorMessage); | ||
}, | ||
}); | ||
|
||
return ( | ||
<div className="min-h-screen flex items-center justify-center bg-gray-50 py-12 px-4 sm:px-6 lg:px-8"> | ||
<Card className="w-full max-w-md"> | ||
<CardHeader className="space-y-1"> | ||
<CardTitle className="text-2xl font-bold text-center"> | ||
Sign in to Sentiopulse | ||
</CardTitle> | ||
<CardDescription className="text-center"> | ||
Enter your credentials to access your account | ||
</CardDescription> | ||
</CardHeader> | ||
|
||
<Form {...form}> | ||
<form onSubmit={form.handleSubmit(execute)}> | ||
<CardContent className="space-y-4"> | ||
<FormInput | ||
control={form.control} | ||
name="email" | ||
label="Email" | ||
placeholder="john@example.com" | ||
type="email" | ||
required | ||
/> | ||
<FormInput | ||
control={form.control} | ||
name="password" | ||
label="Password" | ||
placeholder="Enter your password" | ||
type="password" | ||
required | ||
/> | ||
</CardContent> | ||
|
||
<CardFooter className="flex flex-col space-y-4"> | ||
<FormButton | ||
className="w-full" | ||
loading={isExecuting} | ||
disabled={ | ||
!form.formState.isValid || | ||
!form.formState.isDirty || | ||
isExecuting | ||
} | ||
> | ||
Sign in | ||
</FormButton> | ||
<p className="text-center text-sm text-gray-600"> | ||
Don't have an account?{" "} | ||
<Link | ||
href="/signup" | ||
className="text-blue-600 hover:underline font-medium" | ||
> | ||
Sign up | ||
</Link> | ||
</p> | ||
</CardFooter> | ||
</form> | ||
</Form> | ||
</Card> | ||
</div> | ||
); | ||
} | ||
export function SigninPageContainer(){ | ||
return <SigninForm/> | ||
} |
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.
Checkbox onChange likely sets non-boolean values — fix in FormCheckbox.
Current FormCheckbox uses onChange={field.onChange} on a native checkbox. Controller expects you to pass checked boolean; otherwise RHF may store "on" or the event, breaking z.boolean() and preventing valid submission.
Update FormCheckbox:
File: src/components/shared/Form/FormCheckbox.tsx
📝 Committable suggestion
🤖 Prompt for AI Agents