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
BillingFormfor paid plans. Free plans are created directly without requiring billing details. - Firebase Cloud Function Integration: Interacts with the
createSubscriptionFirebase 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
PlansComponentandBillingFormComponentas 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 anonPlanSelectprop (function that takes aPlanobject). Defaults to the internalPlanscomponent.BillingFormComponent: (Optional) A React component type to render the billing form. It should accept aplanprop (the selectedPlanobject) and anonSubmitprop (function that takespaymentMethodIdandbillingDetails). Defaults to the internalBillingFormcomponent.
Hooks Used
useState: To manage the current step, selected plan, error state, and loading status.useTranslation: For internationalization of text content.useNavigate: Fromreact-router-domfor 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
createSubscriptioncloud function. - For paid plans, the
BillingFormis displayed to collect payment information, which is then sent to thecreateSubscriptioncloud 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.