Skip to content

Conversation

@romitg2
Copy link
Contributor

@romitg2 romitg2 commented Jan 30, 2026

Issue: #3073
Fixes: #3073

Description

  • Converts subscriptions#manage action to render via Inertia instead of ERB template
  • Moves React component from server-components/SubscriptionManager.tsx to pages/Subscriptions/Manage.tsx
  • Removes old ERB template and webpack pack entry point
  • Adds controller specs for Inertia rendering and props validation

Before/After

Before:

Screen.Recording.2026-01-24.at.6.21.48.AM.mov

After:

Screen.Recording.2026-01-24.at.6.19.30.AM.mov

Test Results

 bundle exec rspec spec/controllers/subscriptions_controller_spec.rb spec/presenters/checkout_presenter_spec.rb spec/requests/subscription/
Screenshot 2026-01-24 at 6 15 10 AM Screenshot 2026-01-24 at 6 15 19 AM

Checklist


AI Disclosure

  • used claude-code opus-4.5 to help refactoring code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted cancelSubscriptionByUser function because cancellation is now handled via Inertia form submission with server redirect

Comment on lines -101 to -110
const SubscriptionManager = ({
product,
subscription,
recaptcha_key,
paypal_client_id,
contact_info,
countries,
us_states,
ca_provinces,
used_card,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Props now accessed via usePage().props instead of function parameters

ca_provinces,
used_card,
} = cast<Props>(usePage().props);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Props now accessed via usePage().props instead of function parameters

Copy link
Contributor Author

Choose a reason for hiding this comment

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

File change summary:

• Converted from ReactOnRails server component to Inertia page component
• Now uses usePage hook to get props instead of function parameters
• Replaced custom cancelSubscriptionByUser with Inertia useForm for cancellation
• Replaced window.location.href navigation with router.visit and router.reload

@@ -1,4 +0,0 @@
<%= render("shared/recaptcha_script") %>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reCAPTCHA script is now loaded dynamically via the useRecaptcha hook in React.

The PaymentForm component (which is used in the Manage page) calls:

  // app/javascript/components/Checkout/PaymentForm.tsx:60
  import { useRecaptcha } from "$app/components/useRecaptcha";

  // line 1114
  const recaptcha = useRecaptcha({ siteKey: state.recaptchaKey });

The hook (app/javascript/components/useRecaptcha.tsx) dynamically loads the script when needed:

  const loadRecaptchaScript = (): Promise<void> => {
    // Skip if already loaded
    if ("grecaptcha" in window) {
      return Promise.resolve();
    }

    // Dynamically inject script tag
    const script = document.createElement("script");
    script.src = "https://www.google.com/recaptcha/enterprise.js?render=explicit";
    script.async = true;
    document.head.appendChild(script);
    // ...
  };


import { confirmLineItem } from "$app/data/purchase";
import { cancelSubscriptionByUser, updateSubscription } from "$app/data/subscription";
import { updateSubscription } from "$app/data/subscription";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • updateSubscription is kept as it is because payment flows require client-side 3D Secure handling via Stripe.js. When the server returns requires_card_action, we need to call stripe.confirmCardPayment() in the browser before any navigation occurs.
  • Inertia's redirect-based model doesn't allow intercepting the response to handle 3D Secure before navigation.

@Pradumn27 let me know if you have any opinion/approach in mind here? cc @EmCousin

@romitg2
Copy link
Contributor Author

romitg2 commented Jan 30, 2026

@Pradumn27 _a addressed your comments from #3084. could you please review again? Thank you!

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.

Migrate Subscription Manager Page to Inertia

2 participants