CreatePlan
The CreatePlan
component guides users through the process of creating a new subscription. It supports a two-step flow: first, selecting a plan, and then, if a paid plan is chosen, providing billing information.
Features
- Two-Step Process: Users first select a plan, and if it’s a paid plan, they proceed to a billing form.
- Plan Selection: Displays available plans and allows users to choose one.
- Conditional Billing Form: Automatically presents the
BillingForm
for paid plans. Free plans are created directly without requiring billing details. - Firebase Cloud Function Integration: Interacts with the
createSubscription
Firebase Cloud Function to initiate the subscription on the backend. - Loading and Error Handling: Provides visual feedback during processing and displays error messages for failed operations.
- Customizable Sub-components: Accepts
PlansComponent
andBillingFormComponent
as props, allowing developers to use custom implementations for plan display and billing forms.
Props
PlansComponent
: (Optional) A React component type to render the list of available plans. It should accept anonPlanSelect
prop (function that takes aPlan
object). Defaults to the internalPlans
component.BillingFormComponent
: (Optional) A React component type to render the billing form. It should accept aplan
prop (the selectedPlan
object) and anonSubmit
prop (function that takespaymentMethodId
andbillingDetails
). Defaults to the internalBillingForm
component.
Hooks Used
useState
: To manage the current step, selected plan, error state, and loading status.useTranslation
: For internationalization of text content.useNavigate
: Fromreact-router-dom
for programmatic navigation.useConfig
: To access application configuration, including Firebase Functions instance and page routes.
Firebase Cloud Function
This component interacts with the createSubscription
Firebase Cloud Function to create a new user subscription.
Usage
The CreatePlan
component is typically used within an authenticated route where users can initiate a new subscription.
import { CreatePlan, Plans, BillingForm } from '@fireact.dev/app';
import { Route } from 'react-router-dom';
import appConfig from './config/app.config.json'; // Assuming appConfig is available
// In your main routing setup (e.g., App.tsx)
function AppRoutes() {
return (
// ... other routes and layouts
<Route path={appConfig.pages.createPlan} element={
<CreatePlan
PlansComponent={Plans}
BillingFormComponent={BillingForm}
/>
} />
// ...
);
}
export default AppRoutes;
Important Notes
- For free plans, the subscription is created directly via the
createSubscription
cloud function. - For paid plans, the
BillingForm
is displayed to collect payment information, which is then sent to thecreateSubscription
cloud function. - The component navigates the user to the subscription settings page upon successful subscription creation.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.