@umituz/react-native-subscription 2.15.3 → 2.15.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/presentation/hooks/useSubscriptionSettingsConfig.ts +6 -2
- package/src/revenuecat/infrastructure/config/SandboxDurationConfig.ts +42 -0
- package/src/revenuecat/infrastructure/utils/ExpirationDateCalculator.ts +19 -60
- package/src/revenuecat/infrastructure/utils/SandboxDurationConverter.ts +68 -0
- package/src/domains/README.md.bak +0 -274
- package/src/domains/wallet/README.md.bak +0 -209
- package/src/presentation/README.md.bak +0 -172
- package/src/presentation/components/README.md.bak +0 -217
- package/src/presentation/hooks/useCredits.md.bak +0 -231
- package/src/presentation/hooks/useFeatureGate.md.bak +0 -284
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
# Wallet Domain
|
|
2
|
-
|
|
3
|
-
Credit balance management, transaction history tracking, and product metadata management.
|
|
4
|
-
|
|
5
|
-
## Location
|
|
6
|
-
|
|
7
|
-
**Directory**: `src/domains/wallet/`
|
|
8
|
-
|
|
9
|
-
**Type**: Domain
|
|
10
|
-
|
|
11
|
-
## Strategy
|
|
12
|
-
|
|
13
|
-
### Domain Architecture
|
|
14
|
-
|
|
15
|
-
The Wallet Domain implements a layered architecture for credit management:
|
|
16
|
-
|
|
17
|
-
1. **Domain Layer**
|
|
18
|
-
- Entities: `UserCredits`, `Transaction`, `CreditType`
|
|
19
|
-
- Value Objects: `CreditAmount`, `TransactionReason`
|
|
20
|
-
- Errors: `InsufficientCreditsError`, `InvalidCreditAmountError`
|
|
21
|
-
|
|
22
|
-
2. **Infrastructure Layer**
|
|
23
|
-
- Repositories: `CreditsRepository`, `TransactionsRepository`
|
|
24
|
-
- Firebase Services: Data persistence and real-time updates
|
|
25
|
-
- Mappers: Entity ↔ DTO transformations
|
|
26
|
-
|
|
27
|
-
3. **Presentation Layer**
|
|
28
|
-
- Hooks: `useCredits`, `useDeductCredit`, `useInitializeCredits`
|
|
29
|
-
- Components: Credit displays, transaction lists
|
|
30
|
-
|
|
31
|
-
### Credit Flow
|
|
32
|
-
|
|
33
|
-
1. **Initialization**
|
|
34
|
-
- Fetch initial credit balance from backend
|
|
35
|
-
- Subscribe to real-time credit updates
|
|
36
|
-
- Cache in TanStack Query
|
|
37
|
-
|
|
38
|
-
2. **Operations**
|
|
39
|
-
- Check balance before operations
|
|
40
|
-
- Deduct credits optimistically
|
|
41
|
-
- Sync with backend
|
|
42
|
-
- Rollback on failure
|
|
43
|
-
|
|
44
|
-
3. **Transaction History**
|
|
45
|
-
- Record all credit operations
|
|
46
|
-
- Provide audit trail
|
|
47
|
-
- Support pagination and filtering
|
|
48
|
-
|
|
49
|
-
### Integration Points
|
|
50
|
-
|
|
51
|
-
- **Firebase**: Real database for persistence
|
|
52
|
-
- **TanStack Query**: Client-side caching and state management
|
|
53
|
-
- **RevenueCat**: Purchase flow integration
|
|
54
|
-
- **Presentation Hooks**: UI integration layer
|
|
55
|
-
|
|
56
|
-
## Restrictions
|
|
57
|
-
|
|
58
|
-
### REQUIRED
|
|
59
|
-
|
|
60
|
-
- **User Authentication**: All operations require authenticated user
|
|
61
|
-
- **Server Validation**: Credit operations MUST be validated server-side
|
|
62
|
-
- **Transaction Recording**: All credit changes MUST be recorded in transaction history
|
|
63
|
-
- **Error Handling**: MUST handle insufficient credits gracefully
|
|
64
|
-
|
|
65
|
-
### PROHIBITED
|
|
66
|
-
|
|
67
|
-
- **NEVER** allow client-side credit modifications without server validation
|
|
68
|
-
- **NEVER** deduct credits without sufficient balance
|
|
69
|
-
- **DO NOT** expose internal repository logic to UI
|
|
70
|
-
- **NEVER** store credit balance in AsyncStorage (use secure backend)
|
|
71
|
-
|
|
72
|
-
### CRITICAL SAFETY
|
|
73
|
-
|
|
74
|
-
- **ALWAYS** validate credit amounts (must be positive)
|
|
75
|
-
- **ALWAYS** implement optimistic updates with rollback
|
|
76
|
-
- **NEVER** trust client-side credit balance for security decisions
|
|
77
|
-
- **MUST** implement retry logic for failed operations
|
|
78
|
-
- **ALWAYS** sanitize transaction reasons to prevent injection attacks
|
|
79
|
-
|
|
80
|
-
## Rules
|
|
81
|
-
|
|
82
|
-
### Repository Initialization
|
|
83
|
-
|
|
84
|
-
```typescript
|
|
85
|
-
// CORRECT - Proper repository setup
|
|
86
|
-
const creditsRepository = new CreditsRepository({
|
|
87
|
-
firebase: firebaseInstance,
|
|
88
|
-
userId: user.uid,
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
// INCORRECT - Missing userId
|
|
92
|
-
const creditsRepository = new CreditsRepository({
|
|
93
|
-
firebase: firebaseInstance,
|
|
94
|
-
// userId undefined
|
|
95
|
-
});
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
### Credit Operations
|
|
99
|
-
|
|
100
|
-
```typescript
|
|
101
|
-
// CORRECT - Check before deduct
|
|
102
|
-
const hasEnoughCredits = await creditsRepository.checkBalance(requiredAmount);
|
|
103
|
-
if (hasEnoughCredits) {
|
|
104
|
-
await creditsRepository.deductCredits(requiredAmount, 'feature_usage');
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// INCORRECT - Deduct without checking
|
|
108
|
-
await creditsRepository.deductCredits(requiredAmount, 'feature_usage');
|
|
109
|
-
// May throw InsufficientCreditsError
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
### Transaction Recording
|
|
113
|
-
|
|
114
|
-
```typescript
|
|
115
|
-
// CORRECT - Record all operations
|
|
116
|
-
await creditsRepository.deductCredits(
|
|
117
|
-
amount,
|
|
118
|
-
reason,
|
|
119
|
-
{ featureId, metadata } // Include context
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
// INCORRECT - Missing context
|
|
123
|
-
await creditsRepository.deductCredits(amount, reason);
|
|
124
|
-
// Lost audit trail
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
### Error Handling
|
|
128
|
-
|
|
129
|
-
```typescript
|
|
130
|
-
// CORRECT - Handle specific errors
|
|
131
|
-
try {
|
|
132
|
-
await creditsRepository.deductCredits(amount, reason);
|
|
133
|
-
} catch (error) {
|
|
134
|
-
if (error instanceof InsufficientCreditsError) {
|
|
135
|
-
showUpgradePrompt();
|
|
136
|
-
} else if (error instanceof InvalidCreditAmountError) {
|
|
137
|
-
showInvalidAmountError();
|
|
138
|
-
} else {
|
|
139
|
-
showGenericError();
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// INCORRECT - Generic error handling
|
|
144
|
-
try {
|
|
145
|
-
await creditsRepository.deductCredits(amount, reason);
|
|
146
|
-
} catch (error) {
|
|
147
|
-
console.error(error); // Doesn't help user
|
|
148
|
-
}
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
## AI Agent Guidelines
|
|
152
|
-
|
|
153
|
-
### When Implementing Credit Operations
|
|
154
|
-
|
|
155
|
-
1. **Always** check balance before deducting
|
|
156
|
-
2. **Always** provide transaction reason and metadata
|
|
157
|
-
3. **Always** handle insufficient credits gracefully
|
|
158
|
-
4. **Always** implement optimistic updates with rollback
|
|
159
|
-
5. **Never** trust client-side balance for security
|
|
160
|
-
|
|
161
|
-
### Integration Checklist
|
|
162
|
-
|
|
163
|
-
- [ ] Initialize repository with valid userId
|
|
164
|
-
- [ ] Implement error boundaries
|
|
165
|
-
- [ ] Handle loading states
|
|
166
|
-
- [ ] Provide user feedback for all operations
|
|
167
|
-
- [ ] Test with insufficient credits
|
|
168
|
-
- [ ] Test with zero balance
|
|
169
|
-
- [ ] Test transaction history
|
|
170
|
-
- [ ] Test real-time updates
|
|
171
|
-
- [ ] Implement retry logic
|
|
172
|
-
- [ ] Sanitize user inputs
|
|
173
|
-
|
|
174
|
-
### Common Patterns
|
|
175
|
-
|
|
176
|
-
1. **Pre-check**: Always verify balance before operations
|
|
177
|
-
2. **Optimistic Updates**: Update UI immediately, rollback on failure
|
|
178
|
-
3. **Transaction Context**: Include featureId and metadata in all operations
|
|
179
|
-
4. **Error Recovery**: Provide upgrade path when credits insufficient
|
|
180
|
-
5. **Real-time Sync**: Subscribe to credit changes for multi-device sync
|
|
181
|
-
6. **Audit Trail**: Maintain complete transaction history
|
|
182
|
-
7. **Caching**: Use TanStack Query for performance
|
|
183
|
-
8. **Validation**: Validate all inputs on both client and server
|
|
184
|
-
|
|
185
|
-
## Related Documentation
|
|
186
|
-
|
|
187
|
-
- **Credits Repository**: `infrastructure/repositories/README.md`
|
|
188
|
-
- **useCredits Hook**: `../../presentation/hooks/useCredits.md`
|
|
189
|
-
- **useDeductCredit Hook**: `../../presentation/hooks/useDeductCredit.md`
|
|
190
|
-
- **UserCredits Entity**: `domain/entities/README.md`
|
|
191
|
-
- **Transaction Errors**: `domain/errors/README.md`
|
|
192
|
-
|
|
193
|
-
## Domain Structure
|
|
194
|
-
|
|
195
|
-
```
|
|
196
|
-
src/domains/wallet/
|
|
197
|
-
├── domain/
|
|
198
|
-
│ ├── entities/ # Core entities
|
|
199
|
-
│ │ ├── UserCredits.ts
|
|
200
|
-
│ │ └── Transaction.ts
|
|
201
|
-
│ ├── value-objects/ # Value objects
|
|
202
|
-
│ └── errors/ # Domain errors
|
|
203
|
-
├── infrastructure/
|
|
204
|
-
│ ├── repositories/ # Data access
|
|
205
|
-
│ └── services/ # External services
|
|
206
|
-
└── presentation/
|
|
207
|
-
├── hooks/ # React hooks
|
|
208
|
-
└── components/ # UI components
|
|
209
|
-
```
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
# Presentation Layer
|
|
2
|
-
|
|
3
|
-
UI/UX layer for the subscription system - React hooks, components, and screens.
|
|
4
|
-
|
|
5
|
-
## Location
|
|
6
|
-
|
|
7
|
-
**Directory**: `src/presentation/`
|
|
8
|
-
|
|
9
|
-
**Type**: Layer
|
|
10
|
-
|
|
11
|
-
## Strategy
|
|
12
|
-
|
|
13
|
-
### Layer Responsibilities
|
|
14
|
-
|
|
15
|
-
The Presentation Layer is responsible for:
|
|
16
|
-
|
|
17
|
-
1. **State Management**
|
|
18
|
-
- React hooks for data fetching and mutations
|
|
19
|
-
- TanStack Query for server state management
|
|
20
|
-
- Local state management for UI state
|
|
21
|
-
|
|
22
|
-
2. **UI Components**
|
|
23
|
-
- Reusable subscription components
|
|
24
|
-
- Feature gating UI elements
|
|
25
|
-
- Credit display components
|
|
26
|
-
- Paywall components
|
|
27
|
-
|
|
28
|
-
3. **User Interaction**
|
|
29
|
-
- Handle user actions
|
|
30
|
-
- Display appropriate feedback
|
|
31
|
-
- Guide users through purchase flows
|
|
32
|
-
- Show upgrade prompts at right time
|
|
33
|
-
|
|
34
|
-
### Architecture Pattern
|
|
35
|
-
|
|
36
|
-
The presentation layer follows a layered architecture where:
|
|
37
|
-
- Hooks manage state and data fetching at the top level
|
|
38
|
-
- Components consume hooks and render UI
|
|
39
|
-
- Screens compose multiple components together
|
|
40
|
-
- All layers communicate with the domain layer for business logic
|
|
41
|
-
|
|
42
|
-
### Integration Points
|
|
43
|
-
|
|
44
|
-
- **Domain Layer**: Business logic and data access
|
|
45
|
-
- **TanStack Query**: Server state management
|
|
46
|
-
- **RevenueCat**: Purchase operations
|
|
47
|
-
- **Navigation**: Screen routing
|
|
48
|
-
|
|
49
|
-
## Restrictions
|
|
50
|
-
|
|
51
|
-
### REQUIRED
|
|
52
|
-
|
|
53
|
-
- **Type Safety**: All components MUST be typed with TypeScript
|
|
54
|
-
- **Error Boundaries**: MUST implement error boundaries for all screens
|
|
55
|
-
- **Loading States**: MUST show loading indicators during async operations
|
|
56
|
-
- **User Feedback**: MUST provide feedback for all user actions
|
|
57
|
-
|
|
58
|
-
### PROHIBITED
|
|
59
|
-
|
|
60
|
-
- **NEVER** include business logic in components (use hooks instead)
|
|
61
|
-
- **NEVER** make direct API calls from components (use hooks)
|
|
62
|
-
- **DO NOT** store sensitive data in component state
|
|
63
|
-
- **NEVER** hardcode strings (use localization)
|
|
64
|
-
|
|
65
|
-
### CRITICAL SAFETY
|
|
66
|
-
|
|
67
|
-
- **ALWAYS** validate props before rendering
|
|
68
|
-
- **ALWAYS** handle loading and error states
|
|
69
|
-
- **NEVER** trust client-side state for security decisions
|
|
70
|
-
- **MUST** implement proper error boundaries
|
|
71
|
-
- **ALWAYS** sanitize user inputs before display
|
|
72
|
-
|
|
73
|
-
## Rules
|
|
74
|
-
|
|
75
|
-
### Component Structure
|
|
76
|
-
|
|
77
|
-
**CORRECT**: Proper component structure includes:
|
|
78
|
-
- Define TypeScript interface for props
|
|
79
|
-
- Import and use appropriate hooks for data fetching
|
|
80
|
-
- Return loading indicator when data is fetching
|
|
81
|
-
- Return error display when there's an error
|
|
82
|
-
- Render actual component only when data is available
|
|
83
|
-
|
|
84
|
-
**INCORRECT**: No loading/error handling
|
|
85
|
-
- Don't render component without checking if data is loading
|
|
86
|
-
- Don't display component without handling potential errors
|
|
87
|
-
- Never assume data is always available immediately
|
|
88
|
-
|
|
89
|
-
**INCORRECT**: Business logic in component
|
|
90
|
-
- Don't use useEffect to fetch data directly
|
|
91
|
-
- Don't manage complex state with useState for business logic
|
|
92
|
-
- Never include data transformation logic in components
|
|
93
|
-
|
|
94
|
-
### Hook Usage
|
|
95
|
-
|
|
96
|
-
**CORRECT**: Use hooks for data fetching
|
|
97
|
-
- Call useCredits to get credit balance with loading and error states
|
|
98
|
-
- Call usePremium to check premium status
|
|
99
|
-
- Always check if loading is true before rendering
|
|
100
|
-
- Always check if error exists before rendering
|
|
101
|
-
|
|
102
|
-
**INCORRECT**: Direct API calls in component
|
|
103
|
-
- Don't use useEffect with axios or fetch to call APIs
|
|
104
|
-
- Don't manage async operations manually in components
|
|
105
|
-
- Never handle API responses directly in UI components
|
|
106
|
-
|
|
107
|
-
### Error Boundaries
|
|
108
|
-
|
|
109
|
-
**CORRECT**: Wrap screens with error boundaries
|
|
110
|
-
- Import ErrorBoundary component
|
|
111
|
-
- Create fallback error screen component
|
|
112
|
-
- Wrap screen content with ErrorBoundary component
|
|
113
|
-
- Pass fallback component to ErrorBoundary
|
|
114
|
-
|
|
115
|
-
**INCORRECT**: No error boundary
|
|
116
|
-
- Don't export screens without error boundary wrapper
|
|
117
|
-
- Never let errors crash entire application
|
|
118
|
-
- Don't assume components will never throw errors
|
|
119
|
-
|
|
120
|
-
## AI Agent Guidelines
|
|
121
|
-
|
|
122
|
-
### When Building Presentation Layer
|
|
123
|
-
|
|
124
|
-
1. **Always** use hooks for data fetching and state management
|
|
125
|
-
2. **Always** handle loading and error states
|
|
126
|
-
3. **Always** provide user feedback for actions
|
|
127
|
-
4. **Always** implement error boundaries
|
|
128
|
-
5. **Never** include business logic in components
|
|
129
|
-
|
|
130
|
-
### Integration Checklist
|
|
131
|
-
|
|
132
|
-
- [ ] Use appropriate hooks for data access
|
|
133
|
-
- [ ] Handle loading states
|
|
134
|
-
- [ ] Handle error states
|
|
135
|
-
- [ ] Implement error boundaries
|
|
136
|
-
- [ ] Provide user feedback
|
|
137
|
-
- [ ] Test with various data states
|
|
138
|
-
- [ ] Test error scenarios
|
|
139
|
-
- [ ] Ensure type safety
|
|
140
|
-
- [ ] Use localization for all strings
|
|
141
|
-
- [ ] Test accessibility
|
|
142
|
-
|
|
143
|
-
### Common Patterns
|
|
144
|
-
|
|
145
|
-
1. **Compound Components**: Build complex UIs from simple components
|
|
146
|
-
2. **Render Props**: Share stateful logic between components
|
|
147
|
-
3. **Custom Hooks**: Extract reusable stateful logic
|
|
148
|
-
4. **Error Boundaries**: Prevent crashes from propagating
|
|
149
|
-
5. **Loading Skeletons**: Show placeholder during loading
|
|
150
|
-
6. **Optimistic Updates**: Update UI immediately, rollback on failure
|
|
151
|
-
7. **Graceful Degradation**: Show limited version on error
|
|
152
|
-
8. **Responsive Design**: Support different screen sizes
|
|
153
|
-
|
|
154
|
-
## Related Documentation
|
|
155
|
-
|
|
156
|
-
- **Hooks**: `hooks/README.md`
|
|
157
|
-
- **Components**: `components/README.md`
|
|
158
|
-
- **Screens**: `screens/README.md`
|
|
159
|
-
- **Wallet Domain**: `../../domains/wallet/README.md`
|
|
160
|
-
- **Paywall Domain**: `../../domains/paywall/README.md`
|
|
161
|
-
- **RevenueCat**: `../../revenuecat/README.md`
|
|
162
|
-
|
|
163
|
-
## Directory Structure
|
|
164
|
-
|
|
165
|
-
The presentation layer contains:
|
|
166
|
-
- **hooks/** - React hooks for state management (usePremium, useSubscription, useCredits, useDeductCredit, useFeatureGate)
|
|
167
|
-
- **components/** - UI components organized by functionality
|
|
168
|
-
- **details/** - Detail cards, badges
|
|
169
|
-
- **feedback/** - Modals, feedback components
|
|
170
|
-
- **sections/** - Section components
|
|
171
|
-
- **paywall/** - Paywall components
|
|
172
|
-
- **screens/** - Full-screen components (SubscriptionDetailScreen)
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
# Presentation Components
|
|
2
|
-
|
|
3
|
-
React Native UI components for subscription and paywall features.
|
|
4
|
-
|
|
5
|
-
## Location
|
|
6
|
-
|
|
7
|
-
**Directory**: `src/presentation/components/`
|
|
8
|
-
|
|
9
|
-
**Type**: Component Library
|
|
10
|
-
|
|
11
|
-
## Strategy
|
|
12
|
-
|
|
13
|
-
### Component Categories
|
|
14
|
-
|
|
15
|
-
Components are organized by functionality:
|
|
16
|
-
|
|
17
|
-
1. **Details Components**
|
|
18
|
-
- CreditRow: Display credit balance and info
|
|
19
|
-
- DetailRow: Generic detail display row
|
|
20
|
-
- PremiumStatusBadge: Visual premium indicator
|
|
21
|
-
- PremiumDetailsCard: Premium subscription details
|
|
22
|
-
|
|
23
|
-
2. **Feedback Components**
|
|
24
|
-
- PaywallFeedbackModal: User feedback collection
|
|
25
|
-
- Alert components: Warning and info displays
|
|
26
|
-
|
|
27
|
-
3. **Section Components**
|
|
28
|
-
- SubscriptionSection: Subscription info section
|
|
29
|
-
- CreditsSection: Credits balance section
|
|
30
|
-
|
|
31
|
-
4. **Paywall Components**
|
|
32
|
-
- PaywallModal: Upgrade/purchase modal
|
|
33
|
-
- Purchase options: Subscription and credit packages
|
|
34
|
-
|
|
35
|
-
### Design Principles
|
|
36
|
-
|
|
37
|
-
All components follow these principles:
|
|
38
|
-
- **Reusable**: Composable and configurable
|
|
39
|
-
- **Typed**: Full TypeScript support
|
|
40
|
-
- **Accessible**: WCAG compliant where possible
|
|
41
|
-
- **Testable**: Easy to test in isolation
|
|
42
|
-
- **Themeable**: Support custom styling
|
|
43
|
-
|
|
44
|
-
### Integration Points
|
|
45
|
-
|
|
46
|
-
- **React Native**: Core UI framework
|
|
47
|
-
- **Design System**: Shared UI components
|
|
48
|
-
- **Localization**: i18n string support
|
|
49
|
-
- **Theme**: Custom styling support
|
|
50
|
-
|
|
51
|
-
## Restrictions
|
|
52
|
-
|
|
53
|
-
### REQUIRED
|
|
54
|
-
|
|
55
|
-
- **Props Typing**: All components MUST have TypeScript interfaces
|
|
56
|
-
- **Default Props**: MUST provide sensible defaults
|
|
57
|
-
- **Accessibility**: MUST implement accessibility labels
|
|
58
|
-
- **Responsive**: MUST handle different screen sizes
|
|
59
|
-
|
|
60
|
-
### PROHIBITED
|
|
61
|
-
|
|
62
|
-
- **NEVER** hardcode colors or sizes (use theme)
|
|
63
|
-
- **NEVER** include business logic in components
|
|
64
|
-
- **DO NOT** make direct API calls
|
|
65
|
-
- **NEVER** hardcode strings (use localization)
|
|
66
|
-
|
|
67
|
-
### CRITICAL SAFETY
|
|
68
|
-
|
|
69
|
-
- **ALWAYS** validate props before rendering
|
|
70
|
-
- **ALWAYS** handle loading and error states
|
|
71
|
-
- **NEVER** trust user input for security decisions
|
|
72
|
-
- **MUST** implement proper error boundaries
|
|
73
|
-
- **ALWAYS** sanitize user-provided content
|
|
74
|
-
|
|
75
|
-
## Rules
|
|
76
|
-
|
|
77
|
-
### Component Structure
|
|
78
|
-
|
|
79
|
-
**CORRECT**: Proper component structure
|
|
80
|
-
- Define TypeScript interface for component props
|
|
81
|
-
- List all required props (amount, isLoading, onPress)
|
|
82
|
-
- List optional props with question marks
|
|
83
|
-
- Destructure props in function signature
|
|
84
|
-
- Check loading state and return SkeletonLoader
|
|
85
|
-
- Render TouchableOpacity with conditional disabled
|
|
86
|
-
- Display text content
|
|
87
|
-
|
|
88
|
-
**INCORRECT**: No props interface
|
|
89
|
-
- Don't create components without TypeScript interfaces
|
|
90
|
-
- Never omit type definitions for props
|
|
91
|
-
- Don't use any type or skip type checking
|
|
92
|
-
|
|
93
|
-
### Theme Usage
|
|
94
|
-
|
|
95
|
-
**CORRECT**: Use theme for styling
|
|
96
|
-
- Import and use useTheme hook
|
|
97
|
-
- Access colors from theme object
|
|
98
|
-
- Apply theme colors to styles
|
|
99
|
-
- Use semantic color names (primary, onPrimary)
|
|
100
|
-
|
|
101
|
-
**INCORRECT**: Hardcoded colors
|
|
102
|
-
- Don't use hex color codes directly in styles
|
|
103
|
-
- Never hardcode values like '#007AFF' or '#FFFFFF'
|
|
104
|
-
- Don't skip theme integration
|
|
105
|
-
- Avoid inline color values
|
|
106
|
-
|
|
107
|
-
### Accessibility
|
|
108
|
-
|
|
109
|
-
**CORRECT**: Accessibility support
|
|
110
|
-
- Define accessibilityLabel prop for Button
|
|
111
|
-
- Define accessibilityHint for additional context
|
|
112
|
-
- Set accessibilityState with disabled condition
|
|
113
|
-
- Provide clear, descriptive labels
|
|
114
|
-
- Include hints for complex interactions
|
|
115
|
-
|
|
116
|
-
**INCORRECT**: No accessibility
|
|
117
|
-
- Don't create components without a11y labels
|
|
118
|
-
- Never skip accessibilityHint for complex UI
|
|
119
|
-
- Don't omit accessibilityState for interactive elements
|
|
120
|
-
- Avoid non-descriptive labels
|
|
121
|
-
|
|
122
|
-
### Conditional Rendering
|
|
123
|
-
|
|
124
|
-
**CORRECT**: Handle all states
|
|
125
|
-
- Check if loading and return SkeletonLoader
|
|
126
|
-
- Check if error and return ErrorDisplay
|
|
127
|
-
- Check if credits is undefined and return Placeholder
|
|
128
|
-
- Render content only when all states are valid
|
|
129
|
-
- Handle all possible state combinations
|
|
130
|
-
|
|
131
|
-
**INCORRECT**: Incomplete state handling
|
|
132
|
-
- Don't render content without checking error state
|
|
133
|
-
- Never assume data is always defined
|
|
134
|
-
- Don't skip placeholder for undefined data
|
|
135
|
-
- Avoid incomplete conditional chains
|
|
136
|
-
|
|
137
|
-
## AI Agent Guidelines
|
|
138
|
-
|
|
139
|
-
### When Building Components
|
|
140
|
-
|
|
141
|
-
1. **Always** define TypeScript interfaces for props
|
|
142
|
-
2. **Always** use theme for styling (no hardcoded values)
|
|
143
|
-
3. **Always** implement accessibility labels
|
|
144
|
-
4. **Always** handle loading and error states
|
|
145
|
-
5. **Never** include business logic in components
|
|
146
|
-
|
|
147
|
-
### Integration Checklist
|
|
148
|
-
|
|
149
|
-
- [ ] Define TypeScript interface for props
|
|
150
|
-
- [ ] Use theme for all styling
|
|
151
|
-
- [ ] Implement accessibility labels
|
|
152
|
-
- [ ] Handle loading state
|
|
153
|
-
- [ ] Handle error state
|
|
154
|
-
- [ ] Provide sensible defaults
|
|
155
|
-
- [ ] Test with different screen sizes
|
|
156
|
-
- [ ] Test accessibility
|
|
157
|
-
- [ ] Test with various prop combinations
|
|
158
|
-
- [ ] Document component usage
|
|
159
|
-
|
|
160
|
-
### Common Patterns
|
|
161
|
-
|
|
162
|
-
1. **Compound Components**: Build complex UIs from simple parts
|
|
163
|
-
2. **Render Props**: Share stateful logic
|
|
164
|
-
3. **Slot Pattern**: Allow content injection
|
|
165
|
-
4. **Control Props**: Make components controlled or uncontrolled
|
|
166
|
-
5. **Asynchronous States**: Handle loading, error, success states
|
|
167
|
-
6. **Responsive Design**: Adapt to different screen sizes
|
|
168
|
-
7. **Theme Integration**: Use design system tokens
|
|
169
|
-
8. **Accessibility First**: Include a11y from the start
|
|
170
|
-
|
|
171
|
-
## Related Documentation
|
|
172
|
-
|
|
173
|
-
- **Details Components**: `details/README.md`
|
|
174
|
-
- **Feedback Components**: `feedback/README.md`
|
|
175
|
-
- **Section Components**: `sections/README.md`
|
|
176
|
-
- **Paywall Components**: `paywall/README.md`
|
|
177
|
-
- **Design System**: External design system documentation
|
|
178
|
-
- **Hooks**: `../hooks/README.md`
|
|
179
|
-
|
|
180
|
-
## Component Examples
|
|
181
|
-
|
|
182
|
-
### CreditRow
|
|
183
|
-
|
|
184
|
-
Display user's credit balance with optional actions.
|
|
185
|
-
|
|
186
|
-
Usage:
|
|
187
|
-
- Set amount prop to number of credits
|
|
188
|
-
- Set isLoading to true during data fetch
|
|
189
|
-
- Provide onPress callback for navigation
|
|
190
|
-
- Component displays credit count and handles tap
|
|
191
|
-
|
|
192
|
-
### PremiumStatusBadge
|
|
193
|
-
|
|
194
|
-
Visual indicator for premium subscription status.
|
|
195
|
-
|
|
196
|
-
Usage:
|
|
197
|
-
- Set isPremium to boolean status
|
|
198
|
-
- Set tier to subscription level (gold, silver, etc.)
|
|
199
|
-
- Component renders styled badge
|
|
200
|
-
|
|
201
|
-
### PaywallModal
|
|
202
|
-
|
|
203
|
-
Modal for subscription and credit purchase.
|
|
204
|
-
|
|
205
|
-
Usage:
|
|
206
|
-
- Set isVisible to boolean for show/hide
|
|
207
|
-
- Provide onClose callback
|
|
208
|
-
- Pass features array for premium features list
|
|
209
|
-
- Modal handles purchase flow
|
|
210
|
-
|
|
211
|
-
## Directory Structure
|
|
212
|
-
|
|
213
|
-
The components directory contains:
|
|
214
|
-
- **details/** - Detail display components (CreditRow, DetailRow, PremiumStatusBadge, PremiumDetailsCard)
|
|
215
|
-
- **feedback/** - Feedback and alert components (PaywallFeedbackModal)
|
|
216
|
-
- **sections/** - Section components (SubscriptionSection)
|
|
217
|
-
- **paywall/** - Paywall components (PaywallModal)
|