@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,787 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CheckoutPointsApply — Per-program sliders for applying points at checkout.
|
|
3
|
+
*
|
|
4
|
+
* Renders one slider per linked program, with real-time dollar preview,
|
|
5
|
+
* "Use Max" shortcut, and an order summary showing per-program deductions.
|
|
6
|
+
*
|
|
7
|
+
* In live mode, calls the pay API to reserve/cancel/confirm points.
|
|
8
|
+
* In demo mode, operates on local state only (no API calls).
|
|
9
|
+
*
|
|
10
|
+
* Requires `@react-native-community/slider` as a peer dependency.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* const checkoutRef = useRef<CheckoutPointsApplyHandle>(null);
|
|
15
|
+
*
|
|
16
|
+
* <CheckoutPointsApply
|
|
17
|
+
* ref={checkoutRef}
|
|
18
|
+
* orderTotalCents={4999}
|
|
19
|
+
* onPointsChanged={(applied) => setDiscount(applied.totalValueAmount)}
|
|
20
|
+
* />
|
|
21
|
+
*
|
|
22
|
+
* // To finalize all reservations:
|
|
23
|
+
* await checkoutRef.current?.confirmAll();
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
import React, { useState, useCallback, useMemo, useRef, useEffect, useImperativeHandle, forwardRef } from 'react';
|
|
27
|
+
import {
|
|
28
|
+
View,
|
|
29
|
+
Text,
|
|
30
|
+
TextInput,
|
|
31
|
+
Image,
|
|
32
|
+
Pressable,
|
|
33
|
+
StyleSheet,
|
|
34
|
+
type ViewStyle,
|
|
35
|
+
} from 'react-native';
|
|
36
|
+
import Slider from '@react-native-community/slider';
|
|
37
|
+
import { useOuterJoyn } from '../useOuterJoyn';
|
|
38
|
+
import { OJ_COLORS } from '../core/colors';
|
|
39
|
+
|
|
40
|
+
const OJ_LOGO_URL = 'https://app.outerjoyn.com/outerjoyn-logo.png';
|
|
41
|
+
const PRIMARY = OJ_COLORS.primary;
|
|
42
|
+
const NAVY = OJ_COLORS.navy;
|
|
43
|
+
const ACCENT = OJ_COLORS.accent;
|
|
44
|
+
const SUCCESS = OJ_COLORS.success;
|
|
45
|
+
|
|
46
|
+
export interface AppliedPoints {
|
|
47
|
+
programId: string;
|
|
48
|
+
brandName: string;
|
|
49
|
+
pointsUsed: number;
|
|
50
|
+
valueAmount: number;
|
|
51
|
+
/** Server-issued token for the reservation (null in demo mode) */
|
|
52
|
+
redemptionToken: string | null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface PointsChangedPayload {
|
|
56
|
+
appliedPrograms: AppliedPoints[];
|
|
57
|
+
totalPointsUsed: number;
|
|
58
|
+
totalValueAmount: number;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface CheckoutPointsApplyHandle {
|
|
62
|
+
/** Confirm all applied reservations (calls POST /api/sdk/pay/confirm for each). Returns true if all succeeded. */
|
|
63
|
+
confirmAll: () => Promise<boolean>;
|
|
64
|
+
/** Cancel all applied reservations (calls POST /api/sdk/pay/cancel for each). */
|
|
65
|
+
cancelAll: () => Promise<void>;
|
|
66
|
+
/** Get all current redemption tokens keyed by program ID. */
|
|
67
|
+
getRedemptionTokens: () => Record<string, string>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface CheckoutPointsApplyProps {
|
|
71
|
+
/** Order total in cents (required) */
|
|
72
|
+
orderTotalCents: number;
|
|
73
|
+
/** Called whenever the user adjusts sliders */
|
|
74
|
+
onPointsChanged?: (payload: PointsChangedPayload) => void;
|
|
75
|
+
/** Called when the user taps "Link another program". If provided, overrides the default sheet flow. */
|
|
76
|
+
onLinkAnother?: () => void;
|
|
77
|
+
/** Override the container style */
|
|
78
|
+
style?: ViewStyle;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, CheckoutPointsApplyProps>(function CheckoutPointsApply({
|
|
82
|
+
orderTotalCents,
|
|
83
|
+
onPointsChanged,
|
|
84
|
+
onLinkAnother,
|
|
85
|
+
style,
|
|
86
|
+
}: CheckoutPointsApplyProps, ref) {
|
|
87
|
+
const ctx = useOuterJoyn();
|
|
88
|
+
const { isReady, isLinked, linkedPrograms, loading, demoMode, apiClient, t } = ctx;
|
|
89
|
+
|
|
90
|
+
const [sliderValues, setSliderValues] = useState<Record<string, number>>({});
|
|
91
|
+
const [confirmedPrograms, setConfirmedPrograms] = useState<Set<string>>(new Set());
|
|
92
|
+
/** Redemption tokens keyed by program ID */
|
|
93
|
+
const [redemptionTokens, setRedemptionTokens] = useState<Record<string, string>>({});
|
|
94
|
+
const [apiLoading, setApiLoading] = useState<Record<string, boolean>>({});
|
|
95
|
+
const [apiError, setApiError] = useState<Record<string, string>>({});
|
|
96
|
+
|
|
97
|
+
/** Ref to track tokens for cleanup on unmount */
|
|
98
|
+
const tokensRef = useRef<Record<string, string>>({});
|
|
99
|
+
tokensRef.current = redemptionTokens;
|
|
100
|
+
|
|
101
|
+
const programs = useMemo(
|
|
102
|
+
() => linkedPrograms.filter((p) => p.pointsBalance > 0),
|
|
103
|
+
[linkedPrograms],
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
const buildPayload = useCallback(
|
|
107
|
+
(values: Record<string, number>, confirmed: Set<string>, tokens: Record<string, string> = {}): PointsChangedPayload => {
|
|
108
|
+
const appliedPrograms: AppliedPoints[] = [];
|
|
109
|
+
for (const prog of programs) {
|
|
110
|
+
const pts = confirmed.has(prog.id) ? (values[prog.id] ?? 0) : 0;
|
|
111
|
+
if (pts > 0) {
|
|
112
|
+
appliedPrograms.push({
|
|
113
|
+
programId: prog.id,
|
|
114
|
+
brandName: prog.brandName,
|
|
115
|
+
pointsUsed: pts,
|
|
116
|
+
valueAmount: Math.round(pts * prog.pointValueAmount),
|
|
117
|
+
redemptionToken: tokens[prog.id] || null,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
appliedPrograms,
|
|
123
|
+
totalPointsUsed: appliedPrograms.reduce((s, a) => s + a.pointsUsed, 0),
|
|
124
|
+
totalValueAmount: appliedPrograms.reduce((s, a) => s + a.valueAmount, 0),
|
|
125
|
+
};
|
|
126
|
+
},
|
|
127
|
+
[programs],
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
const handleSliderChange = useCallback(
|
|
131
|
+
(progId: string, value: number) => {
|
|
132
|
+
const rounded = Math.round(value);
|
|
133
|
+
setSliderValues((prev) => {
|
|
134
|
+
const next = { ...prev, [progId]: rounded };
|
|
135
|
+
return next;
|
|
136
|
+
});
|
|
137
|
+
},
|
|
138
|
+
[],
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const handleApply = useCallback(
|
|
142
|
+
async (progId: string) => {
|
|
143
|
+
const prog = programs.find((p) => p.id === progId);
|
|
144
|
+
if (!prog) return;
|
|
145
|
+
|
|
146
|
+
const selectedPoints = sliderValues[progId] ?? 0;
|
|
147
|
+
if (selectedPoints <= 0) return;
|
|
148
|
+
|
|
149
|
+
// Validate orderTotalCents inside callback scope
|
|
150
|
+
const validOrderTotal = (typeof orderTotalCents === 'number' && !Number.isNaN(orderTotalCents))
|
|
151
|
+
? orderTotalCents : 0;
|
|
152
|
+
|
|
153
|
+
// In demo mode or no apiClient, skip API calls
|
|
154
|
+
if (demoMode || !apiClient) {
|
|
155
|
+
setConfirmedPrograms((prev) => {
|
|
156
|
+
const next = new Set(prev);
|
|
157
|
+
next.add(progId);
|
|
158
|
+
return next;
|
|
159
|
+
});
|
|
160
|
+
const confirmed = new Set([...confirmedPrograms, progId]);
|
|
161
|
+
const payload = buildPayload(sliderValues, confirmed, tokensRef.current);
|
|
162
|
+
queueMicrotask(() => onPointsChanged?.(payload));
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Live mode: reserve points on server
|
|
167
|
+
setApiLoading((prev) => ({ ...prev, [progId]: true }));
|
|
168
|
+
setApiError((prev) => { const n = { ...prev }; delete n[progId]; return n; });
|
|
169
|
+
|
|
170
|
+
try {
|
|
171
|
+
const idempotencyKey = `checkout_${progId}_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
|
172
|
+
const res = await apiClient.post<{
|
|
173
|
+
paymentSessionId?: string;
|
|
174
|
+
reservations?: Array<{
|
|
175
|
+
redemptionToken: string;
|
|
176
|
+
pointsReserved?: number;
|
|
177
|
+
valueAmount?: number;
|
|
178
|
+
}>;
|
|
179
|
+
}>('/api/sdk/pay/checkout', {
|
|
180
|
+
merchantOrderId: `checkout_${Date.now()}`,
|
|
181
|
+
orderTotalCents: validOrderTotal,
|
|
182
|
+
currencyCode: 'USD',
|
|
183
|
+
reservations: [{
|
|
184
|
+
memberCurrencyId: prog.memberCurrencyId,
|
|
185
|
+
currencyId: prog.currencyId,
|
|
186
|
+
pointsAmount: selectedPoints,
|
|
187
|
+
pointValueAmount: prog.pointValueAmount,
|
|
188
|
+
}],
|
|
189
|
+
idempotency_key: idempotencyKey,
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// Handle different response shapes: { reservations: [...] } or { data: { reservations: [...] } }
|
|
193
|
+
const resData = (res as any)?.data ?? res;
|
|
194
|
+
const reservations = resData?.reservations ?? (resData?.reservation ? [resData.reservation] : []);
|
|
195
|
+
const reservation = reservations?.[0];
|
|
196
|
+
const redemptionToken = reservation?.redemptionToken ?? reservation?.redemption_token ?? reservation?.token;
|
|
197
|
+
if (!redemptionToken) {
|
|
198
|
+
// No token returned — reservation failed
|
|
199
|
+
throw new Error('No reservation token returned from server');
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const newTokens = { ...redemptionTokens, [progId]: redemptionToken };
|
|
203
|
+
setRedemptionTokens(newTokens);
|
|
204
|
+
|
|
205
|
+
setConfirmedPrograms((prev) => {
|
|
206
|
+
const next = new Set(prev);
|
|
207
|
+
next.add(progId);
|
|
208
|
+
return next;
|
|
209
|
+
});
|
|
210
|
+
// Fire callback outside setState to avoid "setState during render" warning
|
|
211
|
+
const confirmed = new Set([...confirmedPrograms, progId]);
|
|
212
|
+
const payload = buildPayload(sliderValues, confirmed, newTokens);
|
|
213
|
+
queueMicrotask(() => onPointsChanged?.(payload));
|
|
214
|
+
} catch (err: any) {
|
|
215
|
+
// Revert slider on error
|
|
216
|
+
setSliderValues((prev) => ({ ...prev, [progId]: 0 }));
|
|
217
|
+
setApiError((prev) => ({ ...prev, [progId]: err.message || 'Failed to reserve points' }));
|
|
218
|
+
} finally {
|
|
219
|
+
setApiLoading((prev) => ({ ...prev, [progId]: false }));
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
[programs, sliderValues, demoMode, apiClient, orderTotalCents, buildPayload, onPointsChanged, redemptionTokens],
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
const handleRemove = useCallback(
|
|
226
|
+
async (progId: string) => {
|
|
227
|
+
const token = redemptionTokens[progId];
|
|
228
|
+
|
|
229
|
+
// Update local state immediately
|
|
230
|
+
setConfirmedPrograms((prev) => {
|
|
231
|
+
const next = new Set(prev);
|
|
232
|
+
next.delete(progId);
|
|
233
|
+
return next;
|
|
234
|
+
});
|
|
235
|
+
const confirmed = new Set(confirmedPrograms);
|
|
236
|
+
confirmed.delete(progId);
|
|
237
|
+
const newTokens = { ...tokensRef.current };
|
|
238
|
+
delete newTokens[progId];
|
|
239
|
+
const payload = buildPayload(sliderValues, confirmed, newTokens);
|
|
240
|
+
queueMicrotask(() => onPointsChanged?.(payload));
|
|
241
|
+
setSliderValues((prev) => ({ ...prev, [progId]: 0 }));
|
|
242
|
+
setRedemptionTokens((prev) => {
|
|
243
|
+
const next = { ...prev };
|
|
244
|
+
delete next[progId];
|
|
245
|
+
return next;
|
|
246
|
+
});
|
|
247
|
+
setApiError((prev) => { const n = { ...prev }; delete n[progId]; return n; });
|
|
248
|
+
|
|
249
|
+
// In live mode, cancel the reservation on the server
|
|
250
|
+
if (!demoMode && apiClient && token) {
|
|
251
|
+
try {
|
|
252
|
+
await apiClient.post('/api/sdk/pay/cancel', { redemptionToken: token });
|
|
253
|
+
} catch (err: any) {
|
|
254
|
+
// Log but don't crash — local state is already cleared
|
|
255
|
+
console.warn('[OuterJoyn] Cancel reservation failed:', err.message);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
[sliderValues, buildPayload, onPointsChanged, demoMode, apiClient, redemptionTokens],
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
const handleUseMax = useCallback(
|
|
263
|
+
(progId: string, maxPts: number) => {
|
|
264
|
+
setSliderValues((prev) => {
|
|
265
|
+
const next = { ...prev, [progId]: maxPts };
|
|
266
|
+
return next;
|
|
267
|
+
});
|
|
268
|
+
},
|
|
269
|
+
[],
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
// Expose confirmAll / cancelAll via ref
|
|
273
|
+
useImperativeHandle(ref, () => ({
|
|
274
|
+
confirmAll: async () => {
|
|
275
|
+
if (demoMode || !apiClient) return true;
|
|
276
|
+
|
|
277
|
+
let allConfirmed = true;
|
|
278
|
+
for (const [progId, token] of Object.entries(tokensRef.current)) {
|
|
279
|
+
if (!token) continue;
|
|
280
|
+
try {
|
|
281
|
+
await apiClient.post('/api/sdk/pay/confirm', { redemptionToken: token });
|
|
282
|
+
// Clear token so unmount cleanup doesn't cancel a confirmed reservation
|
|
283
|
+
delete tokensRef.current[progId];
|
|
284
|
+
} catch (err: any) {
|
|
285
|
+
console.error('[OuterJoyn] Confirm failed:', err.message);
|
|
286
|
+
allConfirmed = false;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return allConfirmed;
|
|
290
|
+
},
|
|
291
|
+
cancelAll: async () => {
|
|
292
|
+
if (demoMode || !apiClient) return;
|
|
293
|
+
|
|
294
|
+
const tokens = { ...tokensRef.current };
|
|
295
|
+
for (const [, token] of Object.entries(tokens)) {
|
|
296
|
+
if (!token) continue;
|
|
297
|
+
try {
|
|
298
|
+
await apiClient.post('/api/sdk/pay/cancel', { redemptionToken: token });
|
|
299
|
+
} catch (err: any) {
|
|
300
|
+
console.warn('[OuterJoyn] Cancel failed:', err.message);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Clear local state
|
|
305
|
+
setConfirmedPrograms(new Set());
|
|
306
|
+
setSliderValues({});
|
|
307
|
+
setRedemptionTokens({});
|
|
308
|
+
setApiError({});
|
|
309
|
+
},
|
|
310
|
+
/** Get all current redemption tokens (for host apps that confirm directly) */
|
|
311
|
+
getRedemptionTokens: () => ({ ...tokensRef.current }),
|
|
312
|
+
}), [demoMode, apiClient, redemptionTokens]);
|
|
313
|
+
|
|
314
|
+
// NOTE: No unmount cleanup. Reservations expire server-side (10 min TTL).
|
|
315
|
+
// Previous cleanup cancelled confirmed reservations due to a race between
|
|
316
|
+
// confirmAll (async) and the synchronous unmount effect.
|
|
317
|
+
|
|
318
|
+
// Validate orderTotalCents — fall back to 0 if NaN/undefined to prevent crashes
|
|
319
|
+
const safeOrderTotalCents = (typeof orderTotalCents === 'number' && !Number.isNaN(orderTotalCents))
|
|
320
|
+
? orderTotalCents
|
|
321
|
+
: 0;
|
|
322
|
+
|
|
323
|
+
if (!isReady && !loading) return null;
|
|
324
|
+
if (!isLinked || programs.length === 0) return null;
|
|
325
|
+
|
|
326
|
+
// Calculate already-confirmed total to cap remaining programs
|
|
327
|
+
const confirmedTotalCents = programs.reduce((sum, prog) => {
|
|
328
|
+
if (confirmedPrograms.has(prog.id)) {
|
|
329
|
+
return sum + Math.round((sliderValues[prog.id] ?? 0) * prog.pointValueAmount);
|
|
330
|
+
}
|
|
331
|
+
return sum;
|
|
332
|
+
}, 0);
|
|
333
|
+
|
|
334
|
+
return (
|
|
335
|
+
<View style={[styles.container, style]}>
|
|
336
|
+
<Text style={styles.sectionLabel}>{t('banner.pay_with_points')}</Text>
|
|
337
|
+
|
|
338
|
+
{programs.map((prog) => {
|
|
339
|
+
const isConfirmed = confirmedPrograms.has(prog.id);
|
|
340
|
+
const currentPts = sliderValues[prog.id] ?? 0;
|
|
341
|
+
const previewValueAmount = Math.round(currentPts * prog.pointValueAmount);
|
|
342
|
+
const previewDollars = (previewValueAmount / 100).toFixed(2);
|
|
343
|
+
|
|
344
|
+
// Cap slider so total doesn't exceed order
|
|
345
|
+
const otherConfirmedCents = confirmedTotalCents - (isConfirmed ? previewValueAmount : 0);
|
|
346
|
+
const remainingCents = Math.max(0, safeOrderTotalCents - otherConfirmedCents);
|
|
347
|
+
const maxPointsForRemaining =
|
|
348
|
+
prog.pointValueAmount > 0
|
|
349
|
+
? Math.ceil(remainingCents / prog.pointValueAmount)
|
|
350
|
+
: prog.pointsBalance;
|
|
351
|
+
const maxSlider = Math.min(prog.pointsBalance, maxPointsForRemaining);
|
|
352
|
+
const sliderStep = Math.max(1, Math.floor(maxSlider / 100));
|
|
353
|
+
|
|
354
|
+
const isLoading = apiLoading[prog.id] ?? false;
|
|
355
|
+
const errorMsg = apiError[prog.id];
|
|
356
|
+
|
|
357
|
+
return (
|
|
358
|
+
<View
|
|
359
|
+
key={prog.id}
|
|
360
|
+
style={[styles.programCard, isConfirmed && styles.programCardApplied]}
|
|
361
|
+
>
|
|
362
|
+
{/* Header */}
|
|
363
|
+
<View style={styles.programHeader}>
|
|
364
|
+
{prog.brandLogoUrl ? (
|
|
365
|
+
<Image
|
|
366
|
+
source={{ uri: prog.brandLogoUrl }}
|
|
367
|
+
style={styles.brandLogo}
|
|
368
|
+
resizeMode="contain"
|
|
369
|
+
/>
|
|
370
|
+
) : (
|
|
371
|
+
<View
|
|
372
|
+
style={[
|
|
373
|
+
styles.brandLogoFallback,
|
|
374
|
+
{ backgroundColor: prog.iconColor || ACCENT },
|
|
375
|
+
]}
|
|
376
|
+
>
|
|
377
|
+
<Text style={styles.brandLogoFallbackText}>
|
|
378
|
+
{prog.brandName.charAt(0)}
|
|
379
|
+
</Text>
|
|
380
|
+
</View>
|
|
381
|
+
)}
|
|
382
|
+
<View style={styles.programInfo}>
|
|
383
|
+
<Text style={styles.programName}>{prog.brandName}</Text>
|
|
384
|
+
<Text style={styles.programBalance}>
|
|
385
|
+
{prog.pointsBalance.toLocaleString()} {prog.currencyName}
|
|
386
|
+
<Text style={styles.programValueHint}>
|
|
387
|
+
{' '}
|
|
388
|
+
· $
|
|
389
|
+
{(
|
|
390
|
+
Math.round(prog.pointsBalance * prog.pointValueAmount) / 100
|
|
391
|
+
).toFixed(2)}{' '}
|
|
392
|
+
value
|
|
393
|
+
</Text>
|
|
394
|
+
</Text>
|
|
395
|
+
</View>
|
|
396
|
+
{isConfirmed && !isLoading && (
|
|
397
|
+
<Pressable onPress={() => handleRemove(prog.id)} hitSlop={8} accessibilityRole="button" accessibilityLabel={`Remove ${prog.brandName} points`}>
|
|
398
|
+
<Text style={styles.removeButton}>{'\u2715'}</Text>
|
|
399
|
+
</Pressable>
|
|
400
|
+
)}
|
|
401
|
+
</View>
|
|
402
|
+
|
|
403
|
+
{/* Error message */}
|
|
404
|
+
{errorMsg && (
|
|
405
|
+
<Text style={styles.errorText}>{errorMsg}</Text>
|
|
406
|
+
)}
|
|
407
|
+
|
|
408
|
+
{/* Applied state */}
|
|
409
|
+
{isConfirmed ? (
|
|
410
|
+
<View style={styles.appliedRow}>
|
|
411
|
+
<Text style={[styles.checkmark, { color: SUCCESS }]}>{'\u2714'}</Text>
|
|
412
|
+
<Text style={styles.appliedLabel}>
|
|
413
|
+
{currentPts.toLocaleString()} pts applied
|
|
414
|
+
</Text>
|
|
415
|
+
<Text style={styles.appliedAmount}>-${previewDollars}</Text>
|
|
416
|
+
</View>
|
|
417
|
+
) : (
|
|
418
|
+
<>
|
|
419
|
+
{maxSlider > 0 && (
|
|
420
|
+
<>
|
|
421
|
+
<Slider
|
|
422
|
+
style={styles.slider}
|
|
423
|
+
minimumValue={0}
|
|
424
|
+
maximumValue={maxSlider}
|
|
425
|
+
step={sliderStep}
|
|
426
|
+
value={currentPts}
|
|
427
|
+
onValueChange={(v: number) => handleSliderChange(prog.id, v)}
|
|
428
|
+
minimumTrackTintColor={prog.brandColor || prog.iconColor || PRIMARY}
|
|
429
|
+
maximumTrackTintColor="#E5E7EB"
|
|
430
|
+
thumbTintColor={prog.brandColor || prog.iconColor || PRIMARY}
|
|
431
|
+
disabled={isLoading}
|
|
432
|
+
/>
|
|
433
|
+
<View style={styles.sliderRow}>
|
|
434
|
+
<View style={styles.ptsInputRow}>
|
|
435
|
+
<TextInput
|
|
436
|
+
style={styles.ptsInput}
|
|
437
|
+
value={String(currentPts)}
|
|
438
|
+
onChangeText={(text) => {
|
|
439
|
+
const num = parseInt(text.replace(/[^0-9]/g, ''), 10);
|
|
440
|
+
if (isNaN(num)) { handleSliderChange(prog.id, 0); return; }
|
|
441
|
+
handleSliderChange(prog.id, Math.min(num, maxSlider));
|
|
442
|
+
}}
|
|
443
|
+
keyboardType="number-pad"
|
|
444
|
+
selectTextOnFocus
|
|
445
|
+
editable={!isLoading}
|
|
446
|
+
accessibilityLabel={`Enter ${prog.brandName} points`}
|
|
447
|
+
/>
|
|
448
|
+
<Text style={styles.sliderPts}> pts</Text>
|
|
449
|
+
</View>
|
|
450
|
+
<Text
|
|
451
|
+
style={[
|
|
452
|
+
styles.sliderDollar,
|
|
453
|
+
{ color: prog.brandColor || prog.iconColor || PRIMARY },
|
|
454
|
+
]}
|
|
455
|
+
>
|
|
456
|
+
${previewDollars} off
|
|
457
|
+
</Text>
|
|
458
|
+
</View>
|
|
459
|
+
<View style={styles.programActions}>
|
|
460
|
+
<Pressable
|
|
461
|
+
style={styles.maxButton}
|
|
462
|
+
onPress={() => handleUseMax(prog.id, maxSlider)}
|
|
463
|
+
disabled={isLoading}
|
|
464
|
+
accessibilityRole="button"
|
|
465
|
+
accessibilityLabel={`Use maximum ${prog.brandName} points`}
|
|
466
|
+
>
|
|
467
|
+
<Text style={styles.maxButtonText}>{t('pay.use_max')}</Text>
|
|
468
|
+
</Pressable>
|
|
469
|
+
{currentPts > 0 && (
|
|
470
|
+
<Pressable
|
|
471
|
+
style={[
|
|
472
|
+
styles.applyButton,
|
|
473
|
+
{
|
|
474
|
+
backgroundColor:
|
|
475
|
+
prog.brandColor || prog.iconColor || PRIMARY,
|
|
476
|
+
opacity: isLoading ? 0.6 : 1,
|
|
477
|
+
},
|
|
478
|
+
]}
|
|
479
|
+
onPress={() => handleApply(prog.id)}
|
|
480
|
+
disabled={isLoading}
|
|
481
|
+
accessibilityRole="button"
|
|
482
|
+
accessibilityLabel={`Apply ${currentPts.toLocaleString()} ${prog.brandName} points for ${previewDollars} dollars off`}
|
|
483
|
+
>
|
|
484
|
+
<Text style={styles.applyButtonText}>
|
|
485
|
+
{isLoading ? 'Reserving...' : `Apply -$${previewDollars}`}
|
|
486
|
+
</Text>
|
|
487
|
+
</Pressable>
|
|
488
|
+
)}
|
|
489
|
+
</View>
|
|
490
|
+
</>
|
|
491
|
+
)}
|
|
492
|
+
</>
|
|
493
|
+
)}
|
|
494
|
+
</View>
|
|
495
|
+
);
|
|
496
|
+
})}
|
|
497
|
+
|
|
498
|
+
{/* Order summary */}
|
|
499
|
+
{confirmedPrograms.size > 0 && (
|
|
500
|
+
<View style={styles.summaryContainer}>
|
|
501
|
+
<Text style={styles.summaryTitle}>{t('pay.order_summary')}</Text>
|
|
502
|
+
{programs
|
|
503
|
+
.filter((p) => confirmedPrograms.has(p.id))
|
|
504
|
+
.map((prog) => {
|
|
505
|
+
const pts = sliderValues[prog.id] ?? 0;
|
|
506
|
+
const val = Math.round(pts * prog.pointValueAmount) / 100;
|
|
507
|
+
return (
|
|
508
|
+
<View key={prog.id} style={styles.summaryRow}>
|
|
509
|
+
<Text style={styles.summaryBrand}>{prog.brandName}</Text>
|
|
510
|
+
<Text style={styles.summaryDeduction}>
|
|
511
|
+
-{pts.toLocaleString()} pts (-${val.toFixed(2)})
|
|
512
|
+
</Text>
|
|
513
|
+
</View>
|
|
514
|
+
);
|
|
515
|
+
})}
|
|
516
|
+
<View style={[styles.summaryRow, styles.summaryTotalRow]}>
|
|
517
|
+
<Text style={styles.summaryTotalLabel}>Total Discount</Text>
|
|
518
|
+
<Text style={styles.summaryTotalValue}>
|
|
519
|
+
-${(confirmedTotalCents / 100).toFixed(2)}
|
|
520
|
+
</Text>
|
|
521
|
+
</View>
|
|
522
|
+
</View>
|
|
523
|
+
)}
|
|
524
|
+
|
|
525
|
+
{/* Link another program */}
|
|
526
|
+
{(onLinkAnother || ctx.openConnect) && (
|
|
527
|
+
<Pressable
|
|
528
|
+
style={styles.linkMoreButton}
|
|
529
|
+
onPress={() => (onLinkAnother ? onLinkAnother() : ctx.openConnect?.())}
|
|
530
|
+
accessibilityRole="button"
|
|
531
|
+
accessibilityLabel="Link another loyalty program"
|
|
532
|
+
>
|
|
533
|
+
<Text style={styles.linkMorePlus}>+</Text>
|
|
534
|
+
<Text style={styles.linkMoreText}>Link another program</Text>
|
|
535
|
+
</Pressable>
|
|
536
|
+
)}
|
|
537
|
+
|
|
538
|
+
<View style={styles.poweredByRow}>
|
|
539
|
+
<Text style={styles.poweredByText}>Powered by</Text>
|
|
540
|
+
<Image
|
|
541
|
+
source={{ uri: OJ_LOGO_URL }}
|
|
542
|
+
style={styles.poweredByLogo}
|
|
543
|
+
resizeMode="contain"
|
|
544
|
+
/>
|
|
545
|
+
</View>
|
|
546
|
+
</View>
|
|
547
|
+
);
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
const styles = StyleSheet.create({
|
|
551
|
+
container: {},
|
|
552
|
+
sectionLabel: {
|
|
553
|
+
fontSize: 16,
|
|
554
|
+
fontWeight: '700',
|
|
555
|
+
color: NAVY,
|
|
556
|
+
marginBottom: 12,
|
|
557
|
+
},
|
|
558
|
+
programCard: {
|
|
559
|
+
backgroundColor: '#FFFFFF',
|
|
560
|
+
borderRadius: 12,
|
|
561
|
+
padding: 16,
|
|
562
|
+
marginBottom: 10,
|
|
563
|
+
borderWidth: 1,
|
|
564
|
+
borderColor: '#E5E7EB',
|
|
565
|
+
},
|
|
566
|
+
programCardApplied: {
|
|
567
|
+
borderColor: SUCCESS,
|
|
568
|
+
backgroundColor: '#F0FDF4',
|
|
569
|
+
},
|
|
570
|
+
programHeader: {
|
|
571
|
+
flexDirection: 'row',
|
|
572
|
+
alignItems: 'center',
|
|
573
|
+
gap: 10,
|
|
574
|
+
},
|
|
575
|
+
brandLogo: {
|
|
576
|
+
width: 36,
|
|
577
|
+
height: 36,
|
|
578
|
+
borderRadius: 18,
|
|
579
|
+
backgroundColor: '#F3F4F6',
|
|
580
|
+
},
|
|
581
|
+
brandLogoFallback: {
|
|
582
|
+
width: 36,
|
|
583
|
+
height: 36,
|
|
584
|
+
borderRadius: 18,
|
|
585
|
+
alignItems: 'center',
|
|
586
|
+
justifyContent: 'center',
|
|
587
|
+
},
|
|
588
|
+
brandLogoFallbackText: {
|
|
589
|
+
color: '#FFFFFF',
|
|
590
|
+
fontSize: 16,
|
|
591
|
+
fontWeight: '700',
|
|
592
|
+
},
|
|
593
|
+
programInfo: {
|
|
594
|
+
flex: 1,
|
|
595
|
+
},
|
|
596
|
+
programName: {
|
|
597
|
+
fontSize: 15,
|
|
598
|
+
fontWeight: '600',
|
|
599
|
+
color: NAVY,
|
|
600
|
+
},
|
|
601
|
+
programBalance: {
|
|
602
|
+
fontSize: 13,
|
|
603
|
+
color: '#6B7280',
|
|
604
|
+
marginTop: 1,
|
|
605
|
+
},
|
|
606
|
+
programValueHint: {
|
|
607
|
+
color: '#9CA3AF',
|
|
608
|
+
},
|
|
609
|
+
removeButton: {
|
|
610
|
+
fontSize: 16,
|
|
611
|
+
color: '#9CA3AF',
|
|
612
|
+
fontWeight: '600',
|
|
613
|
+
padding: 4,
|
|
614
|
+
},
|
|
615
|
+
errorText: {
|
|
616
|
+
fontSize: 12,
|
|
617
|
+
color: '#DC2626',
|
|
618
|
+
marginTop: 6,
|
|
619
|
+
marginBottom: 2,
|
|
620
|
+
},
|
|
621
|
+
appliedRow: {
|
|
622
|
+
flexDirection: 'row',
|
|
623
|
+
alignItems: 'center',
|
|
624
|
+
marginTop: 10,
|
|
625
|
+
gap: 6,
|
|
626
|
+
},
|
|
627
|
+
checkmark: {
|
|
628
|
+
fontSize: 16,
|
|
629
|
+
fontWeight: '700',
|
|
630
|
+
},
|
|
631
|
+
appliedLabel: {
|
|
632
|
+
fontSize: 13,
|
|
633
|
+
color: '#374151',
|
|
634
|
+
flex: 1,
|
|
635
|
+
},
|
|
636
|
+
appliedAmount: {
|
|
637
|
+
fontSize: 15,
|
|
638
|
+
fontWeight: '700',
|
|
639
|
+
color: SUCCESS,
|
|
640
|
+
},
|
|
641
|
+
slider: {
|
|
642
|
+
width: '100%',
|
|
643
|
+
height: 36,
|
|
644
|
+
marginTop: 8,
|
|
645
|
+
},
|
|
646
|
+
sliderRow: {
|
|
647
|
+
flexDirection: 'row',
|
|
648
|
+
justifyContent: 'space-between',
|
|
649
|
+
alignItems: 'center',
|
|
650
|
+
marginTop: 2,
|
|
651
|
+
},
|
|
652
|
+
ptsInputRow: {
|
|
653
|
+
flexDirection: 'row',
|
|
654
|
+
alignItems: 'center',
|
|
655
|
+
},
|
|
656
|
+
ptsInput: {
|
|
657
|
+
fontSize: 13,
|
|
658
|
+
color: '#111827',
|
|
659
|
+
fontWeight: '600',
|
|
660
|
+
borderWidth: 1,
|
|
661
|
+
borderColor: '#D1D5DB',
|
|
662
|
+
borderRadius: 6,
|
|
663
|
+
paddingHorizontal: 8,
|
|
664
|
+
paddingVertical: 4,
|
|
665
|
+
minWidth: 56,
|
|
666
|
+
textAlign: 'right',
|
|
667
|
+
backgroundColor: '#F9FAFB',
|
|
668
|
+
},
|
|
669
|
+
sliderPts: {
|
|
670
|
+
fontSize: 13,
|
|
671
|
+
color: '#6B7280',
|
|
672
|
+
},
|
|
673
|
+
sliderDollar: {
|
|
674
|
+
fontSize: 14,
|
|
675
|
+
fontWeight: '600',
|
|
676
|
+
},
|
|
677
|
+
programActions: {
|
|
678
|
+
flexDirection: 'row',
|
|
679
|
+
alignItems: 'center',
|
|
680
|
+
gap: 8,
|
|
681
|
+
marginTop: 10,
|
|
682
|
+
},
|
|
683
|
+
maxButton: {
|
|
684
|
+
borderWidth: 1,
|
|
685
|
+
borderColor: '#D1D5DB',
|
|
686
|
+
borderRadius: 8,
|
|
687
|
+
paddingHorizontal: 14,
|
|
688
|
+
paddingVertical: 7,
|
|
689
|
+
},
|
|
690
|
+
maxButtonText: {
|
|
691
|
+
fontSize: 13,
|
|
692
|
+
fontWeight: '500',
|
|
693
|
+
color: '#374151',
|
|
694
|
+
},
|
|
695
|
+
applyButton: {
|
|
696
|
+
borderRadius: 8,
|
|
697
|
+
paddingHorizontal: 16,
|
|
698
|
+
paddingVertical: 8,
|
|
699
|
+
flex: 1,
|
|
700
|
+
alignItems: 'center',
|
|
701
|
+
},
|
|
702
|
+
applyButtonText: {
|
|
703
|
+
color: '#FFFFFF',
|
|
704
|
+
fontSize: 14,
|
|
705
|
+
fontWeight: '600',
|
|
706
|
+
},
|
|
707
|
+
summaryContainer: {
|
|
708
|
+
backgroundColor: '#F9FAFB',
|
|
709
|
+
borderRadius: 10,
|
|
710
|
+
padding: 14,
|
|
711
|
+
marginTop: 4,
|
|
712
|
+
marginBottom: 8,
|
|
713
|
+
},
|
|
714
|
+
summaryTitle: {
|
|
715
|
+
fontSize: 13,
|
|
716
|
+
fontWeight: '600',
|
|
717
|
+
color: '#374151',
|
|
718
|
+
marginBottom: 8,
|
|
719
|
+
},
|
|
720
|
+
summaryRow: {
|
|
721
|
+
flexDirection: 'row',
|
|
722
|
+
justifyContent: 'space-between',
|
|
723
|
+
alignItems: 'center',
|
|
724
|
+
marginBottom: 4,
|
|
725
|
+
},
|
|
726
|
+
summaryBrand: {
|
|
727
|
+
fontSize: 13,
|
|
728
|
+
color: '#6B7280',
|
|
729
|
+
},
|
|
730
|
+
summaryDeduction: {
|
|
731
|
+
fontSize: 13,
|
|
732
|
+
color: SUCCESS,
|
|
733
|
+
fontWeight: '500',
|
|
734
|
+
},
|
|
735
|
+
summaryTotalRow: {
|
|
736
|
+
borderTopWidth: 1,
|
|
737
|
+
borderTopColor: '#E5E7EB',
|
|
738
|
+
paddingTop: 8,
|
|
739
|
+
marginTop: 4,
|
|
740
|
+
marginBottom: 0,
|
|
741
|
+
},
|
|
742
|
+
summaryTotalLabel: {
|
|
743
|
+
fontSize: 14,
|
|
744
|
+
fontWeight: '600',
|
|
745
|
+
color: NAVY,
|
|
746
|
+
},
|
|
747
|
+
summaryTotalValue: {
|
|
748
|
+
fontSize: 15,
|
|
749
|
+
fontWeight: '700',
|
|
750
|
+
color: SUCCESS,
|
|
751
|
+
},
|
|
752
|
+
linkMoreButton: {
|
|
753
|
+
flexDirection: 'row',
|
|
754
|
+
alignItems: 'center',
|
|
755
|
+
justifyContent: 'center',
|
|
756
|
+
gap: 6,
|
|
757
|
+
paddingVertical: 10,
|
|
758
|
+
marginTop: 4,
|
|
759
|
+
marginBottom: 4,
|
|
760
|
+
},
|
|
761
|
+
linkMorePlus: {
|
|
762
|
+
fontSize: 16,
|
|
763
|
+
fontWeight: '600',
|
|
764
|
+
color: '#6B7280',
|
|
765
|
+
},
|
|
766
|
+
linkMoreText: {
|
|
767
|
+
fontSize: 13,
|
|
768
|
+
fontWeight: '500',
|
|
769
|
+
color: '#6B7280',
|
|
770
|
+
},
|
|
771
|
+
poweredByRow: {
|
|
772
|
+
flexDirection: 'row',
|
|
773
|
+
alignItems: 'center',
|
|
774
|
+
justifyContent: 'center',
|
|
775
|
+
gap: 6,
|
|
776
|
+
paddingVertical: 16,
|
|
777
|
+
opacity: 0.5,
|
|
778
|
+
},
|
|
779
|
+
poweredByText: {
|
|
780
|
+
fontSize: 11,
|
|
781
|
+
color: '#9CA3AF',
|
|
782
|
+
},
|
|
783
|
+
poweredByLogo: {
|
|
784
|
+
width: 80,
|
|
785
|
+
height: 16,
|
|
786
|
+
},
|
|
787
|
+
});
|