-
-
Notifications
You must be signed in to change notification settings - Fork 19
Enhance payment system #3112
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
Enhance payment system #3112
Conversation
WalkthroughThis update introduces a new billing product model, including a Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant WebApp
participant Supabase
participant DB
participant PolarAPI
User->>WebApp: Clicks "Upgrade Plan"
WebApp->>Supabase: Auth check, get user info
Supabase->>DB: Call check_ws_creator(ws_id)
DB-->>Supabase: Returns authorization result
Supabase-->>WebApp: User info, authorization
alt Authorized
WebApp->>PolarAPI: Create checkout session (with user, wsId, productId)
PolarAPI-->>WebApp: Checkout URL
WebApp-->>User: Redirect to checkout
else Unauthorized
WebApp-->>User: Show error message
end
sequenceDiagram
participant User
participant WebApp
participant Supabase
participant DB
User->>WebApp: Views Billing Page
WebApp->>Supabase: Fetch workspace subscriptions (limit 5, with product info)
Supabase->>DB: Query workspace_subscription, join workspace_subscription_products
DB-->>Supabase: Returns billing history
Supabase-->>WebApp: Billing history data
WebApp-->>User: Renders BillingHistory table with dynamic data
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
packages/types/src/supabase.tsOops! Something went wrong! :( ESLint: 9.29.0 Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@typescript-eslint/parser' imported from /eslint.config.mjs ✨ Finishing Touches
🧪 Generate Unit Tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @phatgg221, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request focuses on building out and refining the subscription and payment completion flow for workspaces. It involves significant database schema changes to support subscription products, robust access control mechanisms, a complete overhaul of the billing page's user interface to display dynamic history, and improvements to the payment initiation API for better security and data handling.
Highlights
- Subscription Product Management: I've introduced a new
workspace_subscription_products
table in the database and linked it to theworkspace_subscription
table. This allows for better management and storage of different subscription plans and their associated details like name, description, price, and recurring interval. - Enhanced Subscription Authorization: I've implemented and refined a
check_ws_creator
Supabase function and updated Row-Level Security (RLS) policies. This ensures that only the creator of a workspace can initiate a new subscription for it, and only if an active subscription doesn't already exist, preventing unauthorized or duplicate subscriptions. - Dynamic Billing History Display: I've added a new
BillingHistory
React component and integrated it into the billing page. This component dynamically fetches and displays a comprehensive history of a user's workspace subscriptions, including status, dates, and product details, replacing previously static data. - Billing Page UI/UX Improvements: The billing page's user interface has been significantly updated. I've removed the static 'Payment Method' section and refined the layout for displaying current plan details and features, making the page cleaner and more focused on subscription management.
- Secure Payment Initiation: The API route responsible for initiating payments with Polar has been enhanced. It now performs robust authorization checks using the
check_ws_creator
function and securely passes user details (like email and display name) to the Polar checkout session, improving both security and customer identification.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces payment completion features, including new database tables for subscription products, UI updates for the billing page to display current plans and upgrade options, and a new billing history component. API routes and webhooks are updated to handle checkout creation and subscription activation, including an initial usage report to Polar. Key changes involve schema updates, RLS policy adjustments, and frontend components for billing management.
Several areas need attention: database permissions for the new products table are overly permissive, the price
column type could be improved for financial data, and some frontend elements like debug logs and button functionality need refinement. Consistency in price handling (cents vs. currency units) across different parts of the application should also be ensured.
apps/db/supabase/migrations/20250618073214_add_workspace_subscription_products_table.sql
Show resolved
Hide resolved
apps/db/supabase/migrations/20250618073214_add_workspace_subscription_products_table.sql
Show resolved
Hide resolved
apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-history.tsx
Outdated
Show resolved
Hide resolved
apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-history.tsx
Outdated
Show resolved
Hide resolved
Problems: - Cancel subscription needs to be functionally working - Must charge based on how many people in the workspace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 10
🔭 Outside diff range comments (3)
apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/data-polar-checkout.tsx (1)
8-8
: Remove unused customerEmail prop.The
customerEmail
prop is no longer used in the component logic but remains in the interface, which could be confusing for consumers.interface PurchaseLinkProps { productId: string; wsId: string; - customerEmail?: string; theme?: 'light' | 'dark' | 'auto'; className?: string; }
Also remove it from the destructuring:
const PurchaseLink = ({ productId, wsId, theme = 'auto', className, children, }: PropsWithChildren<PurchaseLinkProps>) => {apps/web/src/app/api/[wsId]/[productId]/cancel/route.ts (1)
1-54
: Remove or complete the commented-out implementation.The entire API route is commented out, which suggests incomplete development. Either:
- Complete the implementation if cancellation functionality is needed
- Remove the file if the feature is not ready for this release
Having commented-out code in production deployments can be confusing and should be avoided.
apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx (1)
241-241
: Replace hard-coded email with dynamic value.The
customerEmail
prop uses a hard-coded test email "t@test.com", which should not be used in production code.- customerEmail="t@test.com" + customerEmail={userEmail || ''}Ensure you pass the actual user's email from the parent component or retrieve it from your authentication context.
♻️ Duplicate comments (6)
apps/web/src/app/api/webhooks/route.ts (1)
70-73
: Table usage concern remains unaddressed.The previous review comment about using
workspace_users
vsworkspace_members
for counting workspace seats is still valid. The migration files in this PR useworkspace_members
for workspace membership checks, suggesting potential inconsistency.apps/web/src/app/api/[wsId]/[productId]/payment/route.ts (1)
62-62
: Relative URL concern persists.The
successUrl
still uses a relative path (http://localhost:7803/${wsId}/billing/success
). While this often works, consider using an absolute URL constructed from environment variables for better robustness across different environments.apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-history.tsx (2)
130-137
: Receipt download button lacks functionality.The download receipt button is present but has no
onClick
handler or associated functionality to actually download receipts.
111-111
: Price formatting consistency concern.The price
subscription.product.price
is displayed directly without.toFixed(2)
formatting. Ensure consistent price handling throughout the application.apps/db/supabase/migrations/20250618073214_add_workspace_subscription_products_table.sql (2)
6-6
: Use NUMERIC instead of REAL for monetary values.For monetary values like
price
, useNUMERIC
orDECIMAL
data types instead ofREAL
to avoid precision issues with financial calculations.
21-47
: Excessive permissions granted to anon and authenticated roles.Granting
DELETE
,INSERT
,TRUNCATE
, andUPDATE
permissions onworkspace_subscription_products
to theanon
role is highly insecure. Theanon
role represents unauthenticated users and should have minimal write access.Apply the principle of least privilege:
anon
should have no permissions or onlySELECT
if product information is publicauthenticated
users might only needSELECT
service_role
should handle write operations
🧹 Nitpick comments (2)
apps/web/.env.example (1)
47-48
: Good formatting improvement with optional ordering enhancement.Adding the trailing newline is a good practice for file formatting.
Consider reordering the environment variables as suggested by the linter for better organization:
# Payment Polar.sh -POLAR_WEBHOOK_SECRET=YOUR_POLAR_WEBHOOK_SECRET -NEXT_PUBLIC_POLAR_ACCESS_TOKEN=YOUR_NEXT_PUBLIC_POLAR_ACCESS_TOKEN +NEXT_PUBLIC_POLAR_ACCESS_TOKEN=YOUR_NEXT_PUBLIC_POLAR_ACCESS_TOKEN +POLAR_WEBHOOK_SECRET=YOUR_POLAR_WEBHOOK_SECRETapps/web/src/app/[locale]/(dashboard)/[wsId]/billing/data-polar-checkout.tsx (1)
24-24
: Remove unnecessary toString() call.The
checkoutUrl
is already a string, making the.toString()
call redundant.- href={checkoutUrl.toString()} + href={checkoutUrl}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (18)
apps/db/supabase/migrations/20250618070621_changed_check_creator_function_policy.sql
(1 hunks)apps/db/supabase/migrations/20250618073214_add_workspace_subscription_products_table.sql
(1 hunks)apps/db/supabase/migrations/20250618082551_new_migration.sql
(1 hunks)apps/db/supabase/migrations/20250618083711_new_migration.sql
(1 hunks)apps/db/supabase/migrations/20250618085435_new_migration.sql
(1 hunks)apps/db/supabase/migrations/20250618085749_new_migration.sql
(1 hunks)apps/db/supabase/migrations/20250618090740_new_migration.sql
(1 hunks)apps/db/supabase/migrations/20250618111109_allow_delete_ws_creator.sql
(1 hunks)apps/db/supabase/migrations/20250618161718_new_migration.sql
(1 hunks)apps/web/.env.example
(1 hunks)apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx
(5 hunks)apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-history.tsx
(1 hunks)apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/data-polar-checkout.tsx
(1 hunks)apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/page.tsx
(7 hunks)apps/web/src/app/api/[wsId]/[productId]/cancel/route.ts
(1 hunks)apps/web/src/app/api/[wsId]/[productId]/payment/route.ts
(2 hunks)apps/web/src/app/api/webhooks/route.ts
(2 hunks)packages/types/src/supabase.ts
(20 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
apps/web/src/app/api/[wsId]/[productId]/payment/route.ts (1)
packages/utils/src/user-helper.ts (1)
getCurrentSupabaseUser
(6-14)
apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/page.tsx (2)
apps/web/src/lib/polar.ts (1)
api
(3-6)apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-history.tsx (1)
BillingHistory
(18-147)
🪛 dotenv-linter (3.3.0)
apps/web/.env.example
[warning] 47-47: [UnorderedKey] The NEXT_PUBLIC_POLAR_ACCESS_TOKEN key should go before the POLAR_WEBHOOK_SECRET key
🪛 GitHub Check: codecov/patch
apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/data-polar-checkout.tsx
[warning] 20-20: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/data-polar-checkout.tsx#L20
Added line #L20 was not covered by tests
apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-history.tsx
[warning] 2-147: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-history.tsx#L2-L147
Added lines #L2 - L147 were not covered by tests
apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/page.tsx
[warning] 2-2: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/page.tsx#L2
Added line #L2 was not covered by tests
[warning] 10-10: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/page.tsx#L10
Added line #L10 was not covered by tests
[warning] 31-31: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/page.tsx#L31
Added line #L31 was not covered by tests
[warning] 37-37: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/page.tsx#L37
Added line #L37 was not covered by tests
[warning] 49-49: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/page.tsx#L49
Added line #L49 was not covered by tests
[warning] 53-53: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/page.tsx#L53
Added line #L53 was not covered by tests
[warning] 55-55: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/page.tsx#L55
Added line #L55 was not covered by tests
[warning] 61-61: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/page.tsx#L61
Added line #L61 was not covered by tests
[warning] 71-102: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/page.tsx#L71-L102
Added lines #L71 - L102 were not covered by tests
[warning] 109-116: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/page.tsx#L109-L116
Added lines #L109 - L116 were not covered by tests
[warning] 153-168: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/page.tsx#L153-L168
Added lines #L153 - L168 were not covered by tests
[warning] 185-185: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/page.tsx#L185
Added line #L185 was not covered by tests
apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx
[warning] 5-5: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L5
Added line #L5 was not covered by tests
[warning] 33-33: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L33
Added line #L33 was not covered by tests
[warning] 35-35: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L35
Added line #L35 was not covered by tests
[warning] 43-44: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L43-L44
Added lines #L43 - L44 were not covered by tests
[warning] 47-77: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L47-L77
Added lines #L47 - L77 were not covered by tests
[warning] 103-104: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L103-L104
Added lines #L103 - L104 were not covered by tests
[warning] 117-117: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L117
Added line #L117 was not covered by tests
[warning] 134-136: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L134-L136
Added lines #L134 - L136 were not covered by tests
[warning] 138-138: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L138
Added line #L138 was not covered by tests
[warning] 144-145: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L144-L145
Added lines #L144 - L145 were not covered by tests
[warning] 151-163: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L151-L163
Added lines #L151 - L163 were not covered by tests
[warning] 168-168: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L168
Added line #L168 was not covered by tests
[warning] 170-171: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L170-L171
Added lines #L170 - L171 were not covered by tests
[warning] 173-173: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L173
Added line #L173 was not covered by tests
[warning] 175-178: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L175-L178
Added lines #L175 - L178 were not covered by tests
[warning] 180-181: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L180-L181
Added lines #L180 - L181 were not covered by tests
🔇 Additional comments (20)
apps/db/supabase/migrations/20250618070621_changed_check_creator_function_policy.sql (1)
1-1
: Function body checking is disabled - ensure proper testing.The
set check_function_bodies = off;
directive disables PostgreSQL's function validation during creation. Ensure this function is thoroughly tested since compile-time checks are bypassed.apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/data-polar-checkout.tsx (1)
20-20
: Add test coverage for the checkout URL generation.The static analysis indicates this line lacks test coverage. Consider adding unit tests to verify the correct URL format.
apps/db/supabase/migrations/20250618111109_allow_delete_ws_creator.sql (1)
1-8
: Well-structured RLS policy for delete operations.The policy correctly restricts delete operations to workspace creators by verifying the relationship between the workspace and the authenticated user. The EXISTS clause with proper join conditions ensures security.
apps/web/src/app/api/webhooks/route.ts (4)
7-7
: Verify the server configuration for production readiness.The Polar client is configured to use the 'sandbox' server. Ensure this is appropriate for the target environment.
14-14
: Good addition of debugging logs.The console.log statement will help with troubleshooting webhook payload issues.
75-75
: Good error handling addition.Adding proper error handling for the count operation improves robustness.
80-83
: Event name and metadata structure look correct.The workspace.seats.sync event name and seat_count metadata field appear appropriate for usage reporting.
apps/db/supabase/migrations/20250618090740_new_migration.sql (1)
1-11
: Row-level security policy implementation looks correct.The policy correctly restricts SELECT access to workspace_subscription records based on workspace membership via the workspace_members table. This follows security best practices.
apps/db/supabase/migrations/20250618082551_new_migration.sql (1)
1-11
: Policy logic is correct but check for migration conflicts.The INSERT policy correctly restricts subscription creation to workspace creators. However, there's another migration (20250618083711_new_migration.sql) that also updates a policy with the same name, which could cause conflicts.
#!/bin/bash # Check for duplicate policy names across migrations rg -A 5 "only allow owner of the user to buy subscription" apps/db/supabase/migrations/apps/web/src/app/api/[wsId]/[productId]/payment/route.ts (1)
11-51
: Excellent authentication and authorization implementation.The integration of Supabase authentication with proper error handling and the
check_ws_creator
RPC call provides robust security. The code correctly:
- Validates user authentication
- Fetches user display name with error handling
- Verifies workspace creator permissions
- Returns appropriate HTTP status codes for different scenarios
apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-history.tsx (2)
4-16
: Well-defined TypeScript interface.The
BillingHistoryItem
interface properly defines the structure with appropriate nullable fields and nested product details.
23-38
: Comprehensive status color mapping.The
getStatusColor
function handles all relevant subscription statuses with appropriate color schemes for both light and dark themes.apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/page.tsx (3)
71-101
: Well-implemented subscription fetching function.The
fetchWorkspaceSubscriptions
function properly:
- Uses Supabase client with appropriate select query
- Includes related product data via join
- Implements proper error handling and logging
- Returns empty array on error for graceful degradation
110-116
: Efficient concurrent data fetching.Using
Promise.all
to fetch products, subscription, creator status, and subscription history concurrently is an excellent performance optimization.
153-168
: Proper data transformation for billing history.The mapping from database records to the billing history format handles nullable values appropriately and provides fallback values for missing data.
apps/db/supabase/migrations/20250618161718_new_migration.sql (1)
9-40
: ```shell
#!/bin/bash
echo "Verifying base tables and column existence for the view:"for table in time_tracking_sessions time_tracking_categories tasks; do
echo
echo "=== Table: $table ==="Show the CREATE TABLE statement
rg -n "create table.*$table" -A20 -t sql || echo "
⚠️ No CREATE TABLE found for $table"Define the columns each table must have
if [[ $table == "time_tracking_sessions" ]]; then
cols=(id ws_id user_id task_id category_id title description start_time end_time duration_seconds is_running tags created_at updated_at productivity_score)
elif [[ $table == "time_tracking_categories" ]]; then
cols=(id name color)
else
cols=(id name)
fiVerify each column exists in the SQL schema
echo "Referenced columns:"
for col in "${cols[@]}"; do
if rg -q "^\s*$col\b" -t sql; then
echo " ✔ $col"
else
echo " ❌ $col"
fi
done
done</details> <details> <summary>packages/types/src/supabase.ts (4)</summary> `6176-6176`: **LGTM! Well-designed nullable product_id integration.** The addition of the optional `product_id` field to the workspace_subscription table is properly implemented with consistent nullable typing across Row, Insert, and Update types. This maintains backward compatibility while enabling the new subscription product model. Also applies to: 6188-6188, 6200-6200 --- `6222-6248`: **LGTM! Clean subscription products table definition.** The new `workspace_subscription_products` table is well-designed with appropriate nullable fields and follows consistent naming conventions. The structure supports flexible subscription product management with name, description, price, and recurring interval fields. --- `6206-6212`: **Verify foreign key relationship integrity.** The new foreign key relationship for `product_id` is properly defined, but ensure that the database migration includes the corresponding foreign key constraint and that orphaned subscriptions are handled appropriately. ```shell #!/bin/bash # Description: Verify that the foreign key relationship is properly implemented in migrations # Expected: Find migration files that add the foreign key constraint # Search for migration files that reference the product_id foreign key rg -A 10 -B 5 "product_id.*fkey|workspace_subscription_products.*fkey" --type sql
7466-7466
: ```shell
#!/bin/bashRe-run search across .ts and .tsx files for updated function calls and old parameter patterns
Search for calls to modified functions with context
rg -n -A5 'create_ai_chat(' -g '.ts' -g '.tsx'
rg -n -A5 'generate_cross_app_token(' -g '.ts' -g '.tsx'
rg -n -A5 'get_inventory_products(' -g '.ts' -g '.tsx'
rg -n -A5 'get_workspace_users(' -g '.ts' -g '.tsx'
rg -n -A5 'search_users(' -g '.ts' -g '.tsx'Check for any remaining calls using old parameter order or names
rg -n 'create_ai_chat([^)]message[^)]title' -g '.ts' -g '.tsx'
rg -n 'generate_cross_app_token([^)]session_data[^)]expiry' -g '.ts' -g '.tsx'</details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
apps/db/supabase/migrations/20250618070621_changed_check_creator_function_policy.sql
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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
♻️ Duplicate comments (7)
apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-history.tsx (2)
111-111
: Inconsistent price formatting requires verification.The price display uses
${subscription.product.price}
without explicit formatting. This could lead to display issues if prices contain fractional cents or are stored differently than expected.Please verify the price format consistency across the application. Run this script to check how prices are stored and formatted:
#!/bin/bash # Check price field usage and format across the codebase rg -A 3 -B 1 "price.*toFixed|\.price" --type ts --type tsx
131-137
: Missing download receipt functionality.The receipt download button is displayed but lacks an
onClick
handler or any functionality to actually download receipts.Either implement the download functionality or remove/disable the button until the feature is ready. Would you like me to help implement a basic receipt download handler?
apps/db/supabase/migrations/20250618070621_changed_check_creator_function_policy.sql (1)
3-16
: Function has NULL handling issues and misleading name.The function has the same issues highlighted in previous reviews:
- NULL handling: When workspace doesn't exist, the subquery returns NULL, making
NULL = auth.uid()
always false- Misleading name:
check_ws_creator
suggests it only checks creator status, but it also enforces no existing subscriptionApply this fix to handle NULL cases explicitly and improve clarity:
-CREATE OR REPLACE FUNCTION public.check_ws_creator(ws_id uuid) - RETURNS boolean - LANGUAGE plpgsql -AS $function$BEGIN - RETURN ( - ( - SELECT creator_id FROM public.workspaces WHERE id = check_ws_creator.ws_id - ) = auth.uid() - AND NOT EXISTS ( - SELECT 1 FROM public.workspace_subscription - WHERE public.workspace_subscription.ws_id = check_ws_creator.ws_id - ) - ); -END;$function$ +CREATE OR REPLACE FUNCTION public.check_ws_creator_can_subscribe(ws_id uuid) + RETURNS boolean + LANGUAGE plpgsql +AS $function$BEGIN + RETURN ( + EXISTS ( + SELECT 1 FROM public.workspaces + WHERE id = ws_id AND creator_id = auth.uid() + ) + AND NOT EXISTS ( + SELECT 1 FROM public.workspace_subscription + WHERE public.workspace_subscription.ws_id = ws_id + ) + ); +END;$function$apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx (4)
33-35
: New props added to interface but not consistently used.The interface defines
product_id
andactiveSubscriptionId
but they're commented out in the destructuring, creating inconsistency.Either use these props or remove them from the interface:
interface BillingClientProps { currentPlan: Plan; upgradePlans: UpgradePlan[]; wsId: string; - product_id: string; isCreator: boolean; - activeSubscriptionId?: string; }Or uncomment their usage if they're needed for the cancellation feature.
47-48
: Remove unused state variables.The state variables
_isLoading
andmessage
with underscore prefixes indicate they're unused, creating dead code.Remove these unused state declarations:
- const [_isLoading, _setIsLoading] = useState(false); - const [message, _setMessage] = useState('');
50-77
: Complete or remove commented-out cancellation logic.The entire
handleCancelSubscription
function is commented out, indicating incomplete implementation.Either implement the complete cancellation functionality or remove this commented code block to maintain code clarity.
151-161
: Message display references unused state.The message display logic uses the
message
state variable, but its setter_setMessage
has an underscore prefix indicating it's unused.Either implement proper message handling by removing the underscore prefix and adding logic to set messages, or remove this entire conditional block.
🧹 Nitpick comments (2)
apps/upskii/src/components/request-education-banner.tsx (1)
4-5
: Add test coverage for the new icons
Static analysis flags these lines as not covered by tests. Please add a rendering or snapshot test forEducationBanner
to verifyBookOpenText
andSparkles
render correctly.apps/calendar/src/app/[locale]/(root)/scheduler/page.tsx (1)
34-39
: Add tests for new imports and functionality
Static coverage reports show that the newly added imports and corresponding component logic aren’t covered by tests. Consider adding unit or integration tests (e.g., with React Testing Library) to verify icon rendering, tab interactions, time input handling, anddayjs
-based active hours updates. I can help generate test stubs if needed.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (23)
apps/calendar/src/app/[locale]/(root)/scheduler/components/AlgorithmInsights.tsx
(1 hunks)apps/calendar/src/app/[locale]/(root)/scheduler/components/ScheduleDisplay.tsx
(1 hunks)apps/calendar/src/app/[locale]/(root)/scheduler/components/TaskList.tsx
(1 hunks)apps/calendar/src/app/[locale]/(root)/scheduler/components/TaskModal.tsx
(1 hunks)apps/calendar/src/app/[locale]/(root)/scheduler/components/TemplateScenarios.tsx
(1 hunks)apps/calendar/src/app/[locale]/(root)/scheduler/page.tsx
(1 hunks)apps/db/supabase/migrations/20250618070621_changed_check_creator_function_policy.sql
(1 hunks)apps/db/supabase/migrations/20250618073214_add_workspace_subscription_products_table.sql
(1 hunks)apps/db/supabase/migrations/20250618161718_new_migration.sql
(1 hunks)apps/upskii/src/components/request-education-banner.tsx
(1 hunks)apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx
(5 hunks)apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-history.tsx
(1 hunks)apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/success/page.tsx
(1 hunks)apps/web/src/app/[locale]/(dashboard)/[wsId]/nav-link.tsx
(1 hunks)apps/web/src/app/[locale]/(dashboard)/settings/account/sessions/sessions-card.tsx
(1 hunks)apps/web/src/app/[locale]/(dashboard)/settings/account/settings-nav.tsx
(1 hunks)apps/web/src/components/command/add-task-form.tsx
(1 hunks)apps/web/src/components/command/board-navigation.tsx
(1 hunks)apps/web/src/components/command/coming-soon.tsx
(1 hunks)apps/web/src/components/command/command-header.tsx
(1 hunks)apps/web/src/components/command/empty-state.tsx
(1 hunks)apps/web/src/components/command/quick-actions.tsx
(1 hunks)apps/web/src/components/command/quick-time-tracker.tsx
(1 hunks)
✅ Files skipped from review due to trivial changes (9)
- apps/web/src/app/[locale]/(dashboard)/[wsId]/nav-link.tsx
- apps/web/src/components/command/command-header.tsx
- apps/web/src/components/command/board-navigation.tsx
- apps/web/src/components/command/quick-time-tracker.tsx
- apps/web/src/components/command/coming-soon.tsx
- apps/web/src/components/command/empty-state.tsx
- apps/web/src/components/command/quick-actions.tsx
- apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/success/page.tsx
- apps/web/src/app/[locale]/(dashboard)/settings/account/sessions/sessions-card.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
- apps/db/supabase/migrations/20250618161718_new_migration.sql
- apps/db/supabase/migrations/20250618073214_add_workspace_subscription_products_table.sql
🧰 Additional context used
🪛 GitHub Check: codecov/patch
apps/calendar/src/app/[locale]/(root)/scheduler/components/AlgorithmInsights.tsx
[warning] 22-24: apps/calendar/src/app/[locale]/(root)/scheduler/components/AlgorithmInsights.tsx#L22-L24
Added lines #L22 - L24 were not covered by tests
apps/calendar/src/app/[locale]/(root)/scheduler/components/ScheduleDisplay.tsx
[warning] 18-21: apps/calendar/src/app/[locale]/(root)/scheduler/components/ScheduleDisplay.tsx#L18-L21
Added lines #L18 - L21 were not covered by tests
apps/calendar/src/app/[locale]/(root)/scheduler/components/TaskList.tsx
[warning] 13-20: apps/calendar/src/app/[locale]/(root)/scheduler/components/TaskList.tsx#L13-L20
Added lines #L13 - L20 were not covered by tests
apps/calendar/src/app/[locale]/(root)/scheduler/components/TaskModal.tsx
[warning] 13-13: apps/calendar/src/app/[locale]/(root)/scheduler/components/TaskModal.tsx#L13
Added line #L13 was not covered by tests
apps/calendar/src/app/[locale]/(root)/scheduler/components/TemplateScenarios.tsx
[warning] 27-27: apps/calendar/src/app/[locale]/(root)/scheduler/components/TemplateScenarios.tsx#L27
Added line #L27 was not covered by tests
apps/calendar/src/app/[locale]/(root)/scheduler/page.tsx
[warning] 34-39: apps/calendar/src/app/[locale]/(root)/scheduler/page.tsx#L34-L39
Added lines #L34 - L39 were not covered by tests
apps/upskii/src/components/request-education-banner.tsx
[warning] 4-5: apps/upskii/src/components/request-education-banner.tsx#L4-L5
Added lines #L4 - L5 were not covered by tests
apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx
[warning] 33-33: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L33
Added line #L33 was not covered by tests
[warning] 35-35: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L35
Added line #L35 was not covered by tests
[warning] 43-44: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L43-L44
Added lines #L43 - L44 were not covered by tests
[warning] 47-77: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L47-L77
Added lines #L47 - L77 were not covered by tests
[warning] 103-104: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L103-L104
Added lines #L103 - L104 were not covered by tests
[warning] 117-117: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L117
Added line #L117 was not covered by tests
[warning] 134-136: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L134-L136
Added lines #L134 - L136 were not covered by tests
[warning] 138-138: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L138
Added line #L138 was not covered by tests
[warning] 144-145: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L144-L145
Added lines #L144 - L145 were not covered by tests
[warning] 151-163: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L151-L163
Added lines #L151 - L163 were not covered by tests
[warning] 168-168: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L168
Added line #L168 was not covered by tests
[warning] 170-171: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L170-L171
Added lines #L170 - L171 were not covered by tests
[warning] 173-173: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L173
Added line #L173 was not covered by tests
[warning] 175-178: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L175-L178
Added lines #L175 - L178 were not covered by tests
[warning] 180-181: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx#L180-L181
Added lines #L180 - L181 were not covered by tests
apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-history.tsx
[warning] 2-147: apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-history.tsx#L2-L147
Added lines #L2 - L147 were not covered by tests
⏰ Context from checks skipped due to timeout of 90000ms (8)
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Deploy-Preview
- GitHub Check: Verify generated types
- GitHub Check: Deploy-Preview
- GitHub Check: Deploy-Preview
- GitHub Check: Deploy-Preview
- GitHub Check: Deploy-Preview
- GitHub Check: Prettier Check (23)
🔇 Additional comments (14)
apps/upskii/src/components/request-education-banner.tsx (1)
4-4
: Approve internalizing icon imports
The import has been correctly switched fromlucide-react
to our internal@tuturuuu/ui/icons
package, aligning with the project's standardized icon usage.apps/calendar/src/app/[locale]/(root)/scheduler/components/TaskModal.tsx (1)
13-13
: LGTM! Consistent icon import refactoring.Good refactoring to consolidate icon imports under the internal UI library. This change maintains consistency with the broader codebase migration from
lucide-react
to@tuturuuu/ui/icons
.apps/calendar/src/app/[locale]/(root)/scheduler/components/TemplateScenarios.tsx (1)
27-27
: LGTM! Icon import standardization.Excellent consistency in migrating icon imports to the internal UI library. This maintains the same functionality while centralizing icon management.
apps/calendar/src/app/[locale]/(root)/scheduler/components/TaskList.tsx (1)
13-20
: LGTM! Comprehensive icon import refactoring.Well-executed migration of all icon imports to the internal UI library. The multi-line import structure is maintained for readability, and this change aligns perfectly with the codebase-wide standardization effort.
apps/calendar/src/app/[locale]/(root)/scheduler/components/ScheduleDisplay.tsx (1)
18-21
: LGTM! Icon refactoring with improved import organization.Great job on both migrating icon imports to the internal UI library and reorganizing imports for better grouping. This maintains functionality while improving code organization and consistency.
apps/calendar/src/app/[locale]/(root)/scheduler/components/AlgorithmInsights.tsx (1)
22-24
: LGTM! Completes the systematic icon refactoring.Excellent completion of the icon import migration across scheduler components. The import reorganization improves code structure while maintaining all functionality. This systematic approach ensures consistency across the entire feature set.
apps/calendar/src/app/[locale]/(root)/scheduler/page.tsx (1)
34-39
: Import sources updated to internal design system
Imports for icons, UI components, anddayjs
have been correctly switched to use the internal@tuturuuu/ui
library and reordered accordingly.apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-history.tsx (2)
4-16
: Well-structured interface definition.The
BillingHistoryItem
interface properly handles nullable fields and nested product data, providing good type safety for the component.
23-38
: Comprehensive status handling with proper dark mode support.The
getStatusColor
function covers all expected subscription statuses and provides consistent styling with dark mode variants.apps/db/supabase/migrations/20250618070621_changed_check_creator_function_policy.sql (1)
19-48
: RLS policies are well-structured and secure.The row-level security policies properly enforce:
- Only workspace creators can insert subscriptions
- Only workspace members can view subscriptions
- Only workspace creators can delete subscriptions
The policies use appropriate EXISTS clauses for security.
apps/web/src/app/[locale]/(dashboard)/[wsId]/billing/billing-client.tsx (2)
5-5
: Good improvement: Standardized icon imports.The change from
lucide-react
to@tuturuuu/ui/icons
aligns with the UI library standardization mentioned in the PR objectives.
103-104
: UI layout improvements enhance user experience.The simplified grid layout, updated feature list styling, and improved spacing create a cleaner interface for the billing information.
Also applies to: 117-117, 134-145
apps/web/src/components/command/add-task-form.tsx (1)
9-16
: ```shell
#!/bin/bashLocate all "icons" directories and verify exports for required icons
find . -type d -name icons | while read dir; do
echo "Icons directory: $dir"
for icon in AlertTriangle Check Clock List Loader Plus; do
matches=$(rg -n "export.*${icon}" "$dir" || true)
if [ -z "$matches" ]; then
echo " ❌ Missing export: $icon"
else
echo " ✅ Found export(s) for $icon:"
echo "$matches"
fi
done
done</details> <details> <summary>apps/web/src/app/[locale]/(dashboard)/settings/account/settings-nav.tsx (1)</summary> `11-12`: Let’s locate where and how the UI package actually exports its icons to confirm that importing from `@tuturuuu/ui/icons` will work as expected: ```shell #!/bin/bash # 1) List any .tsx files under src/components/ui that reference “icons” in their path echo "📂 Icon-related files in UI package:" fd --type f --extension tsx packages/ui/src/components/ui | grep -i icons || echo " ⚠️ No icon-related .tsx files found" # 2) If there’s an icons.tsx or index under an icons folder, dump its top lines ICON_FILES=$(fd --type f --extension tsx packages/ui/src/components/ui | grep -Ei 'icons(\.tsx|/index\.tsx)' || true) if [ -n "$ICON_FILES" ]; then echo for f in $ICON_FILES; do echo "===== $f =====" sed -n '1,50p' "$f" echo done else echo "🔍 No single-entry icons file found (icons.tsx or icons/index.tsx)." fi # 3) Search for where individual icons (Bell, ChevronRight, etc.) are defined or re-exported echo "🔎 Searching for 'export' lines mentioning each icon:" rg --color never -n "^export.*(Bell|ChevronRight|CreditCard|Settings|Shield|Smartphone|User)" packages/ui/src
…ace_subscription_products
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks @phatgg221.
Summary by CodeRabbit
New Features
Bug Fixes
Style
Chores