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

corrected the cards of the categories #2325

Merged
merged 3 commits into from
Oct 17, 2024

Conversation

SadafKausar2025
Copy link
Contributor

@SadafKausar2025 SadafKausar2025 commented Oct 17, 2024

Fixes Issue #2326

Closes #2326

Changes proposed

Screenshots

before:
Screenshot (2494)
after:
Screenshot (2492)

Note to reviewers

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Introduced a "⚡Buy Now" button linking to the payment page, enhancing purchasing options.
  • Improvements
    • Enhanced readability of product pricing and layout in the ProductGrid.
    • Adjusted button functionalities for better user interaction with wishlist and cart features.

Copy link

vercel bot commented Oct 17, 2024

@SadafKausar2025 is attempting to deploy a commit to the Vivek Prajapati's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Oct 17, 2024

Walkthrough

The changes in this pull request primarily focus on the ProductGrid component within the src/User/components/Popular_Categories/ProductGrid.jsx file. Key modifications include the addition of a PaymentPage import, enhancements to the readability of the getNewPrice function, and adjustments to the mapping of products. The ProductCard component has seen updates in the button elements for wishlist actions, the product title's styling, and the introduction of a new "⚡Buy Now" button that links to the payment feature. Overall, these changes aim to improve code clarity and user interaction.

Changes

File Path Change Summary
src/User/components/Popular_Categories/ProductGrid.jsx - Added import for PaymentPage.
- Reformatted getNewPrice return statement for clarity.
- Improved readability in products mapping.
- Updated ProductCard buttons for wishlist actions.
- Modified h3 product title for better overflow handling.
- Restructured cart button into a flex container and added "⚡Buy Now" button, conditionally disabled based on cart item presence.

Assessment against linked issues

Objective Addressed Explanation
Improve spacing of cards in view (#2326) No changes related to card spacing were made.

Poem

🐇 In the grid where products shine,
A new button sparks, oh how divine!
"Buy Now" whispers, a payment delight,
With clearer code, our future is bright.
Buttons dance, and titles flow,
Hopping forward, watch us grow! 🌟


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.

@SadafKausar2025
Copy link
Contributor Author

hello @codervivek5
please review this PR and merge under hactoberfest 2024

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 (1)
src/User/components/Popular_Categories/ProductGrid.jsx (1)

90-90: Improved product title styling for better text handling.

The removal of the height constraint and addition of the overflow-hidden class improves the handling of product titles with varying lengths. This change enhances the component's flexibility and prevents text overflow issues.

Consider adding text-ellipsis and whitespace-nowrap classes to truncate long titles with an ellipsis for a more consistent appearance across all product cards.

-<h3 className="font-bold text-sm overflow-hidden">{product.title}</h3>
+<h3 className="font-bold text-sm overflow-hidden text-ellipsis whitespace-nowrap">{product.title}</h3>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 22699fa and a4f92a1.

📒 Files selected for processing (1)
  • src/User/components/Popular_Categories/ProductGrid.jsx (6 hunks)
🧰 Additional context used
🔇 Additional comments (4)
src/User/components/Popular_Categories/ProductGrid.jsx (4)

13-13: Improved formatting for better readability.

The reformatting of the getNewPrice function's return statement enhances code readability without changing the logic. This is a good practice.


23-27: Improved code formatting in product mapping.

The multi-line formatting of the product.newPrice assignment and the separate line for the ProductCard return statement enhance code readability. This change is beneficial for maintaining clean and understandable code.


67-67: Minor formatting improvement in wishlist buttons.

The closing brackets for the wishlist buttons have been moved to new lines, slightly improving code readability. This change is consistent with good coding practices.

Also applies to: 76-76


92-98: Enhanced price display with improved styling.

The updated price display using flexbox and the addition of the original price with a line-through style improve the visual presentation of pricing information. This change clearly shows the discount and enhances the overall user experience.

Comment on lines 108 to 135
<div className="flex h-10 gap-2">
<button
className="mt-1 bg-[#166635ff] text-white px-4 py-2 rounded text-sm w-full hover:bg-[#3d9970ff] transition-colors disabled:opacity-45 disabled:pointer-events-none"
onClick={() => {
onAddToCart(product);
}}
disabled={cartItems.find((item) => item.id === product.id)}>
{/* <lord-icon
style={{
height: "20px",
width: "20px",
}}
src="https://cdn.lordicon.com/pbrgppbb.json"
trigger="hover"
colors="primary:#ffffff"></lord-icon> */}
{cartItems.find((item) => item.id === product.id)
? "Added to cart"
: "Add to Cart"}
</button>
<button
className="mt-1 bg-orange-600 text-white px-4 py-2 rounded text-sm w-full hover:bg-orange-700 transition-colors disabled:opacity-45 disabled:pointer-events-none"
onClick={() => PaymentPage}
disabled={cartItems.find((item) => item.id === product.id)}>
{cartItems.find((item) => item.id === product.id)
? "⚡Buy Now"
: "⚡Buy Now"}
</button>
</div>
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

Improved button layout with new "Buy Now" option, but potential issue in onClick handler.

The addition of a flex container for buttons and the new "⚡Buy Now" button enhances the user interface and provides a direct purchase option. However, there's a potential issue with the onClick handler of the "Buy Now" button.

  1. The onClick handler is incorrectly set to PaymentPage instead of a function that navigates to or renders the PaymentPage component.
  2. The "Buy Now" button is disabled when the item is in the cart, which might not be the desired behavior.

Consider updating the "Buy Now" button implementation as follows:

 <button
   className="mt-1 bg-orange-600 text-white px-4 py-2 rounded text-sm w-full hover:bg-orange-700 transition-colors disabled:opacity-45 disabled:pointer-events-none"
-  onClick={() => PaymentPage}
-  disabled={cartItems.find((item) => item.id === product.id)}>
+  onClick={() => navigate('/payment', { state: { product } })}>
   ⚡Buy Now
 </button>

Also, ensure that the necessary state management for the payment process is implemented.

Committable suggestion was skipped due to low confidence.

@codervivek5
Copy link
Owner

Kindly add issue number

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)
vigybag ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 17, 2024 2:24pm

@codervivek5
Copy link
Owner

Kindly take a look of code rabbit code... When you fix it the let me know I'll merge 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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between a4f92a1 and c25e98e.

📒 Files selected for processing (1)
  • src/User/components/Popular_Categories/ProductGrid.jsx (6 hunks)
🧰 Additional context used
🔇 Additional comments (4)
src/User/components/Popular_Categories/ProductGrid.jsx (4)

13-13: Improved code formatting enhances readability.

The reformatting of the getNewPrice function and the product.newPrice assignment improves code readability without changing functionality. This adheres to good coding practices.

These changes make the code more maintainable and easier to understand. Good job!

Also applies to: 23-27


67-67: Improved conciseness in wishlist button handlers.

The simplification of the wishlist button onClick handlers improves code readability.

This change makes the code more maintainable and easier to understand.

Also applies to: 76-76


90-92: Verify text overflow handling for product title.

The removal of the specific height constraint on the product title h3 element may affect text overflow handling.

Please ensure that long product titles are displayed correctly and do not disrupt the layout. Consider adding ellipsis or other text truncation methods if necessary.


112-112: Improved button layout with flex container.

The introduction of a flex container for the buttons enhances the layout and provides better control over button positioning.

This change improves the overall design and user interface of the product card.

@@ -5,12 +5,12 @@ import { manageWishlistItem } from "../../redux/wishlist";
import toast from "react-hot-toast";
import { useNavigate } from "react-router-dom";
import { FaHeart, FaRegHeart } from "react-icons/fa";
import PaymentPage from "../../pages/Payment/Payment";
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

Verify the necessity and usage of the PaymentPage import.

The PaymentPage component is imported but not visibly used in the code. This may lead to unnecessary imports and potential confusion.

Consider one of the following actions:

  1. If PaymentPage is used elsewhere in this component, ensure it's properly implemented.
  2. If it's not used, remove the unused import to keep the code clean.

Additionally, based on a previous review comment, ensure that PaymentPage is not misused in any onClick handlers. It should be used for navigation or state changes, not directly rendered in an event handler.

src/User/components/Popular_Categories/ProductGrid.jsx Outdated Show resolved Hide resolved
@SadafKausar2025
Copy link
Contributor Author

hello @codervivek5
please merge this PR

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: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c25e98e and 6a545a2.

📒 Files selected for processing (1)
  • src/User/components/Popular_Categories/ProductGrid.jsx (7 hunks)
🧰 Additional context used
🔇 Additional comments (1)
src/User/components/Popular_Categories/ProductGrid.jsx (1)

141-145: Consider enabling the "Buy Now" button even if the item is in the cart

Currently, the "Buy Now" button is disabled when the item is already in the cart. This may not be the desired behavior, as users might want to proceed to purchase immediately, regardless of the cart status.

Comment on lines +45 to +47
const handleBuyNow = () => {
navigate(`/payment`);
};
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

Ensure product data is passed to the payment page

The handleBuyNow function navigates to /payment, but it's unclear how the payment page receives the product information necessary for processing the payment.

Modify the handleBuyNow function to include the product data using the state parameter of navigate:

const handleBuyNow = () => {
-  navigate(`/payment`);
+  navigate(`/payment`, { state: { product } });
};

Additionally, ensure that the PaymentPage component accesses the passed state correctly:

// In PaymentPage.jsx
const location = useLocation();
const { product } = location.state || {};

Comment on lines +23 to +26
product.newPrice = getNewPrice(
product.discountPercentage,
product.price
);
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 mutating product objects directly in the map function

Modifying the product object directly within the map function can lead to unintended side effects, especially if products is derived from props or state. This practice can cause unexpected bugs elsewhere in your application.

Consider creating a new object or passing the computed newPrice as a prop to ProductCard without mutating the original product object:

{products.map((product) => {
-  product.newPrice = getNewPrice(
-    product.discountPercentage,
-    product.price
-  );
-  return <ProductCard key={product.id} product={product} />;
+  const newPrice = getNewPrice(
+    product.discountPercentage,
+    product.price
+  );
+  return <ProductCard key={product.id} product={{ ...product, newPrice }} />;
})}
📝 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
product.newPrice = getNewPrice(
product.discountPercentage,
product.price
);
const newPrice = getNewPrice(
product.discountPercentage,
product.price
);
return <ProductCard key={product.id} product={{ ...product, newPrice }} />;

Comment on lines +136 to +139
onClick={() => {
onAddToCart(product); // First, add the product to the cart
handleBuyNow(); // Then, navigate to the payment page
}}
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

Re-evaluate adding the product to the cart before "Buy Now"

The "Buy Now" button currently adds the product to the cart before navigating to the payment page. If the intention is to allow users to purchase the item directly without adding it to the cart, consider removing the onAddToCart(product) call.

Update the onClick handler to navigate directly to the payment page with the product data:

<button
  onClick={() => {
-    onAddToCart(product); // First, add the product to the cart
    handleBuyNow(); // Then, navigate to the payment page
  }}
  className="..."
>

Committable suggestion was skipped due to low confidence.

@codervivek5 codervivek5 merged commit cd2ed8f into codervivek5:main Oct 17, 2024
2 checks passed
Copy link

Congratulations, Your pull request has been successfully merged 🥳🎉 Thank you for your contribution to the project 🚀 Keep Contributing!! ✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Making the cards more correct in view
2 participants