-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
1642 lines (1461 loc) · 45.5 KB
/
setup.sh
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# This script sets up a complete Next.js application structure for a MongoDB AI Lab Assistant
# Previously created directories and files are maintained in the script
# Create the base directory structure
mkdir -p app/api/auth
mkdir -p app/api/chat
mkdir -p app/api/admin
mkdir -p app/api/design-review
mkdir -p app/\(auth\)/login
mkdir -p app/\(auth\)/profile
mkdir -p app/admin/questions
mkdir -p app/admin/users
mkdir -p app/admin/statistics
mkdir -p app/admin/design-reviews
mkdir -p app/chat
mkdir -p app/about
mkdir -p app/design-review
mkdir -p app/components/ui
mkdir -p app/components/layout
mkdir -p app/components/chat
mkdir -p app/components/admin
mkdir -p app/lib
mkdir -p app/hooks
mkdir -p app/context
mkdir -p app/public
mkdir -p app/theme
# --- API Routes ---
# Previous API Routes remain the same (auth, chat, admin routes)
# New API routes for design reviews
cat > app/api/design-review/route.js << 'EOL'
import { NextResponse } from 'next/server';
import { getServerSession } from 'next-auth/next';
import { authOptions } from '../auth/[...nextauth]/route';
import clientPromise from '@/lib/mongodb';
import { ObjectId } from 'mongodb';
export async function POST(request) {
try {
const session = await getServerSession(authOptions);
if (!session) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const { title, description, requirements, attachmentUrls } = await request.json();
if (!title || !description) {
return NextResponse.json({ error: 'Title and description are required' }, { status: 400 });
}
const client = await clientPromise;
const db = client.db(process.env.MONGODB_DB);
const designReview = {
title,
description,
requirements: requirements || '',
attachment_urls: attachmentUrls || [],
status: 'pending',
user_id: session.user.id,
user_name: session.user.name,
created_at: new Date(),
updated_at: new Date()
};
const result = await db.collection('design_reviews').insertOne(designReview);
return NextResponse.json({
message: 'Design review request submitted successfully',
request_id: result.insertedId.toString()
}, { status: 201 });
} catch (error) {
console.error('Error submitting design review:', error);
return NextResponse.json({ error: 'An internal error occurred' }, { status: 500 });
}
}
export async function GET(request) {
try {
const session = await getServerSession(authOptions);
if (!session) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const client = await clientPromise;
const db = client.db(process.env.MONGODB_DB);
let query = {};
// If not admin, only show user's own requests
if (!session.user.isAdmin) {
query.user_id = session.user.id;
}
const designReviews = await db.collection('design_reviews')
.find(query)
.sort({ created_at: -1 })
.toArray();
// Convert ObjectIds to strings for JSON serialization
const serializedReviews = designReviews.map(review => ({
...review,
_id: review._id.toString(),
created_at: review.created_at.toISOString(),
updated_at: review.updated_at.toISOString()
}));
return NextResponse.json(serializedReviews);
} catch (error) {
console.error('Error fetching design reviews:', error);
return NextResponse.json({ error: 'An internal error occurred' }, { status: 500 });
}
}
EOL
# --- Add Main Page Components ---
# Root layout
cat > app/layout.js << 'EOL'
import { Inter } from 'next/font/google';
import { ThemeProvider } from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline';
import theme from '@/theme/theme';
import Header from '@/components/layout/Header';
import AuthProvider from '@/context/AuthProvider';
import '@fontsource/roboto/300.css';
import '@fontsource/roboto/400.css';
import '@fontsource/roboto/500.css';
import '@fontsource/roboto/700.css';
const inter = Inter({ subsets: ['latin'] });
export const metadata = {
title: 'MongoDB AI Lab Assistant',
description: 'An AI-powered assistant for MongoDB knowledge and design reviews',
};
export default function RootLayout({ children }) {
return (
<html lang="en">
<body className={inter.className}>
<AuthProvider>
<ThemeProvider theme={theme}>
<CssBaseline />
<Header />
<main>{children}</main>
</ThemeProvider>
</AuthProvider>
</body>
</html>
);
}
EOL
# Home page
cat > app/page.js << 'EOL'
import { Box, Container, Typography, Button, Grid, Paper } from '@mui/material';
import Link from 'next/link';
import Image from 'next/image';
export default function Home() {
return (
<Container maxWidth="lg" sx={{ mt: 12, mb: 6 }}>
<Grid container spacing={6} alignItems="center">
<Grid item xs={12} md={6}>
<Typography
component="h1"
variant="h2"
color="primary.main"
fontWeight="bold"
gutterBottom
>
MongoDB AI Lab Assistant
</Typography>
<Typography variant="h5" color="text.secondary" paragraph>
An AI-powered assistant that helps you with MongoDB queries, architecture decisions,
and design reviews. Leverage the power of AI to accelerate your MongoDB development.
</Typography>
<Box sx={{ mt: 4, display: 'flex', gap: 2 }}>
<Button
component={Link}
href="/chat"
variant="contained"
size="large"
color="primary"
>
Ask a Question
</Button>
<Button
component={Link}
href="/design-review"
variant="outlined"
size="large"
color="primary"
>
Request Design Review
</Button>
</Box>
</Grid>
<Grid item xs={12} md={6} sx={{ display: 'flex', justifyContent: 'center' }}>
<Paper
elevation={3}
sx={{
p: 2,
borderRadius: 2,
width: '100%',
height: '300px',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
bgcolor: 'grey.100'
}}
>
<Typography variant="body1" color="text.secondary">
MongoDB Logo Placeholder
</Typography>
{/* Replace with actual MongoDB logo */}
{/* <Image src="/mongodb-logo.png" alt="MongoDB Logo" width={400} height={250} /> */}
</Paper>
</Grid>
</Grid>
<Box sx={{ mt: 8 }}>
<Typography variant="h4" color="primary" gutterBottom>
Features
</Typography>
<Grid container spacing={4} sx={{ mt: 2 }}>
<Grid item xs={12} sm={6} md={4}>
<Paper elevation={2} sx={{ p: 3, height: '100%', borderRadius: 2 }}>
<Typography variant="h6" gutterBottom>AI-Powered Answers</Typography>
<Typography variant="body2">
Get instant answers to your MongoDB questions using our AI-powered search and OpenAI integration.
</Typography>
</Paper>
</Grid>
<Grid item xs={12} sm={6} md={4}>
<Paper elevation={2} sx={{ p: 3, height: '100%', borderRadius: 2 }}>
<Typography variant="h6" gutterBottom>Design Reviews</Typography>
<Typography variant="body2">
Submit your MongoDB schema designs and architecture plans for expert AI-assisted review.
</Typography>
</Paper>
</Grid>
<Grid item xs={12} sm={6} md={4}>
<Paper elevation={2} sx={{ p: 3, height: '100%', borderRadius: 2 }}>
<Typography variant="h6" gutterBottom>Knowledge Base</Typography>
<Typography variant="body2">
Access a growing knowledge base of MongoDB best practices, patterns, and solutions.
</Typography>
</Paper>
</Grid>
</Grid>
</Box>
</Container>
);
}
EOL
# Chat page
cat > app/chat/page.js << 'EOL'
'use client';
import { useEffect } from 'react';
import { Container } from '@mui/material';
import { useRouter } from 'next/navigation';
import { useSession } from 'next-auth/react';
import ChatInterface from '@/components/chat/ChatInterface';
export default function ChatPage() {
const { data: session, status } = useSession();
const router = useRouter();
useEffect(() => {
if (status === 'unauthenticated') {
router.push('/login');
}
}, [status, router]);
if (status === 'loading') {
return <div>Loading...</div>;
}
if (!session) {
return null;
}
return (
<Container maxWidth="xl" disableGutters sx={{ height: '100vh' }}>
<ChatInterface />
</Container>
);
}
EOL
# Design Review page
cat > app/design-review/page.js << 'EOL'
'use client';
import { useState } from 'react';
import {
Container,
Typography,
Box,
TextField,
Button,
Paper,
Grid,
Alert,
Snackbar,
CircularProgress
} from '@mui/material';
import { useSession } from 'next-auth/react';
import { useRouter } from 'next/navigation';
export default function DesignReviewPage() {
const { data: session, status } = useSession();
const router = useRouter();
const [formData, setFormData] = useState({
title: '',
description: '',
requirements: '',
attachmentUrls: []
});
const [loading, setLoading] = useState(false);
const [success, setSuccess] = useState(false);
const [error, setError] = useState('');
const handleChange = (e) => {
const { name, value } = e.target;
setFormData(prev => ({ ...prev, [name]: value }));
};
const handleSubmit = async (e) => {
e.preventDefault();
setLoading(true);
setError('');
try {
const response = await fetch('/api/design-review', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(formData),
});
if (!response.ok) {
const data = await response.json();
throw new Error(data.error || 'Failed to submit design review request');
}
setSuccess(true);
setFormData({
title: '',
description: '',
requirements: '',
attachmentUrls: []
});
// Redirect to dashboard after 2 seconds
setTimeout(() => {
router.push('/profile');
}, 2000);
} catch (err) {
setError(err.message);
} finally {
setLoading(false);
}
};
if (status === 'loading') {
return <div>Loading...</div>;
}
if (!session) {
router.push('/login');
return null;
}
return (
<Container maxWidth="md" sx={{ mt: 12, mb: 6 }}>
<Paper elevation={3} sx={{ p: 4, borderRadius: 2 }}>
<Typography component="h1" variant="h4" color="primary" gutterBottom>
Request a Design Review
</Typography>
<Typography variant="body1" color="text.secondary" paragraph>
Submit your MongoDB schema, architecture, or query patterns for an AI-powered review.
</Typography>
<Box component="form" onSubmit={handleSubmit} sx={{ mt: 4 }}>
<Grid container spacing={3}>
<Grid item xs={12}>
<TextField
label="Title"
name="title"
value={formData.title}
onChange={handleChange}
fullWidth
required
variant="outlined"
/>
</Grid>
<Grid item xs={12}>
<TextField
label="Description"
name="description"
value={formData.description}
onChange={handleChange}
fullWidth
required
multiline
rows={4}
variant="outlined"
helperText="Describe what you're trying to accomplish with your design"
/>
</Grid>
<Grid item xs={12}>
<TextField
label="Requirements & Constraints"
name="requirements"
value={formData.requirements}
onChange={handleChange}
fullWidth
multiline
rows={3}
variant="outlined"
helperText="List any specific requirements, constraints, or concerns"
/>
</Grid>
<Grid item xs={12}>
<Typography variant="body2" color="text.secondary" gutterBottom>
Note: File upload functionality will be implemented in a future update.
</Typography>
</Grid>
<Grid item xs={12}>
<Button
type="submit"
variant="contained"
color="primary"
size="large"
disabled={loading}
sx={{ mt: 2 }}
>
{loading ? <CircularProgress size={24} /> : 'Submit for Review'}
</Button>
</Grid>
</Grid>
</Box>
</Paper>
<Snackbar open={success} autoHideDuration={6000} onClose={() => setSuccess(false)}>
<Alert onClose={() => setSuccess(false)} severity="success" sx={{ width: '100%' }}>
Design review request submitted successfully!
</Alert>
</Snackbar>
{error && (
<Alert severity="error" sx={{ mt: 2 }}>
{error}
</Alert>
)}
</Container>
);
}
EOL
# --- Additional Components ---
# Create missing chat components
cat > app/components/chat/ModuleSelect.js << 'EOL'
import { Autocomplete, TextField } from '@mui/material';
const modules = [
{ label: 'MongoDB Basics', value: 'basics' },
{ label: 'MongoDB Atlas', value: 'atlas' },
{ label: 'Aggregation Framework', value: 'aggregation' },
{ label: 'Data Modeling', value: 'data_modeling' },
{ label: 'Indexing & Performance', value: 'indexing' },
{ label: 'Atlas Search', value: 'atlas_search' },
{ label: 'Atlas Vector Search', value: 'vector_search' },
{ label: 'Schema Design', value: 'schema_design' },
{ label: 'Realm/App Services', value: 'realm' }
];
export default function ModuleSelect({ value, onChange }) {
return (
<Autocomplete
sx={{ width: 250 }}
options={modules}
value={value}
onChange={onChange}
renderInput={(params) => (
<TextField
{...params}
label="Select Module"
variant="outlined"
size="medium"
/>
)}
/>
);
}
EOL
# Create Layout components
cat > app/components/layout/Header.js << 'EOL'
'use client';
import { useState } from 'react';
import {
AppBar,
Toolbar,
Typography,
Button,
IconButton,
Box,
Menu,
MenuItem,
Avatar,
Drawer,
List,
ListItem,
ListItemText,
ListItemIcon,
Divider
} from '@mui/material';
import MenuIcon from '@mui/icons-material/Menu';
import QuestionAnswerIcon from '@mui/icons-material/QuestionAnswer';
import DesignServicesIcon from '@mui/icons-material/DesignServices';
import InfoIcon from '@mui/icons-material/Info';
import AccountCircleIcon from '@mui/icons-material/AccountCircle';
import AdminPanelSettingsIcon from '@mui/icons-material/AdminPanelSettings';
import LogoutIcon from '@mui/icons-material/Logout';
import Link from 'next/link';
import { useSession, signOut } from 'next-auth/react';
import { usePathname } from 'next/navigation';
export default function Header() {
const { data: session } = useSession();
const pathname = usePathname();
const [anchorEl, setAnchorEl] = useState(null);
const [drawerOpen, setDrawerOpen] = useState(false);
const handleMenu = (event) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
const handleDrawerToggle = () => {
setDrawerOpen(!drawerOpen);
};
const handleSignOut = () => {
handleClose();
signOut({ callbackUrl: '/' });
};
const navItems = [
{ text: 'Chat', href: '/chat', icon: <QuestionAnswerIcon /> },
{ text: 'Design Review', href: '/design-review', icon: <DesignServicesIcon /> },
{ text: 'About', href: '/about', icon: <InfoIcon /> },
];
return (
<>
<AppBar position="fixed">
<Toolbar>
<IconButton
size="large"
edge="start"
color="inherit"
aria-label="menu"
sx={{ mr: 2, display: { sm: 'flex', md: 'none' } }}
onClick={handleDrawerToggle}
>
<MenuIcon />
</IconButton>
<Typography variant="h6" component={Link} href="/" sx={{
flexGrow: 1,
textDecoration: 'none',
color: 'white',
fontWeight: 'bold',
display: 'flex',
alignItems: 'center'
}}>
MongoDB AI Lab Assistant
</Typography>
<Box sx={{ display: { xs: 'none', md: 'flex' }, alignItems: 'center' }}>
{navItems.map((item) => (
<Button
key={item.text}
component={Link}
href={item.href}
color="inherit"
sx={{
mx: 1,
borderBottom: pathname === item.href ? '2px solid white' : 'none',
borderRadius: 0,
paddingBottom: '4px'
}}
>
{item.text}
</Button>
))}
</Box>
{session ? (
<Box sx={{ ml: 2 }}>
<IconButton onClick={handleMenu} color="inherit">
<Avatar sx={{ width: 32, height: 32, bgcolor: 'secondary.main' }}>
{session.user.name?.charAt(0) || 'U'}
</Avatar>
</IconButton>
<Menu
id="menu-appbar"
anchorEl={anchorEl}
anchorOrigin={{
vertical: 'bottom',
horizontal: 'right',
}}
keepMounted
transformOrigin={{
vertical: 'top',
horizontal: 'right',
}}
open={Boolean(anchorEl)}
onClose={handleClose}
>
<MenuItem component={Link} href="/profile" onClick={handleClose}>
<ListItemIcon><AccountCircleIcon fontSize="small" /></ListItemIcon>
Profile
</MenuItem>
{session.user.isAdmin && (
<MenuItem component={Link} href="/admin" onClick={handleClose}>
<ListItemIcon><AdminPanelSettingsIcon fontSize="small" /></ListItemIcon>
Admin Dashboard
</MenuItem>
)}
<Divider />
<MenuItem onClick={handleSignOut}>
<ListItemIcon><LogoutIcon fontSize="small" /></ListItemIcon>
Logout
</MenuItem>
</Menu>
</Box>
) : (
<Button color="inherit" component={Link} href="/login">
Login
</Button>
)}
</Toolbar>
</AppBar>
<Drawer
anchor="left"
open={drawerOpen}
onClose={handleDrawerToggle}
>
<Box
sx={{ width: 250 }}
role="presentation"
onClick={handleDrawerToggle}
>
<List>
{navItems.map((item) => (
<ListItem
button
key={item.text}
component={Link}
href={item.href}
selected={pathname === item.href}
>
<ListItemIcon>{item.icon}</ListItemIcon>
<ListItemText primary={item.text} />
</ListItem>
))}
</List>
</Box>
</Drawer>
</>
);
}
EOL
# Create context providers
cat > app/context/AuthProvider.js << 'EOL'
'use client';
import { SessionProvider } from 'next-auth/react';
export default function AuthProvider({ children }) {
return <SessionProvider>{children}</SessionProvider>;
}
EOL
# Create theme
cat > app/theme/theme.js << 'EOL'
'use client';
import { createTheme } from '@mui/material/styles';
const theme = createTheme({
palette: {
primary: {
main: '#00684A', // MongoDB Green
light: '#4CAF50',
dark: '#005240',
contrastText: '#fff',
},
secondary: {
main: '#3D5AFE', // Bright Blue
light: '#8187FF',
dark: '#0031CA',
contrastText: '#fff',
},
error: {
main: '#FF4436',
},
warning: {
main: '#FFC017',
},
info: {
main: '#13AA52',
},
success: {
main: '#00ED64',
},
background: {
default: '#F9FAFB',
paper: '#FFFFFF',
},
},
typography: {
fontFamily: [
'Roboto',
'"Helvetica Neue"',
'Arial',
'sans-serif',
].join(','),
h1: {
fontWeight: 600,
},
h2: {
fontWeight: 600,
},
h3: {
fontWeight: 600,
},
h4: {
fontWeight: 500,
},
h5: {
fontWeight: 500,
},
h6: {
fontWeight: 500,
},
},
shape: {
borderRadius: 8,
},
components: {
MuiButton: {
styleOverrides: {
root: {
textTransform: 'none',
fontWeight: 500,
},
},
},
MuiAppBar: {
styleOverrides: {
root: {
backgroundColor: '#00684A', // MongoDB Green
},
},
},
},
});
export default theme;
EOL
# Create Login page
cat > app/\(auth\)/login/page.js << 'EOL'
'use client';
import { useEffect } from 'react';
import { Container, Box, Button, Typography, Paper, Divider } from '@mui/material';
import { signIn, useSession } from 'next-auth/react';
import { useRouter } from 'next/navigation';
import GoogleIcon from '@mui/icons-material/Google';
export default function LoginPage() {
const { data: session, status } = useSession();
const router = useRouter();
useEffect(() => {
if (status === 'authenticated') {
router.push('/');
}
}, [status, router]);
const handleGoogleSignIn = () => {
signIn('google', { callbackUrl: '/' });
};
if (status === 'loading') {
return <div>Loading...</div>;
}
if (status === 'authenticated') {
return null;
}
return (
<Container maxWidth="sm" sx={{ mt: 12, mb: 6 }}>
<Paper elevation={3} sx={{ p: 4, textAlign: 'center', borderRadius: 2 }}>
<Typography component="h1" variant="h4" color="primary" gutterBottom>
Welcome to MongoDB AI Lab Assistant
</Typography>
<Typography variant="body1" color="text.secondary" sx={{ mb: 4 }}>
Please sign in to continue
</Typography>
<Divider sx={{ my: 3 }} />
<Box sx={{ mt: 3 }}>
<Button
variant="contained"
size="large"
startIcon={<GoogleIcon />}
onClick={handleGoogleSignIn}
fullWidth
sx={{ py: 1.5 }}
>
Sign in with Google
</Button>
</Box>
</Paper>
</Container>
);
}
EOL
# Create Profile page
cat > app/\(auth\)/profile/page.js << 'EOL'
'use client';
import { useEffect, useState } from 'react';
import { Container, Typography, Box, Paper, Divider, Grid, Chip, CircularProgress, Tab, Tabs } from '@mui/material';
import { useSession } from 'next-auth/react';
import { useRouter } from 'next/navigation';
export default function ProfilePage() {
const { data: session, status } = useSession();
const router = useRouter();
const [designReviews, setDesignReviews] = useState([]);
const [loading, setLoading] = useState(true);
const [tabValue, setTabValue] = useState(0);
useEffect(() => {
if (status === 'unauthenticated') {
router.push('/login');
}
if (status === 'authenticated') {
fetchDesignReviews();
}
}, [status, router]);
const fetchDesignReviews = async () => {
try {
const response = await fetch('/api/design-review');
if (response.ok) {
const data = await response.json();
setDesignReviews(data);
}
} catch (error) {
console.error('Error fetching design reviews:', error);
} finally {
setLoading(false);
}
};
const handleTabChange = (event, newValue) => {
setTabValue(newValue);
};
if (status === 'loading') {
return <div>Loading...</div>;
}
if (!session) {
return null;
}
return (
<Container maxWidth="md" sx={{ mt: 12, mb: 6 }}>
<Paper elevation={3} sx={{ p: 4, borderRadius: 2 }}>
<Box sx={{ display: 'flex', alignItems: 'center', mb: 3 }}>
<Box sx={{ ml: 2 }}>
<Typography variant="h4" gutterBottom>
{session.user.name}
</Typography>
<Typography variant="body1" color="text.secondary">
{session.user.email}
</Typography>
{session.user.isAdmin && (
<Chip
label="Admin"
color="primary"
size="small"
sx={{ mt: 1 }}
/>
)}
</Box>
</Box>
<Divider sx={{ my: 3 }} />
<Box sx={{ width: '100%' }}>
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
<Tabs
value={tabValue}
onChange={handleTabChange}
aria-label="profile tabs"
indicatorColor="primary"
textColor="primary"
>
<Tab label="Design Reviews" />
<Tab label="Chat History" />
<Tab label="Account Settings" />
</Tabs>
</Box>
<TabPanel value={tabValue} index={0}>
{loading ? (
<Box sx={{ display: 'flex', justifyContent: 'center', my: 4 }}>
<CircularProgress />
</Box>
) : designReviews.length > 0 ? (
<Grid container spacing={3} sx={{ mt: 1 }}>
{designReviews.map((review) => (
<Grid item xs={12} key={review._id}>
<Paper
elevation={1}
sx={{
p: 2,
borderLeft: '4px solid',
borderColor:
review.status === 'completed' ? 'success.main' :
review.status === 'in_progress' ? 'info.main' :
'warning.main'
}}
>
<Typography variant="h6">{review.title}</Typography>
<Typography variant="body2" color="text.secondary" sx={{ mb: 1 }}>
Submitted on {new Date(review.created_at).toLocaleDateString()}
</Typography>
<Chip
label={review.status.replace('_', ' ')}
color={
review.status === 'completed' ? 'success' :
review.status === 'in_progress' ? 'info' :
'warning'
}
size="small"
/>
</Paper>
</Grid>
))}
</Grid>
) : (
<Box sx={{ textAlign: 'center', my: 4 }}>
<Typography variant="body1" color="text.secondary">
You haven't submitted any design reviews yet.
</Typography>
</Box>
)}
</TabPanel>
<TabPanel value={tabValue} index={1}>