-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a8d7251
commit 26466d7
Showing
14 changed files
with
725 additions
and
17 deletions.
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
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
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,22 @@ | ||
import * as React from "react" | ||
import * as CheckboxPrimitive from "@radix-ui/react-checkbox" | ||
import { CheckIcon } from "@radix-ui/react-icons" | ||
|
||
import { cn } from "@/src/lib/utils" | ||
|
||
const Checkbox = React.forwardRef(({ className, ...props }, ref) => ( | ||
<CheckboxPrimitive.Root | ||
ref={ref} | ||
className={cn( | ||
"peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground", | ||
className | ||
)} | ||
{...props}> | ||
<CheckboxPrimitive.Indicator className={cn("flex items-center justify-center text-current")}> | ||
<CheckIcon className="h-4 w-4" /> | ||
</CheckboxPrimitive.Indicator> | ||
</CheckboxPrimitive.Root> | ||
)) | ||
Checkbox.displayName = CheckboxPrimitive.Root.displayName | ||
|
||
export { Checkbox } |
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,133 @@ | ||
import * as React from "react" | ||
import { Slot } from "@radix-ui/react-slot" | ||
import { Controller, FormProvider, useFormContext } from "react-hook-form"; | ||
|
||
import { cn } from "@/src/lib/utils" | ||
import { Label } from "@/src/components/ui/label" | ||
|
||
const Form = FormProvider | ||
|
||
const FormFieldContext = React.createContext({}) | ||
|
||
const FormField = ( | ||
{ | ||
...props | ||
} | ||
) => { | ||
return ( | ||
(<FormFieldContext.Provider value={{ name: props.name }}> | ||
<Controller {...props} /> | ||
</FormFieldContext.Provider>) | ||
); | ||
} | ||
|
||
const useFormField = () => { | ||
const fieldContext = React.useContext(FormFieldContext) | ||
const itemContext = React.useContext(FormItemContext) | ||
const { getFieldState, formState } = useFormContext() | ||
|
||
const fieldState = getFieldState(fieldContext.name, formState) | ||
|
||
if (!fieldContext) { | ||
throw new Error("useFormField should be used within <FormField>") | ||
} | ||
|
||
const { id } = itemContext | ||
|
||
return { | ||
id, | ||
name: fieldContext.name, | ||
formItemId: `${id}-form-item`, | ||
formDescriptionId: `${id}-form-item-description`, | ||
formMessageId: `${id}-form-item-message`, | ||
...fieldState, | ||
} | ||
} | ||
|
||
const FormItemContext = React.createContext({}) | ||
|
||
const FormItem = React.forwardRef(({ className, ...props }, ref) => { | ||
const id = React.useId() | ||
|
||
return ( | ||
(<FormItemContext.Provider value={{ id }}> | ||
<div ref={ref} className={cn("space-y-2", className)} {...props} /> | ||
</FormItemContext.Provider>) | ||
); | ||
}) | ||
FormItem.displayName = "FormItem" | ||
|
||
const FormLabel = React.forwardRef(({ className, ...props }, ref) => { | ||
const { error, formItemId } = useFormField() | ||
|
||
return ( | ||
(<Label | ||
ref={ref} | ||
className={cn(error && "text-destructive", className)} | ||
htmlFor={formItemId} | ||
{...props} />) | ||
); | ||
}) | ||
FormLabel.displayName = "FormLabel" | ||
|
||
const FormControl = React.forwardRef(({ ...props }, ref) => { | ||
const { error, formItemId, formDescriptionId, formMessageId } = useFormField() | ||
|
||
return ( | ||
(<Slot | ||
ref={ref} | ||
id={formItemId} | ||
aria-describedby={ | ||
!error | ||
? `${formDescriptionId}` | ||
: `${formDescriptionId} ${formMessageId}` | ||
} | ||
aria-invalid={!!error} | ||
{...props} />) | ||
); | ||
}) | ||
FormControl.displayName = "FormControl" | ||
|
||
const FormDescription = React.forwardRef(({ className, ...props }, ref) => { | ||
const { formDescriptionId } = useFormField() | ||
|
||
return ( | ||
(<p | ||
ref={ref} | ||
id={formDescriptionId} | ||
className={cn("text-[0.8rem] text-muted-foreground", className)} | ||
{...props} />) | ||
); | ||
}) | ||
FormDescription.displayName = "FormDescription" | ||
|
||
const FormMessage = React.forwardRef(({ className, children, ...props }, ref) => { | ||
const { error, formMessageId } = useFormField() | ||
const body = error ? String(error?.message) : children | ||
|
||
if (!body) { | ||
return null | ||
} | ||
|
||
return ( | ||
(<p | ||
ref={ref} | ||
id={formMessageId} | ||
className={cn("text-[0.8rem] font-medium text-destructive", className)} | ||
{...props}> | ||
{body} | ||
</p>) | ||
); | ||
}) | ||
FormMessage.displayName = "FormMessage" | ||
|
||
export { | ||
useFormField, | ||
Form, | ||
FormItem, | ||
FormLabel, | ||
FormControl, | ||
FormDescription, | ||
FormMessage, | ||
FormField, | ||
} |
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,19 @@ | ||
import * as React from "react" | ||
|
||
import { cn } from "@/src/lib/utils" | ||
|
||
const Input = React.forwardRef(({ className, type, ...props }, ref) => { | ||
return ( | ||
(<input | ||
type={type} | ||
className={cn( | ||
"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50", | ||
className | ||
)} | ||
ref={ref} | ||
{...props} />) | ||
); | ||
}) | ||
Input.displayName = "Input" | ||
|
||
export { Input } |
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,16 @@ | ||
import * as React from "react" | ||
import * as LabelPrimitive from "@radix-ui/react-label" | ||
import { cva } from "class-variance-authority"; | ||
|
||
import { cn } from "@/src/lib/utils" | ||
|
||
const labelVariants = cva( | ||
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" | ||
) | ||
|
||
const Label = React.forwardRef(({ className, ...props }, ref) => ( | ||
<LabelPrimitive.Root ref={ref} className={cn(labelVariants(), className)} {...props} /> | ||
)) | ||
Label.displayName = LabelPrimitive.Root.displayName | ||
|
||
export { Label } |
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,120 @@ | ||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
import { SubmitHandler, useForm } from "react-hook-form"; | ||
import * as z from "zod"; | ||
import { | ||
Form, | ||
FormControl, | ||
FormDescription, | ||
FormField, | ||
FormItem, | ||
FormLabel, | ||
FormMessage, | ||
} from "@/src/components/ui/form"; | ||
import { Input } from "@/src/components/ui/input"; | ||
import Link from "next/link"; | ||
import { Checkbox } from "@/src/components/ui/checkbox"; | ||
import { Button } from "@/src/components/ui/button"; | ||
import AuthLayout from "@/src/views/pages/auth/auth-layout"; | ||
|
||
const loginSchema = z.object({ | ||
email: z.string().email({ | ||
message: "error.invalid_email", | ||
}), | ||
password: z.string().min(8, { | ||
message: "error.min_length", | ||
}), | ||
remember: z.boolean().optional(), | ||
}); | ||
|
||
const LoginPage = () => { | ||
const form = useForm({ | ||
resolver: zodResolver(loginSchema), | ||
defaultValues: { | ||
email: "", | ||
password: "", | ||
remember: false, | ||
}, | ||
}); | ||
|
||
const onSubmit = (data) => { | ||
console.log(data); | ||
}; | ||
|
||
return ( | ||
<AuthLayout> | ||
<div className="flex flex-col justify-center"> | ||
<h1 className="mb-2">👋 Hoş geldiniz</h1> | ||
<p className="mb-4">Toplulukları keşfedin.</p> | ||
<Form {...form}> | ||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4"> | ||
<FormField | ||
control={form.control} | ||
name="email" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>E-posta adresi</FormLabel> | ||
<FormControl> | ||
<Input placeholder="E-posta adresinizi girin" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name="password" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Şifre</FormLabel> | ||
<FormControl> | ||
<Input placeholder="Şifrenizi girin" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<div className="flex justify-between"> | ||
<FormField | ||
control={form.control} | ||
name="remember" | ||
render={({ field }) => ( | ||
<FormItem className="flex justify-center items-center space-x-2"> | ||
<FormControl> | ||
<Checkbox | ||
checked={field.value} | ||
onCheckedChange={field.onChange} | ||
/> | ||
</FormControl> | ||
<FormLabel className="text-primary font-normal"> | ||
Beni hatırla | ||
</FormLabel> | ||
</FormItem> | ||
)} | ||
/> | ||
<Link | ||
href="/auth/forgot-password" | ||
className="text-muted hover:underline text-sm" | ||
> | ||
Şifremi unuttum | ||
</Link> | ||
</div> | ||
<Button type="submit" size="lg" className="w-full"> | ||
Giriş Yap | ||
</Button> | ||
</form> | ||
</Form> | ||
<div className="flex items-center justify-center space-x-2 my-4"> | ||
<p className="text-sm">Hesabınız yok mu?</p> | ||
<Link | ||
href="/auth/register" | ||
className="text-primary hover:underline text-sm" | ||
> | ||
Kayıt ol | ||
</Link> | ||
</div> | ||
</div> | ||
</AuthLayout> | ||
); | ||
}; | ||
|
||
export default LoginPage; |
Oops, something went wrong.