Skip to content

Commit

Permalink
[fix] Resolve compiling project issues | upd 2
Browse files Browse the repository at this point in the history
  • Loading branch information
romashka-dev committed Jan 1, 2025
1 parent 4ae959e commit c4e6abe
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 68 deletions.
21 changes: 15 additions & 6 deletions components/ui/CreateJobForm/CreateJobForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,30 @@ const CreateJobForm = () => {
<h2 className="capitalize font-semibold text-4xl mb-6">add job</h2>
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3 items-start">
{/* position */}
<CustomFormField name="position" control={form.control} />
<CustomFormField<CreateAndEditJobType>
name="position"
control={form.control}
/>
{/* company */}
<CustomFormField name="company" control={form.control} />
<CustomFormField<CreateAndEditJobType>
name="company"
control={form.control}
/>
{/* location */}
<CustomFormField name="location" control={form.control} />
<CustomFormField<CreateAndEditJobType>
name="location"
control={form.control}
/>

{/* job status */}
<CustomFormSelect
<CustomFormSelect<CreateAndEditJobType>
name="status"
control={form.control}
labelText="job status"
labelText="Job status"
items={Object.values(JobStatus)}
/>
{/* job mode */}
<CustomFormSelect
<CustomFormSelect<CreateAndEditJobType>
name="mode"
control={form.control}
labelText="job mode"
Expand Down
112 changes: 50 additions & 62 deletions components/ui/FormComponents/FormComponents.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Control, FieldValues } from 'react-hook-form'
import { Control, FieldValues, Path } from 'react-hook-form'
import {
Select,
SelectContent,
Expand All @@ -15,81 +15,69 @@ import {
} from '../Form'
import { Input } from '../Input'

type CustomFormFieldProps = {
name: string
control: Control<FieldValues>
type CustomFormFieldProps<T extends FieldValues> = {
name: Path<T>
control: Control<T>
}

const CustomFormField = ({ name, control }: CustomFormFieldProps) => {
const CustomFormField = <T extends FieldValues>({
name,
control,
}: CustomFormFieldProps<T>) => {
return (
<>
<FormField
control={control}
name={name}
render={({ field }) => (
<FormItem>
<FormLabel className="capitalize">{name}</FormLabel>
<FormControl>
<Input {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</>
<FormField
control={control}
name={name}
render={({ field }) => (
<FormItem>
<FormLabel className="capitalize">{name}</FormLabel>
<FormControl>
<Input {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
)
}

type CustomFormSelectProps = {
name: string
control: Control<FieldValues>
items: string[]
type CustomFormSelectProps<T extends FieldValues> = {
name: Path<T>
control: Control<T>
items: Array<string>
labelText?: string
}

const CustomFormSelect = ({
const CustomFormSelect = <T extends FieldValues>({
name,
control,
items,
labelText,
}: CustomFormSelectProps) => {
}: CustomFormSelectProps<T>) => {
return (
<>
<FormField
control={control}
name={name}
render={({ field }) => {
return (
<>
<FormItem>
<FormLabel className="capitalize">
{labelText || name}
</FormLabel>
<Select
onValueChange={field.onChange}
defaultValue={field.value}
>
<FormControl>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
</FormControl>
<SelectContent>
{items.map((item) => {
return (
<SelectItem key={item} value={item}>
{item}
</SelectItem>
)
})}
</SelectContent>
</Select>
</FormItem>
</>
)
}}
></FormField>
</>
<FormField
control={control}
name={name}
render={({ field }) => (
<FormItem>
<FormLabel className="capitalize">{labelText || name}</FormLabel>
<Select onValueChange={field.onChange} defaultValue={field.value}>
<FormControl>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
</FormControl>
<SelectContent>
{items.map((item) => (
<SelectItem key={item} value={item}>
{item}
</SelectItem>
))}
</SelectContent>
</Select>
</FormItem>
)}
/>
)
}

Expand Down

0 comments on commit c4e6abe

Please sign in to comment.