-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.tsx
More file actions
342 lines (318 loc) · 10.5 KB
/
App.tsx
File metadata and controls
342 lines (318 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
import { useEffect, useState, useCallback } from 'react';
import {
Box,
Container,
Typography,
AppBar,
Toolbar,
Button,
Paper,
Stepper,
Step,
StepLabel,
Card,
CardContent,
Chip,
LinearProgress,
Alert,
Snackbar,
Divider,
} from '@mui/material';
import { ThemeProvider, createTheme } from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline';
import AccountBalanceIcon from '@mui/icons-material/AccountBalance';
import DescriptionIcon from '@mui/icons-material/Description';
import CheckCircleIcon from '@mui/icons-material/CheckCircle';
import BusinessIcon from '@mui/icons-material/Business';
import './App.css';
// Professional dark theme with accent color
const theme = createTheme({
palette: {
mode: 'light',
primary: {
main: '#1a365d', // Deep navy blue
light: '#2d4a7c',
dark: '#0f2744',
},
secondary: {
main: '#38a169', // Success green
light: '#68d391',
dark: '#276749',
},
background: {
default: '#f7fafc',
paper: '#ffffff',
},
text: {
primary: '#1a202c',
secondary: '#4a5568',
},
},
typography: {
fontFamily: '"Inter", "Helvetica", "Arial", sans-serif',
h1: {
fontWeight: 700,
letterSpacing: '-0.02em',
},
h2: {
fontWeight: 700,
letterSpacing: '-0.01em',
},
h3: {
fontWeight: 600,
},
h4: {
fontWeight: 600,
},
h5: {
fontWeight: 600,
},
h6: {
fontWeight: 600,
},
},
shape: {
borderRadius: 12,
},
components: {
MuiButton: {
styleOverrides: {
root: {
textTransform: 'none',
fontWeight: 600,
padding: '12px 24px',
},
},
},
MuiCard: {
styleOverrides: {
root: {
boxShadow: '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)',
},
},
},
},
});
// Widget event types
interface WidgetEvent {
type: string;
uploads?: Array<{ name: string; size: number; type: string; bookUuid?: string; message?: string }>;
uploadedFileCount?: number;
error?: {
errorType: string;
errorCode: string;
displayMessage: string;
};
}
const steps = ['Business Information', 'Financial Documents', 'Review & Submit'];
function App() {
const [activeStep] = useState(1); // Start on Financial Documents step
const [widgetReady, setWidgetReady] = useState(false);
const [snackbar, setSnackbar] = useState<{ open: boolean; message: string; severity: 'success' | 'error' | 'info' }>({
open: false,
message: '',
severity: 'info',
});
const [uploadStats, setUploadStats] = useState({ received: 0, completed: 0, failed: 0 });
const [bankConnected, setBankConnected] = useState(false);
// Set up getAuthToken for the widget
useEffect(() => {
(window as any).getAuthToken = async function () {
const response = await fetch('https://auth.ocrolusexample.com/token', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
userId: `user-${Date.now()}`, // Auto-generate user ID
bookName: 'SMB Loan Application',
}),
});
const json = await response.json();
return json.accessToken;
};
setWidgetReady(true);
}, []);
// Listen for widget events
const handleWidgetEvent = useCallback((event: MessageEvent) => {
const data = event.data as WidgetEvent;
if (!data?.type) return;
// Handle specific events
switch (data.type) {
case 'USER_UPLOAD_RECEIVED':
setUploadStats(prev => ({ ...prev, received: prev.received + (data.uploads?.length || 0) }));
setSnackbar({ open: true, message: `${data.uploads?.length || 0} file(s) received`, severity: 'info' });
break;
case 'USER_UPLOAD_COMPLETE':
setUploadStats(prev => ({ ...prev, completed: prev.completed + (data.uploads?.length || 0) }));
setSnackbar({ open: true, message: `Document uploaded successfully!`, severity: 'success' });
break;
case 'USER_UPLOAD_FAILED':
setUploadStats(prev => ({ ...prev, failed: prev.failed + (data.uploads?.length || 0) }));
setSnackbar({ open: true, message: `Upload failed: ${data.uploads?.[0]?.message || 'Unknown error'}`, severity: 'error' });
break;
case 'LINK_SUCCESS':
setBankConnected(true);
setSnackbar({ open: true, message: 'Bank account connected successfully!', severity: 'success' });
break;
case 'PLAID_ERROR':
setSnackbar({ open: true, message: data.error?.displayMessage || 'Bank connection error', severity: 'error' });
break;
}
}, []);
useEffect(() => {
window.addEventListener('message', handleWidgetEvent);
return () => window.removeEventListener('message', handleWidgetEvent);
}, [handleWidgetEvent]);
const handleCloseSnackbar = () => {
setSnackbar(prev => ({ ...prev, open: false }));
};
return (
<ThemeProvider theme={theme}>
<CssBaseline />
<Box sx={{ minHeight: '100vh', backgroundColor: 'background.default' }}>
{/* Header */}
<AppBar position="static" elevation={0} sx={{ backgroundColor: 'primary.main' }}>
<Toolbar sx={{ py: 1 }}>
<BusinessIcon sx={{ mr: 1, fontSize: 32 }} />
<Typography variant="h5" component="div" sx={{ flexGrow: 1, fontWeight: 700 }}>
Ocrolus Example Broker
</Typography>
</Toolbar>
</AppBar>
{/* Hero Banner */}
<Box
sx={{
background: 'linear-gradient(135deg, #1a365d 0%, #2d4a7c 100%)',
color: 'white',
py: 4,
textAlign: 'center',
}}
>
<Container maxWidth="md">
<Typography variant="h4" gutterBottom fontWeight={700}>
Business Loan Application
</Typography>
</Container>
</Box>
{/* Progress Stepper */}
<Container maxWidth="lg" sx={{ mt: -3 }}>
<Paper sx={{ p: 3, mb: 4 }}>
<Stepper activeStep={activeStep} alternativeLabel>
{steps.map((label, index) => (
<Step key={label} completed={index < activeStep}>
<StepLabel>{label}</StepLabel>
</Step>
))}
</Stepper>
</Paper>
</Container>
{/* Main Content */}
<Container maxWidth="lg">
<Card sx={{ mb: 3 }}>
<CardContent sx={{ p: 4 }}>
<Box sx={{ display: 'flex', alignItems: 'center', mb: 3 }}>
<DescriptionIcon sx={{ fontSize: 32, color: 'primary.main', mr: 2 }} />
<Box>
<Typography variant="h5" gutterBottom sx={{ mb: 0 }}>
Submit Your Financial Documents
</Typography>
<Typography variant="body2" color="text.secondary">
Upload bank statements or connect your bank account directly
</Typography>
</Box>
</Box>
<Divider sx={{ my: 3 }} />
{/* Widget Container */}
<Box
sx={{
minHeight: 300,
border: '2px dashed',
borderColor: 'grey.300',
borderRadius: 2,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'grey.50',
position: 'relative',
overflow: 'hidden',
}}
>
{!widgetReady && (
<Box sx={{ textAlign: 'center' }}>
<LinearProgress sx={{ width: 200, mb: 2 }} />
<Typography color="text.secondary">Loading widget...</Typography>
</Box>
)}
<Box
id="ocrolus-widget-frame"
sx={{
width: '100%',
height: '100%',
minHeight: 300,
display: widgetReady ? 'block' : 'none',
}}
/>
</Box>
{/* Upload Stats */}
{(uploadStats.received > 0 || uploadStats.completed > 0 || bankConnected) && (
<Box sx={{ mt: 3, display: 'flex', gap: 2, flexWrap: 'wrap' }}>
{uploadStats.completed > 0 && (
<Chip
icon={<CheckCircleIcon />}
label={`${uploadStats.completed} document(s) uploaded`}
color="success"
variant="outlined"
/>
)}
{uploadStats.received > uploadStats.completed && (
<Chip
label={`${uploadStats.received - uploadStats.completed} processing...`}
color="warning"
variant="outlined"
/>
)}
{uploadStats.failed > 0 && (
<Chip
label={`${uploadStats.failed} failed`}
color="error"
variant="outlined"
/>
)}
{bankConnected && (
<Chip
icon={<AccountBalanceIcon />}
label="Bank connected"
color="success"
variant="outlined"
/>
)}
</Box>
)}
</CardContent>
</Card>
</Container>
{/* Footer */}
<Box sx={{ backgroundColor: 'primary.dark', color: 'white', py: 3, mt: 6 }}>
<Container maxWidth="lg">
<Box sx={{ textAlign: 'center' }}>
<Typography variant="body2" sx={{ opacity: 0.7 }}>
© 2026 Ocrolus Example Broker. Demo application for Ocrolus Widget Quickstart.
</Typography>
</Box>
</Container>
</Box>
</Box>
{/* Snackbar for notifications */}
<Snackbar
open={snackbar.open}
autoHideDuration={4000}
onClose={handleCloseSnackbar}
anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}
>
<Alert onClose={handleCloseSnackbar} severity={snackbar.severity} variant="filled">
{snackbar.message}
</Alert>
</Snackbar>
</ThemeProvider>
);
}
export default App;