Skip to content

Conversation

@Nil2000
Copy link
Contributor

@Nil2000 Nil2000 commented Oct 17, 2024

✨ Codu Pull Request 💻

Fixes #1140

Pull Request details

  • Validation part attached

Any Breaking changes

  • None

Associated Screenshots

image
image

@Nil2000 Nil2000 requested a review from a team as a code owner October 17, 2024 16:56
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 17, 2024

Walkthrough

The changes in this pull request enhance the Content component in the app/(app)/jobs/create/_client.tsx file by integrating form handling with the react-hook-form library. This includes managing form state, registering input fields, and implementing error handling for validation. A new schema for job postings is introduced in schema/job.ts using the Zod library, which defines validation rules and a TypeScript type alias for job data. The updates improve the form's interactivity and robustness, ensuring required fields are validated before submission.

Changes

File Change Summary
app/(app)/jobs/create/_client.tsx Integrated react-hook-form for form handling, added validation and error messages, updated onSubmit function, and modified input fields for job data.
schema/job.ts Introduced saveJobsSchema for job posting validation using Zod and added type alias saveJobsInput.

Assessment against linked issues

Objective Addressed Explanation
Validation is absent in the Jobs Create page (#1140)

Possibly related PRs

  • UI part done for posting jobs #1106: Enhances the Content component in the same file by integrating form handling and validation, directly relating to the UI work done for the job posting form.

Suggested labels

hacktoberfest-accepted, hacktoberfest

Suggested reviewers

  • John-Paul-Larkin
  • NiallJoeMaher

Poem

In the fields of code we play,
Forms now dance and validation sway.
With hooks and schemas, oh what a sight,
Job postings shine, all errors take flight!
A rabbit's cheer for changes so bright! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@vercel
Copy link

vercel bot commented Oct 17, 2024

@Nil2000 is attempting to deploy a commit to the Codú Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (10)
schema/job.ts (5)

4-7: Fix typo in error message and LGTM for companyName field.

The validation rules for the companyName field are appropriate. However, there's a minor typo in the error message for the minimum length.

Please apply this change:

-    .min(1, "Company name should contain atleast 1 character")
+    .min(1, "Company name should contain at least 1 character")

8-11: Fix typo in error message and LGTM for jobTitle field.

The validation rules for the jobTitle field are appropriate. However, there's a minor typo in the error message for the minimum length, similar to the companyName field.

Please apply this change:

-    .min(3, "Job title should contain atleast 3 character")
+    .min(3, "Job title should contain at least 3 characters")

12-15: Consider increasing the maximum length for jobDescription.

The jobDescription field is correctly set as optional, which is appropriate. However, the maximum length of 200 characters seems quite restrictive for a comprehensive job description.

Consider increasing the maximum length to allow for more detailed job descriptions. A length between 1000 to 5000 characters is more common for job descriptions. For example:

-    .max(200, "Job Description should contain atmost 200 characters")
+    .max(5000, "Job Description should contain at most 5000 characters")

16-19: Standardize error message format for jobLocation field.

The validation rules for the jobLocation field are appropriate. However, there's a minor inconsistency in the error message format compared to other fields.

Please apply this change to standardize the error message format:

-    .max(40, "Max location length is 40 characters.")
+    .max(40, "Location should contain at most 40 characters")

28-28: Consider adding "contract" to jobType options.

The jobType field is well-implemented using an enum to restrict job types to specific values. The provided options cover common job types.

Consider adding "contract" as an option, as it's a common job type distinct from "freelancer". For example:

-  jobType: z.enum(["full-time", "part-time", "freelancer", "other"]),
+  jobType: z.enum(["full-time", "part-time", "freelancer", "contract", "other"]),
app/(app)/jobs/create/_client.tsx (5)

Line range hint 181-194: Register the location checkboxes with react-hook-form

The checkboxes for "Work is remote," "Relocation package given," and "Visa sponsorship provided" are not registered with react-hook-form. As a result, their values won't be included in the form submission data. To capture these values, register each checkbox using the register method.

Apply this diff to register the checkboxes:

<CheckboxGroup className="mt-3">
  <CheckboxField>
-   <Checkbox name="remote" value="is_remote" />
+   <Checkbox value="is_remote" {...register("isRemote")} />
    <Label>Work is remote</Label>
  </CheckboxField>
  <CheckboxField>
-   <Checkbox name="relocation" value="is_relocation_package" />
+   <Checkbox value="is_relocation_package" {...register("isRelocationPackage")} />
    <Label>Relocation package given</Label>
  </CheckboxField>
  <CheckboxField>
-   <Checkbox name="visa" value="is_visa_sponsored" />
+   <Checkbox value="is_visa_sponsored" {...register("isVisaSponsored")} />
    <Label>Visa sponsorship provided</Label>
  </CheckboxField>
</CheckboxGroup>

Line range hint 231-250: Register the Job Type radio buttons with react-hook-form

The RadioGroup for "Job Type" is not registered with react-hook-form, so the selected job type won't be included in the form data upon submission. To fix this, register the radio buttons to ensure the value is captured.

Apply this diff to register the RadioGroup:

- <RadioGroup defaultValue="full-time">
+ <RadioGroup defaultValue="full-time" {...register("jobType")}>

302-307: Provide visual feedback during form submission

To enhance user experience, consider showing a loading indicator or disabling the button text when the form is submitting. This provides clear feedback to the user that their submission is being processed.


178-181: Ensure consistent autoComplete attributes for input fields

The Input for "Locations" is missing an autoComplete attribute. Adding it improves form accessibility and user experience.

Apply this diff to add the autoComplete attribute:

<Input
  placeholder="Dublin (2 days in the office per week)"
+ autoComplete="address-level2"
  {...register("jobLocation")}
/>

48-50: Remove unnecessary TypeScript type annotation for data

The onSubmit function parameter data already infers the type saveJobsInput from the useForm generic parameter. Explicitly annotating the type is redundant.

Apply this diff to simplify the code:

- const onSubmit = (data: saveJobsInput) => {
+ const onSubmit = (data) => {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between a30156b and 71e0b04.

📒 Files selected for processing (2)
  • app/(app)/jobs/create/_client.tsx (11 hunks)
  • schema/job.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (7)
schema/job.ts (7)

1-1: LGTM: Zod import is correct.

The import statement for Zod is correct and follows common practices.


20-24: LGTM: applicationUrl field implementation is correct and flexible.

The applicationUrl field is well-implemented. It correctly allows for optional valid URLs or empty strings, providing appropriate flexibility for job postings.


25-25: LGTM: remote field is correctly implemented.

The remote field is correctly implemented as an optional boolean with a default value of false. This is appropriate for representing remote work options in job postings.


26-26: LGTM: relocation field is correctly implemented.

The relocation field is correctly implemented as an optional boolean with a default value of false. This is appropriate for representing relocation options in job postings.


27-27: LGTM: visa field is correctly implemented.

The visa field is correctly implemented as an optional boolean with a default value of false. This is appropriate for representing visa sponsorship options in job postings.


31-31: LGTM: Type alias export is correct.

The saveJobsInput type alias is correctly exported using z.TypeOf<typeof saveJobsSchema>. This allows for type-safe usage of the schema in other parts of the application.


1-31: Overall, great implementation of the job posting schema.

This schema provides a solid foundation for form validation in the Jobs Create page, directly addressing the objectives outlined in the PR. It covers all necessary fields with appropriate validation rules. The minor suggestions for improvement (typos in error messages, considering longer job descriptions, and adding a "contract" job type) will further enhance its effectiveness.

Great job on implementing this validation schema, which will significantly improve the user experience on the Jobs Create page by preventing incorrect form submissions.

Comment on lines 49 to 50
console.log(data);
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Avoid logging sensitive user data in production code

Logging user-submitted data with console.log(data); can lead to security concerns, especially in a production environment. Consider removing this console statement or ensuring it is only used during development.

Comment on lines 51 to 53
if (errors) {
console.log(errors);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Handle errors appropriately instead of logging to the console

While logging errors can be helpful during development, directly logging errors to the console in production may expose sensitive information. Consider implementing user-friendly error handling or displaying validation messages within the UI.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (2)
app/(app)/jobs/create/_client.tsx (2)

34-44: LGTM: Form setup with react-hook-form and Zod validation

The integration of react-hook-form with Zod schema validation is well-implemented and addresses the PR objective of adding validation to the form.

Consider adding default values for other form fields as well, to improve the user experience and ensure consistent initial form state.


116-120: LGTM: Form fields correctly integrated with react-hook-form and error handling added

The integration of form fields with react-hook-form using the register function is well-implemented. The addition of error handling for each field ensures that validation errors are displayed to the user, which directly addresses the PR objective.

Consider adding aria-invalid attributes to the input fields based on the error state to improve accessibility. For example:

<Input
  id="company-name"
  type="text"
  placeholder="Pixel Pulse Studios"
  autoComplete="given-company-name"
  aria-invalid={errors.companyName ? "true" : "false"}
  {...register("companyName")}
/>

This will help screen readers communicate the validation state of the form fields to users.

Also applies to: 137-141, 157-161, 175-178, 193-195, 212-216

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 71e0b04 and dd4e39f.

📒 Files selected for processing (1)
  • app/(app)/jobs/create/_client.tsx (11 hunks)
🧰 Additional context used
🔇 Additional comments (4)
app/(app)/jobs/create/_client.tsx (4)

10-15: LGTM: Necessary imports added for form validation

The new imports for form-related components, Zod schema, and react-hook-form are appropriate for implementing the required form validation. These changes align well with the PR objective of adding validation to the jobs create page.

Also applies to: 25-25, 27-27, 31-31


56-59: LGTM: Form submission correctly integrated with react-hook-form

The addition of onSubmit={handleSubmit(onSubmit)} to the form element correctly integrates the form submission with react-hook-form. This ensures that form validation occurs before submission, which aligns with the PR objective of adding validation to the jobs create page.


299-304: LGTM: Submit button correctly configured

The changes to the submit button are well-implemented:

  1. The type="submit" attribute ensures that the button triggers form submission.
  2. The disabled={isSubmitting} prop prevents multiple submissions while the form is being processed.

These improvements enhance the user experience and prevent potential issues with duplicate submissions.


Line range hint 1-310: Overall: Good implementation of form validation with some areas for improvement

The changes in this file successfully implement form validation for the jobs create page using react-hook-form and Zod, which meets the main PR objective. The integration is generally well-done, with proper error handling and improved user experience.

Main points for improvement:

  1. Remove the console.log in the onSubmit function and implement proper form submission logic with API calls and user feedback.
  2. Integrate the RadioGroup for job type selection with react-hook-form.
  3. Consider adding aria-invalid attributes to input fields for improved accessibility.
  4. Add default values for more form fields to ensure a consistent initial form state.

Once these points are addressed, the implementation will be more robust and provide a better user experience.

Comment on lines 48 to 50
const onSubmit = (data: saveJobsInput) => {
console.log(data);
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove console.log and implement proper form submission

While the typed parameter for onSubmit is good for type safety, there are a couple of issues to address:

  1. As mentioned in a previous review, logging user-submitted data with console.log(data); can lead to security concerns, especially in a production environment.
  2. The current implementation doesn't actually submit the form data or provide user feedback.

Please remove the console.log statement and implement proper form submission logic. Consider the following steps:

  1. Remove the console.log statement.
  2. Implement an API call to submit the form data.
  3. Handle success and error states appropriately.
  4. Provide user feedback (e.g., success message, error message).

Example:

const onSubmit = async (data: saveJobsInput) => {
  try {
    // Implement API call to submit form data
    // const response = await api.submitJobPost(data);
    // Handle success (e.g., show success message, redirect user)
  } catch (error) {
    // Handle error (e.g., show error message)
  }
};

</div>
<Field>
<RadioGroup defaultValue="full_time">
<RadioGroup defaultValue="full-time">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Integrate RadioGroup with react-hook-form

While the addition of defaultValue to the RadioGroup and value props to individual Radio components improves usability, the RadioGroup is not currently integrated with react-hook-form. This means that the selected job type is not included in the form data and won't be validated.

Please integrate the RadioGroup with react-hook-form. Here's an example of how you can do this:

<RadioGroup {...register("jobType")}>
  <RadioField>
    <Radio value="full-time" />
    <Label>Full-time (€150)</Label>
    <Description>Salaried Position</Description>
  </RadioField>
  {/* ... other radio fields ... */}
</RadioGroup>
{errors?.jobType && (
  <ErrorMessage>{errors.jobType.message}</ErrorMessage>
)}

Don't forget to add the jobType field to your Zod schema and the saveJobsInput type.

Also applies to: 230-230, 235-235

@vercel
Copy link

vercel bot commented Oct 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
codu ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 18, 2024 7:33am

schema/job.ts Outdated
.max(50, "Job title should contain atmost 50 characters"),
jobDescription: z
.string()
.max(200, "Job Description should contain atmost 200 characters")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a min character count on this too. Without a job description the post will be pretty bad. Say 100 characters. you can max it at 2000.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ✅

relocation: z.boolean().optional().default(false),
visa: z.boolean().optional().default(false),
jobType: z.enum(["full-time", "part-time", "freelancer", "other"]),
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would love some thoughts on if you think all of these are sensible too? 🦾

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think yes, these should also be populated. As a result these values can be shown in the jobs page with their associated jobs.
A sample shown below present on YC jobs page

image

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 637fd86 and f7c6478.

📒 Files selected for processing (2)
  • app/(app)/jobs/create/_client.tsx (9 hunks)
  • schema/job.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • schema/job.ts
🧰 Additional context used
🔇 Additional comments (6)
app/(app)/jobs/create/_client.tsx (6)

10-15: Excellent implementation of form handling and validation!

The integration of react-hook-form with Zod schema validation significantly improves the form's robustness and user experience. The use of defaultValues in the useForm setup is a good practice, ensuring that all form fields have initial values. This implementation will make it easier to manage form state, handle submissions, and provide user feedback.

Also applies to: 25-27, 31-31, 34-53


65-68: Great implementation of form submission and field validation

The changes to the form element and the company name input field are well-implemented:

  1. The form now correctly uses the handleSubmit function from react-hook-form.
  2. The company name input is properly registered with react-hook-form.
  3. Error handling and display for the company name field have been added, improving user feedback.

These improvements enhance the form's functionality and user experience.

Also applies to: 125-129


146-150: Consistent implementation of form field validation

The job title and job description inputs have been updated in line with best practices:

  1. Both fields are correctly registered with react-hook-form.
  2. Error handling and display have been added for both fields.

This consistent approach to form field validation improves the overall reliability of the form and provides clear feedback to users when input errors occur.

Also applies to: 166-170


335-340: Excellent improvements to the submit button

The changes to the submit button enhance the form's usability and prevent potential issues:

  1. The type="submit" attribute ensures that the button correctly triggers form submission.
  2. The disabled={isSubmitting} prop prevents multiple submissions while the form is being processed.

These improvements contribute to a better user experience and help prevent data inconsistencies.


Line range hint 1-346: Overall excellent improvements to the job creation form

The integration of react-hook-form with Zod schema validation has significantly enhanced the form's functionality, validation, and user experience. The consistent implementation across all form fields is commendable. Here's a summary of the improvements and remaining issues:

Improvements:

  1. Proper form state management and validation using react-hook-form and Zod.
  2. Consistent error handling and display for most form fields.
  3. Use of the Controller component for complex form controls like checkboxes and radio buttons.
  4. Improved submit button functionality to prevent multiple submissions.

Remaining issues to address:

  1. Implement proper form submission logic in the onSubmit function.
  2. Correct the typo in the "visa_sponsership" field name.
  3. Add error handling for the job type field.

Once these minor issues are resolved, the form will be robust and user-friendly.


57-59: ⚠️ Potential issue

Implement proper form submission and remove console logging

The current implementation of the onSubmit function only logs the form data to the console, which is insufficient for a production environment and poses potential security risks. Consider the following improvements:

  1. Remove the console.log(values) statement.
  2. Implement an API call to submit the form data.
  3. Handle success and error states appropriately.
  4. Provide user feedback (e.g., success message, error message).

Example implementation:

const onSubmit: SubmitHandler<saveJobsInput> = async (values) => {
  try {
    // Implement API call to submit form data
    // const response = await api.submitJobPost(values);
    // Handle success (e.g., show success message, redirect user)
  } catch (error) {
    // Handle error (e.g., show error message)
  }
};

Comment on lines +239 to +243
{...register("applicationUrl")}
/>
{errors?.applicationUrl && (
<ErrorMessage>{errors.applicationUrl.message}</ErrorMessage>
)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Good implementation of application URL and job type fields, but missing error handling for job type

The changes to the application URL input and job type radio group are well-implemented:

  1. The application URL input is correctly registered with react-hook-form.
  2. The job type radio group uses the Controller component, which is appropriate for this type of form control.
  3. Error handling has been added for the application URL field.

However, error handling for the job type field is missing. Consider adding error display for the job type field to maintain consistency with other form fields.

Add error handling for the job type field:

{errors?.jobType && (
  <ErrorMessage>{errors.jobType.message}</ErrorMessage>
)}

Also applies to: 255-289

Comment on lines 184 to 222
<Input
placeholder="Dublin (2 days in the office per week)"
{...register("jobLocation")}
/>
<CheckboxGroup className="mt-3">
<CheckboxField>
<Checkbox name="remote" value="is_remote" />
<Controller
name="remote"
control={control}
render={({ field }) => (
<Checkbox checked={field.value} onChange={field.onChange} />
)}
/>
<Label>Work is remote</Label>
</CheckboxField>
<CheckboxField>
<Checkbox name="relocation" value="is_relocation_package" />
<Controller
name="relocation"
control={control}
render={({ field }) => (
<Checkbox checked={field.value} onChange={field.onChange} />
)}
/>
<Label>Relocation package given</Label>
</CheckboxField>
<CheckboxField>
<Checkbox name="visa" value="is_visa_sponsored" />
<Controller
name="visa_sponsership"
control={control}
render={({ field }) => (
<Checkbox checked={field.value} onChange={field.onChange} />
)}
/>
<Label>Visa sponsorship provided</Label>
</CheckboxField>
</CheckboxGroup>
{errors?.jobLocation && (
<ErrorMessage>{errors.jobLocation.message}</ErrorMessage>
)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Good implementation of location field and checkboxes, but there's a typo

The changes to the location input and checkbox fields are well-implemented:

  1. The location input is correctly registered with react-hook-form.
  2. Checkbox fields now use the Controller component, which is appropriate for more complex form controls.
  3. Error handling has been added for the location field.

However, there's a typo in the "visa_sponsership" field name. It should be "visa_sponsorship".

Please correct the typo in the field name:

-                name="visa_sponsership"
+                name="visa_sponsorship"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<Input
placeholder="Dublin (2 days in the office per week)"
{...register("jobLocation")}
/>
<CheckboxGroup className="mt-3">
<CheckboxField>
<Checkbox name="remote" value="is_remote" />
<Controller
name="remote"
control={control}
render={({ field }) => (
<Checkbox checked={field.value} onChange={field.onChange} />
)}
/>
<Label>Work is remote</Label>
</CheckboxField>
<CheckboxField>
<Checkbox name="relocation" value="is_relocation_package" />
<Controller
name="relocation"
control={control}
render={({ field }) => (
<Checkbox checked={field.value} onChange={field.onChange} />
)}
/>
<Label>Relocation package given</Label>
</CheckboxField>
<CheckboxField>
<Checkbox name="visa" value="is_visa_sponsored" />
<Controller
name="visa_sponsership"
control={control}
render={({ field }) => (
<Checkbox checked={field.value} onChange={field.onChange} />
)}
/>
<Label>Visa sponsorship provided</Label>
</CheckboxField>
</CheckboxGroup>
{errors?.jobLocation && (
<ErrorMessage>{errors.jobLocation.message}</ErrorMessage>
)}
<Input
placeholder="Dublin (2 days in the office per week)"
{...register("jobLocation")}
/>
<CheckboxGroup className="mt-3">
<CheckboxField>
<Controller
name="remote"
control={control}
render={({ field }) => (
<Checkbox checked={field.value} onChange={field.onChange} />
)}
/>
<Label>Work is remote</Label>
</CheckboxField>
<CheckboxField>
<Controller
name="relocation"
control={control}
render={({ field }) => (
<Checkbox checked={field.value} onChange={field.onChange} />
)}
/>
<Label>Relocation package given</Label>
</CheckboxField>
<CheckboxField>
<Controller
name="visa_sponsorship"
control={control}
render={({ field }) => (
<Checkbox checked={field.value} onChange={field.onChange} />
)}
/>
<Label>Visa sponsorship provided</Label>
</CheckboxField>
</CheckboxGroup>
{errors?.jobLocation && (
<ErrorMessage>{errors.jobLocation.message}</ErrorMessage>
)}

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
app/(app)/jobs/create/_client.tsx (2)

34-53: LGTM: Form setup with react-hook-form and Zod

The integration of react-hook-form with Zod for form handling and validation is well-implemented. The default values for form fields are appropriately set.

Consider extracting the default values into a separate constant for better maintainability:

const DEFAULT_FORM_VALUES: saveJobsInput = {
  companyName: "",
  jobTitle: "",
  // ... other fields
};

const { ... } = useForm<saveJobsInput>({
  resolver: zodResolver(saveJobsSchema),
  defaultValues: DEFAULT_FORM_VALUES,
});

This change would make it easier to update default values in the future and improve code readability.


125-129: LGTM: Input fields correctly integrated with react-hook-form

The input fields are now properly registered with react-hook-form, and error handling has been added for each field. This implementation addresses the PR objectives by adding validation to the jobs create page.

However, the jobLocation field is missing the id attribute. Consider adding it for better accessibility:

<Input
  id="job-location"
  placeholder="Dublin (2 days in the office per week)"
  {...register("jobLocation")}
/>

This change will improve the accessibility of the form by associating the input field with its label.

Also applies to: 146-150, 166-170, 184-187, 220-222, 239-243

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f7c6478 and f930ab3.

📒 Files selected for processing (2)
  • app/(app)/jobs/create/_client.tsx (9 hunks)
  • schema/job.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • schema/job.ts
🧰 Additional context used
🔇 Additional comments (7)
app/(app)/jobs/create/_client.tsx (7)

10-15: LGTM: Necessary imports added for form validation

The new imports from react-hook-form, @hookform/resolvers/zod, and additional UI components are appropriate for implementing form validation. These changes align well with the PR objectives of adding validation to the jobs create page.

Also applies to: 25-25, 27-27, 31-31


65-68: LGTM: Correct integration of form submission with react-hook-form

The form element is now properly set up with the onSubmit handler using handleSubmit from react-hook-form. This ensures that form validation will be performed before the onSubmit function is called, which aligns with the PR objectives of adding validation to the jobs create page.


255-289: LGTM: Radio group correctly integrated with react-hook-form

The radio group for job type is well-implemented using the Controller component from react-hook-form. This ensures that the selected job type will be included in the form data and properly validated. The implementation includes all necessary job type options and aligns with the overall form validation strategy.


335-340: LGTM: Submit button properly configured

The submit button is now correctly set up with the type="submit" attribute and is disabled during form submission. These changes improve the form submission process by ensuring that:

  1. The button triggers form submission when clicked.
  2. Multiple submissions are prevented while the form is being processed.

This implementation aligns with best practices for form handling and enhances the overall user experience.


Line range hint 1-345: Overall assessment: Good implementation with minor improvements needed

The changes in this file successfully implement form validation for the jobs create page using react-hook-form and Zod, addressing the main objectives of the PR. The form fields are properly integrated with the validation system, and error handling has been added where necessary.

Key points:

  1. Form setup and field integration are well-implemented.
  2. Proper use of Controller components for complex form controls.
  3. Submit button is correctly configured to prevent multiple submissions.

Areas for improvement:

  1. Implement proper form submission logic instead of console.log.
  2. Fix the typo in the visa_sponsorship field name.
  3. Add an id attribute to the jobLocation input for better accessibility.
  4. Consider extracting default form values into a separate constant.

Once these minor issues are addressed, the implementation will be robust and align perfectly with the PR objectives.


57-59: ⚠️ Potential issue

Implement proper form submission and remove console.log

The current implementation doesn't actually submit the form data or provide user feedback. Additionally, logging user-submitted data with console.log(values); can lead to security concerns, especially in a production environment.

Please implement proper form submission logic and remove the console.log statement. Consider the following steps:

  1. Remove the console.log statement.
  2. Implement an API call to submit the form data.
  3. Handle success and error states appropriately.
  4. Provide user feedback (e.g., success message, error message).

Example:

const onSubmit: SubmitHandler<saveJobsInput> = async (values) => {
  try {
    // Implement API call to submit form data
    // const response = await api.submitJobPost(values);
    // Handle success (e.g., show success message, redirect user)
  } catch (error) {
    // Handle error (e.g., show error message)
  }
};

190-216: ⚠️ Potential issue

Fix typo in visa_sponsorship field name

The integration of checkbox fields with react-hook-form using the Controller component is well-implemented. However, there's a typo in the "visa_sponsorship" field name. It's currently spelled as "visa_sponsership".

Please correct the typo in the field name:

-                name="visa_sponsership"
+                name="visa_sponsorship"

This correction will ensure that the form data is properly handled and validated for the visa sponsorship field.

@Nil2000
Copy link
Contributor Author

Nil2000 commented Oct 18, 2024

@NiallJoeMaher @John-Paul-Larkin Can I implement the upload image functionality here (similar to settings page)?

@NiallJoeMaher
Copy link
Contributor

Yes, in fact you could do it with an action similar to how I handle the upload on the blog post. I'll share a link when I'm on my laptop.

Copy link
Contributor

@NiallJoeMaher NiallJoeMaher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! You can work on the image upload next. Create the issue and I'll
Assign you.

@NiallJoeMaher NiallJoeMaher merged commit 8052ad1 into codu-code:develop Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validation is absent in the Jobs Create page

2 participants