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

Implement admin page for gift cards #377

Merged
merged 3 commits into from
Dec 18, 2023
Merged

Conversation

BerglundDaniel
Copy link
Member

@BerglundDaniel BerglundDaniel commented Dec 4, 2023

This PR adds an admin page for the gift cards with related entities etc. The view is similar to the one for transactions.

Screenshot from 2023-12-04 15-18-41

Screenshot from 2023-12-04 15-18-22

Summary by CodeRabbit

  • New Features

    • Introduced Gift Card management with the ability to view and delete gift cards.
    • Added a new Gift Card List component to display all gift cards with details.
    • Created a Gift Card Show component to present individual gift card information and associated products.
    • Incorporated new navigation menu entry for Gift Cards in the admin panel.
  • Enhancements

    • Updated Order List with improved rendering and date-time display.
  • API & Database Updates

    • Implemented new routes and entities for handling gift cards.
    • Adjusted database schema for gift cards, including status and amount fields.
  • Bug Fixes

    • Fixed issues with initial data creation for shop transactions and gift cards.

@BerglundDaniel BerglundDaniel force-pushed the db/admin-page-gift-cards branch from 4cf7347 to e615341 Compare December 4, 2023 15:23
amount=product.price,
validation_code=12989519,
email="[email protected]",
status="activated",
Copy link
Member

Choose a reason for hiding this comment

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

What does the activated status mean for a gift card? Has that been used?

I would think a gift card had the following states:

  • Valid (when it has been bought and not yet used)
  • Used (when it has been used by a customer and cannot be used again)
  • Cancelled (if we have paid it back to the customer for whatever reason, and the customer should not be allowed to use it)

Copy link
Member Author

Choose a reason for hiding this comment

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

Cancelling would be useful, we should add that

@emanuelen5
Copy link
Member

I think it would be nice if the admin page had a way to cancel the gift cards in case they are paid back. This can be implemented in a later PR (just create an issue for it, in that case).

@BerglundDaniel
Copy link
Member Author

I opened a new issue about cancelling gift cards

@BerglundDaniel
Copy link
Member Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Dec 15, 2023

Walkthrough

The recent changes involve the introduction of gift card functionality within an e-commerce platform, both on the admin frontend and the API backend. New classes for handling gift cards were added to the admin models, and corresponding React components were created to display and manage gift cards. Backend changes include database schema updates, new API routes for gift cards, and modifications to existing entities and models to support gift card transactions.

Changes

Files Change Summaries
admin/src/Models/GiftCard.js, admin/src/Models/GiftCardRow.js Added GiftCard and GiftCardRow classes extending Base with del methods and model properties.
admin/src/Sales/GiftCardList.js New file with GiftCardList React component extending CollectionNavigation to render gift card details.
admin/src/Sales/GiftCardShow.js Initialized and subscribed to gift_card data, updated state, and rendered gift card details with associated products.
admin/src/Sales/OrderList.js Updated Row component for conditional rendering and DateTimeShow usage, adjusted this.state access, and columns structure.
admin/src/Sales/Routes.jsx Added GiftCardList and GiftCardShow components with respective routes to admin section features.
admin/src/app.jsx Inserted navigation menu entry for "Presentkort" targeting "/sales/gift-card".
api/src/firstrun.py Modified create_shop_transactions and create_shop_gift_cards functions.
api/src/migrations/0025_initial_gift_card.sql Altered database schema for gift cards, updating status field and adding amount field.
api/src/shop/entities.py, api/src/shop/models.py Included DESC in imports, added GiftCard and ProductGiftCardMapping entities, updated status enum in GiftCard, and added amount in ProductGiftCardMapping.
api/src/shop/views.py Added API routes for gift cards and related products.

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 X ?


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • You can reply to a review comment made by CodeRabbit.
  • You can tag CodeRabbit on specific lines of code or files in the PR by tagging @coderabbitai in a comment.
  • You can tag @coderabbitai in a PR comment and ask one-off questions about the PR and the codebase. Use quoted replies to pass the context for follow-up questions.

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

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

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ad3d99d and 9a59c96.
Files selected for processing (12)
  • admin/src/Models/GiftCard.js (1 hunks)
  • admin/src/Models/GiftCardRow.js (1 hunks)
  • admin/src/Sales/GiftCardList.js (1 hunks)
  • admin/src/Sales/GiftCardShow.js (1 hunks)
  • admin/src/Sales/OrderList.js (2 hunks)
  • admin/src/Sales/Routes.jsx (2 hunks)
  • admin/src/app.jsx (1 hunks)
  • api/src/firstrun.py (3 hunks)
  • api/src/migrations/0025_initial_gift_card.sql (2 hunks)
  • api/src/shop/entities.py (3 hunks)
  • api/src/shop/models.py (2 hunks)
  • api/src/shop/views.py (2 hunks)
Files skipped from review due to trivial changes (1)
  • admin/src/Sales/OrderList.js
Additional comments: 29
admin/src/Models/GiftCard.js (1)
  • 6-8: The del method in the GiftCard class correctly throws an error to prevent deletion of gift card data, which is a good practice for sensitive information. Ensure that this behavior is documented in the codebase and that any client code is aware that deletion is not supported for gift cards.
admin/src/Models/GiftCardRow.js (3)
  • 6-8: The del method in GiftCardRow correctly throws an error to prevent deletion operations, which aligns with the need to retain sensitive gift card data for records or compliance.

  • 11-19: Ensure that the attributes defined in GiftCardRow.model match the backend schema and that the frontend correctly handles the default values, such as null for amount and product_quantity, and an empty string for name.

  • 4-19: The GiftCardRow class appears to be a simple data model without much logic, which is acceptable if the business logic is handled elsewhere. Ensure that this design is consistent with the rest of the system's architecture.

admin/src/Sales/GiftCardList.js (5)
  • 1-8: The imports and component setup in GiftCardList.js appear to be correctly implemented and follow standard React conventions.

  • 10-20: The Row functional component is implemented correctly, with proper usage of the item prop to render gift card details.

  • 23-30: The initialization of this.collection with the GiftCard model and URL endpoint in the GiftCardList constructor appears to be correct. Verify that the URL /webshop/gift-card correctly points to the gift card data endpoint.

  • 32-47: The render method in GiftCardList is correctly implemented, with the CollectionTable and SearchBox components being used appropriately to render the UI.

  • 51-51: The export of the GiftCardList component is correct, allowing it to be used in other parts of the admin system.

admin/src/Sales/GiftCardShow.js (2)
  • 61-61: The currency value calculation seems to assume a fixed conversion rate of 100. If this is not the case, consider using a dynamic conversion rate or clarify the logic behind this fixed value.

  • 39-44: Ensure that the display of email and validation code adheres to privacy and security best practices, and that only authorized users can access this sensitive information.

admin/src/Sales/Routes.jsx (2)
  • 4-5: The imports for GiftCardList and GiftCardShow are correctly added to the file.

  • 18-19: The routes for GiftCardList and GiftCardShow are correctly set up and follow the existing routing pattern.

admin/src/app.jsx (1)
  • 80-83: The addition of the "Presentkort" navigation item is consistent with the PR objectives and integrates well with the existing navigation structure.
api/src/firstrun.py (3)
  • 315-315: The change from a fixed test_date to datetime.now() for the created_at field of transactions will result in transactions having the current timestamp. Confirm that this change aligns with the intended behavior of the script, as it may affect tests or other operations that rely on the firstrun.py script.

  • 335-335: The completed_at field in TransactionAction is now set to datetime.now(), which could affect the reproducibility of test data. Ensure this change is consistent with the intended use of the script.

  • 414-436: The loop in create_shop_gift_cards creates gift cards with alternating "valid" and "used" statuses. Verify that the number of gift cards created and their properties meet the requirements for initial data setup. Additionally, consider adding comments to explain the logic behind the alternating statuses and the significance of the validation code values.

api/src/migrations/0025_initial_gift_card.sql (3)
  • 7-7: The status field in the webshop_gift_card table has been correctly updated to include the new enum values 'valid', 'used', 'expired', and 'cancelled', which is consistent with the PR objectives and AI-generated summaries.

  • 18-18: The addition of the amount field to the webshop_product_gift_card_mapping table is consistent with the PR objectives and AI-generated summaries, and the SQL syntax for its definition is correct.

  • 4-10: > Note: This review was outside the patches, and no patch overlapping with it was found. Original lines [22-22]

The ALTER TABLE statement making the member_id column in the webshop_transactions table nullable is not mentioned in the PR objectives or AI-generated summaries. It appears to be an important change to allow gift cards to be purchasable without being a member. Please verify that this change is intentional and correctly implemented.

Verification successful

The change to make the member_id column nullable in the webshop_transactions table is confirmed by the migration file 0025_initial_gift_card.sql. The corresponding model in api/src/shop/models.py has been updated to reflect this change (nullable=True), and the references in api/src/shop/views.py indicate that the application logic is prepared to handle nullable member_id. No additional constraints or triggers related to this change have been found. The change appears to be intentional and correctly implemented to support the purchase of gift cards without requiring membership.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the `member_id` column is now nullable and check if there are any constraints or triggers related to this column that might need to be updated.
rg 'member_id' api/src/ --files-with-matches

Length of output: 2469



Script:

#!/bin/bash
# Check the contents of the migration file for changes to the `member_id` column
cat api/src/migrations/0025_initial_gift_card.sql

# Look for references to the `member_id` column in the shop models and views
rg 'member_id' api/src/shop/models.py
rg 'member_id' api/src/shop/views.py

Length of output: 2126

api/src/shop/entities.py (4)
  • 2-2: The import modification to include DESC is correct and aligns with the usage in the new entity declarations.

  • 58-62: The gift_card_entity declaration appears correct, with appropriate search_columns specified. Ensure that all fields listed are indexed for performance optimization.

  • 65-69: The gift_card_content_entity declaration includes an expand_fields definition for product. Verify that the ProductGiftCardMapping.product relationship is correctly set up and that the Product.name field is accessible as intended.

  • 58-70: Confirm that the new GiftCard and ProductGiftCardMapping entities are properly integrated into the system, including views, serializers, and any other components that may interact with them.

api/src/shop/models.py (2)
  • 185-202: The changes to the GiftCard class status enum values and the default status are consistent with the PR objectives and the AI-generated summary. Ensure that all parts of the codebase that interact with the GiftCard status are updated to reflect these new enum values.

  • 221-229: The addition of the amount column to the ProductGiftCardMapping class aligns with the PR objectives. Ensure that this new column is properly handled in all parts of the code where ProductGiftCardMapping instances are created or manipulated.

api/src/shop/views.py (3)
  • 32-33:
    The addition of gift_card_entity and gift_card_content_entity imports aligns with the PR's objective to introduce gift card management in the admin system.

  • 143-148:
    The new service entity route for /gift-card is correctly set up with appropriate permissions for the WEBSHOP role, which is consistent with the existing permission structure.

  • 150-155:
    The related entity route for gift card products is correctly defined with an OrmSingeRelation and the correct permission for the WEBSHOP role.

api/src/firstrun.py Show resolved Hide resolved
api/src/shop/views.py Show resolved Hide resolved
admin/src/Sales/GiftCardShow.js Show resolved Hide resolved
admin/src/Models/GiftCard.js Outdated Show resolved Hide resolved
api/src/shop/models.py Show resolved Hide resolved
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 9a59c96 and 9ab13a8.
Files selected for processing (2)
  • admin/src/Models/GiftCard.js (1 hunks)
  • api/src/shop/models.py (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • admin/src/Models/GiftCard.js
  • api/src/shop/models.py

@BerglundDaniel BerglundDaniel merged commit dc90969 into master Dec 18, 2023
2 checks passed
@BerglundDaniel BerglundDaniel deleted the db/admin-page-gift-cards branch December 18, 2023 15:41
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