-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
"Update User model, fix auth issues, and update README"
- Loading branch information
1 parent
7ea999a
commit b3ab947
Showing
23 changed files
with
1,209 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { NextResponse } from 'next/server' | ||
import { prisma } from '@/lib/prisma' | ||
import { getServerSession } from 'next-auth' | ||
import { authOptions } from '@/lib/auth-options' | ||
import { Session } from 'next-auth' | ||
|
||
type AnalyticsItem = { | ||
date: Date | ||
userCount: number | ||
} | ||
|
||
export async function GET() { | ||
try { | ||
const session = await getServerSession(authOptions) as Session | null | ||
if (!session || !session.user || !session.user.email) { | ||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) | ||
} | ||
|
||
// Get analytics data for the last 6 months | ||
const sixMonthsAgo = new Date() | ||
sixMonthsAgo.setMonth(sixMonthsAgo.getMonth() - 6) | ||
|
||
const analytics = await prisma.analytics.findMany({ | ||
where: { | ||
date: { | ||
gte: sixMonthsAgo, | ||
}, | ||
}, | ||
orderBy: { | ||
date: 'asc', | ||
}, | ||
}) as AnalyticsItem[] | ||
|
||
// Format data for chart | ||
const data = { | ||
labels: analytics.map(item => { | ||
const date = new Date(item.date) | ||
return `${date.getMonth() + 1}/${date.getFullYear()}` | ||
}), | ||
datasets: [ | ||
{ | ||
label: 'Users', | ||
data: analytics.map(item => item.userCount), | ||
borderColor: 'rgb(75, 192, 192)', | ||
backgroundColor: 'rgba(75, 192, 192, 0.5)', | ||
} | ||
], | ||
} | ||
|
||
return NextResponse.json(data) | ||
} catch (error) { | ||
console.error('Error fetching analytics:', error) | ||
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { NextResponse } from 'next/server'; | ||
|
||
export async function GET(request: Request) { | ||
const { searchParams } = new URL(request.url); | ||
const location = searchParams.get('location'); | ||
|
||
if (!location) { | ||
return NextResponse.json( | ||
{ error: 'Location parameter is required' }, | ||
{ status: 400 } | ||
); | ||
} | ||
|
||
try { | ||
// Replace with your actual weather API key and endpoint | ||
const WEATHER_API_KEY = process.env.WEATHER_API_KEY; | ||
const response = await fetch( | ||
`https://api.weatherapi.com/v1/current.json?key=${WEATHER_API_KEY}&q=${location}&aqi=no` | ||
); | ||
|
||
if (!response.ok) { | ||
throw new Error('Weather API request failed'); | ||
} | ||
|
||
const data = await response.json(); | ||
|
||
// Transform the API response to match our interface | ||
const weatherData = { | ||
temperature: data.current.temp_c, | ||
condition: data.current.condition.text, | ||
humidity: data.current.humidity, | ||
windSpeed: data.current.wind_kph, | ||
}; | ||
|
||
return NextResponse.json(weatherData); | ||
} catch (error) { | ||
console.error('Weather API error:', error); | ||
return NextResponse.json( | ||
{ error: 'Failed to fetch weather data' }, | ||
{ status: 500 } | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use client'; | ||
|
||
import React from 'react'; | ||
import AnalyticsChart from './analytics-chart'; | ||
import RecentUsers from './recent-users'; | ||
import StatsCard from './stats-card'; | ||
import { Users, FolderGit, BarChart3 } from 'lucide-react'; | ||
|
||
export default function DashboardGrid() { | ||
return ( | ||
<div className="grid gap-6 p-6"> | ||
{/* Top Stats Row */} | ||
<div className="grid grid-cols-1 md:grid-cols-3 gap-6"> | ||
<StatsCard | ||
title="Total Users" | ||
value="1,234" | ||
change="+12%" | ||
trend="up" | ||
icon={<Users className="w-4 h-4" />} | ||
/> | ||
<StatsCard | ||
title="Active Projects" | ||
value="56" | ||
change="+8%" | ||
trend="up" | ||
icon={<FolderGit className="w-4 h-4" />} | ||
/> | ||
<StatsCard | ||
title="Completion Rate" | ||
value="94%" | ||
change="+5%" | ||
trend="up" | ||
icon={<BarChart3 className="w-4 h-4" />} | ||
/> | ||
</div> | ||
|
||
{/* Main Content Grid */} | ||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6"> | ||
<AnalyticsChart /> | ||
</div> | ||
|
||
{/* Bottom Row */} | ||
<div className="grid grid-cols-1"> | ||
<RecentUsers /> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,10 +11,34 @@ export interface User { | |
} | ||
|
||
interface RecentUsersProps { | ||
users: User[] | ||
users?: User[] | ||
} | ||
|
||
export function RecentUsers({ users }: RecentUsersProps) { | ||
// todo: replace user emails with first names only | ||
const mockUsers: User[] = [ | ||
{ | ||
id: "1", | ||
email: "[email protected]", | ||
createdAt: "2024-01-01", | ||
}, | ||
{ | ||
id: "2", | ||
email: "[email protected]", | ||
createdAt: "2024-01-02", | ||
}, | ||
{ | ||
id: "3", | ||
email: "[email protected]", | ||
createdAt: "2024-01-03", | ||
}, | ||
{ | ||
id: "4", | ||
email: "[email protected]", | ||
createdAt: "2024-01-04", | ||
}, | ||
] | ||
|
||
export default function RecentUsers({ users = mockUsers }: RecentUsersProps) { | ||
return ( | ||
<Card className="p-6"> | ||
<h2 className="text-xl font-semibold mb-4">Recent Users</h2> | ||
|
Oops, something went wrong.