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

Chore: fixed past date selection for reservation #288

Conversation

lade6501
Copy link
Contributor

@lade6501 lade6501 commented Oct 14, 2024

Fixes: #237

Changes In PR

  • Setting minimum date as today's date
  • Added validation for manual input

Demo
Playcafe-Disabled-Previous_Date

Playcafe-Validation-Manual-Type.mov

Summary by CodeRabbit

  • New Features

    • Enhanced date selection in the registration component to prevent users from selecting dates before today.
    • Implemented dynamic minimum date setting based on the current date.
  • Bug Fixes

    • Added validation to alert users when an invalid date is selected.
  • Style

    • Updated formatting in the signup component for consistency, including import statements and password strength meter display logic.

Copy link

vercel bot commented Oct 14, 2024

@lade6501 is attempting to deploy a commit to the bunty's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Oct 14, 2024

Walkthrough

The changes in the Register component involve the introduction of a new state variable minDate, which is set to today's date upon component mount. A date validation function has been added to ensure users cannot select a past date. The date input field now includes a min attribute tied to minDate, and the validation function is triggered on input blur. These modifications enhance the date selection process by limiting user choices to the current date and future dates.

Changes

Files Change Summary
frontend/src/components/Pages/Register.jsx Added minDate state variable; updated useEffect to set minDate to today's date; implemented handleDateValidation function; modified date input field to include min attribute and validate on blur.
frontend/src/components/Pages/Signup.jsx Reformatted import statements and string literals to single quotes; updated rendering logic for password strength meter; minor stylistic adjustments.

Assessment against linked issues

Objective Addressed Explanation
Prevent selection of past dates for reservation (#237)

🐰 In the meadow where the sun shines bright,
I’ve fixed the dates, oh what a delight!
No more past days, just future in sight,
Hop along, friends, everything feels right!
🌼✨

Possibly related PRs

  • Fixed overlapping #279: The new Register component introduced in this PR is directly related to the changes made in the main PR, as both involve modifications to the Register component in frontend/src/components/Pages/Register.jsx.

Suggested labels

bug, level1, enhancement, gssoc-ext

Suggested reviewers

  • RamakrushnaBiswal

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8295c71 and 7f38ea3.

📒 Files selected for processing (1)
  • frontend/src/components/Pages/Register.jsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/components/Pages/Register.jsx

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.

Copy link
Contributor

Thank you for submitting your pull request! 🙌 We'll review it as soon as possible. In the meantime, please ensure that your changes align with our CONTRIBUTING.md. If there are any specific instructions or feedback regarding your PR, we'll provide them here. Thanks again for your contribution! 😊

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 (3)
frontend/src/components/Pages/Register.jsx (3)

38-44: Good implementation, but consider improving user experience.

The handleDateValidation function correctly implements the logic to prevent selection of past dates. However, automatically resetting the date might be confusing for users.

Consider the following improvement:

  • Instead of automatically resetting the date, you could set an error state and display an error message near the input field. This allows users to correct their input themselves.

Here's a suggested implementation:

const [dateError, setDateError] = useState('');

const handleDateValidation = () => {
  if (date.length === 10 && date < minDate) {
    setDateError('You cannot select a date before today.');
  } else {
    setDateError('');
  }
};

// In your JSX, add this below the date input:
{dateError && <p className="text-red-500 text-sm mt-1">{dateError}</p>}

This approach provides a better user experience by allowing users to see and correct their mistakes.


118-121: LGTM: Date input field properly restricted and validated.

The modifications to the date input field effectively implement the date restriction:

  • Setting min={minDate} prevents selection of dates before today in the date picker.
  • Adding onBlur={handleDateValidation} ensures validation when the user leaves the field.

These changes, combined with the handleDateValidation function, successfully prevent users from selecting past dates for reservations.

Consider adding an aria-describedby attribute to improve accessibility:

aria-describedby="dateInstructions"

And add this element near the input:

<p id="dateInstructions" className="sr-only">Please select a date from today onwards.</p>

This will provide screen reader users with clear instructions about the date restriction.


Line range hint 1-214: Summary: Effective implementation of date restriction feature.

The changes in this file successfully address the PR objective of preventing users from selecting past dates for reservations. The implementation is comprehensive, covering both the date picker UI restriction and manual input validation. Key points:

  1. Introduction of minDate state variable.
  2. Proper initialization of minDate in the useEffect hook.
  3. Implementation of handleDateValidation function for manual input validation.
  4. Modification of the date input field to include min attribute and onBlur event.

These changes effectively solve the issue without negatively impacting existing functionality. The code is clean and well-integrated into the existing component structure.

For future enhancements, consider:

  1. Implementing client-side form validation for all fields before submission.
  2. Adding server-side validation as well to ensure data integrity.
  3. Implementing error handling for the fetch call in handleSubmit.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 99c2b0d and 9dab9cf.

📒 Files selected for processing (1)
  • frontend/src/components/Pages/Register.jsx (3 hunks)
🧰 Additional context used
🔇 Additional comments (2)
frontend/src/components/Pages/Register.jsx (2)

14-14: LGTM: New state variable for minimum date.

The addition of the minDate state variable is a good approach to implement the date restriction feature. This aligns well with the PR objective of preventing users from selecting past dates for reservations.


48-49: LGTM: Proper initialization of minimum date.

The useEffect hook correctly sets the minDate to today's date when the component mounts. This ensures that users cannot select dates before today, which aligns with the PR objective.

@RamakrushnaBiswal
Copy link
Owner

@lade6501 good work but instead using normal alert user antd message for that
ref:- check in login page

@lade6501
Copy link
Contributor Author

@lade6501 good work but instead using normal alert user antd message for that ref:- check in login page

Yeah was thinking the same , but was not sure thanks for feedback.

@lade6501
Copy link
Contributor Author

Hi @RamakrushnaBiswal like this ?
Screenshot 2024-10-15 at 8 18 20 AM

@RamakrushnaBiswal
Copy link
Owner

@lade6501 yes

@RamakrushnaBiswal
Copy link
Owner

@lade6501 commit ?

@lade6501
Copy link
Contributor Author

@lade6501 commit ?

just pushing

@lade6501
Copy link
Contributor Author

pushed @RamakrushnaBiswal, sorry for delay.

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 (4)
frontend/src/components/Pages/Signup.jsx (4)

1-7: LGTM: Consistent quote usage in imports.

The change to single quotes in import statements improves consistency. To maintain this style throughout the project, consider using a linter with appropriate rules.

Consider adding an ESLint rule to enforce consistent quote usage:

{
  "rules": {
    "quotes": ["error", "single"]
  }
}

20-20: LGTM: Consistent semicolon usage.

Adding a semicolon at the end of the useState declaration improves consistency. Ensure this style is maintained throughout the file and project.

Consider using a linter rule to enforce consistent semicolon usage:

{
  "rules": {
    "semi": ["error", "always"]
  }
}

133-143: LGTM: Improved password visibility toggle implementation.

The changes to the password input and visibility toggle button improve code readability and maintain consistent styling. The dynamic password input type based on the hidden state is a good implementation.

Consider adding an aria-label to the visibility toggle button to improve accessibility:

 <button
   className="absolute top-1/2 -translate-y-1/2 right-4"
   onClick={(e) => {
     e.preventDefault();
     setHidden(!hidden);
   }}
+  aria-label={hidden ? "Show password" : "Hide password"}
 >
   {hidden ? <FaEyeSlash /> : <FaEye />}
 </button>

148-161: Great addition: Password strength meter with conditional rendering.

The new password strength meter enhances the user experience by providing visual feedback. The conditional rendering is a good practice to prevent unnecessary display when the password field is empty.

Consider adding an aria-live region to announce password strength changes for screen reader users:

 {data.password && (
-  <div className="w-full mt-2">
+  <div className="w-full mt-2" aria-live="polite">
     <div
       className="h-2 rounded-full"
       style={{
         backgroundColor: getPasswordStrengthColor(passwordStrength),
         width: `${(passwordStrength + 1) * 20}%`,
       }}
     ></div>
     <p className="text-sm text-[#666] mt-1">
       Strength: {getPasswordStrengthText(passwordStrength)}
     </p>
   </div>
 )}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9dab9cf and 8295c71.

📒 Files selected for processing (2)
  • frontend/src/components/Pages/Register.jsx (3 hunks)
  • frontend/src/components/Pages/Signup.jsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/components/Pages/Register.jsx
🧰 Additional context used
🔇 Additional comments (4)
frontend/src/components/Pages/Signup.jsx (4)

25-28: LGTM: Consistent quote usage in handleChange function.

The change to single quotes for the password field name comparison is consistent with the earlier changes and maintains the existing functionality.


83-85: LGTM: Consistent quote usage in useEffect hook.

The formatting change in the useEffect hook to use single quotes is consistent with the earlier changes and maintains the existing functionality.


88-94: LGTM: Consistent quote usage in password strength functions.

The changes to use single quotes in the getPasswordStrengthColor and getPasswordStrengthText functions are consistent with the earlier changes and maintain the existing functionality.


Line range hint 1-161: Overall: Improved code consistency and enhanced user interface.

The changes in this file primarily focus on improving code consistency through uniform quote usage and minor stylistic adjustments. The addition of the password strength meter enhances the user experience during the signup process. These changes maintain the existing functionality while improving code readability and providing valuable visual feedback to users.

Key improvements:

  1. Consistent use of single quotes throughout the file.
  2. Enhanced password visibility toggle implementation.
  3. Addition of a password strength meter with conditional rendering.

The changes align well with the PR objectives of improving the user experience in the signup process. No major issues or bugs were introduced, and the overall quality of the code has been improved.

@RamakrushnaBiswal
Copy link
Owner

RamakrushnaBiswal commented Oct 16, 2024

one conflict @lade6501

@lade6501 lade6501 force-pushed the issue#237-past-date-selection branch from 8295c71 to 7f38ea3 Compare October 17, 2024 05:03
Copy link

vercel bot commented Oct 18, 2024

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

Name Status Preview Comments Updated (UTC)
play-cafe ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 18, 2024 2:46am

@RamakrushnaBiswal RamakrushnaBiswal self-requested a review October 18, 2024 02:46
@RamakrushnaBiswal RamakrushnaBiswal added bug Something isn't working level1 for 10 points gssoc-ext gssoc-extd program hacktoberfest accepted hacktoberfest-accepted repo labels Oct 18, 2024
@RamakrushnaBiswal RamakrushnaBiswal merged commit 654d4bb into RamakrushnaBiswal:main Oct 18, 2024
5 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working gssoc-ext gssoc-extd program hacktoberfest accepted hacktoberfest-accepted repo level1 for 10 points
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Able to select past date for reservation
2 participants