Skip to content
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

Form select on status #791

Merged

Conversation

John-Paul-Larkin
Copy link
Member

@John-Paul-Larkin John-Paul-Larkin commented Mar 2, 2024

Pull Request details

  • Removed the unused additionalDetails Zod schema, as it has been separated into the appropriate form-specific schema.

  • Updated the main component to redirect users to the next incomplete onboarding form, based on their progress.

  • If all fields have been input we redirect to the /settings route.

  • Retained useSearchParams, to support back button functionality.

  • Open to discussion on whether the back button is necessary for the onboarding flow.

Next steps
Edit - Also need to remove the slide4 and slideButtons component as they are no longer required.

  • Implement logic to redirect new users to the first onboarding form.
  • Modify the /settings route to display and handle the new fields.

Summary by CodeRabbit

  • Refactor
    • Improved the logic for determining the user's progress during the sign-up process based on provided details.
    • Enhanced the validation process for additional user details during sign-up, ensuring a smoother user experience.

@John-Paul-Larkin John-Paul-Larkin requested a review from a team as a code owner March 2, 2024 11:41
Copy link

vercel bot commented Mar 2, 2024

@John-Paul-Larkin 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 bot commented Mar 2, 2024

Walkthrough

The recent update involves a significant refactor in handling additional user sign-up details. The logic for determining the slide value in the sign-up process has been optimized based on the presence of specific user details and search parameters. Concurrently, the validation schema for these additional details has been overhauled, with the removal of a general schema and the distribution of its validation rules into more focused, individual schemas.

Changes

Files Change Summary
app/.../_client.tsx Refactored logic for setting slide value based on user details and search parameters.
schema/additionalUserDetails.ts Removed AdditionalDetailsSchema and redistributed its validation logic into specific schemas.

"In the code's woven warren, changes abound,
🐾 Through lines of logic, new pathways found.
Where once was clutter, now clarity sings,
As validation spreads its newly feathered wings.
🎉 Let's hop with joy, for progress we hail,
On this digital journey, we boldly sail."

  • 🐰 CodeRabbit

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 4

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7ee7120 and e15dbc1.
Files selected for processing (2)
  • app/(app)/alpha/additional-details/_client.tsx (1 hunks)
  • schema/additionalUserDetails.ts (2 hunks)
Additional comments: 10
schema/additionalUserDetails.ts (4)
  • 1-1: The import statement for zod is correct and follows standard practices for importing external libraries.
  • 1-5: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [3-12]

The slideOneSchema correctly defines the validation rules for the first slide of the form. It ensures that firstName, surname, and username are strings, trimmed, and within specified length limits. location is also validated as a non-empty string. This aligns well with best practices for form validation.

  • 1-5: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [14-18]

The slideTwoSchema is well-defined for validating gender as a non-empty string and dateOfBirth as a date. This schema is simple and follows best practices for data validation.

  • 1-5: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [52-54]

The type exports TypeSlideOneSchema, TypeSlideTwoSchema, and TypeSlideThreeSchema are correctly defined using Zod's TypeOf utility. This is a good practice for type safety and maintainability.

app/(app)/alpha/additional-details/_client.tsx (6)
  • 75-75: The redirection logic for users without a session to the /get-started route is correctly implemented. This ensures that only authenticated users can access the onboarding forms.
  • 76-76: The rendering logic for different slides based on the slide variable is correctly implemented. This modular approach enhances readability and maintainability of the code.
  • 78-78: The SlideOne component correctly uses useForm with zodResolver for form validation. This is a good practice for ensuring data integrity and user input validation.
  • 78-78: The form submission logic in SlideOne, SlideTwo, and SlideThree components correctly handles success and error states using toast notifications. This enhances the user experience by providing immediate feedback.
  • 78-78: In SlideThree, the logic for triggering validation based on professionalOrStudent status is innovative. However, ensure that this logic is thoroughly tested to catch any edge cases that might not be immediately apparent.
  • 78-78: The SignupProgressBar component effectively visualizes the user's progress through the onboarding process. This is a user-friendly feature that enhances the onboarding experience.

Comment on lines 1 to 5
import z from "zod";

export const AdditionalDetailsSchema = z
.object({
firstName: z
.string()
.trim()
.min(2, "Min name length is 2 characters.")
.max(50, "Max name length is 50 characters."),
surname: z
.string()
.trim()
.min(2, "Min name length is 2 characters.")
.max(50, "Max name length is 50 characters."),
username: z
.string()
.trim()
.min(3, "Min name length is 3 characters.")
.max(40, "Max name length is 40 characters."),
location: z.string().min(1, "Location is required"),
gender: z.string().min(1, "Gender is required"),
dateOfBirth: z.date(),
professionalOrStudent: z.string().min(1, "Select an option"),

workplace: z.string().max(30, "Max length is 30 characters."),
jobTitle: z.string().max(30, "Max length is 30 characters."),
levelOfStudy: z.string(),
course: z.string().max(30, "Max name length is 30 characters."),
})
.superRefine((val, ctx) => {
if (
val.professionalOrStudent === "Current student" &&
val.levelOfStudy === ""
) {
ctx.addIssue({
path: ["levelOfStudy"],
code: "custom",
message: "required",
});
}

if (val.professionalOrStudent === "Current student" && val.course === "") {
ctx.addIssue({
path: ["course"],
code: "custom",
message: "required",
});
}

if (
val.professionalOrStudent === "Working professional" &&
val.workplace === ""
) {
ctx.addIssue({
path: ["workplace"],
code: "custom",
message: "required",
});
}

if (
val.professionalOrStudent === "Working professional" &&
val.jobTitle === ""
) {
ctx.addIssue({
path: ["jobTitle"],
code: "custom",
message: "required",
});
}
});

export const slideOneSchema = z.object({
firstName: z
.string()
Copy link
Contributor

Choose a reason for hiding this comment

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

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [20-50]

The slideThreeSchema includes custom validation logic to ensure that certain fields are required based on the value of professionalOrStudent. This logic is correctly implemented using .superRefine(). However, consider adding comments to explain the custom validation logic for future maintainability.

+ // Custom validation to ensure required fields based on professionalOrStudent status
  .superRefine((val, ctx) => {

Comment on lines +53 to +74
const {
surname,
firstName,
username,
location,
dateOfBirth,
gender,
professionalOrStudent,
} = details;

let slide: number;
if (searchParams.get("slide")) {
slide = Number(searchParams.get("slide"));
} else if (!surname || !firstName || !username || !location) {
slide = 1;
} else if (!dateOfBirth || !gender) {
slide = 2;
} else if (!professionalOrStudent) {
slide = 3;
} else {
return redirect("/settings");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The logic for determining the current slide based on user details and search parameters is clear and follows a logical progression. However, consider adding comments to explain the logic for future maintainability, especially for the conditions that determine the slide number.

+ // Determine the current slide based on user details and search parameters
  let slide: number;

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.

Suggested change
const {
surname,
firstName,
username,
location,
dateOfBirth,
gender,
professionalOrStudent,
} = details;
let slide: number;
if (searchParams.get("slide")) {
slide = Number(searchParams.get("slide"));
} else if (!surname || !firstName || !username || !location) {
slide = 1;
} else if (!dateOfBirth || !gender) {
slide = 2;
} else if (!professionalOrStudent) {
slide = 3;
} else {
return redirect("/settings");
}
const {
surname,
firstName,
username,
location,
dateOfBirth,
gender,
professionalOrStudent,
} = details;
// Determine the current slide based on user details and search parameters
let slide: number;
if (searchParams.get("slide")) {
slide = Number(searchParams.get("slide"));
} else if (!surname || !firstName || !username || !location) {
slide = 1;
} else if (!dateOfBirth || !gender) {
slide = 2;
} else if (!professionalOrStudent) {
slide = 3;
} else {
return redirect("/settings");
}

} else {
return redirect("/settings");
}

if (!session) {
return redirect("/get-started");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding error handling for the useForm hook in SlideOne, SlideTwo, and SlideThree components to catch and handle potential errors during form initialization.

+ // Add error handling for useForm hook
  const { register, handleSubmit, formState: { errors, isSubmitting } } = useForm<TypeSlideOneSchema>({

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.

Suggested change
}
// Add error handling for useForm hook
const { register, handleSubmit, formState: { errors, isSubmitting } } = useForm<TypeSlideOneSchema>({
}

The SlideButtons component is a reusable component for navigation buttons in the form slides. This is a good practice for code reuse and maintainability. However, consider adding prop types or TypeScript interfaces for better type safety and documentation.

+ // Add TypeScript interface for SlideButtonsProps
  type SlideButtonsProps = {

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.

Suggested change
}
// Add TypeScript interface for SlideButtonsProps
type SlideButtonsProps = {
}

Copy link

vercel bot commented Mar 3, 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 Mar 3, 2024 7:31pm

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.

🌮

@NiallJoeMaher NiallJoeMaher merged commit 3a3cd19 into codu-code:develop Mar 3, 2024
4 checks passed
@John-Paul-Larkin John-Paul-Larkin deleted the form-select-on-status branch March 27, 2024 13:06
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.

2 participants