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

Fix subscription button text for different billing intervals #359

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

skeleton1231
Copy link

@skeleton1231 skeleton1231 commented Jul 10, 2024

Fix subscription button text and enhance subscription handling

Problem:

  • When a user has a monthly subscription and switches to the yearly billing interval tab, the button still shows "Manage" instead of "Subscribe" for the yearly plan, even though the user does not have a yearly subscription. If clicked, the button redirects to the Stripe checkout URL, which seems incorrect.
  • The getSubscription function retrieves data without filtering by the user.

Solution:

  • Added getUserSubscriptions method in supabase/queries to fetch user subscriptions, ordered by creation time in descending order.
  • Updated Pricing component to handle user subscriptions:
    • Show "Manage" button for subscribed products and redirect to the account management page.
    • Show "Subscribe" button for unsubscribed products.
  • Modified PricingPage to fetch user and their subscriptions, and pass them to the Pricing component.
  • Adjusted Account page to display the user's latest subscription and personal information.
  • Ensured that the button text accurately reflects the user's subscription status for the selected billing interval.

These changes improve the overall user experience by accurately reflecting the user's subscription status and providing appropriate actions based on their subscriptions.

If I have misunderstood any aspects of the problem or solution, please forgive my oversight. I look forward to your feedback and hope these changes align with the project's goals. Thank you for your understanding and support.

Copy link

vercel bot commented Jul 10, 2024

@skeleton1231 is attempting to deploy a commit to the Vercel Solutions Team on Vercel.

A member of the Team first needs to authorize it.

- Added `getUserSubscriptions` method in `supabase/queries` to fetch user subscriptions, ordered by creation time in descending order.
- Updated `Pricing` component to handle user subscriptions:
  - Show "Manage" button for subscribed products and redirect to account management page.
  - Show "Subscribe" button for unsubscribed products.
- Modified `PricingPage` to fetch user and their subscriptions, and pass them to the `Pricing` component.
- Adjusted `Account` page to display the user's latest subscription and personal information.
const { data: subscriptions, error } = await supabase
.from('subscriptions')
.select('*, prices(*, products(*))')
.eq('user_id', user.id)
Copy link

Choose a reason for hiding this comment

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

This is not necessary because subscriptions table in Supabase has enabled Row-Level Security (RLS) policies, meaning that, users can only access their own data.

@@ -37,3 +43,24 @@ export const getUserDetails = cache(async (supabase: SupabaseClient) => {
.single();
return userDetails;
});

export const getUserSubscriptions = cache(async (supabase: SupabaseClient, user: User | null) => {
Copy link

Choose a reason for hiding this comment

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

This function doesn't seem necessary. When there are multiple subscriptions, the UI should generate an error to let the user know, because multiple subscriptions don't make sense to users.

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