Skip to content

Commit

Permalink
add form profile component
Browse files Browse the repository at this point in the history
  • Loading branch information
dEdmishka committed Jan 28, 2024
1 parent 755ba4c commit cf0037d
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions src/components/pages/profile/form-profile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
'use client'

import { Button } from '@/components/ui/button'
import {
Form,
FormControl,
FormField,
FormItem,
FormMessage,
} from '@/components/ui/form'
import { Input } from '@/components/ui/input'
import { PROFILE_NAME_LENGTH } from '@/constants'
import { classnames } from '@/utils'
import { zodResolver } from '@hookform/resolvers/zod'
import { FC } from 'react'
import { useForm } from 'react-hook-form'
import * as z from 'zod'

type FormProfileProps = { className?: string }

const formSchema = z.object({
profileName: z
.string()
.min(PROFILE_NAME_LENGTH, 'The field must not be empty'),
})

const ProfileForm: FC<FormProfileProps> = ({ className }) => {
const form = useForm<z.infer<typeof formSchema>>({
defaultValues: {
profileName: '',
},
resolver: zodResolver(formSchema),
})

function onSubmit(values: z.infer<typeof formSchema>) {
alert(JSON.stringify(values))
console.log(values)
}

return (
<Form {...form}>
<form
className={classnames('space-y-8 pr-[9.75rem]', className)}
onSubmit={form.handleSubmit(onSubmit)}
>
<FormField
control={form.control}
name="profileName"
render={({ field }) => (
<FormItem>
<FormControl>
<Input
className="sm:min-w-[343px]"
id="profile_name"
placeholder="Profile Name"
type="text"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<Button className="!mt-8 w-full" type="submit">
Submit
</Button>
</form>
</Form>
)
}

export default ProfileForm

0 comments on commit cf0037d

Please sign in to comment.