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

Refactor property form and add rooms list component #29

Merged
merged 24 commits into from
Mar 12, 2024

Conversation

SirSanctified
Copy link
Owner

@SirSanctified SirSanctified commented Mar 12, 2024

This pull request includes several changes to the codebase:

  • Added the PropertyForm component to the CreatePropertyPage.

  • Merged the 'main' branch from the remote repository.

  • Disabled pagination for the AmenityViewSet.

  • Refactored the PropertyForm component to include form submission logic.

  • Refactored code in MyDetails and added the UpdateProperty and CreatePropertyPage components.

  • Updated the user avatar alt text.

  • Refactored the property update and create pages.

  • Fixed a bug in the property form initialization.

  • Refactored the AmenitySerializer in serializers.py.

  • Refactored the PropertySerializer to use HyperlinkedRelatedField for amenities.

  • Updated the City type and added the Amenity type.

  • Refactored the PropertyForm component and updated API calls.

  • Refactored the property page and added property details.

  • Refactored the PropertySerializer and added the rooms field.

  • Added the formatCurrency function and updated the Property and Room types.

  • Added the Card component and related UI components.

  • Refactored the footer in the dashboard layout.

  • Added the RoomCard component.

  • Added the RoomsList component.

  • Added the RoomsList component to the PropertyDetails page.

  • Refactored the property details page layout and content.

  • Added an edit button to the property page.

Summary by CodeRabbit

  • New Features
    • Introduced a new RoomCard component for displaying room details.
    • Added a RoomsList component to render a list of room cards.
    • Implemented a PropertyForm for creating and updating property details.
    • New Checkbox component for enhanced form inputs.
    • Added currency formatting utility function.
  • Enhancements
    • Updated Property and Amenity serializers for better data handling.
    • Improved UI layout by adjusting the footer positioning in the dashboard.
    • Enhanced user avatar display logic for better fallback handling.
  • Bug Fixes
    • Removed unnecessary logging in the MyDetails component.
  • Refactor
    • Pagination functionality disabled for amenities for streamlined data presentation.
  • Documentation
    • Updated types to reflect changes in the property and amenity models.

@SirSanctified SirSanctified linked an issue Mar 12, 2024 that may be closed by this pull request
Copy link
Contributor

coderabbitai bot commented Mar 12, 2024

Warning

Rate Limit Exceeded

@SirSanctified has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 54 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 745dc06 and 1f08aa6.

Walkthrough

This update brings significant enhancements to a property management application, focusing on backend and client-side improvements. It reorganizes property and amenity handling in the backend, disables pagination for amenities, and refines the UI/UX on the client side by adjusting layouts and introducing new components for property details, including room listings and property forms. Additionally, it improves data handling and UI components like user avatars and checkboxes, alongside utility functions for better usability and presentation.

Changes

Files Summary
backend/core/serializers.py Swapped PropertySerializer and AmenitySerializer classes; added rooms and amenities fields to PropertySerializer.
backend/core/views.py Set pagination_class to None in AmenityViewSet.
client/src/app/(auth)/my-details/page.tsx Removed logging of city.
client/src/app/(dashboard)/layout.tsx Moved and restyled the footer element.
client/src/app/(dashboard)/profile/[id]/landlords/properties/[propertyId]/page.tsx, client/src/components/shared/properties/propertyForm.tsx Enhanced property details handling and form functionality for creating and updating properties.
client/src/components/shared/properties/roomCard.tsx, client/src/components/shared/properties/roomsList.tsx Introduced RoomCard and RoomsList components for displaying room details.
client/src/components/shared/userAvatar.tsx Updated conditional rendering with optional chaining and nullish coalescing.
client/src/components/ui/card.tsx, client/src/components/ui/checkbox.tsx Added new UI components for cards and checkboxes.
client/src/lib/utils.ts Added formatCurrency function.
client/src/types/index.ts Updated and added types for amenities, properties, and rooms.

Poem

In the land of code and byte,
Where changes shine so bright,
A rabbit hopped with sheer delight,
🐰 For improvements were in sight.

"To the devs," it squeaked with glee,
"For making the app what it should be,
A better place for you and me."
With a hop, it left, as happy as can be. 🌟

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.
    • 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 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 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.

@SirSanctified SirSanctified self-assigned this Mar 12, 2024
@SirSanctified SirSanctified added the enhancement New feature or request label Mar 12, 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.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 12ec2d8 and 11a888f.
Files ignored due to path filters (2)
  • client/package-lock.json is excluded by: !**/*.json
  • client/package.json is excluded by: !**/*.json
Files selected for processing (15)
  • backend/core/serializers.py (2 hunks)
  • backend/core/views.py (1 hunks)
  • client/src/app/(auth)/my-details/page.tsx (1 hunks)
  • client/src/app/(dashboard)/layout.tsx (1 hunks)
  • client/src/app/(dashboard)/profile/[id]/landlords/properties/[propertyId]/page.tsx (1 hunks)
  • client/src/app/(dashboard)/profile/[id]/landlords/properties/[propertyId]/update/page.tsx (1 hunks)
  • client/src/app/(dashboard)/profile/[id]/landlords/properties/create/page.tsx (1 hunks)
  • client/src/components/shared/properties/propertyForm.tsx (1 hunks)
  • client/src/components/shared/properties/roomCard.tsx (1 hunks)
  • client/src/components/shared/properties/roomsList.tsx (1 hunks)
  • client/src/components/shared/userAvatar.tsx (1 hunks)
  • client/src/components/ui/card.tsx (1 hunks)
  • client/src/components/ui/checkbox.tsx (1 hunks)
  • client/src/lib/utils.ts (1 hunks)
  • client/src/types/index.ts (1 hunks)
Files not reviewed due to errors (1)
  • backend/core/views.py (Error: unable to parse review)
Additional comments: 7
client/src/lib/utils.ts (1)
  • 8-14: The formatCurrency function correctly formats a given number as a currency value in USD with two decimal places. This is a useful utility function for displaying currency values consistently across the application. Good use of the Intl.NumberFormat API for localization and formatting.
client/src/components/shared/userAvatar.tsx (1)
  • 7-11: The update to the UserAvatar component introduces optional chaining (?.) and nullish coalescing (??) operators, enhancing the robustness of the component by gracefully handling cases where user.first_name or user.email might be null or undefined. This is a good practice for improving the reliability of the component.
client/src/app/(dashboard)/profile/[id]/landlords/properties/create/page.tsx (1)
  • 1-14: The changes to the CreatePropertyPage component correctly incorporate the PropertyForm component, along with a descriptive heading and paragraph to guide users through the process of adding a new property. This enhances the user experience by providing clear instructions and a streamlined form for property creation.
client/src/components/shared/properties/roomCard.tsx (1)
  • 8-66: The RoomCard component is well-structured and makes good use of external UI components and utilities for displaying room details. However, there are a few areas for improvement:
  1. Image Alt Text (Line 15): The alt text for the room image is static ("Room"). Consider making it more descriptive or dynamic based on the room's properties to improve accessibility.

  2. Link Component Usage (Lines 10-62): The entire card is wrapped in a Link component, which is a good practice for making the card clickable. However, ensure that the URL structure (/listings/${room.id}) is consistent with the application's routing conventions.

  3. Styling Consistency: The component uses Tailwind CSS for styling, which is consistent with the rest of the application. Ensure that the chosen colors and spacing align with the application's design system.

  4. Prop Types (Line 8): The component correctly destructures its props and provides an optional property prop. Consider using TypeScript's PropTypes or a similar mechanism to enforce type checking for props, enhancing code reliability.

Overall, the component is implemented correctly and follows best practices for React component development. Just pay attention to the minor suggestions above to further refine the component.

client/src/components/shared/properties/propertyForm.tsx (1)
  • 1-226: The PropertyForm component has been significantly refactored to include comprehensive form handling, data fetching, and UI updates. Here are some key observations and suggestions:
  1. Use of React Hooks (Lines 26-38, 40-102): The component makes good use of React hooks for state management and side effects. The useEffect hook is correctly used to fetch cities and amenities data. Ensure that dependencies in the dependency array of useEffect are correctly specified to avoid unnecessary re-renders.

  2. Form Submission Handling (Lines 104-148): The form submission logic is well-implemented, with clear differentiation between "Update" and "Create" actions. Error handling in the catch block is appropriate, providing user feedback through toast notifications. Consider validating the form data before submission to enhance user experience and data integrity.

  3. Accessibility and Usability (Lines 151-226): The form fields and select components are well-structured, contributing to a good user experience. Ensure that all form elements are accessible, including proper labeling and keyboard navigation support.

  4. Environment Variables (Lines 45, 48, 120, 131): The use of environment variables for API URLs is a good practice for maintainability and security. Ensure that these variables are correctly configured in all deployment environments.

  5. Error Handling in Data Fetching (Lines 40-78): The error handling in the data fetching logic is minimal. Consider providing more specific error messages or fallbacks to enhance the user experience in case of API failures.

Overall, the PropertyForm component is well-constructed with a clear focus on functionality and user experience. Pay attention to the minor suggestions above to further refine the component.

client/src/app/(auth)/my-details/page.tsx (1)
  • 73-78: > 📝 NOTE

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

The MyDetails component is well-structured and provides a comprehensive form for users to update their details. Here are some key observations and suggestions:

  1. State Management and Data Fetching (Lines 1-226): The component effectively uses React hooks for state management and fetching data for institutions and cities. Ensure that error handling in data fetching is robust to provide a better user experience in case of API failures.

  2. Form Submission Logic (Lines 1-226): The form submission logic is clear, with specific actions based on the user's role (student or landlord). Consider adding form validation to ensure that all required fields are filled out before submission.

  3. Accessibility and Usability: Ensure that all form elements are accessible, including proper labeling and keyboard navigation support. The use of ComboBoxResponsive and Select components should contribute to a good user experience.

  4. Routing and Authentication Checks (Lines 1-226): The component correctly checks for authentication status and redirects unauthenticated users. Ensure that the routing paths used (/signin, /, /verification) are consistent with the application's routing conventions.

  5. Environment Variables: The use of environment variables for API URLs in the form submission logic is not visible in the provided code. Ensure that these variables are correctly configured in all deployment environments.

Overall, the MyDetails component is implemented correctly, focusing on functionality and user experience. Pay attention to the minor suggestions above to further refine the component.

backend/core/serializers.py (1)
  • 275-345: > 📝 NOTE

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

The changes to the PropertySerializer and AmenitySerializer classes in serializers.py are well-implemented, with a focus on enhancing data representation and handling. Here are some key observations and suggestions:

  1. AmenitySerializer (Lines 170-181): The AmenitySerializer is straightforward and correctly defines the fields for the Amenity model. Ensure that any additional fields or model relationships that might be relevant are also included.

  2. PropertySerializer (Lines 278-342): The PropertySerializer has been significantly updated to include rooms and amenities fields, improving the representation of property data. The use of HyperlinkedRelatedField for amenities and the custom RoomSerializer for rooms are good practices for RESTful API design. Ensure that the create and update methods correctly handle the relationships and data integrity.

  3. Error Handling and Validation: Both serializers include custom logic in their create and update methods. Ensure that error handling and validation are robust, especially when dealing with relationships and constraints (e.g., unique room names within a property).

  4. Use of timezone.now() (Lines 332, 342): The use of timezone.now() to update the updated_at field is appropriate. Consider applying this pattern consistently across all serializers to ensure that the updated_at field is always accurately maintained.

Overall, the changes to the serializers are well-thought-out and contribute to the application's functionality and data integrity. Pay attention to the minor suggestions above to further refine the serializers.

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

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 11a888f and 745dc06.
Files selected for processing (1)
  • client/src/app/(dashboard)/profile/[id]/landlords/properties/[propertyId]/page.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • client/src/app/(dashboard)/profile/[id]/landlords/properties/[propertyId]/page.tsx

@SirSanctified SirSanctified merged commit 81e4191 into main Mar 12, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Property Management in Roomio
1 participant