@outerjoyn/react-native 1.1.0
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/README.md +133 -0
- package/package.json +57 -0
- package/src/NativeSDK.ts +164 -0
- package/src/OuterJoynProvider.tsx +828 -0
- package/src/OuterJoynSDK.ts +261 -0
- package/src/OuterJoynSheet.tsx +218 -0
- package/src/PromotionsView.tsx +76 -0
- package/src/components/BalanceSummary.tsx +267 -0
- package/src/components/CheckoutPointsApply.tsx +787 -0
- package/src/components/LoyaltyBanner.tsx +281 -0
- package/src/components/LoyaltyProfileSection.tsx +273 -0
- package/src/components/PostCheckoutSavePrompt.tsx +369 -0
- package/src/components/index.ts +30 -0
- package/src/core/ErrorBoundary.tsx +51 -0
- package/src/core/analytics.ts +264 -0
- package/src/core/api-client.ts +253 -0
- package/src/core/colors.ts +20 -0
- package/src/core/event-stream.ts +229 -0
- package/src/core/i18n.ts +666 -0
- package/src/core/offline.ts +148 -0
- package/src/core/types.ts +214 -0
- package/src/core/version.ts +2 -0
- package/src/html.ts +154 -0
- package/src/index.ts +102 -0
- package/src/screens/AccountScreen.tsx +701 -0
- package/src/screens/ConnectScreen.tsx +1499 -0
- package/src/screens/ExchangeScreen.tsx +706 -0
- package/src/screens/RedeemScreen.tsx +683 -0
- package/src/screens/index.ts +21 -0
- package/src/types.ts +116 -0
- package/src/useOuterJoyn.ts +45 -0
- package/src/widgets.tsx +226 -0
|
@@ -0,0 +1,701 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AccountScreen -- Member loyalty account overview.
|
|
3
|
+
*
|
|
4
|
+
* State: overview -> brand-detail (and back)
|
|
5
|
+
*
|
|
6
|
+
* Ported from web AccountWidget with native RN UI:
|
|
7
|
+
* profile header, connected brands FlatList, brand detail with tier progress
|
|
8
|
+
* and data sharing scopes, recent activity timeline, unlink button.
|
|
9
|
+
*
|
|
10
|
+
* @module @outerjoyn/react-native/screens/AccountScreen
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import React, { useState, useEffect, useCallback, useRef } from 'react';
|
|
14
|
+
import {
|
|
15
|
+
View,
|
|
16
|
+
Text,
|
|
17
|
+
Image,
|
|
18
|
+
Modal,
|
|
19
|
+
Pressable,
|
|
20
|
+
ActivityIndicator,
|
|
21
|
+
FlatList,
|
|
22
|
+
StyleSheet,
|
|
23
|
+
Alert,
|
|
24
|
+
ScrollView,
|
|
25
|
+
} from 'react-native';
|
|
26
|
+
import { useOuterJoyn } from '../useOuterJoyn';
|
|
27
|
+
import { APIClient } from '../core/api-client';
|
|
28
|
+
|
|
29
|
+
// =============================================================================
|
|
30
|
+
// Types
|
|
31
|
+
// =============================================================================
|
|
32
|
+
|
|
33
|
+
export interface AccountScreenProps {
|
|
34
|
+
/** Controls modal visibility */
|
|
35
|
+
visible: boolean;
|
|
36
|
+
/** Called when user dismisses the screen */
|
|
37
|
+
onClose?: () => void;
|
|
38
|
+
/** Called on error */
|
|
39
|
+
onError?: (error: Error) => void;
|
|
40
|
+
/** Override session token */
|
|
41
|
+
sessionToken?: string;
|
|
42
|
+
/** Override API base URL */
|
|
43
|
+
apiBaseUrl?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface MemberProfile {
|
|
47
|
+
member_id: string;
|
|
48
|
+
name: string;
|
|
49
|
+
email: string;
|
|
50
|
+
tier: string;
|
|
51
|
+
points_balance: number;
|
|
52
|
+
points_unit: string;
|
|
53
|
+
linked_count: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface ConnectedBrand {
|
|
57
|
+
brand_id: string;
|
|
58
|
+
name: string;
|
|
59
|
+
logo_url: string | null;
|
|
60
|
+
category: string;
|
|
61
|
+
currency_unit: string;
|
|
62
|
+
balance: number;
|
|
63
|
+
tier: string;
|
|
64
|
+
tier_progress: number;
|
|
65
|
+
tier_next: string;
|
|
66
|
+
total_earned: number;
|
|
67
|
+
total_redeemed: number;
|
|
68
|
+
scopes: string[];
|
|
69
|
+
linked_at: string;
|
|
70
|
+
partnership_id?: number;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
interface ActivityItem {
|
|
74
|
+
id: string;
|
|
75
|
+
description: string;
|
|
76
|
+
amount: number;
|
|
77
|
+
currency_unit: string;
|
|
78
|
+
type: string;
|
|
79
|
+
date: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const OJ_LOGO_URL = 'https://app.outerjoyn.com/outerjoyn-logo.png';
|
|
83
|
+
|
|
84
|
+
type ViewState = 'overview' | 'brand-detail';
|
|
85
|
+
|
|
86
|
+
// =============================================================================
|
|
87
|
+
// Demo data
|
|
88
|
+
// =============================================================================
|
|
89
|
+
|
|
90
|
+
const DEMO_PROFILE: MemberProfile = {
|
|
91
|
+
member_id: 'demo-1',
|
|
92
|
+
name: 'Alex Johnson',
|
|
93
|
+
email: 'alex@example.com',
|
|
94
|
+
tier: 'Gold',
|
|
95
|
+
points_balance: 42500,
|
|
96
|
+
points_unit: 'Points',
|
|
97
|
+
linked_count: 3,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const DEMO_BRANDS: ConnectedBrand[] = [
|
|
101
|
+
{
|
|
102
|
+
brand_id: '1',
|
|
103
|
+
name: 'SkyMiles',
|
|
104
|
+
logo_url: null,
|
|
105
|
+
category: 'Travel',
|
|
106
|
+
currency_unit: 'Miles',
|
|
107
|
+
balance: 25000,
|
|
108
|
+
tier: 'Gold',
|
|
109
|
+
tier_progress: 0.72,
|
|
110
|
+
tier_next: 'Platinum',
|
|
111
|
+
total_earned: 48000,
|
|
112
|
+
total_redeemed: 23000,
|
|
113
|
+
scopes: ['balance', 'transactions', 'tier'],
|
|
114
|
+
linked_at: '2025-11-15',
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
brand_id: '2',
|
|
118
|
+
name: 'Glow Points',
|
|
119
|
+
logo_url: null,
|
|
120
|
+
category: 'Beauty',
|
|
121
|
+
currency_unit: 'Points',
|
|
122
|
+
balance: 10500,
|
|
123
|
+
tier: 'Silver',
|
|
124
|
+
tier_progress: 0.45,
|
|
125
|
+
tier_next: 'Gold',
|
|
126
|
+
total_earned: 18000,
|
|
127
|
+
total_redeemed: 7500,
|
|
128
|
+
scopes: ['balance', 'transactions'],
|
|
129
|
+
linked_at: '2026-01-20',
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
brand_id: '3',
|
|
133
|
+
name: 'Urban Coffee',
|
|
134
|
+
logo_url: null,
|
|
135
|
+
category: 'Food & Drink',
|
|
136
|
+
currency_unit: 'Stars',
|
|
137
|
+
balance: 7000,
|
|
138
|
+
tier: 'Regular',
|
|
139
|
+
tier_progress: 0.2,
|
|
140
|
+
tier_next: 'Silver',
|
|
141
|
+
total_earned: 9200,
|
|
142
|
+
total_redeemed: 2200,
|
|
143
|
+
scopes: ['balance'],
|
|
144
|
+
linked_at: '2026-03-01',
|
|
145
|
+
},
|
|
146
|
+
];
|
|
147
|
+
|
|
148
|
+
const DEMO_ACTIVITY: ActivityItem[] = [
|
|
149
|
+
{ id: '1', description: 'Flight purchase bonus', amount: 3200, currency_unit: 'Miles', type: 'earn', date: '2026-04-03' },
|
|
150
|
+
{ id: '2', description: 'Coffee reward redemption', amount: -500, currency_unit: 'Stars', type: 'redeem', date: '2026-04-02' },
|
|
151
|
+
{ id: '3', description: 'Points exchange from Glow', amount: 2000, currency_unit: 'Miles', type: 'exchange', date: '2026-04-01' },
|
|
152
|
+
{ id: '4', description: 'Skincare purchase', amount: 1500, currency_unit: 'Points', type: 'earn', date: '2026-03-30' },
|
|
153
|
+
{ id: '5', description: 'Gift card redemption', amount: -5000, currency_unit: 'Points', type: 'redeem', date: '2026-03-28' },
|
|
154
|
+
];
|
|
155
|
+
|
|
156
|
+
// =============================================================================
|
|
157
|
+
// Component
|
|
158
|
+
// =============================================================================
|
|
159
|
+
|
|
160
|
+
/** Account overview screen with profile, connected brands, and activity timeline. */
|
|
161
|
+
export function AccountScreen({
|
|
162
|
+
visible,
|
|
163
|
+
onClose,
|
|
164
|
+
onError,
|
|
165
|
+
sessionToken: propToken,
|
|
166
|
+
apiBaseUrl,
|
|
167
|
+
}: AccountScreenProps) {
|
|
168
|
+
const ctx = useOuterJoyn();
|
|
169
|
+
const { t } = ctx;
|
|
170
|
+
const token = propToken ?? ctx.sessionToken;
|
|
171
|
+
const isDemo = ctx.demoMode || !token;
|
|
172
|
+
|
|
173
|
+
// Use shared API client from context, fall back to creating one (fix #6)
|
|
174
|
+
const clientRef = useRef<APIClient | null>(null);
|
|
175
|
+
useEffect(() => {
|
|
176
|
+
if (ctx.apiClient) {
|
|
177
|
+
clientRef.current = ctx.apiClient;
|
|
178
|
+
} else if (token) {
|
|
179
|
+
clientRef.current = new APIClient(token, apiBaseUrl ?? ctx.apiBaseUrl ?? 'https://api.outerjoyn.com');
|
|
180
|
+
}
|
|
181
|
+
}, [token, apiBaseUrl, ctx.apiClient, ctx.apiBaseUrl]);
|
|
182
|
+
|
|
183
|
+
// State
|
|
184
|
+
const [view, setView] = useState<ViewState>('overview');
|
|
185
|
+
const [profile, setProfile] = useState<MemberProfile | null>(null);
|
|
186
|
+
const [brands, setBrands] = useState<ConnectedBrand[]>([]);
|
|
187
|
+
const [activity, setActivity] = useState<ActivityItem[]>([]);
|
|
188
|
+
const [selectedBrand, setSelectedBrand] = useState<ConnectedBrand | null>(null);
|
|
189
|
+
const [loading, setLoading] = useState(false);
|
|
190
|
+
|
|
191
|
+
// Load data — use linkedPrograms from SDK context (real payable_balances data)
|
|
192
|
+
// instead of the separate /api/sdk/account endpoint which often falls back
|
|
193
|
+
// to demo data with fake brand_ids that can't be unlinked.
|
|
194
|
+
useEffect(() => {
|
|
195
|
+
if (!visible) return;
|
|
196
|
+
if (isDemo) {
|
|
197
|
+
setProfile(DEMO_PROFILE);
|
|
198
|
+
setBrands(DEMO_BRANDS);
|
|
199
|
+
setActivity(DEMO_ACTIVITY);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const programs = ctx.linkedPrograms;
|
|
204
|
+
if (programs.length > 0) {
|
|
205
|
+
// Build profile from aggregated program data
|
|
206
|
+
const totalBalance = programs.reduce((sum, p) => sum + p.pointsBalance, 0);
|
|
207
|
+
let memberTier = 'Standard';
|
|
208
|
+
if (totalBalance >= 50000) memberTier = 'Platinum';
|
|
209
|
+
else if (totalBalance >= 20000) memberTier = 'Gold';
|
|
210
|
+
else if (totalBalance >= 5000) memberTier = 'Silver';
|
|
211
|
+
else if (totalBalance >= 1000) memberTier = 'Active';
|
|
212
|
+
|
|
213
|
+
setProfile({
|
|
214
|
+
member_id: programs[0]?.membershipId || '',
|
|
215
|
+
name: 'Member',
|
|
216
|
+
email: '',
|
|
217
|
+
tier: memberTier,
|
|
218
|
+
points_balance: totalBalance,
|
|
219
|
+
points_unit: 'Points',
|
|
220
|
+
linked_count: programs.length,
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
// Map LinkedProgram → ConnectedBrand
|
|
224
|
+
setBrands(programs.map((p) => {
|
|
225
|
+
const balance = p.pointsBalance;
|
|
226
|
+
let tier = 'Standard';
|
|
227
|
+
if (balance >= 50000) tier = 'Platinum';
|
|
228
|
+
else if (balance >= 20000) tier = 'Gold';
|
|
229
|
+
else if (balance >= 5000) tier = 'Silver';
|
|
230
|
+
else if (balance >= 1000) tier = 'Active';
|
|
231
|
+
|
|
232
|
+
let tierProgress = 0.25;
|
|
233
|
+
let tierNext = 'Active';
|
|
234
|
+
if (tier === 'Platinum') { tierProgress = 0.85; tierNext = 'Diamond'; }
|
|
235
|
+
else if (tier === 'Gold') { tierProgress = 0.75; tierNext = 'Platinum'; }
|
|
236
|
+
else if (tier === 'Silver') { tierProgress = 0.55; tierNext = 'Gold'; }
|
|
237
|
+
else if (tier === 'Active') { tierProgress = 0.40; tierNext = 'Silver'; }
|
|
238
|
+
|
|
239
|
+
return {
|
|
240
|
+
brand_id: String(p.currencyId || p.id),
|
|
241
|
+
name: p.brandName,
|
|
242
|
+
logo_url: p.brandLogoUrl,
|
|
243
|
+
category: 'Loyalty Program',
|
|
244
|
+
currency_unit: p.currencyName,
|
|
245
|
+
balance: p.pointsBalance,
|
|
246
|
+
tier,
|
|
247
|
+
tier_progress: tierProgress,
|
|
248
|
+
tier_next: tierNext,
|
|
249
|
+
total_earned: 0,
|
|
250
|
+
total_redeemed: 0,
|
|
251
|
+
scopes: ['balance'],
|
|
252
|
+
linked_at: '',
|
|
253
|
+
partnership_id: p.partnershipId,
|
|
254
|
+
};
|
|
255
|
+
}));
|
|
256
|
+
setActivity([]);
|
|
257
|
+
} else {
|
|
258
|
+
setProfile(DEMO_PROFILE);
|
|
259
|
+
setBrands(DEMO_BRANDS);
|
|
260
|
+
setActivity(DEMO_ACTIVITY);
|
|
261
|
+
}
|
|
262
|
+
setLoading(false);
|
|
263
|
+
}, [visible, isDemo, ctx.linkedPrograms]);
|
|
264
|
+
|
|
265
|
+
// Reset on close
|
|
266
|
+
useEffect(() => {
|
|
267
|
+
if (!visible) {
|
|
268
|
+
setView('overview');
|
|
269
|
+
setSelectedBrand(null);
|
|
270
|
+
}
|
|
271
|
+
}, [visible]);
|
|
272
|
+
|
|
273
|
+
const fmt = (n: number) => n.toLocaleString();
|
|
274
|
+
|
|
275
|
+
const handleBrandPress = useCallback((brand: ConnectedBrand) => {
|
|
276
|
+
setSelectedBrand(brand);
|
|
277
|
+
setView('brand-detail');
|
|
278
|
+
}, []);
|
|
279
|
+
|
|
280
|
+
const handleUnlink = useCallback((brand: ConnectedBrand) => {
|
|
281
|
+
Alert.alert(
|
|
282
|
+
t('account.unlink'),
|
|
283
|
+
t('connect.remove_confirm', { program: brand.name }),
|
|
284
|
+
[
|
|
285
|
+
{ text: t('common.cancel'), style: 'cancel' },
|
|
286
|
+
{
|
|
287
|
+
text: t('account.unlink'),
|
|
288
|
+
style: 'destructive',
|
|
289
|
+
onPress: async () => {
|
|
290
|
+
try {
|
|
291
|
+
if (!isDemo && clientRef.current) {
|
|
292
|
+
await clientRef.current.post('/api/sdk/sessions/connect/disconnect', {
|
|
293
|
+
...(brand.partnership_id
|
|
294
|
+
? { partnership_id: brand.partnership_id }
|
|
295
|
+
: { institution_id: brand.brand_id }),
|
|
296
|
+
});
|
|
297
|
+
try { await ctx.refreshBalances(); } catch { /* non-fatal */ }
|
|
298
|
+
}
|
|
299
|
+
setBrands((prev) => prev.filter((b) => b.brand_id !== brand.brand_id));
|
|
300
|
+
setView('overview');
|
|
301
|
+
setSelectedBrand(null);
|
|
302
|
+
} catch (e: any) {
|
|
303
|
+
onError?.(e);
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
],
|
|
308
|
+
);
|
|
309
|
+
}, [isDemo, onError]);
|
|
310
|
+
|
|
311
|
+
// Tier badge color
|
|
312
|
+
const tierColor = (tier: string): string => {
|
|
313
|
+
const t = tier.toLowerCase();
|
|
314
|
+
if (t === 'platinum' || t === 'diamond') return '#A78BFA';
|
|
315
|
+
if (t === 'gold') return '#F59E0B';
|
|
316
|
+
if (t === 'silver') return '#9CA3AF';
|
|
317
|
+
return COLORS.muted;
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
// =========================================================================
|
|
321
|
+
// Render: Overview
|
|
322
|
+
// =========================================================================
|
|
323
|
+
|
|
324
|
+
const renderOverview = () => (
|
|
325
|
+
<ScrollView style={styles.content} showsVerticalScrollIndicator={false}>
|
|
326
|
+
{loading ? (
|
|
327
|
+
<View style={styles.loadingContainer}>
|
|
328
|
+
<ActivityIndicator size="large" color={COLORS.primary} />
|
|
329
|
+
</View>
|
|
330
|
+
) : (
|
|
331
|
+
<>
|
|
332
|
+
{/* Profile header */}
|
|
333
|
+
{profile && (
|
|
334
|
+
<View style={styles.profileCard}>
|
|
335
|
+
<View style={styles.avatar}>
|
|
336
|
+
<Text style={styles.avatarText}>
|
|
337
|
+
{profile.name.split(' ').map((w) => w[0]).join('').slice(0, 2)}
|
|
338
|
+
</Text>
|
|
339
|
+
</View>
|
|
340
|
+
<Text style={styles.profileName}>{profile.name}</Text>
|
|
341
|
+
<View style={styles.tierBadgeRow}>
|
|
342
|
+
<View style={[styles.tierBadge, { backgroundColor: tierColor(profile.tier) + '22' }]}>
|
|
343
|
+
<Text style={[styles.tierBadgeText, { color: tierColor(profile.tier) }]}>
|
|
344
|
+
{profile.tier}
|
|
345
|
+
</Text>
|
|
346
|
+
</View>
|
|
347
|
+
</View>
|
|
348
|
+
<Text style={styles.totalPoints}>
|
|
349
|
+
{fmt(profile.points_balance)} {profile.points_unit}
|
|
350
|
+
</Text>
|
|
351
|
+
</View>
|
|
352
|
+
)}
|
|
353
|
+
|
|
354
|
+
{/* Connected brands */}
|
|
355
|
+
<Text style={styles.sectionTitle}>{t('account.programs_linked', { count: String(brands.length) })}</Text>
|
|
356
|
+
{brands.map((brand) => (
|
|
357
|
+
<Pressable key={brand.brand_id} style={styles.brandRow} onPress={() => handleBrandPress(brand)}>
|
|
358
|
+
<View style={[styles.brandIcon, { backgroundColor: COLORS.primary + '18' }]}>
|
|
359
|
+
<Text style={styles.brandIconText}>{brand.name[0]}</Text>
|
|
360
|
+
</View>
|
|
361
|
+
<View style={styles.brandInfo}>
|
|
362
|
+
<Text style={styles.brandName}>{brand.name}</Text>
|
|
363
|
+
<Text style={styles.brandBalance}>
|
|
364
|
+
{fmt(brand.balance)} {brand.currency_unit}
|
|
365
|
+
</Text>
|
|
366
|
+
</View>
|
|
367
|
+
<View style={styles.brandRight}>
|
|
368
|
+
<View style={[styles.tierPill, { backgroundColor: tierColor(brand.tier) + '22' }]}>
|
|
369
|
+
<Text style={[styles.tierPillText, { color: tierColor(brand.tier) }]}>{brand.tier}</Text>
|
|
370
|
+
</View>
|
|
371
|
+
<Text style={styles.chevron}>{'\u203A'}</Text>
|
|
372
|
+
</View>
|
|
373
|
+
</Pressable>
|
|
374
|
+
))}
|
|
375
|
+
|
|
376
|
+
{/* Activity timeline */}
|
|
377
|
+
{activity.length > 0 && (
|
|
378
|
+
<>
|
|
379
|
+
<Text style={[styles.sectionTitle, { marginTop: 24 }]}>{t('account.recent_activity')}</Text>
|
|
380
|
+
{activity.slice(0, 5).map((item) => (
|
|
381
|
+
<View key={item.id} style={styles.activityRow}>
|
|
382
|
+
<View
|
|
383
|
+
style={[
|
|
384
|
+
styles.activityDot,
|
|
385
|
+
{ backgroundColor: item.amount >= 0 ? COLORS.success : COLORS.error },
|
|
386
|
+
]}
|
|
387
|
+
/>
|
|
388
|
+
<View style={styles.activityInfo}>
|
|
389
|
+
<Text style={styles.activityDesc}>{item.description}</Text>
|
|
390
|
+
<Text style={styles.activityDate}>{item.date}</Text>
|
|
391
|
+
</View>
|
|
392
|
+
<Text
|
|
393
|
+
style={[
|
|
394
|
+
styles.activityAmount,
|
|
395
|
+
{ color: item.amount >= 0 ? COLORS.success : COLORS.error },
|
|
396
|
+
]}
|
|
397
|
+
>
|
|
398
|
+
{item.amount >= 0 ? '+' : ''}{fmt(item.amount)} {item.currency_unit}
|
|
399
|
+
</Text>
|
|
400
|
+
</View>
|
|
401
|
+
))}
|
|
402
|
+
</>
|
|
403
|
+
)}
|
|
404
|
+
|
|
405
|
+
{/* Spacer for footer */}
|
|
406
|
+
<View style={{ height: 20 }} />
|
|
407
|
+
</>
|
|
408
|
+
)}
|
|
409
|
+
</ScrollView>
|
|
410
|
+
);
|
|
411
|
+
|
|
412
|
+
// =========================================================================
|
|
413
|
+
// Render: Brand Detail
|
|
414
|
+
// =========================================================================
|
|
415
|
+
|
|
416
|
+
const renderBrandDetail = () => {
|
|
417
|
+
if (!selectedBrand) return null;
|
|
418
|
+
const b = selectedBrand;
|
|
419
|
+
return (
|
|
420
|
+
<ScrollView style={styles.content} showsVerticalScrollIndicator={false}>
|
|
421
|
+
<Pressable onPress={() => setView('overview')} style={styles.backButton}>
|
|
422
|
+
<Text style={styles.backText}>{'\u2190'} Back</Text>
|
|
423
|
+
</Pressable>
|
|
424
|
+
|
|
425
|
+
{/* Brand header */}
|
|
426
|
+
<View style={styles.brandDetailHeader}>
|
|
427
|
+
<View style={[styles.brandDetailIcon, { backgroundColor: COLORS.primary + '18' }]}>
|
|
428
|
+
<Text style={styles.brandDetailIconText}>{b.name[0]}</Text>
|
|
429
|
+
</View>
|
|
430
|
+
<Text style={styles.brandDetailName}>{b.name}</Text>
|
|
431
|
+
<Text style={styles.brandDetailCategory}>{b.category}</Text>
|
|
432
|
+
</View>
|
|
433
|
+
|
|
434
|
+
{/* Balance card */}
|
|
435
|
+
<View style={styles.detailCard}>
|
|
436
|
+
<Text style={styles.detailCardLabel}>Balance</Text>
|
|
437
|
+
<Text style={styles.detailCardValue}>
|
|
438
|
+
{fmt(b.balance)} {b.currency_unit}
|
|
439
|
+
</Text>
|
|
440
|
+
</View>
|
|
441
|
+
|
|
442
|
+
{/* Tier progress */}
|
|
443
|
+
<View style={styles.detailCard}>
|
|
444
|
+
<View style={styles.tierProgressHeader}>
|
|
445
|
+
<Text style={styles.detailCardLabel}>{b.tier} Tier</Text>
|
|
446
|
+
<Text style={styles.tierProgressNext}>Next: {b.tier_next}</Text>
|
|
447
|
+
</View>
|
|
448
|
+
<View style={styles.progressBarTrack}>
|
|
449
|
+
<View
|
|
450
|
+
style={[
|
|
451
|
+
styles.progressBarFill,
|
|
452
|
+
{ width: `${Math.min(b.tier_progress * 100, 100)}%`, backgroundColor: tierColor(b.tier) },
|
|
453
|
+
]}
|
|
454
|
+
/>
|
|
455
|
+
</View>
|
|
456
|
+
<Text style={styles.tierProgressPct}>{Math.round(b.tier_progress * 100)}%</Text>
|
|
457
|
+
</View>
|
|
458
|
+
|
|
459
|
+
{/* Earned / Redeemed */}
|
|
460
|
+
<View style={styles.statsRow}>
|
|
461
|
+
<View style={styles.statBox}>
|
|
462
|
+
<Text style={styles.statLabel}>Total Earned</Text>
|
|
463
|
+
<Text style={[styles.statValue, { color: COLORS.success }]}>{fmt(b.total_earned)}</Text>
|
|
464
|
+
</View>
|
|
465
|
+
<View style={styles.statBox}>
|
|
466
|
+
<Text style={styles.statLabel}>Total Redeemed</Text>
|
|
467
|
+
<Text style={[styles.statValue, { color: COLORS.error }]}>{fmt(b.total_redeemed)}</Text>
|
|
468
|
+
</View>
|
|
469
|
+
</View>
|
|
470
|
+
|
|
471
|
+
{/* Data sharing scopes */}
|
|
472
|
+
<View style={styles.detailCard}>
|
|
473
|
+
<Text style={styles.detailCardLabel}>Data Sharing</Text>
|
|
474
|
+
<View style={styles.scopeList}>
|
|
475
|
+
{b.scopes.map((scope) => (
|
|
476
|
+
<View key={scope} style={styles.scopeChip}>
|
|
477
|
+
<Text style={styles.scopeChipText}>{scope}</Text>
|
|
478
|
+
</View>
|
|
479
|
+
))}
|
|
480
|
+
</View>
|
|
481
|
+
</View>
|
|
482
|
+
|
|
483
|
+
{/* Linked date */}
|
|
484
|
+
<Text style={styles.linkedDate}>Linked {b.linked_at}</Text>
|
|
485
|
+
|
|
486
|
+
{/* Unlink */}
|
|
487
|
+
<Pressable style={styles.unlinkButton} onPress={() => handleUnlink(b)}>
|
|
488
|
+
<Text style={styles.unlinkButtonText}>{t('account.unlink')}</Text>
|
|
489
|
+
</Pressable>
|
|
490
|
+
|
|
491
|
+
<View style={{ height: 20 }} />
|
|
492
|
+
</ScrollView>
|
|
493
|
+
);
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
return (
|
|
497
|
+
<Modal visible={visible} animationType="slide" presentationStyle="pageSheet" onRequestClose={onClose}>
|
|
498
|
+
<View style={styles.container}>
|
|
499
|
+
<View style={styles.header}>
|
|
500
|
+
<Text style={styles.headerTitle}>{t('account.title')}</Text>
|
|
501
|
+
<Pressable onPress={onClose} hitSlop={12}>
|
|
502
|
+
<Text style={styles.closeButton}>{'\u2715'}</Text>
|
|
503
|
+
</Pressable>
|
|
504
|
+
</View>
|
|
505
|
+
|
|
506
|
+
{view === 'overview' ? renderOverview() : renderBrandDetail()}
|
|
507
|
+
|
|
508
|
+
<View style={styles.poweredByRow}>
|
|
509
|
+
<Text style={styles.poweredByText}>Powered by</Text>
|
|
510
|
+
<Image
|
|
511
|
+
source={{ uri: OJ_LOGO_URL }}
|
|
512
|
+
style={styles.poweredByLogo}
|
|
513
|
+
resizeMode="contain"
|
|
514
|
+
/>
|
|
515
|
+
</View>
|
|
516
|
+
</View>
|
|
517
|
+
</Modal>
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// =============================================================================
|
|
522
|
+
// Colors
|
|
523
|
+
// =============================================================================
|
|
524
|
+
|
|
525
|
+
const COLORS = {
|
|
526
|
+
primary: '#0c90eb',
|
|
527
|
+
navy: '#0D1B4C',
|
|
528
|
+
accent: '#3B82F6',
|
|
529
|
+
bg: '#FFFFFF',
|
|
530
|
+
surface: '#F8FAFC',
|
|
531
|
+
border: '#E2E8F0',
|
|
532
|
+
text: '#0F172A',
|
|
533
|
+
muted: '#94A3B8',
|
|
534
|
+
success: '#10B981',
|
|
535
|
+
error: '#EF4444',
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
// =============================================================================
|
|
539
|
+
// Styles
|
|
540
|
+
// =============================================================================
|
|
541
|
+
|
|
542
|
+
const styles = StyleSheet.create({
|
|
543
|
+
container: { flex: 1, backgroundColor: COLORS.bg },
|
|
544
|
+
header: {
|
|
545
|
+
flexDirection: 'row',
|
|
546
|
+
justifyContent: 'space-between',
|
|
547
|
+
alignItems: 'center',
|
|
548
|
+
paddingHorizontal: 20,
|
|
549
|
+
paddingVertical: 16,
|
|
550
|
+
borderBottomWidth: 1,
|
|
551
|
+
borderBottomColor: COLORS.border,
|
|
552
|
+
backgroundColor: COLORS.navy,
|
|
553
|
+
},
|
|
554
|
+
headerTitle: { fontSize: 18, fontWeight: '700', color: '#FFFFFF' },
|
|
555
|
+
closeButton: { fontSize: 20, color: '#FFFFFF', fontWeight: '600' },
|
|
556
|
+
content: { flex: 1, padding: 16 },
|
|
557
|
+
poweredByRow: {
|
|
558
|
+
flexDirection: 'row',
|
|
559
|
+
alignItems: 'center',
|
|
560
|
+
justifyContent: 'center',
|
|
561
|
+
gap: 6,
|
|
562
|
+
paddingVertical: 16,
|
|
563
|
+
opacity: 0.5,
|
|
564
|
+
borderTopWidth: 1,
|
|
565
|
+
borderTopColor: COLORS.border,
|
|
566
|
+
},
|
|
567
|
+
poweredByText: { fontSize: 11, color: '#9CA3AF' },
|
|
568
|
+
poweredByLogo: { width: 80, height: 16 },
|
|
569
|
+
loadingContainer: { flex: 1, justifyContent: 'center', alignItems: 'center', paddingTop: 80 },
|
|
570
|
+
|
|
571
|
+
// Profile
|
|
572
|
+
profileCard: { alignItems: 'center', paddingVertical: 20, marginBottom: 8 },
|
|
573
|
+
avatar: {
|
|
574
|
+
width: 64,
|
|
575
|
+
height: 64,
|
|
576
|
+
borderRadius: 32,
|
|
577
|
+
backgroundColor: COLORS.navy,
|
|
578
|
+
justifyContent: 'center',
|
|
579
|
+
alignItems: 'center',
|
|
580
|
+
marginBottom: 12,
|
|
581
|
+
},
|
|
582
|
+
avatarText: { fontSize: 22, fontWeight: '700', color: '#FFFFFF' },
|
|
583
|
+
profileName: { fontSize: 20, fontWeight: '700', color: COLORS.text, marginBottom: 6 },
|
|
584
|
+
tierBadgeRow: { flexDirection: 'row', marginBottom: 8 },
|
|
585
|
+
tierBadge: { paddingHorizontal: 12, paddingVertical: 4, borderRadius: 12 },
|
|
586
|
+
tierBadgeText: { fontSize: 13, fontWeight: '700' },
|
|
587
|
+
totalPoints: { fontSize: 24, fontWeight: '700', color: COLORS.primary },
|
|
588
|
+
|
|
589
|
+
// Section
|
|
590
|
+
sectionTitle: { fontSize: 14, fontWeight: '700', color: COLORS.muted, textTransform: 'uppercase', marginBottom: 10 },
|
|
591
|
+
|
|
592
|
+
// Brand rows
|
|
593
|
+
brandRow: {
|
|
594
|
+
flexDirection: 'row',
|
|
595
|
+
alignItems: 'center',
|
|
596
|
+
padding: 14,
|
|
597
|
+
borderWidth: 1,
|
|
598
|
+
borderColor: COLORS.border,
|
|
599
|
+
borderRadius: 12,
|
|
600
|
+
marginBottom: 8,
|
|
601
|
+
backgroundColor: COLORS.bg,
|
|
602
|
+
},
|
|
603
|
+
brandIcon: {
|
|
604
|
+
width: 40,
|
|
605
|
+
height: 40,
|
|
606
|
+
borderRadius: 20,
|
|
607
|
+
justifyContent: 'center',
|
|
608
|
+
alignItems: 'center',
|
|
609
|
+
marginRight: 12,
|
|
610
|
+
},
|
|
611
|
+
brandIconText: { fontSize: 16, fontWeight: '700', color: COLORS.primary },
|
|
612
|
+
brandInfo: { flex: 1 },
|
|
613
|
+
brandName: { fontSize: 15, fontWeight: '600', color: COLORS.text },
|
|
614
|
+
brandBalance: { fontSize: 13, color: COLORS.muted, marginTop: 2 },
|
|
615
|
+
brandRight: { flexDirection: 'row', alignItems: 'center' },
|
|
616
|
+
tierPill: { paddingHorizontal: 8, paddingVertical: 2, borderRadius: 8, marginRight: 8 },
|
|
617
|
+
tierPillText: { fontSize: 11, fontWeight: '700' },
|
|
618
|
+
chevron: { fontSize: 22, color: COLORS.muted },
|
|
619
|
+
|
|
620
|
+
// Activity
|
|
621
|
+
activityRow: { flexDirection: 'row', alignItems: 'center', paddingVertical: 10 },
|
|
622
|
+
activityDot: { width: 8, height: 8, borderRadius: 4, marginRight: 12 },
|
|
623
|
+
activityInfo: { flex: 1 },
|
|
624
|
+
activityDesc: { fontSize: 14, color: COLORS.text },
|
|
625
|
+
activityDate: { fontSize: 12, color: COLORS.muted, marginTop: 2 },
|
|
626
|
+
activityAmount: { fontSize: 14, fontWeight: '700' },
|
|
627
|
+
|
|
628
|
+
// Brand detail
|
|
629
|
+
backButton: { marginBottom: 12 },
|
|
630
|
+
backText: { fontSize: 15, color: COLORS.primary, fontWeight: '600' },
|
|
631
|
+
brandDetailHeader: { alignItems: 'center', paddingVertical: 16, marginBottom: 8 },
|
|
632
|
+
brandDetailIcon: {
|
|
633
|
+
width: 56,
|
|
634
|
+
height: 56,
|
|
635
|
+
borderRadius: 28,
|
|
636
|
+
justifyContent: 'center',
|
|
637
|
+
alignItems: 'center',
|
|
638
|
+
marginBottom: 10,
|
|
639
|
+
},
|
|
640
|
+
brandDetailIconText: { fontSize: 24, fontWeight: '700', color: COLORS.primary },
|
|
641
|
+
brandDetailName: { fontSize: 22, fontWeight: '700', color: COLORS.text },
|
|
642
|
+
brandDetailCategory: { fontSize: 13, color: COLORS.muted, marginTop: 2 },
|
|
643
|
+
|
|
644
|
+
// Detail cards
|
|
645
|
+
detailCard: {
|
|
646
|
+
padding: 16,
|
|
647
|
+
borderWidth: 1,
|
|
648
|
+
borderColor: COLORS.border,
|
|
649
|
+
borderRadius: 12,
|
|
650
|
+
backgroundColor: COLORS.bg,
|
|
651
|
+
marginBottom: 10,
|
|
652
|
+
},
|
|
653
|
+
detailCardLabel: { fontSize: 13, fontWeight: '600', color: COLORS.muted, textTransform: 'uppercase', marginBottom: 6 },
|
|
654
|
+
detailCardValue: { fontSize: 22, fontWeight: '700', color: COLORS.text },
|
|
655
|
+
|
|
656
|
+
// Tier progress
|
|
657
|
+
tierProgressHeader: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' },
|
|
658
|
+
tierProgressNext: { fontSize: 12, color: COLORS.muted },
|
|
659
|
+
progressBarTrack: { height: 8, borderRadius: 4, backgroundColor: COLORS.border, marginTop: 8 },
|
|
660
|
+
progressBarFill: { height: 8, borderRadius: 4, position: 'absolute', left: 0, top: 0 },
|
|
661
|
+
tierProgressPct: { fontSize: 12, color: COLORS.muted, marginTop: 4, textAlign: 'right' },
|
|
662
|
+
|
|
663
|
+
// Stats
|
|
664
|
+
statsRow: { flexDirection: 'row', marginBottom: 10 },
|
|
665
|
+
statBox: {
|
|
666
|
+
flex: 1,
|
|
667
|
+
padding: 14,
|
|
668
|
+
borderWidth: 1,
|
|
669
|
+
borderColor: COLORS.border,
|
|
670
|
+
borderRadius: 12,
|
|
671
|
+
marginRight: 5,
|
|
672
|
+
alignItems: 'center',
|
|
673
|
+
},
|
|
674
|
+
statLabel: { fontSize: 12, color: COLORS.muted, marginBottom: 4 },
|
|
675
|
+
statValue: { fontSize: 18, fontWeight: '700' },
|
|
676
|
+
|
|
677
|
+
// Scopes
|
|
678
|
+
scopeList: { flexDirection: 'row', flexWrap: 'wrap', marginTop: 4 },
|
|
679
|
+
scopeChip: {
|
|
680
|
+
paddingHorizontal: 10,
|
|
681
|
+
paddingVertical: 4,
|
|
682
|
+
borderRadius: 8,
|
|
683
|
+
backgroundColor: COLORS.primary + '14',
|
|
684
|
+
marginRight: 6,
|
|
685
|
+
marginBottom: 6,
|
|
686
|
+
},
|
|
687
|
+
scopeChipText: { fontSize: 12, color: COLORS.primary, fontWeight: '600' },
|
|
688
|
+
|
|
689
|
+
// Linked date
|
|
690
|
+
linkedDate: { fontSize: 12, color: COLORS.muted, textAlign: 'center', marginTop: 8, marginBottom: 12 },
|
|
691
|
+
|
|
692
|
+
// Unlink
|
|
693
|
+
unlinkButton: {
|
|
694
|
+
paddingVertical: 14,
|
|
695
|
+
borderRadius: 12,
|
|
696
|
+
borderWidth: 1,
|
|
697
|
+
borderColor: COLORS.error + '44',
|
|
698
|
+
alignItems: 'center',
|
|
699
|
+
},
|
|
700
|
+
unlinkButtonText: { fontSize: 15, fontWeight: '600', color: COLORS.error },
|
|
701
|
+
});
|