@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.
@@ -0,0 +1,281 @@
1
+ /**
2
+ * LoyaltyBanner — Discovery banner for home screens.
3
+ *
4
+ * Two states:
5
+ * - Linked: shows balance, brand logos, and CTA to view rewards
6
+ * - Unlinked: shows available brands and connect CTA
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * <LoyaltyBanner onPress={() => navigation.navigate('Rewards')} layout="full" />
11
+ * ```
12
+ */
13
+ import React from 'react';
14
+ import {
15
+ View,
16
+ Text,
17
+ Image,
18
+ Pressable,
19
+ StyleSheet,
20
+ type ViewStyle,
21
+ type TextStyle,
22
+ } from 'react-native';
23
+ import { useOuterJoyn } from '../useOuterJoyn';
24
+ import { OJ_COLORS } from '../core/colors';
25
+
26
+ const PRIMARY = OJ_COLORS.primary;
27
+ const NAVY = OJ_COLORS.navy;
28
+ const ACCENT = OJ_COLORS.accent;
29
+
30
+ export interface LoyaltyBannerProps {
31
+ /** Called when the banner is pressed */
32
+ onPress?: () => void;
33
+ /** Layout variant */
34
+ layout?: 'compact' | 'full';
35
+ /** Override the container style */
36
+ style?: ViewStyle;
37
+ /** Override the title text style */
38
+ titleStyle?: TextStyle;
39
+ /** Maximum number of logos to display before "+N more" */
40
+ maxLogos?: number;
41
+ }
42
+
43
+ export function LoyaltyBanner({
44
+ onPress,
45
+ layout = 'full',
46
+ style,
47
+ titleStyle,
48
+ maxLogos = 5,
49
+ }: LoyaltyBannerProps) {
50
+ const {
51
+ isReady,
52
+ isLinked,
53
+ linkedPrograms,
54
+ totalAvailablePoints,
55
+ totalAvailableValue,
56
+ brandConfig,
57
+ loading,
58
+ t,
59
+ } = useOuterJoyn();
60
+
61
+ if (!isReady && !loading) return null;
62
+
63
+ const primary = brandConfig?.theme?.primaryColor ?? PRIMARY;
64
+ const isCompact = layout === 'compact';
65
+ const visiblePrograms = linkedPrograms.slice(0, maxLogos);
66
+ const overflowCount = linkedPrograms.length - maxLogos;
67
+
68
+ return (
69
+ <Pressable
70
+ style={[
71
+ styles.container,
72
+ { backgroundColor: NAVY },
73
+ isCompact && styles.containerCompact,
74
+ style,
75
+ ]}
76
+ onPress={onPress}
77
+ accessibilityRole="button"
78
+ accessibilityLabel={isLinked ? `${t('banner.pay_with_points')}. ${(totalAvailableValue / 100).toFixed(2)} dollars available` : t('banner.use_points_here')}
79
+ >
80
+ {isLinked ? (
81
+ <>
82
+ <View style={styles.topRow}>
83
+ <View style={[styles.iconCircle, { backgroundColor: primary }]}>
84
+ <Text style={styles.iconText}>{'$'}</Text>
85
+ </View>
86
+ <Text style={[styles.label, titleStyle]}>{t('banner.pay_with_points').toUpperCase()}</Text>
87
+ <Text style={styles.chevron}>{'>'}</Text>
88
+ </View>
89
+
90
+ {!isCompact && (
91
+ <>
92
+ <Text style={styles.amount}>
93
+ {t('banner.available', { amount: `$${(totalAvailableValue / 100).toFixed(2)}` })}
94
+ </Text>
95
+ <Text style={styles.subtext}>
96
+ {t('banner.points_from', { count: totalAvailablePoints.toLocaleString(), programs: String(linkedPrograms.length) })}
97
+ </Text>
98
+ </>
99
+ )}
100
+
101
+ {isCompact && (
102
+ <Text style={styles.compactAmount}>
103
+ ${(totalAvailableValue / 100).toLocaleString()} /{' '}
104
+ {totalAvailablePoints.toLocaleString()} pts
105
+ </Text>
106
+ )}
107
+
108
+ <View style={styles.logoRow}>
109
+ {visiblePrograms.map((prog) =>
110
+ prog.brandLogoUrl ? (
111
+ <Image
112
+ key={prog.id}
113
+ source={{ uri: prog.brandLogoUrl }}
114
+ style={styles.brandLogo}
115
+ resizeMode="contain"
116
+ accessibilityLabel={prog.brandName}
117
+ />
118
+ ) : (
119
+ <View
120
+ key={prog.id}
121
+ style={[styles.brandDot, { backgroundColor: prog.iconColor || ACCENT }]}
122
+ />
123
+ ),
124
+ )}
125
+ {overflowCount > 0 && (
126
+ <View style={styles.moreBadge}>
127
+ <Text style={styles.moreText}>+{overflowCount}</Text>
128
+ </View>
129
+ )}
130
+ </View>
131
+ </>
132
+ ) : (
133
+ <>
134
+ <View style={styles.topRow}>
135
+ <View style={[styles.iconCircle, { backgroundColor: primary }]}>
136
+ <Text style={styles.iconText}>{'+'}</Text>
137
+ </View>
138
+ <Text style={[styles.label, titleStyle]}>{t('banner.new_pay_with_points').toUpperCase()}</Text>
139
+ <Text style={styles.chevron}>{'>'}</Text>
140
+ </View>
141
+
142
+ {!isCompact && (
143
+ <>
144
+ <Text style={styles.amount}>{t('banner.use_points_here')}</Text>
145
+ <Text style={styles.subtext}>
146
+ {t('connect.link_desc')}
147
+ </Text>
148
+ </>
149
+ )}
150
+
151
+ {isCompact && (
152
+ <Text style={styles.compactAmount}>
153
+ {t('connect.link_desc')}
154
+ </Text>
155
+ )}
156
+
157
+ {!isCompact && (
158
+ <View style={[styles.connectButton, { backgroundColor: primary }]} accessibilityRole="button" accessibilityLabel={t('banner.connect_programs')}>
159
+ <Text style={styles.connectText}>{t('banner.connect_programs')}</Text>
160
+ </View>
161
+ )}
162
+ </>
163
+ )}
164
+
165
+ {loading && (
166
+ <View style={styles.loadingOverlay}>
167
+ <Text style={styles.loadingText}>{t('common.loading')}</Text>
168
+ </View>
169
+ )}
170
+ </Pressable>
171
+ );
172
+ }
173
+
174
+ const styles = StyleSheet.create({
175
+ container: {
176
+ borderRadius: 16,
177
+ padding: 20,
178
+ overflow: 'hidden',
179
+ },
180
+ containerCompact: {
181
+ padding: 14,
182
+ borderRadius: 12,
183
+ },
184
+ topRow: {
185
+ flexDirection: 'row',
186
+ alignItems: 'center',
187
+ marginBottom: 8,
188
+ },
189
+ iconCircle: {
190
+ width: 28,
191
+ height: 28,
192
+ borderRadius: 14,
193
+ alignItems: 'center',
194
+ justifyContent: 'center',
195
+ marginRight: 8,
196
+ },
197
+ iconText: {
198
+ color: '#FFFFFF',
199
+ fontSize: 14,
200
+ fontWeight: '700',
201
+ },
202
+ label: {
203
+ color: 'rgba(255,255,255,0.9)',
204
+ fontSize: 11,
205
+ fontWeight: '700',
206
+ letterSpacing: 1.2,
207
+ flex: 1,
208
+ },
209
+ chevron: {
210
+ color: 'rgba(255,255,255,0.5)',
211
+ fontSize: 16,
212
+ fontWeight: '600',
213
+ },
214
+ amount: {
215
+ color: '#FFFFFF',
216
+ fontSize: 22,
217
+ fontWeight: '700',
218
+ marginBottom: 4,
219
+ },
220
+ compactAmount: {
221
+ color: '#FFFFFF',
222
+ fontSize: 15,
223
+ fontWeight: '600',
224
+ marginBottom: 4,
225
+ },
226
+ subtext: {
227
+ color: 'rgba(255,255,255,0.65)',
228
+ fontSize: 13,
229
+ marginBottom: 12,
230
+ },
231
+ logoRow: {
232
+ flexDirection: 'row',
233
+ alignItems: 'center',
234
+ gap: 8,
235
+ marginTop: 8,
236
+ },
237
+ brandLogo: {
238
+ width: 32,
239
+ height: 32,
240
+ borderRadius: 16,
241
+ backgroundColor: '#FFFFFF',
242
+ },
243
+ brandDot: {
244
+ width: 32,
245
+ height: 32,
246
+ borderRadius: 16,
247
+ },
248
+ moreBadge: {
249
+ backgroundColor: 'rgba(255,255,255,0.2)',
250
+ paddingHorizontal: 8,
251
+ paddingVertical: 4,
252
+ borderRadius: 10,
253
+ },
254
+ moreText: {
255
+ color: '#FFFFFF',
256
+ fontSize: 11,
257
+ fontWeight: '600',
258
+ },
259
+ connectButton: {
260
+ borderRadius: 10,
261
+ paddingVertical: 10,
262
+ alignItems: 'center',
263
+ marginTop: 8,
264
+ },
265
+ connectText: {
266
+ color: '#FFFFFF',
267
+ fontSize: 14,
268
+ fontWeight: '600',
269
+ },
270
+ loadingOverlay: {
271
+ ...StyleSheet.absoluteFillObject,
272
+ backgroundColor: 'rgba(13,27,76,0.6)',
273
+ alignItems: 'center',
274
+ justifyContent: 'center',
275
+ borderRadius: 16,
276
+ },
277
+ loadingText: {
278
+ color: 'rgba(255,255,255,0.7)',
279
+ fontSize: 13,
280
+ },
281
+ });
@@ -0,0 +1,273 @@
1
+ /**
2
+ * LoyaltyProfileSection — Drop-in profile card for user settings/profile screens.
3
+ *
4
+ * If linked: shows program list with logos, balances, membership IDs, and a "Manage" link.
5
+ * If not linked: shows a connect CTA banner.
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * <LoyaltyProfileSection
10
+ * onManagePress={() => navigation.navigate('LoyaltyManage')}
11
+ * onConnectPress={() => outerjoyn.openConnect()}
12
+ * />
13
+ * ```
14
+ */
15
+ import React from 'react';
16
+ import {
17
+ View,
18
+ Text,
19
+ Image,
20
+ Pressable,
21
+ StyleSheet,
22
+ type ViewStyle,
23
+ } from 'react-native';
24
+ import { useOuterJoyn } from '../useOuterJoyn';
25
+ import { OJ_COLORS } from '../core/colors';
26
+
27
+ const PRIMARY = OJ_COLORS.primary;
28
+ const NAVY = OJ_COLORS.navy;
29
+ const ACCENT = OJ_COLORS.accent;
30
+
31
+ export interface LoyaltyProfileSectionProps {
32
+ /** Called when "Manage" is pressed */
33
+ onManagePress?: () => void;
34
+ /** Called when the connect CTA is pressed */
35
+ onConnectPress?: () => void;
36
+ /** Override the container style */
37
+ style?: ViewStyle;
38
+ }
39
+
40
+ export function LoyaltyProfileSection({
41
+ onManagePress,
42
+ onConnectPress,
43
+ style,
44
+ }: LoyaltyProfileSectionProps) {
45
+ const {
46
+ isReady,
47
+ isLinked,
48
+ linkedPrograms,
49
+ totalAvailablePoints,
50
+ totalAvailableValue,
51
+ loading,
52
+ t,
53
+ } = useOuterJoyn();
54
+
55
+ if (!isReady && !loading) return null;
56
+
57
+ // Unlinked state
58
+ if (!isLinked) {
59
+ return (
60
+ <Pressable style={[styles.connectBanner, style]} onPress={onConnectPress} accessibilityRole="button" accessibilityLabel={t('profile.connect_programs')}>
61
+ <View style={[styles.connectIconCircle, { backgroundColor: PRIMARY }]}>
62
+ <Text style={styles.connectIcon}>+</Text>
63
+ </View>
64
+ <View style={styles.connectInfo}>
65
+ <Text style={styles.connectTitle}>{t('profile.connect_programs')}</Text>
66
+ <Text style={styles.connectDesc}>
67
+ {t('connect.link_desc')}
68
+ </Text>
69
+ </View>
70
+ <Text style={styles.connectChevron}>{'>'}</Text>
71
+ </Pressable>
72
+ );
73
+ }
74
+
75
+ // Linked state
76
+ return (
77
+ <View style={[styles.container, style]}>
78
+ {/* Section header */}
79
+ <View style={styles.sectionHeader}>
80
+ <Text style={styles.sectionTitle}>{t('profile.loyalty_programs')}</Text>
81
+ {onManagePress && (
82
+ <Pressable onPress={onManagePress} accessibilityRole="button" accessibilityLabel={t('profile.manage')}>
83
+ <Text style={[styles.manageLink, { color: PRIMARY }]}>{t('profile.manage')}</Text>
84
+ </Pressable>
85
+ )}
86
+ </View>
87
+
88
+ {/* Program list */}
89
+ {linkedPrograms.map((prog) => (
90
+ <View key={prog.id} style={styles.programCard}>
91
+ {prog.brandLogoUrl ? (
92
+ <Image
93
+ source={{ uri: prog.brandLogoUrl }}
94
+ style={styles.brandLogo}
95
+ resizeMode="contain"
96
+ />
97
+ ) : (
98
+ <View
99
+ style={[styles.brandDot, { backgroundColor: prog.iconColor || ACCENT }]}
100
+ />
101
+ )}
102
+ <View style={styles.programInfo}>
103
+ <Text style={styles.programName}>{prog.brandName}</Text>
104
+ <Text style={styles.memberId}>{prog.membershipId}</Text>
105
+ </View>
106
+ <View style={styles.balanceContainer}>
107
+ <Text style={styles.balance}>
108
+ {prog.pointsBalance.toLocaleString()}
109
+ </Text>
110
+ <Text style={styles.currencyName}>{prog.currencyName}</Text>
111
+ </View>
112
+ </View>
113
+ ))}
114
+
115
+ {/* Total summary */}
116
+ <View style={styles.totalRow}>
117
+ <View>
118
+ <Text style={styles.totalPoints}>
119
+ {totalAvailablePoints.toLocaleString()} points
120
+ </Text>
121
+ <Text style={styles.totalValue}>
122
+ {t('profile.total_value', { amount: `$${(totalAvailableValue / 100).toFixed(0)}`, count: String(linkedPrograms.length) })}
123
+ </Text>
124
+ </View>
125
+ </View>
126
+
127
+ {loading && <Text style={styles.loadingText}>{t('common.loading')}</Text>}
128
+ </View>
129
+ );
130
+ }
131
+
132
+ const styles = StyleSheet.create({
133
+ container: {
134
+ backgroundColor: '#FFFFFF',
135
+ borderRadius: 16,
136
+ padding: 16,
137
+ shadowColor: '#000',
138
+ shadowOffset: { width: 0, height: 2 },
139
+ shadowOpacity: 0.06,
140
+ shadowRadius: 6,
141
+ elevation: 2,
142
+ },
143
+ sectionHeader: {
144
+ flexDirection: 'row',
145
+ justifyContent: 'space-between',
146
+ alignItems: 'center',
147
+ marginBottom: 14,
148
+ },
149
+ sectionTitle: {
150
+ fontSize: 16,
151
+ fontWeight: '700',
152
+ color: NAVY,
153
+ },
154
+ manageLink: {
155
+ fontSize: 14,
156
+ fontWeight: '600',
157
+ },
158
+ programCard: {
159
+ flexDirection: 'row',
160
+ alignItems: 'center',
161
+ paddingVertical: 10,
162
+ borderBottomWidth: 1,
163
+ borderBottomColor: '#F3F4F6',
164
+ gap: 12,
165
+ },
166
+ brandLogo: {
167
+ width: 36,
168
+ height: 36,
169
+ borderRadius: 18,
170
+ backgroundColor: '#F3F4F6',
171
+ },
172
+ brandDot: {
173
+ width: 36,
174
+ height: 36,
175
+ borderRadius: 18,
176
+ },
177
+ programInfo: {
178
+ flex: 1,
179
+ },
180
+ programName: {
181
+ fontSize: 15,
182
+ fontWeight: '600',
183
+ color: NAVY,
184
+ },
185
+ memberId: {
186
+ fontSize: 12,
187
+ color: '#9CA3AF',
188
+ marginTop: 1,
189
+ },
190
+ balanceContainer: {
191
+ alignItems: 'flex-end',
192
+ },
193
+ balance: {
194
+ fontSize: 16,
195
+ fontWeight: '700',
196
+ color: NAVY,
197
+ },
198
+ currencyName: {
199
+ fontSize: 11,
200
+ color: '#9CA3AF',
201
+ marginTop: 1,
202
+ },
203
+ totalRow: {
204
+ flexDirection: 'row',
205
+ justifyContent: 'space-between',
206
+ alignItems: 'center',
207
+ marginTop: 14,
208
+ paddingTop: 12,
209
+ borderTopWidth: 1,
210
+ borderTopColor: '#E5E7EB',
211
+ },
212
+ totalPoints: {
213
+ fontSize: 15,
214
+ fontWeight: '700',
215
+ color: NAVY,
216
+ },
217
+ totalValue: {
218
+ fontSize: 13,
219
+ color: '#6B7280',
220
+ marginTop: 2,
221
+ },
222
+ loadingText: {
223
+ fontSize: 11,
224
+ color: '#9CA3AF',
225
+ marginTop: 8,
226
+ textAlign: 'center',
227
+ },
228
+
229
+ // Unlinked connect banner
230
+ connectBanner: {
231
+ flexDirection: 'row',
232
+ alignItems: 'center',
233
+ backgroundColor: '#FFFFFF',
234
+ borderRadius: 16,
235
+ padding: 16,
236
+ gap: 12,
237
+ shadowColor: '#000',
238
+ shadowOffset: { width: 0, height: 2 },
239
+ shadowOpacity: 0.06,
240
+ shadowRadius: 6,
241
+ elevation: 2,
242
+ },
243
+ connectIconCircle: {
244
+ width: 40,
245
+ height: 40,
246
+ borderRadius: 20,
247
+ alignItems: 'center',
248
+ justifyContent: 'center',
249
+ },
250
+ connectIcon: {
251
+ color: '#FFFFFF',
252
+ fontSize: 20,
253
+ fontWeight: '700',
254
+ },
255
+ connectInfo: {
256
+ flex: 1,
257
+ },
258
+ connectTitle: {
259
+ fontSize: 15,
260
+ fontWeight: '600',
261
+ color: NAVY,
262
+ },
263
+ connectDesc: {
264
+ fontSize: 13,
265
+ color: '#6B7280',
266
+ marginTop: 2,
267
+ },
268
+ connectChevron: {
269
+ fontSize: 16,
270
+ fontWeight: '600',
271
+ color: '#9CA3AF',
272
+ },
273
+ });