@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,267 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BalanceSummary — Displays aggregated loyalty balance.
|
|
3
|
+
*
|
|
4
|
+
* Three layout variants:
|
|
5
|
+
* - 'card': Full card with total value, points count, and per-program pills
|
|
6
|
+
* - 'compact': Single-row summary (value + points)
|
|
7
|
+
* - 'inline': Text-only rendering for embedding in other views
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* <BalanceSummary layout="card" onProgramPress={(p) => console.log(p.brandName)} />
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
import React from 'react';
|
|
15
|
+
import {
|
|
16
|
+
View,
|
|
17
|
+
Text,
|
|
18
|
+
Image,
|
|
19
|
+
Pressable,
|
|
20
|
+
ScrollView,
|
|
21
|
+
StyleSheet,
|
|
22
|
+
type ViewStyle,
|
|
23
|
+
type TextStyle,
|
|
24
|
+
} from 'react-native';
|
|
25
|
+
import { useOuterJoyn } from '../useOuterJoyn';
|
|
26
|
+
import { OJ_COLORS } from '../core/colors';
|
|
27
|
+
import type { LinkedProgram } from '../core/types';
|
|
28
|
+
|
|
29
|
+
const PRIMARY = OJ_COLORS.primary;
|
|
30
|
+
const NAVY = OJ_COLORS.navy;
|
|
31
|
+
const ACCENT = OJ_COLORS.accent;
|
|
32
|
+
|
|
33
|
+
export interface BalanceSummaryProps {
|
|
34
|
+
/** Layout variant */
|
|
35
|
+
layout?: 'compact' | 'card' | 'inline';
|
|
36
|
+
/** Called when a program pill is pressed */
|
|
37
|
+
onProgramPress?: (program: LinkedProgram) => void;
|
|
38
|
+
/** Override the container style */
|
|
39
|
+
style?: ViewStyle;
|
|
40
|
+
/** Override the value text style */
|
|
41
|
+
valueStyle?: TextStyle;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function BalanceSummary({
|
|
45
|
+
layout = 'card',
|
|
46
|
+
onProgramPress,
|
|
47
|
+
style,
|
|
48
|
+
valueStyle,
|
|
49
|
+
}: BalanceSummaryProps) {
|
|
50
|
+
const {
|
|
51
|
+
isReady,
|
|
52
|
+
isLinked,
|
|
53
|
+
linkedPrograms,
|
|
54
|
+
totalAvailablePoints,
|
|
55
|
+
totalAvailableValue,
|
|
56
|
+
loading,
|
|
57
|
+
t,
|
|
58
|
+
} = useOuterJoyn();
|
|
59
|
+
|
|
60
|
+
if (!isReady && !loading) return null;
|
|
61
|
+
|
|
62
|
+
const dollarValue = (totalAvailableValue / 100).toLocaleString(undefined, {
|
|
63
|
+
minimumFractionDigits: 2,
|
|
64
|
+
maximumFractionDigits: 2,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// Inline: just text
|
|
68
|
+
if (layout === 'inline') {
|
|
69
|
+
if (!isLinked) return null;
|
|
70
|
+
return (
|
|
71
|
+
<Text style={[styles.inlineText, style as TextStyle]}>
|
|
72
|
+
<Text style={[styles.inlineValue, valueStyle]}>${dollarValue}</Text>
|
|
73
|
+
{' '}({totalAvailablePoints.toLocaleString()} pts)
|
|
74
|
+
</Text>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Compact: single row
|
|
79
|
+
if (layout === 'compact') {
|
|
80
|
+
return (
|
|
81
|
+
<View style={[styles.compactContainer, style]}>
|
|
82
|
+
{isLinked ? (
|
|
83
|
+
<View style={styles.compactRow}>
|
|
84
|
+
<Text style={[styles.compactValue, valueStyle]}>${dollarValue}</Text>
|
|
85
|
+
<Text style={styles.compactPoints}>
|
|
86
|
+
{t('balance.points_across', { count: totalAvailablePoints.toLocaleString(), programs: String(linkedPrograms.length) })}
|
|
87
|
+
</Text>
|
|
88
|
+
</View>
|
|
89
|
+
) : (
|
|
90
|
+
<Text style={styles.emptyText}>{t('profile.connect_programs')}</Text>
|
|
91
|
+
)}
|
|
92
|
+
</View>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Card layout (default)
|
|
97
|
+
if (!isLinked) {
|
|
98
|
+
return (
|
|
99
|
+
<View style={[styles.cardContainer, style]}>
|
|
100
|
+
<Text style={styles.emptyTitle}>{t('profile.connect_programs')}</Text>
|
|
101
|
+
<Text style={styles.emptySubtitle}>
|
|
102
|
+
{t('connect.link_desc')}
|
|
103
|
+
</Text>
|
|
104
|
+
</View>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<View style={[styles.cardContainer, style]}>
|
|
110
|
+
{loading && <Text style={styles.loadingText}>{t('common.loading')}</Text>}
|
|
111
|
+
|
|
112
|
+
<Text style={styles.cardLabel}>{t('balance.total_value').toUpperCase()}</Text>
|
|
113
|
+
<Text style={[styles.cardValue, valueStyle]} accessibilityRole="text" accessibilityLabel={`${t('balance.total_value')}: ${dollarValue}`}>${dollarValue}</Text>
|
|
114
|
+
<Text style={styles.cardPoints}>
|
|
115
|
+
{t('balance.points_across', { count: totalAvailablePoints.toLocaleString(), programs: String(linkedPrograms.length) })}
|
|
116
|
+
</Text>
|
|
117
|
+
|
|
118
|
+
<ScrollView
|
|
119
|
+
horizontal
|
|
120
|
+
showsHorizontalScrollIndicator={false}
|
|
121
|
+
style={styles.pillScroll}
|
|
122
|
+
contentContainerStyle={styles.pillScrollContent}
|
|
123
|
+
>
|
|
124
|
+
{linkedPrograms.map((prog) => (
|
|
125
|
+
<Pressable
|
|
126
|
+
key={prog.id}
|
|
127
|
+
style={styles.programPill}
|
|
128
|
+
onPress={() => onProgramPress?.(prog)}
|
|
129
|
+
accessibilityRole="button"
|
|
130
|
+
accessibilityLabel={`${prog.brandName}: ${prog.pointsBalance.toLocaleString()} points`}
|
|
131
|
+
>
|
|
132
|
+
{prog.brandLogoUrl ? (
|
|
133
|
+
<Image
|
|
134
|
+
source={{ uri: prog.brandLogoUrl }}
|
|
135
|
+
style={styles.pillLogo}
|
|
136
|
+
resizeMode="contain"
|
|
137
|
+
/>
|
|
138
|
+
) : (
|
|
139
|
+
<View
|
|
140
|
+
style={[styles.pillDot, { backgroundColor: prog.iconColor || ACCENT }]}
|
|
141
|
+
/>
|
|
142
|
+
)}
|
|
143
|
+
<Text style={styles.pillText} numberOfLines={1}>
|
|
144
|
+
{prog.brandName}: {prog.pointsBalance.toLocaleString()}
|
|
145
|
+
</Text>
|
|
146
|
+
</Pressable>
|
|
147
|
+
))}
|
|
148
|
+
</ScrollView>
|
|
149
|
+
</View>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const styles = StyleSheet.create({
|
|
154
|
+
// Card layout
|
|
155
|
+
cardContainer: {
|
|
156
|
+
backgroundColor: '#FFFFFF',
|
|
157
|
+
borderRadius: 16,
|
|
158
|
+
padding: 20,
|
|
159
|
+
shadowColor: '#000',
|
|
160
|
+
shadowOffset: { width: 0, height: 2 },
|
|
161
|
+
shadowOpacity: 0.08,
|
|
162
|
+
shadowRadius: 8,
|
|
163
|
+
elevation: 3,
|
|
164
|
+
},
|
|
165
|
+
cardLabel: {
|
|
166
|
+
fontSize: 11,
|
|
167
|
+
fontWeight: '700',
|
|
168
|
+
letterSpacing: 1,
|
|
169
|
+
color: '#6B7280',
|
|
170
|
+
marginBottom: 4,
|
|
171
|
+
},
|
|
172
|
+
cardValue: {
|
|
173
|
+
fontSize: 32,
|
|
174
|
+
fontWeight: '800',
|
|
175
|
+
color: NAVY,
|
|
176
|
+
marginBottom: 2,
|
|
177
|
+
},
|
|
178
|
+
cardPoints: {
|
|
179
|
+
fontSize: 14,
|
|
180
|
+
color: '#6B7280',
|
|
181
|
+
marginBottom: 16,
|
|
182
|
+
},
|
|
183
|
+
pillScroll: {
|
|
184
|
+
marginHorizontal: -4,
|
|
185
|
+
},
|
|
186
|
+
pillScrollContent: {
|
|
187
|
+
gap: 8,
|
|
188
|
+
paddingHorizontal: 4,
|
|
189
|
+
},
|
|
190
|
+
programPill: {
|
|
191
|
+
flexDirection: 'row',
|
|
192
|
+
alignItems: 'center',
|
|
193
|
+
backgroundColor: '#F3F4F6',
|
|
194
|
+
borderRadius: 20,
|
|
195
|
+
paddingHorizontal: 12,
|
|
196
|
+
paddingVertical: 6,
|
|
197
|
+
gap: 6,
|
|
198
|
+
},
|
|
199
|
+
pillLogo: {
|
|
200
|
+
width: 20,
|
|
201
|
+
height: 20,
|
|
202
|
+
borderRadius: 10,
|
|
203
|
+
},
|
|
204
|
+
pillDot: {
|
|
205
|
+
width: 20,
|
|
206
|
+
height: 20,
|
|
207
|
+
borderRadius: 10,
|
|
208
|
+
},
|
|
209
|
+
pillText: {
|
|
210
|
+
fontSize: 13,
|
|
211
|
+
fontWeight: '500',
|
|
212
|
+
color: '#374151',
|
|
213
|
+
maxWidth: 160,
|
|
214
|
+
},
|
|
215
|
+
|
|
216
|
+
// Compact layout
|
|
217
|
+
compactContainer: {
|
|
218
|
+
paddingVertical: 8,
|
|
219
|
+
paddingHorizontal: 12,
|
|
220
|
+
},
|
|
221
|
+
compactRow: {
|
|
222
|
+
flexDirection: 'row',
|
|
223
|
+
alignItems: 'baseline',
|
|
224
|
+
gap: 8,
|
|
225
|
+
},
|
|
226
|
+
compactValue: {
|
|
227
|
+
fontSize: 18,
|
|
228
|
+
fontWeight: '700',
|
|
229
|
+
color: NAVY,
|
|
230
|
+
},
|
|
231
|
+
compactPoints: {
|
|
232
|
+
fontSize: 13,
|
|
233
|
+
color: '#6B7280',
|
|
234
|
+
},
|
|
235
|
+
|
|
236
|
+
// Inline layout
|
|
237
|
+
inlineText: {
|
|
238
|
+
fontSize: 14,
|
|
239
|
+
color: '#6B7280',
|
|
240
|
+
},
|
|
241
|
+
inlineValue: {
|
|
242
|
+
fontWeight: '700',
|
|
243
|
+
color: NAVY,
|
|
244
|
+
},
|
|
245
|
+
|
|
246
|
+
// Empty states
|
|
247
|
+
emptyText: {
|
|
248
|
+
fontSize: 13,
|
|
249
|
+
color: '#9CA3AF',
|
|
250
|
+
},
|
|
251
|
+
emptyTitle: {
|
|
252
|
+
fontSize: 17,
|
|
253
|
+
fontWeight: '600',
|
|
254
|
+
color: NAVY,
|
|
255
|
+
marginBottom: 6,
|
|
256
|
+
},
|
|
257
|
+
emptySubtitle: {
|
|
258
|
+
fontSize: 14,
|
|
259
|
+
color: '#6B7280',
|
|
260
|
+
},
|
|
261
|
+
|
|
262
|
+
loadingText: {
|
|
263
|
+
fontSize: 11,
|
|
264
|
+
color: '#9CA3AF',
|
|
265
|
+
marginBottom: 4,
|
|
266
|
+
},
|
|
267
|
+
});
|