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

Bugfix: Make sure amount displayed on campaign page is dynamically calculated #1008

Merged
merged 3 commits into from
Jan 12, 2025

Conversation

mkue
Copy link
Contributor

@mkue mkue commented Jan 12, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced contribution tracking by dynamically fetching data from Firestore.
  • Bug Fixes

    • None
  • Refactor

    • Standardized naming conventions for social media link properties in campaign configuration.
    • Removed direct amount_collected_chf and contributions properties from campaign data model.
  • Documentation

    • Added clarifying comments for contribution type definitions.
    • Updated comments for Stripe contribution reference ID.
  • Chores

    • Simplified Stripe event handling by removing campaign update logic.

Copy link

vercel bot commented Jan 12, 2025

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

Name Status Preview Comments Updated (UTC)
public ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 12, 2025 9:05pm

Copy link

coderabbitai bot commented Jan 12, 2025

📝 Walkthrough

Walkthrough

This pull request introduces changes to campaign-related configurations and data handling across multiple files. The modifications primarily involve renaming properties from title to name for social media links, removing amount_collected_chf and contributions properties, and updating how contributions are retrieved and calculated. The changes reflect a shift in data model structure and contribution tracking methodology.

Changes

File Change Summary
admin/src/collections/Campaigns.ts - Renamed title to name for social media link fields
- Removed amount_collected_chf and contributions properties
- Updated validation message from matchMessage to matchesMessage
shared/src/stripe/StripeEventHandler.ts - Removed maybeUpdateCampaign method
shared/src/types/campaign.ts - Deleted amount_collected_chf and contributions properties
shared/src/types/contribution.ts - Added BaseContribution type
- Added comments for amount_chf and fees_chf
- Updated reference_id comment
website/src/app/[lang]/[region]/(website)/campaign/[campaign]/page.tsx - Imported Contribution type
- Modified contributions retrieval logic using Firestore collection group query

Possibly related PRs

Suggested Labels

fundraisers, website

Suggested Reviewers

  • andrashee
  • ssandino
  • socialincome-dev

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 219495d and 4932dff.

📒 Files selected for processing (1)
  • website/src/app/[lang]/[region]/(website)/campaign/[campaign]/page.tsx (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Test website
  • GitHub Check: Security checks (typescript)
  • GitHub Check: Prettify
🔇 Additional comments (1)
website/src/app/[lang]/[region]/(website)/campaign/[campaign]/page.tsx (1)

9-9: LGTM!

The new imports are correctly placed and properly organized.


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

@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: 1

🧹 Nitpick comments (4)
shared/src/types/contribution.ts (1)

33-34: Consider enhancing fee documentation.

While the comments are clear, consider documenting:

  • Types of fees included
  • Whether fees are percentage-based or fixed
admin/src/collections/Campaigns.ts (1)

Line range hint 37-37: Fix typo in property name

There's a typo in "Thrird Description Title" that should be corrected.

-			name: 'Thrird Description Title',
+			name: 'Third Description Title',
website/src/app/[lang]/[region]/(website)/campaign/[campaign]/page.tsx (2)

93-93: Simplify 'amountCollected' calculation and handle potential undefined values

The ?? 0 is unnecessary since the reduce function starts with an initial value of 0. Additionally, consider handling cases where amount_chf might be undefined.

You can simplify the calculation:

-     const amountCollected = (contributions.docs.reduce((sum, c) => sum + c.data().amount_chf, 0) ?? 0) * exchangeRate;
+     const amountCollected = contributions.docs.reduce((sum, c) => sum + (c.data().amount_chf || 0), 0) * exchangeRate;

129-129: Ensure consistent use of 'contributions.size' for counts

You have updated the count parameter to use contributions.size. Verify that all other instances where contributions represents the count are also using contributions.size to prevent any inconsistencies.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3633007 and 12dd4d6.

📒 Files selected for processing (5)
  • admin/src/collections/Campaigns.ts (2 hunks)
  • shared/src/stripe/StripeEventHandler.ts (0 hunks)
  • shared/src/types/campaign.ts (0 hunks)
  • shared/src/types/contribution.ts (1 hunks)
  • website/src/app/[lang]/[region]/(website)/campaign/[campaign]/page.tsx (3 hunks)
💤 Files with no reviewable changes (2)
  • shared/src/types/campaign.ts
  • shared/src/stripe/StripeEventHandler.ts
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Test admin
  • GitHub Check: Test shared code
  • GitHub Check: Test website
  • GitHub Check: Test functions
  • GitHub Check: Security checks (typescript)
  • GitHub Check: Prettify
🔇 Additional comments (6)
shared/src/types/contribution.ts (2)

42-42: LGTM! Helpful API documentation link.

The Stripe API reference link improves code maintainability.


25-27: LGTM! Clear documentation of the contribution model.

The BaseContribution type documentation clearly explains how the net amount is calculated.

Let's verify this calculation is used consistently:

✅ Verification successful

Documentation accurately reflects the contribution model

The fields amount_chf and fees_chf are consistently used across the codebase, with proper handling in payment processing, statistics calculation, and test cases.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for places where amount_chf and fees_chf are used together
rg -l 'amount_chf.*fees_chf|fees_chf.*amount_chf'

Length of output: 84


Script:

#!/bin/bash
# Search for actual calculations or assignments involving these fields
ast-grep --pattern 'amount_chf - fees_chf'
ast-grep --pattern 'fees_chf + $_'
ast-grep --pattern '$_ = amount_chf'

# Also search for any references to these fields in function bodies
rg -A 2 -B 2 '\b(amount_chf|fees_chf)\b' --type ts

Length of output: 11014

admin/src/collections/Campaigns.ts (3)

72-72: LGTM: Property renames improve consistency

The renaming of properties from 'title' to 'name' for social media links standardizes the naming convention.

Also applies to: 78-78, 84-84, 90-90, 96-96


145-145: LGTM: Validation message property update

The update from matchMessage to matchesMessage aligns with the API requirements.


Line range hint 1-164: Verify dynamic amount calculation implementation

The removal of amount_collected_chf and contributions properties suggests these values will be calculated dynamically. However, I don't see the implementation for this dynamic calculation in the provided changes.

Let's verify where these calculations are implemented:

✅ Verification successful

Dynamic calculation implementation verified

The removed properties amount_collected_chf and contributions are now dynamically calculated through Firestore queries, summing the amount_chf from all related contributions and applying current exchange rates.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for files that might contain the dynamic amount calculation implementation
rg -l "amount.*collected" --type ts
rg -l "contribution.*total" --type ts

Length of output: 713


Script:

#!/bin/bash
# Search for campaign-related calculation implementations
rg -l "campaign.*contribution" --type ts
rg -l "campaign.*amount" --type ts

# Look for potential API endpoints or database queries
ast-grep --pattern 'export async function $FUNC($$$) {
  $$$
  campaign$$$
  $$$
}'

Length of output: 236


Script:

#!/bin/bash
# Check campaign page implementation
cat website/src/app/[lang]/[region]/\(website\)/campaign/[campaign]/page.tsx

# Search for Firestore/database related files
fd -e ts firestore
rg -l "getContributions|getCampaign" --type ts

Length of output: 13540

website/src/app/[lang]/[region]/(website)/campaign/[campaign]/page.tsx (1)

9-9: Import statement is correct

The import of the Contribution type is appropriate.

Copy link

Visit the preview URL for this PR (updated for commit 12dd4d6):

https://si-admin-staging--pr1008-michael-campaign-sta-ursb8pkw.web.app

(expires Sun, 19 Jan 2025 20:29:49 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: b7b0969384059dce6ea8fad1ee1d1737e54e6676

Copy link

@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
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 12dd4d6 and 219495d.

📒 Files selected for processing (1)
  • website/src/app/[lang]/[region]/(website)/campaign/[campaign]/page.tsx (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: CodeQL
  • GitHub Check: Test website
  • GitHub Check: Prettify
  • GitHub Check: Security checks (typescript)
🔇 Additional comments (2)
website/src/app/[lang]/[region]/(website)/campaign/[campaign]/page.tsx (2)

9-9: LGTM: Import additions are appropriate

The new imports support the dynamic contribution calculation implementation.


89-91: Verify campaign_path field comparison

The Firestore query compares 'campaign_path' with a DocumentReference. Ensure the field is stored as a DocumentReference in Firestore.

@mkue mkue merged commit f4572ce into main Jan 12, 2025
16 checks passed
@mkue mkue deleted the michael/campaign-stats-fix branch January 12, 2025 21: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.

1 participant