Skip to content

Commit 99b8511

Browse files
committed
custom development docs
1 parent 4817130 commit 99b8511

File tree

8 files changed

+515
-68
lines changed

8 files changed

+515
-68
lines changed

content/custom-development/_index.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,29 @@ cascade:
88
type: "docs"
99
---
1010

11-
This section provides high-level overviews of key components within a Fireact application, helping developers understand the architecture and how to approach custom development.
11+
This section is dedicated to guiding developers through custom development within a Fireact.dev application. To effectively extend and customize your project, it's essential to understand the core architectural patterns and how various framework components interact.
12+
13+
### Key Areas for Custom Development:
14+
15+
To get started with custom development, familiarize yourself with the following fundamental aspects of a Fireact.dev application:
16+
17+
* **Developing Custom Components and Pages**: Learn how to build your own React components and integrate them into the Fireact.dev framework. This covers the basic structure and common patterns for creating new UI elements and views.
18+
* **Data Fetching**: Understand how data is retrieved and managed within the application, including authentication, configuration, and subscription details, using Fireact.dev's provided hooks and context providers.
19+
* **Localization**: Discover how to implement and manage multi-language support, allowing you to translate your application's content for a global audience.
20+
* **Routing and Permission Control**: Learn how navigation is handled and how access to different parts of your application is controlled based on user roles and subscription permissions.
21+
22+
### Example Code References:
23+
24+
Throughout these guides, we refer to key files within your Fireact.dev project that serve as excellent examples for understanding the framework's implementation:
25+
26+
* **`src/App.tsx`**: This file is the entry point of your React application and demonstrates the top-level setup for routing, context providers (Authentication, Loading, Configuration, Subscription), and overall application structure. It's a crucial file for understanding how all the pieces fit together.
27+
* **`src/components/SubscriptionDashboard.tsx`**: This component serves as a practical example of how to fetch and display user-specific data (subscriptions), interact with application configuration, and utilize internationalization within a custom component. It showcases many of the concepts discussed in this section.
28+
29+
### Utilizing Framework Components and Functions:
30+
31+
Beyond understanding the core architectural patterns, a significant part of custom development involves leveraging the rich set of pre-built components, hooks, and Firebase Cloud Functions provided by the Fireact.dev framework. These resources are designed to handle common SaaS functionalities, allowing you to focus on your unique business logic.
32+
33+
* **App Package (`@fireact.dev/app`)**: This package contains all the reusable React frontend components, hooks, contexts, and utilities. By using these, you can quickly build out your UI and integrate with core application features like authentication, subscriptions, and common UI elements. Refer to the [App Package documentation](../app/_index.md) for a comprehensive list and usage details.
34+
* **Functions Package (`@fireact.dev/functions`)**: This package provides the Firebase Cloud Functions backend for Fireact applications. These functions handle server-side logic, integrations with services like Stripe, and other backend operations. Understanding and utilizing these functions is crucial for implementing robust features. Refer to the [Functions Package documentation](../functions/_index.md) for details on available cloud functions and their usage.
35+
36+
By reviewing these core files, the dedicated documentation in this section, and the comprehensive package documentation, you will gain a solid foundation for building and customizing your Fireact.dev application.

content/custom-development/app-tsx.md

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
title: "Data Fetching in Fireact.dev"
3+
linkTitle: "Data Fetching"
4+
weight: 3
5+
description: >
6+
Understand how data is fetched and managed in Fireact.dev applications using hooks and providers.
7+
---
8+
9+
Fireact.dev applications leverage a set of powerful React hooks and context providers to simplify data fetching and state management, especially for common application concerns like authentication, configuration, loading states, and subscription details. These components abstract away much of the complexity of interacting with Firebase and Stripe, allowing you to focus on building your application's unique features.
10+
11+
### Core Data Fetching Hooks and Providers:
12+
13+
The framework provides dedicated hooks that give you access to specific data and functionalities. These hooks typically rely on corresponding Context Providers that wrap your application's components, making the data available down the component tree.
14+
15+
1. **Authentication Data (`useAuth` and `AuthProvider`)**:
16+
* **`AuthProvider`**: This provider wraps your application (or parts of it) to make authentication-related data and functions available. It initializes Firebase Authentication and manages the user's authentication state.
17+
* **`useAuth` Hook**: Use this hook to access the current user's authentication status, user object (e.g., `user.uid`, `user.email`), and authentication-related functions (e.g., `signIn`, `signOut`).
18+
* **Example Usage**:
19+
```typescript
20+
import { useAuth } from '@fireact.dev/app';
21+
22+
function MyComponent() {
23+
const { user, loading, error } = useAuth();
24+
25+
if (loading) return <div>Loading authentication...</div>;
26+
if (error) return <div>Error: {error.message}</div>;
27+
28+
return (
29+
<div>
30+
{user ? `Welcome, ${user.email}` : 'Please sign in.'}
31+
</div>
32+
);
33+
}
34+
```
35+
* For more details, refer to the [`useAuth` documentation](../app/hooks/useAuth.md) and [`AuthContext` documentation](../app/contexts/AuthContext.md).
36+
37+
2. **Application Configuration (`useConfig` and `ConfigProvider`)**:
38+
* **`ConfigProvider`**: This provider makes your application's global configuration (from `firebase.config.json`, `app.config.json`, `stripe.config.json`) accessible throughout your application.
39+
* **`useConfig` Hook**: Allows you to retrieve configuration values, such as page routes, Stripe plan details, and other application-wide settings.
40+
* **Example Usage**:
41+
```typescript
42+
import { useConfig } from '@fireact.dev/app';
43+
44+
function MyComponent() {
45+
const config = useConfig();
46+
const homePagePath = config.appConfig.pages.home;
47+
// ... use homePagePath for navigation or other purposes
48+
return <div>...</div>;
49+
}
50+
```
51+
* For more details, refer to the [`useConfig` documentation](../app/hooks/useConfig.md) and [`ConfigContext` documentation](../app/contexts/ConfigContext.md).
52+
53+
3. **Loading States (`useLoading` and `LoadingProvider`)**:
54+
* **`LoadingProvider`**: Manages a global loading state for your application, useful for indicating ongoing asynchronous operations.
55+
* **`useLoading` Hook**: Provides access to the global loading state and functions to set it.
56+
* For more details, refer to the [`useLoading` documentation](../app/hooks/useLoading.md) and [`LoadingContext` documentation](../app/contexts/LoadingContext.md).
57+
58+
4. **Subscription Details (`useSubscription`, `useSubscriptionInvoices` and `SubscriptionProvider`)**:
59+
* **`SubscriptionProvider`**: This provider makes subscription-related data available to its children. It fetches and manages the current user's subscription details.
60+
* **`useSubscription` Hook**: Provides access to the current user's subscription object, including its status, plan ID, and settings. This is crucial for rendering subscription-gated content.
61+
* **`useSubscriptionInvoices` Hook**: Fetches a list of invoices associated with the user's subscription.
62+
* **Example Usage (`SubscriptionDashboard.tsx`)**:
63+
```typescript
64+
import { useSubscription } from '@fireact.dev/app';
65+
66+
export default function SubscriptionDashboard() {
67+
const { subscription, loading, error } = useSubscription();
68+
69+
if (loading) {
70+
return <div>Loading subscription...</div>;
71+
}
72+
73+
if (error || !subscription) {
74+
return <div>No active subscription found or an error occurred.</div>;
75+
}
76+
77+
return (
78+
<div>
79+
<h2>Subscription: {subscription.settings?.name}</h2>
80+
<p>Status: {subscription.status}</p>
81+
</div>
82+
);
83+
}
84+
```
85+
* For more details, refer to the [`useSubscription` documentation](../app/hooks/useSubscription.md), [`useSubscriptionInvoices` documentation](../app/hooks/useSubscriptionInvoices.md) and [`SubscriptionContext` documentation](../app/contexts/SubscriptionContext.md).
86+
87+
### General Data Fetching Patterns:
88+
89+
* **Conditional Rendering**: Always handle `loading` and `error` states when using data-fetching hooks. Display loading indicators or error messages as appropriate.
90+
* **Data Availability**: Ensure that the necessary providers (`AuthProvider`, `ConfigProvider`, `SubscriptionProvider`, etc.) are wrapping the components that rely on their respective hooks. The `App.tsx` file typically sets up these top-level providers.
91+
* **Custom Data**: For data not covered by the built-in hooks, you can implement your own data fetching logic using standard React patterns (e.g., `useState`, `useEffect`) and interact directly with Firebase SDKs or other APIs.
92+
93+
By understanding and utilizing these hooks and providers, you can efficiently manage data flow and build dynamic, responsive applications with Fireact.dev.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
title: "Developing Custom Components and Pages"
3+
linkTitle: "Custom Components"
4+
weight: 2
5+
description: >
6+
Learn how to develop your own components and pages using the Fireact.dev framework, with SubscriptionDashboard.tsx as an example.
7+
---
8+
9+
When developing custom components or pages within a Fireact.dev application, you'll often interact with various hooks and utilities provided by the framework to handle common tasks like authentication, data fetching, and configuration. This guide uses the `SubscriptionDashboard.tsx` component as an example to illustrate these concepts.
10+
11+
### Example: `SubscriptionDashboard.tsx`
12+
13+
The `SubscriptionDashboard.tsx` component demonstrates how to display user-specific subscription details and features. It showcases several key integrations with the Fireact.dev framework:
14+
15+
```typescript
16+
import { Navigate } from 'react-router-dom';
17+
import { useTranslation } from 'react-i18next';
18+
import { useConfig, useSubscription } from '@fireact.dev/app';
19+
20+
export default function SubscriptionDashboard() {
21+
const { subscription, loading, error } = useSubscription();
22+
const { t } = useTranslation();
23+
const config = useConfig();
24+
25+
if (loading) {
26+
return (
27+
<div className="flex justify-center items-center h-64">
28+
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-indigo-600"></div>
29+
</div>
30+
);
31+
}
32+
33+
if (error || !subscription) {
34+
return <Navigate to={config.appConfig.pages.home} replace />;
35+
}
36+
37+
// Find the plan configuration
38+
const planConfig = config.appConfig.stripe?.plans?.find(plan => plan.id === subscription.plan_id);
39+
40+
return (
41+
<div className="space-y-6">
42+
{/* ... JSX for displaying subscription details and features ... */}
43+
</div>
44+
);
45+
}
46+
```
47+
48+
### Key Framework Integrations:
49+
50+
1. **Authentication and User Context (`useSubscription`)**:
51+
The `useSubscription` hook from `@fireact.dev/app` is central to accessing user-specific subscription data. It automatically handles fetching the current user's subscription details.
52+
* `subscription`: Contains the subscription object if an active subscription is found.
53+
* `loading`: A boolean indicating if the data is currently being fetched. You should display a loading indicator when this is `true`.
54+
* `error`: An error object if something went wrong during data fetching.
55+
* **Handling States**: As seen in the example, you should handle `loading` and `error` states. If `error` is true or `subscription` is null (e.g., no active subscription), you might redirect the user to a different page (e.g., the home page or a pricing page).
56+
57+
2. **Application Configuration (`useConfig`)**:
58+
The `useConfig` hook provides access to your application's global configuration, typically defined in `app.config.json`. This is useful for:
59+
* **Accessing Page Routes**: `config.appConfig.pages.home` is used to get the path for the home page, enabling dynamic navigation.
60+
* **Stripe Plan Details**: `config.appConfig.stripe?.plans` allows you to retrieve details about your Stripe plans, such as `descriptionKeys` used to list features associated with a plan. This enables dynamic rendering of features based on the user's current subscription plan.
61+
62+
3. **Internationalization (`useTranslation`)**:
63+
The `useTranslation` hook from `react-i18next` is used for multi-language support. For a detailed guide on how to manage translations and languages, refer to the [Localization in Fireact.dev](../custom-development/localization.md) documentation.
64+
65+
### Developing Your Own Components:
66+
67+
When building your own components or pages, consider the following patterns demonstrated by `SubscriptionDashboard.tsx`:
68+
69+
* **Data Fetching**: For any user-specific or application-wide data, Fireact.dev provides a set of powerful hooks and context providers. For a detailed guide on how data is fetched and managed in the framework, refer to the [Data Fetching in Fireact.dev](../custom-development/data-fetching.md) documentation.
70+
* **State Management**: Effectively manage loading, error, and data states to provide a smooth user experience. Conditional rendering based on these states is crucial.
71+
* **Configuration-Driven UI**: Leverage `useConfig` to make your components more flexible and configurable. Instead of hardcoding values, retrieve them from the application configuration. This is particularly useful for dynamic content like feature lists or navigation paths.
72+
* **Localization**: Always use `useTranslation` for any user-facing text to ensure your application supports multiple languages.
73+
* **Routing**: Fireact.dev uses `react-router-dom` for routing, along with integrated permission control. For a detailed guide on how routing is managed and permissions are enforced, refer to the [Routing and Permission Control](../custom-development/routing-and-permission-control.md) documentation.
74+
75+
By following these patterns and utilizing the provided hooks, you can efficiently develop robust and integrated custom components and pages within your Fireact.dev application.

0 commit comments

Comments
 (0)