Compare commits
6
Commits
lookAndFeel
...
adminUI
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0abb41f573 | ||
|
|
02c9681aca | ||
|
|
912981e3f3 | ||
|
|
963404434a | ||
|
|
7f22a39886 | ||
|
|
0776517fb7 |
No files matched your search
Binary file not shown.
@@ -0,0 +1,142 @@
|
|||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
import { auth } from "@clerk/nextjs/server";
|
||||||
|
import { getDatabase } from "@/lib/database";
|
||||||
|
import { ensureUserSynced } from "@/lib/sync-user";
|
||||||
|
import { successResponse } from "@/lib/api/responses";
|
||||||
|
import { db as rawDb, sql } from "@fitai/database";
|
||||||
|
|
||||||
|
interface UserGrowthPoint {
|
||||||
|
label: string;
|
||||||
|
value: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MembershipDistributionPoint {
|
||||||
|
label: string;
|
||||||
|
value: number;
|
||||||
|
color: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RevenuePoint {
|
||||||
|
label: string;
|
||||||
|
value: number;
|
||||||
|
color: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AnalyticsData {
|
||||||
|
userGrowth: UserGrowthPoint[];
|
||||||
|
membershipDistribution: MembershipDistributionPoint[];
|
||||||
|
revenue: RevenuePoint[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function GET(req: NextRequest) {
|
||||||
|
try {
|
||||||
|
const { userId } = await auth();
|
||||||
|
if (!userId) {
|
||||||
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const database = await getDatabase();
|
||||||
|
const user = await ensureUserSynced(userId, database);
|
||||||
|
|
||||||
|
if (!user || (user.role !== "admin" && user.role !== "superAdmin")) {
|
||||||
|
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = new URL(req.url);
|
||||||
|
const months = parseInt(url.searchParams.get("months") || "6");
|
||||||
|
|
||||||
|
const allUsers = await database.getAllUsers();
|
||||||
|
const allClients = await database.getAllClients();
|
||||||
|
|
||||||
|
const paymentsRaw = await rawDb.all(
|
||||||
|
sql`SELECT * FROM payments WHERE status = 'completed' AND paid_at IS NOT NULL`,
|
||||||
|
);
|
||||||
|
const payments: any[] = paymentsRaw || [];
|
||||||
|
|
||||||
|
const now = new Date();
|
||||||
|
const userGrowth: UserGrowthPoint[] = [];
|
||||||
|
|
||||||
|
for (let i = months - 1; i >= 0; i--) {
|
||||||
|
const date = new Date(now.getFullYear(), now.getMonth() - i, 1);
|
||||||
|
const monthLabel = date.toLocaleDateString("en-US", { month: "short" });
|
||||||
|
|
||||||
|
const usersCreatedByMonth = allUsers.filter((u: any) => {
|
||||||
|
const createdAt = new Date(u.createdAt);
|
||||||
|
return (
|
||||||
|
createdAt.getFullYear() === date.getFullYear() &&
|
||||||
|
createdAt.getMonth() === date.getMonth()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
userGrowth.push({
|
||||||
|
label: monthLabel,
|
||||||
|
value: usersCreatedByMonth.length,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let runningTotal = 0;
|
||||||
|
for (const point of userGrowth) {
|
||||||
|
runningTotal += point.value;
|
||||||
|
point.value = runningTotal;
|
||||||
|
}
|
||||||
|
|
||||||
|
const membershipCounts: Record<string, number> = {
|
||||||
|
basic: 0,
|
||||||
|
premium: 0,
|
||||||
|
vip: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const client of allClients) {
|
||||||
|
const membershipType = (client as any).membershipType || "basic";
|
||||||
|
if (membershipCounts[membershipType] !== undefined) {
|
||||||
|
membershipCounts[membershipType]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const membershipDistribution: MembershipDistributionPoint[] = [
|
||||||
|
{ label: "Basic", value: membershipCounts.basic, color: "#6b7280" },
|
||||||
|
{ label: "Premium", value: membershipCounts.premium, color: "#3b82f6" },
|
||||||
|
{ label: "VIP", value: membershipCounts.vip, color: "#f59e0b" },
|
||||||
|
];
|
||||||
|
|
||||||
|
const revenue: RevenuePoint[] = [];
|
||||||
|
|
||||||
|
for (let i = months - 1; i >= 0; i--) {
|
||||||
|
const date = new Date(now.getFullYear(), now.getMonth() - i, 1);
|
||||||
|
const monthLabel = date.toLocaleDateString("en-US", { month: "short" });
|
||||||
|
const nextMonthDate = new Date(
|
||||||
|
now.getFullYear(),
|
||||||
|
now.getMonth() - i + 1,
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
|
||||||
|
const monthlyRevenue = payments
|
||||||
|
.filter((p: any) => {
|
||||||
|
const paidAt = p.paid_at ? new Date(p.paid_at) : null;
|
||||||
|
if (!paidAt) return false;
|
||||||
|
return paidAt >= date && paidAt < nextMonthDate;
|
||||||
|
})
|
||||||
|
.reduce((sum: number, p: any) => sum + (p.amount || 0), 0);
|
||||||
|
|
||||||
|
revenue.push({
|
||||||
|
label: monthLabel,
|
||||||
|
value: monthlyRevenue,
|
||||||
|
color: "#10b981",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const analyticsData: AnalyticsData = {
|
||||||
|
userGrowth,
|
||||||
|
membershipDistribution,
|
||||||
|
revenue,
|
||||||
|
};
|
||||||
|
|
||||||
|
return successResponse({ analytics: analyticsData });
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Analytics error:", error);
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: "Internal server error" },
|
||||||
|
{ status: 500 },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,27 +1,26 @@
|
|||||||
import { auth } from '@clerk/nextjs/server'
|
import { auth } from "@clerk/nextjs/server";
|
||||||
import { NextResponse } from 'next/server'
|
import { NextResponse } from "next/server";
|
||||||
import { getDatabase } from '@/lib/database'
|
import { getDatabase } from "@/lib/database";
|
||||||
import { ensureUserSynced } from '@/lib/sync-user'
|
import { ensureUserSynced } from "@/lib/sync-user";
|
||||||
|
import { successResponse } from "@/lib/api/responses";
|
||||||
|
|
||||||
export async function GET(req: Request) {
|
export async function GET(req: Request) {
|
||||||
try {
|
try {
|
||||||
const { userId } = await auth()
|
const { userId } = await auth();
|
||||||
if (!userId) return new NextResponse('Unauthorized', { status: 401 })
|
if (!userId) return new NextResponse("Unauthorized", { status: 401 });
|
||||||
|
|
||||||
const db = await getDatabase()
|
const db = await getDatabase();
|
||||||
|
|
||||||
// Ensure user is synced (handles seed script ID mismatch)
|
const user = await ensureUserSynced(userId, db);
|
||||||
// We need to import ensureUserSynced
|
|
||||||
const user = await ensureUserSynced(userId, db)
|
|
||||||
|
|
||||||
if (!user || (user.role !== 'admin' && user.role !== 'superAdmin')) {
|
if (!user || (user.role !== "admin" && user.role !== "superAdmin")) {
|
||||||
return new NextResponse('Forbidden', { status: 403 })
|
return new NextResponse("Forbidden", { status: 403 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const attendance = await db.getAllAttendance()
|
const attendance = await db.getAllAttendance();
|
||||||
return NextResponse.json(attendance)
|
return successResponse({ records: attendance });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Admin attendance error:', error)
|
console.error("Admin attendance error:", error);
|
||||||
return new NextResponse('Internal Server Error', { status: 500 })
|
return new NextResponse("Internal Server Error", { status: 500 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ import { auth } from "@clerk/nextjs/server";
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { getDatabase } from "@/lib/database";
|
import { getDatabase } from "@/lib/database";
|
||||||
import { ensureUserSynced } from "@/lib/sync-user";
|
import { ensureUserSynced } from "@/lib/sync-user";
|
||||||
|
import { successResponse } from "@/lib/api/responses";
|
||||||
|
|
||||||
export async function GET(req: Request) {
|
export async function GET(req: Request) {
|
||||||
try {
|
try {
|
||||||
@@ -51,7 +52,7 @@ export async function GET(req: Request) {
|
|||||||
revenueGrowth: 0,
|
revenueGrowth: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
return NextResponse.json(stats);
|
return successResponse({ stats });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Dashboard stats error:", error);
|
console.error("Dashboard stats error:", error);
|
||||||
return new NextResponse("Internal Server Error", { status: 500 });
|
return new NextResponse("Internal Server Error", { status: 500 });
|
||||||
|
|||||||
@@ -1,96 +1,102 @@
|
|||||||
'use client'
|
"use client";
|
||||||
|
|
||||||
import { useState, useEffect } from 'react'
|
import { useAttendance } from "@/hooks/use-api";
|
||||||
import { format } from 'date-fns'
|
import { PageHeader } from "@/components/ui/PageHeader";
|
||||||
|
import { Badge } from "@/components/ui/badge";
|
||||||
interface Attendance {
|
|
||||||
id: string
|
|
||||||
clientId: string
|
|
||||||
checkInTime: string
|
|
||||||
checkOutTime?: string
|
|
||||||
type: string
|
|
||||||
notes?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function AttendancePage() {
|
export default function AttendancePage() {
|
||||||
const [attendance, setAttendance] = useState<Attendance[]>([])
|
const { data: attendance = [], isLoading } = useAttendance();
|
||||||
const [loading, setLoading] = useState(true)
|
|
||||||
|
|
||||||
useEffect(() => {
|
if (isLoading) {
|
||||||
const fetchAttendance = async () => {
|
return (
|
||||||
try {
|
<div className="space-y-8">
|
||||||
const res = await fetch('/api/admin/attendance')
|
<PageHeader
|
||||||
if (res.ok) {
|
title="Attendance"
|
||||||
const data = await res.json()
|
description="Monitor gym check-ins and check-outs"
|
||||||
setAttendance(data)
|
breadcrumbs={[{ label: "Attendance" }]}
|
||||||
}
|
/>
|
||||||
} catch (error) {
|
<div className="card-modern">
|
||||||
console.error('Error fetching attendance:', error)
|
<div className="animate-pulse space-y-4">
|
||||||
} finally {
|
{[...Array(5)].map((_, i) => (
|
||||||
setLoading(false)
|
<div key={i} className="h-12 bg-muted rounded" />
|
||||||
}
|
))}
|
||||||
}
|
</div>
|
||||||
|
</div>
|
||||||
fetchAttendance()
|
</div>
|
||||||
}, [])
|
);
|
||||||
|
|
||||||
if (loading) {
|
|
||||||
return <div className="p-8">Loading...</div>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-8">
|
<div className="space-y-8">
|
||||||
<h1 className="text-2xl font-bold mb-6">Attendance Monitoring</h1>
|
<PageHeader
|
||||||
|
title="Attendance"
|
||||||
|
description="Monitor gym check-ins and check-outs"
|
||||||
|
breadcrumbs={[{ label: "Attendance" }]}
|
||||||
|
/>
|
||||||
|
|
||||||
<div className="bg-white rounded-lg shadow overflow-hidden">
|
<div className="card-modern">
|
||||||
<table className="min-w-full divide-y divide-gray-200">
|
<div className="overflow-x-auto">
|
||||||
<thead className="bg-gray-50">
|
<table className="w-full">
|
||||||
<tr>
|
<thead>
|
||||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
<tr className="border-b border-border">
|
||||||
Client ID
|
<th className="text-left py-3 px-4 text-sm font-medium text-muted-foreground">
|
||||||
|
Client
|
||||||
</th>
|
</th>
|
||||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
<th className="text-left py-3 px-4 text-sm font-medium text-muted-foreground">
|
||||||
Type
|
Type
|
||||||
</th>
|
</th>
|
||||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
<th className="text-left py-3 px-4 text-sm font-medium text-muted-foreground">
|
||||||
Check In
|
Check In
|
||||||
</th>
|
</th>
|
||||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
<th className="text-left py-3 px-4 text-sm font-medium text-muted-foreground">
|
||||||
Check Out
|
Check Out
|
||||||
</th>
|
</th>
|
||||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
<th className="text-left py-3 px-4 text-sm font-medium text-muted-foreground">
|
||||||
Status
|
Status
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody className="bg-white divide-y divide-gray-200">
|
<tbody>
|
||||||
{attendance.map((record) => (
|
{attendance.map((record) => (
|
||||||
<tr key={record.id}>
|
<tr
|
||||||
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
|
key={record.id}
|
||||||
{record.clientId}
|
className="border-b border-border/50 hover:bg-muted/50 transition-colors"
|
||||||
|
>
|
||||||
|
<td className="py-3 px-4 text-sm">
|
||||||
|
{record.userId.substring(0, 8)}...
|
||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500 capitalize">
|
<td className="py-3 px-4 text-sm capitalize text-muted-foreground">
|
||||||
{record.type}
|
{record.type}
|
||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
<td className="py-3 px-4 text-sm text-muted-foreground">
|
||||||
{format(new Date(record.checkInTime), 'PP p')}
|
{new Date(record.checkIn).toLocaleString()}
|
||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
<td className="py-3 px-4 text-sm text-muted-foreground">
|
||||||
{record.checkOutTime ? format(new Date(record.checkOutTime), 'PP p') : '-'}
|
{record.checkOut
|
||||||
|
? new Date(record.checkOut).toLocaleString()
|
||||||
|
: "-"}
|
||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-4 whitespace-nowrap">
|
<td className="py-3 px-4">
|
||||||
<span className={`px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${record.checkOutTime
|
<Badge variant={record.checkOut ? "gray" : "success"}>
|
||||||
? 'bg-gray-100 text-gray-800'
|
{record.checkOut ? "Completed" : "Active"}
|
||||||
: 'bg-green-100 text-green-800'
|
</Badge>
|
||||||
}`}>
|
|
||||||
{record.checkOutTime ? 'Completed' : 'Active'}
|
|
||||||
</span>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
|
{attendance.length === 0 && (
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
colSpan={5}
|
||||||
|
className="py-8 text-center text-muted-foreground"
|
||||||
|
>
|
||||||
|
No attendance records found
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
@layer base {
|
@layer base {
|
||||||
:root {
|
:root {
|
||||||
--background: 0 0% 100%;
|
--background: 0 0% 98%;
|
||||||
--foreground: 222.2 84% 4.9%;
|
--foreground: 222.2 84% 4.9%;
|
||||||
|
|
||||||
--card: 0 0% 100%;
|
--card: 0 0% 100%;
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
--popover: 0 0% 100%;
|
--popover: 0 0% 100%;
|
||||||
--popover-foreground: 222.2 84% 4.9%;
|
--popover-foreground: 222.2 84% 4.9%;
|
||||||
|
|
||||||
--primary: 222.2 47.4% 11.2%;
|
--primary: 221.2 83.2% 53.3%;
|
||||||
--primary-foreground: 210 40% 98%;
|
--primary-foreground: 210 40% 98%;
|
||||||
|
|
||||||
--secondary: 210 40% 96.1%;
|
--secondary: 210 40% 96.1%;
|
||||||
@@ -28,24 +28,42 @@
|
|||||||
--destructive: 0 84.2% 60.2%;
|
--destructive: 0 84.2% 60.2%;
|
||||||
--destructive-foreground: 210 40% 98%;
|
--destructive-foreground: 210 40% 98%;
|
||||||
|
|
||||||
|
--success: 142.1 76.2% 36.3%;
|
||||||
|
--success-foreground: 355.7 100% 97.3%;
|
||||||
|
|
||||||
|
--warning: 37.7 93.1% 50.2%;
|
||||||
|
--warning-foreground: 222.2 47.4% 11.2%;
|
||||||
|
|
||||||
|
--info: 199.4 86.4% 48.4%;
|
||||||
|
--info-foreground: 210 40% 98%;
|
||||||
|
|
||||||
--border: 214.3 31.8% 91.4%;
|
--border: 214.3 31.8% 91.4%;
|
||||||
--input: 214.3 31.8% 91.4%;
|
--input: 214.3 31.8% 91.4%;
|
||||||
--ring: 222.2 84% 4.9%;
|
--ring: 221.2 83.2% 53.3%;
|
||||||
|
|
||||||
--radius: 0.5rem;
|
--radius: 0.625rem;
|
||||||
|
|
||||||
|
--sidebar-background: 222.2 47.4% 7.8%;
|
||||||
|
--sidebar-foreground: 210 40% 98%;
|
||||||
|
--sidebar-primary: 221.2 83.2% 53.3%;
|
||||||
|
--sidebar-primary-foreground: 210 40% 98%;
|
||||||
|
--sidebar-accent: 217.2 32.6% 17.5%;
|
||||||
|
--sidebar-accent-foreground: 210 40% 98%;
|
||||||
|
--sidebar-border: 217.2 32.6% 17.5%;
|
||||||
|
--sidebar-ring: 217.2 91.6% 59.8%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dark {
|
.dark {
|
||||||
--background: 222.2 84% 4.9%;
|
--background: 222.2 84% 4.9%;
|
||||||
--foreground: 210 40% 98%;
|
--foreground: 210 40% 98%;
|
||||||
|
|
||||||
--card: 222.2 84% 4.9%;
|
--card: 222.2 47.4% 10.2%;
|
||||||
--card-foreground: 210 40% 98%;
|
--card-foreground: 210 40% 98%;
|
||||||
|
|
||||||
--popover: 222.2 84% 4.9%;
|
--popover: 222.2 47.4% 10.2%;
|
||||||
--popover-foreground: 210 40% 98%;
|
--popover-foreground: 210 40% 98%;
|
||||||
|
|
||||||
--primary: 210 40% 98%;
|
--primary: 217.2 91.2% 59.8%;
|
||||||
--primary-foreground: 222.2 47.4% 11.2%;
|
--primary-foreground: 222.2 47.4% 11.2%;
|
||||||
|
|
||||||
--secondary: 217.2 32.6% 17.5%;
|
--secondary: 217.2 32.6% 17.5%;
|
||||||
@@ -60,9 +78,27 @@
|
|||||||
--destructive: 0 62.8% 30.6%;
|
--destructive: 0 62.8% 30.6%;
|
||||||
--destructive-foreground: 210 40% 98%;
|
--destructive-foreground: 210 40% 98%;
|
||||||
|
|
||||||
|
--success: 142.1 76.2% 36.3%;
|
||||||
|
--success-foreground: 355.7 100% 97.3%;
|
||||||
|
|
||||||
|
--warning: 37.7 93.1% 50.2%;
|
||||||
|
--warning-foreground: 222.2 47.4% 11.2%;
|
||||||
|
|
||||||
|
--info: 199.4 86.4% 48.4%;
|
||||||
|
--info-foreground: 210 40% 98%;
|
||||||
|
|
||||||
--border: 217.2 32.6% 17.5%;
|
--border: 217.2 32.6% 17.5%;
|
||||||
--input: 217.2 32.6% 17.5%;
|
--input: 217.2 32.6% 17.5%;
|
||||||
--ring: 212.7 26.8% 83.9%;
|
--ring: 224.3 76.3% 48%;
|
||||||
|
|
||||||
|
--sidebar-background: 222.2 47.4% 7.8%;
|
||||||
|
--sidebar-foreground: 210 40% 98%;
|
||||||
|
--sidebar-primary: 217.2 91.2% 59.8%;
|
||||||
|
--sidebar-primary-foreground: 222.2 47.4% 11.2%;
|
||||||
|
--sidebar-accent: 217.2 32.6% 17.5%;
|
||||||
|
--sidebar-accent-foreground: 210 40% 98%;
|
||||||
|
--sidebar-border: 217.2 32.6% 17.5%;
|
||||||
|
--sidebar-ring: 217.2 91.6% 59.8%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,3 +110,139 @@
|
|||||||
@apply bg-background text-foreground;
|
@apply bg-background text-foreground;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@layer utilities {
|
||||||
|
.gradient-mesh {
|
||||||
|
background:
|
||||||
|
radial-gradient(
|
||||||
|
at 40% 20%,
|
||||||
|
hsla(221, 83%, 53%, 0.1) 0px,
|
||||||
|
transparent 50%
|
||||||
|
),
|
||||||
|
radial-gradient(at 80% 0%, hsla(189, 97%, 66%, 0.1) 0px, transparent 50%),
|
||||||
|
radial-gradient(at 0% 50%, hsla(355, 85%, 93%, 0.3) 0px, transparent 50%),
|
||||||
|
radial-gradient(
|
||||||
|
at 80% 50%,
|
||||||
|
hsla(240, 75%, 98%, 0.3) 0px,
|
||||||
|
transparent 50%
|
||||||
|
),
|
||||||
|
radial-gradient(at 0% 100%, hsla(22, 100%, 92%, 0.2) 0px, transparent 50%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.glass {
|
||||||
|
@apply backdrop-blur-xl bg-white/70 dark:bg-black/70;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-gradient {
|
||||||
|
@apply bg-clip-text text-transparent bg-gradient-to-r from-primary to-primary/60;
|
||||||
|
}
|
||||||
|
|
||||||
|
.animate-fade-in {
|
||||||
|
animation: fadeIn 0.5s ease-out forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
.animate-slide-up {
|
||||||
|
animation: slideUp 0.5s ease-out forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
.animate-scale-in {
|
||||||
|
animation: scaleIn 0.3s ease-out forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes fadeIn {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes slideUp {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateY(20px);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes scaleIn {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
transform: scale(0.95);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
transform: scale(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.stagger-1 {
|
||||||
|
animation-delay: 0.1s;
|
||||||
|
}
|
||||||
|
.stagger-2 {
|
||||||
|
animation-delay: 0.2s;
|
||||||
|
}
|
||||||
|
.stagger-3 {
|
||||||
|
animation-delay: 0.3s;
|
||||||
|
}
|
||||||
|
.stagger-4 {
|
||||||
|
animation-delay: 0.4s;
|
||||||
|
}
|
||||||
|
.stagger-5 {
|
||||||
|
animation-delay: 0.5s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@layer components {
|
||||||
|
.btn-primary {
|
||||||
|
@apply inline-flex items-center justify-center rounded-lg bg-primary px-4 py-2 text-sm font-medium text-primary-foreground shadow-sm transition-all duration-200 hover:bg-primary/90 hover:shadow-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-secondary {
|
||||||
|
@apply inline-flex items-center justify-center rounded-lg bg-secondary px-4 py-2 text-sm font-medium text-secondary-foreground shadow-sm transition-all duration-200 hover:bg-secondary/80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-ghost {
|
||||||
|
@apply inline-flex items-center justify-center rounded-lg px-4 py-2 text-sm font-medium text-muted-foreground transition-all duration-200 hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-danger {
|
||||||
|
@apply inline-flex items-center justify-center rounded-lg bg-destructive px-4 py-2 text-sm font-medium text-destructive-foreground shadow-sm transition-all duration-200 hover:bg-destructive/90 hover:shadow-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-modern {
|
||||||
|
@apply rounded-xl border border-border/50 bg-card p-6 shadow-sm transition-all duration-200 hover:shadow-md;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-elevated {
|
||||||
|
@apply rounded-xl border border-border/50 bg-card p-6 shadow-lg transition-all duration-200 hover:shadow-xl hover:-translate-y-0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-modern {
|
||||||
|
@apply flex h-10 w-full rounded-lg border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 transition-all duration-200;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-success {
|
||||||
|
@apply inline-flex items-center rounded-full bg-green-100 px-2.5 py-0.5 text-xs font-medium text-green-800 dark:bg-green-900/30 dark:text-green-400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-warning {
|
||||||
|
@apply inline-flex items-center rounded-full bg-yellow-100 px-2.5 py-0.5 text-xs font-medium text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-error {
|
||||||
|
@apply inline-flex items-center rounded-full bg-red-100 px-2.5 py-0.5 text-xs font-medium text-red-800 dark:bg-red-900/30 dark:text-red-400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-info {
|
||||||
|
@apply inline-flex items-center rounded-full bg-blue-100 px-2.5 py-0.5 text-xs font-medium text-blue-800 dark:bg-blue-900/30 dark:text-blue-400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-default {
|
||||||
|
@apply inline-flex items-center rounded-full bg-gray-100 px-2.5 py-0.5 text-xs font-medium text-gray-800 dark:bg-gray-800 dark:text-gray-300;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
} from "@clerk/nextjs";
|
} from "@clerk/nextjs";
|
||||||
import { Sidebar } from "@/components/ui/Sidebar";
|
import { Sidebar } from "@/components/ui/Sidebar";
|
||||||
import { Toaster } from "sonner";
|
import { Toaster } from "sonner";
|
||||||
|
import { QueryProvider } from "@/components/providers/QueryProvider";
|
||||||
|
|
||||||
const inter = Inter({ subsets: ["latin"] });
|
const inter = Inter({ subsets: ["latin"] });
|
||||||
|
|
||||||
@@ -25,15 +26,19 @@ export default function RootLayout({
|
|||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<ClerkProvider>
|
<ClerkProvider>
|
||||||
|
<QueryProvider>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<body className={inter.className}>
|
<body className={inter.className}>
|
||||||
<div className="flex min-h-screen bg-slate-50">
|
<div className="flex min-h-screen bg-background">
|
||||||
<Sidebar />
|
<Sidebar />
|
||||||
<main className="flex-1 ml-20 p-8">{children}</main>
|
<main className="flex-1 p-6 lg:p-8 min-h-screen">
|
||||||
|
<div className="max-w-7xl mx-auto space-y-8">{children}</div>
|
||||||
|
</main>
|
||||||
</div>
|
</div>
|
||||||
<Toaster richColors position="top-right" />
|
<Toaster richColors position="top-right" />
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
</QueryProvider>
|
||||||
</ClerkProvider>
|
</ClerkProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
+82
-50
@@ -1,69 +1,82 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useEffect, useState } from "react";
|
import {
|
||||||
import { Users, CreditCard, CalendarCheck, TrendingUp } from "lucide-react";
|
Users,
|
||||||
import { StatsCard } from "@/components/ui/StatsCard";
|
CreditCard,
|
||||||
|
CalendarCheck,
|
||||||
|
TrendingUp,
|
||||||
|
RefreshCw,
|
||||||
|
} from "lucide-react";
|
||||||
|
import { StatsCard, StatsCardSkeleton } from "@/components/ui/StatsCard";
|
||||||
|
import { PageHeader } from "@/components/ui/PageHeader";
|
||||||
import { UserManagement } from "@/components/users/UserManagement";
|
import { UserManagement } from "@/components/users/UserManagement";
|
||||||
import { AnalyticsDashboard } from "@/components/analytics/AnalyticsDashboard";
|
import { AnalyticsDashboard } from "@/components/analytics/AnalyticsDashboard";
|
||||||
import axios from "axios";
|
import { useDashboardStats } from "@/hooks/use-api";
|
||||||
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
interface DashboardStats {
|
import { Button } from "@/components/ui/button";
|
||||||
totalUsers: number;
|
|
||||||
activeClients: number;
|
|
||||||
totalRevenue: number;
|
|
||||||
revenueGrowth: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
const [stats, setStats] = useState<DashboardStats>({
|
const { data: stats, isLoading, refetch, isFetching } = useDashboardStats();
|
||||||
totalUsers: 0,
|
const queryClient = useQueryClient();
|
||||||
activeClients: 0,
|
|
||||||
totalRevenue: 0,
|
|
||||||
revenueGrowth: 0,
|
|
||||||
});
|
|
||||||
const [loading, setLoading] = useState(true);
|
|
||||||
|
|
||||||
useEffect(() => {
|
const handleRefresh = () => {
|
||||||
const fetchStats = async () => {
|
queryClient.invalidateQueries({ queryKey: ["dashboard-stats"] });
|
||||||
try {
|
queryClient.invalidateQueries({ queryKey: ["analytics"] });
|
||||||
const response = await axios.get("/api/admin/stats");
|
refetch();
|
||||||
setStats(response.data);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Failed to fetch dashboard stats:", error);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchStats();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const formatCurrency = (value: number) => {
|
const formatCurrency = (value: number) => {
|
||||||
return new Intl.NumberFormat("en-US", {
|
return new Intl.NumberFormat("en-US", {
|
||||||
style: "currency",
|
style: "currency",
|
||||||
currency: "USD",
|
currency: "USD",
|
||||||
}).format(value);
|
minimumFractionDigits: 0,
|
||||||
|
maximumFractionDigits: 0,
|
||||||
|
}).format(value || 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-8">
|
<div className="space-y-8">
|
||||||
<div>
|
<PageHeader
|
||||||
<h2 className="text-3xl font-bold text-slate-900">Dashboard</h2>
|
title="Dashboard"
|
||||||
<p className="text-slate-500 mt-2">Welcome back, here's what's happening today.</p>
|
description="Welcome back! Here's what's happening with your gym today."
|
||||||
</div>
|
actions={
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={handleRefresh}
|
||||||
|
disabled={isFetching}
|
||||||
|
className="gap-2"
|
||||||
|
>
|
||||||
|
<RefreshCw
|
||||||
|
className={`h-4 w-4 ${isFetching ? "animate-spin" : ""}`}
|
||||||
|
/>
|
||||||
|
Refresh
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
|
{/* Stats Grid */}
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
|
||||||
|
{isLoading ? (
|
||||||
|
<>
|
||||||
|
<StatsCardSkeleton />
|
||||||
|
<StatsCardSkeleton />
|
||||||
|
<StatsCardSkeleton />
|
||||||
|
<StatsCardSkeleton />
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
<StatsCard
|
<StatsCard
|
||||||
title="Total Users"
|
title="Total Users"
|
||||||
value={loading ? "..." : stats.totalUsers}
|
value={stats?.totalUsers ?? 0}
|
||||||
change="+12%" // Placeholder for now as we don't track historical growth yet
|
change="+12%"
|
||||||
trend="up"
|
trend="up"
|
||||||
icon={Users}
|
icon={Users}
|
||||||
color="blue"
|
color="blue"
|
||||||
/>
|
/>
|
||||||
<StatsCard
|
<StatsCard
|
||||||
title="Active Clients"
|
title="Active Clients"
|
||||||
value={loading ? "..." : stats.activeClients}
|
value={stats?.activeClients ?? 0}
|
||||||
change="+5%"
|
change="+5%"
|
||||||
trend="up"
|
trend="up"
|
||||||
icon={CalendarCheck}
|
icon={CalendarCheck}
|
||||||
@@ -71,32 +84,51 @@ export default function Home() {
|
|||||||
/>
|
/>
|
||||||
<StatsCard
|
<StatsCard
|
||||||
title="Revenue"
|
title="Revenue"
|
||||||
value={loading ? "..." : formatCurrency(stats.totalRevenue)}
|
value={formatCurrency(stats?.totalRevenue ?? 0)}
|
||||||
change={`${stats.revenueGrowth > 0 ? "+" : ""}${stats.revenueGrowth}%`}
|
change={`${(stats?.revenueGrowth ?? 0) > 0 ? "+" : ""}${stats?.revenueGrowth ?? 0}%`}
|
||||||
trend={stats.revenueGrowth >= 0 ? "up" : "down"}
|
trend={(stats?.revenueGrowth ?? 0) >= 0 ? "up" : "down"}
|
||||||
icon={CreditCard}
|
icon={CreditCard}
|
||||||
color="purple"
|
color="purple"
|
||||||
/>
|
/>
|
||||||
<StatsCard
|
<StatsCard
|
||||||
title="Growth"
|
title="Growth"
|
||||||
value="24%" // Placeholder
|
value="24%"
|
||||||
change="-2%"
|
change="-2%"
|
||||||
trend="down"
|
trend="down"
|
||||||
icon={TrendingUp}
|
icon={TrendingUp}
|
||||||
color="orange"
|
color="orange"
|
||||||
/>
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-col gap-8">
|
{/* Main Content Grid */}
|
||||||
<div className="bg-white rounded-xl shadow-sm border border-slate-100 p-6">
|
<div className="grid grid-cols-1 xl:grid-cols-3 gap-6">
|
||||||
<h3 className="text-xl font-bold text-slate-900 mb-6">Recent Activity</h3>
|
{/* <div className="xl:col-span-2"> */}
|
||||||
<UserManagement />
|
{/* <div className="card-modern"> */}
|
||||||
|
{/* <div className="mb-6"> */}
|
||||||
|
{/* <h3 className="text-lg font-semibold">Recent Activity</h3> */}
|
||||||
|
{/* <p className="text-sm text-muted-foreground"> */}
|
||||||
|
{/* Manage and view your users */}
|
||||||
|
{/* </p> */}
|
||||||
|
{/* </div> */}
|
||||||
|
{/* <UserManagement /> */}
|
||||||
|
{/* </div> */}
|
||||||
|
{/* </div> */}
|
||||||
|
|
||||||
|
{/* Analytics Sidebar */}
|
||||||
|
<div className="xl:col-span-3">
|
||||||
|
<div className="card-modern">
|
||||||
|
<div className="mb-6">
|
||||||
|
<h3 className="text-lg font-semibold">Quick Analytics</h3>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Overview of your gym metrics
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="bg-white rounded-xl shadow-sm border border-slate-100 p-6">
|
|
||||||
<h3 className="text-xl font-bold text-slate-900 mb-6">Quick Analytics</h3>
|
|
||||||
<AnalyticsDashboard />
|
<AnalyticsDashboard />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,7 @@ export default function ProfilePage() {
|
|||||||
<div className="flex justify-between items-center mb-6">
|
<div className="flex justify-between items-center mb-6">
|
||||||
<h1 className="text-2xl font-bold">Profile</h1>
|
<h1 className="text-2xl font-bold">Profile</h1>
|
||||||
<Button
|
<Button
|
||||||
variant={isEditing ? "primary" : "secondary"}
|
variant={isEditing ? "default" : "secondary"}
|
||||||
onClick={() => setIsEditing(!isEditing)}
|
onClick={() => setIsEditing(!isEditing)}
|
||||||
>
|
>
|
||||||
{isEditing ? "Cancel" : "Edit Profile"}
|
{isEditing ? "Cancel" : "Edit Profile"}
|
||||||
|
|||||||
@@ -1,86 +1,41 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useEffect, useState } from "react";
|
import { useState } from "react";
|
||||||
import { useUser } from "@clerk/nextjs";
|
import { useUser } from "@clerk/nextjs";
|
||||||
import log from "@/lib/logger";
|
import log from "@/lib/logger";
|
||||||
import { toast } from "@/lib/toast";
|
import { toast } from "@/lib/toast";
|
||||||
|
import {
|
||||||
interface User {
|
useUsers,
|
||||||
id: string;
|
useRecommendations,
|
||||||
firstName: string;
|
useGenerateRecommendations,
|
||||||
lastName: string;
|
useApproveRecommendation,
|
||||||
email: string;
|
useUpdateRecommendation,
|
||||||
}
|
type Recommendation,
|
||||||
|
} from "@/hooks/use-api";
|
||||||
interface Recommendation {
|
import { PageHeader } from "@/components/ui/PageHeader";
|
||||||
id: string;
|
|
||||||
userId: string;
|
|
||||||
content: string;
|
|
||||||
recommendationText: string;
|
|
||||||
activityPlan: string;
|
|
||||||
dietPlan: string;
|
|
||||||
status: string;
|
|
||||||
createdAt: Date;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function RecommendationsPage() {
|
export default function RecommendationsPage() {
|
||||||
const { user } = useUser();
|
const { user } = useUser();
|
||||||
const [users, setUsers] = useState<User[]>([]);
|
|
||||||
const [pendingRecommendations, setPendingRecommendations] = useState<
|
|
||||||
Recommendation[]
|
|
||||||
>([]);
|
|
||||||
const [loading, setLoading] = useState(true);
|
|
||||||
const [generating, setGenerating] = useState<string | null>(null);
|
|
||||||
const [useExternalModel, setUseExternalModel] = useState(false);
|
const [useExternalModel, setUseExternalModel] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
const { data: users = [], isLoading: usersLoading } = useUsers();
|
||||||
fetchData();
|
const { data: allRecommendations = [], isLoading: recsLoading } =
|
||||||
}, []);
|
useRecommendations();
|
||||||
|
const pendingRecommendations = allRecommendations.filter(
|
||||||
const fetchData = async () => {
|
(r) => r.status === "pending",
|
||||||
try {
|
|
||||||
// Fetch users - API returns { success: true, data: { users: [...] }, meta: {...} }
|
|
||||||
const usersRes = await fetch("/api/users");
|
|
||||||
const usersResult = await usersRes.json();
|
|
||||||
const usersArray = usersResult.data?.users || usersResult.users || [];
|
|
||||||
setUsers(usersArray);
|
|
||||||
|
|
||||||
// Fetch pending recommendations - API returns { success: true, data: { recommendations: [...] }, meta: {...} }
|
|
||||||
const recsRes = await fetch("/api/recommendations");
|
|
||||||
const recsResult = await recsRes.json();
|
|
||||||
const allRecs =
|
|
||||||
recsResult.data?.recommendations || recsResult.recommendations || [];
|
|
||||||
setPendingRecommendations(
|
|
||||||
allRecs.filter((r: Recommendation) => r.status === "pending"),
|
|
||||||
);
|
);
|
||||||
} catch (error) {
|
|
||||||
log.error("Failed to fetch data", error);
|
const generateRec = useGenerateRecommendations();
|
||||||
} finally {
|
const approveRec = useApproveRecommendation();
|
||||||
setLoading(false);
|
const updateRec = useUpdateRecommendation();
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleGenerate = async (userId: string) => {
|
const handleGenerate = async (userId: string) => {
|
||||||
setGenerating(userId);
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch("/api/recommendations/generate", {
|
await generateRec.mutateAsync(userId);
|
||||||
method: "POST",
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify({ userId, useExternalModel }),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!res.ok) {
|
|
||||||
const error = await res.json();
|
|
||||||
toast.error(`Error: ${error.error}`);
|
|
||||||
} else {
|
|
||||||
toast.success("Recommendation generated successfully!");
|
toast.success("Recommendation generated successfully!");
|
||||||
fetchData(); // Refresh data
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error("Failed to generate recommendation", error);
|
log.error("Failed to generate recommendation", error);
|
||||||
toast.error("Failed to generate recommendation.");
|
toast.error("Failed to generate recommendation.");
|
||||||
} finally {
|
|
||||||
setGenerating(null);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -89,25 +44,11 @@ export default function RecommendationsPage() {
|
|||||||
status: "approved" | "rejected",
|
status: "approved" | "rejected",
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch("/api/recommendations/approve", {
|
await approveRec.mutateAsync({
|
||||||
method: "POST",
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify({
|
|
||||||
recommendationId,
|
recommendationId,
|
||||||
status,
|
approved: status === "approved",
|
||||||
approvedBy: user?.id || "admin",
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!res.ok) {
|
|
||||||
const errorData = await res.json();
|
|
||||||
toast.error(
|
|
||||||
`Failed to update status: ${errorData.error || "Unknown error"}`,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
toast.success("Recommendation status updated");
|
toast.success("Recommendation status updated");
|
||||||
fetchData(); // Refresh data
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error("Failed to approve recommendation", error);
|
log.error("Failed to approve recommendation", error);
|
||||||
toast.error("Error processing request");
|
toast.error("Error processing request");
|
||||||
@@ -124,159 +65,129 @@ export default function RecommendationsPage() {
|
|||||||
newActivityPlan === null ||
|
newActivityPlan === null ||
|
||||||
newDietPlan === null
|
newDietPlan === null
|
||||||
) {
|
) {
|
||||||
// User cancelled one of the prompts
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch("/api/recommendations", {
|
await updateRec.mutateAsync({
|
||||||
method: "PUT",
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify({
|
|
||||||
id: rec.id,
|
id: rec.id,
|
||||||
content: newContent,
|
content: newContent,
|
||||||
activityPlan: newActivityPlan,
|
activityPlan: newActivityPlan,
|
||||||
dietPlan: newDietPlan,
|
dietPlan: newDietPlan,
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!res.ok) {
|
|
||||||
const errorData = await res.json();
|
|
||||||
toast.error(
|
|
||||||
`Failed to update recommendation: ${errorData.error || "Unknown error"}`,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
toast.success("Recommendation updated successfully!");
|
toast.success("Recommendation updated successfully!");
|
||||||
fetchData(); // Refresh data
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error("Failed to update recommendation", error);
|
log.error("Failed to update recommendation", error);
|
||||||
toast.error("Failed to update recommendation.");
|
toast.error("Failed to update recommendation.");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (loading) {
|
if (usersLoading || recsLoading) {
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center justify-center h-screen">
|
<div className="flex items-center justify-center h-64">
|
||||||
<div className="text-xl">Loading...</div>
|
<div className="text-lg">Loading...</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="container mx-auto py-10 px-4">
|
<div className="space-y-8">
|
||||||
<div className="flex justify-between items-center mb-8">
|
<PageHeader
|
||||||
<h1 className="text-3xl font-bold">AI Recommendations</h1>
|
title="AI Recommendations"
|
||||||
|
description="Generate and manage AI-powered fitness recommendations"
|
||||||
{/* Model Selection Toggle */}
|
breadcrumbs={[{ label: "AI Recommendations" }]}
|
||||||
<div className="flex items-center gap-3 bg-white px-4 py-2 rounded-lg shadow">
|
|
||||||
<span className="text-sm font-medium text-gray-700">
|
|
||||||
{useExternalModel ? "DeepSeek AI" : "Local Ollama"}
|
|
||||||
</span>
|
|
||||||
<button
|
|
||||||
onClick={() => setUseExternalModel(!useExternalModel)}
|
|
||||||
className={`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${
|
|
||||||
useExternalModel ? "bg-blue-600" : "bg-gray-300"
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
className={`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${
|
|
||||||
useExternalModel ? "translate-x-6" : "translate-x-1"
|
|
||||||
}`}
|
|
||||||
/>
|
/>
|
||||||
</button>
|
|
||||||
<span className="text-xs text-gray-500">
|
|
||||||
{useExternalModel ? "External" : "Local"}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-8">
|
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
||||||
{/* Generate Section */}
|
{/* Generate Section */}
|
||||||
<div>
|
<div className="card-modern">
|
||||||
<h2 className="text-2xl font-semibold mb-4">
|
<div className="mb-6">
|
||||||
Generate Recommendations
|
<h3 className="text-lg font-semibold">Generate Recommendations</h3>
|
||||||
</h2>
|
<p className="text-sm text-muted-foreground">
|
||||||
<div className="bg-white shadow rounded-lg p-6">
|
|
||||||
<p className="mb-4 text-gray-600">
|
|
||||||
Select a user to generate a new daily recommendation.
|
Select a user to generate a new daily recommendation.
|
||||||
</p>
|
</p>
|
||||||
|
</div>
|
||||||
<ul className="space-y-4">
|
<ul className="space-y-4">
|
||||||
{users.map((user) => (
|
{users.map((user) => (
|
||||||
<li
|
<li
|
||||||
key={user.id}
|
key={user.id}
|
||||||
className="flex items-center justify-between border-b pb-2"
|
className="flex items-center justify-between border-b border-border/50 pb-4 last:border-0 last:pb-0"
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<p className="font-medium">
|
<p className="font-medium">
|
||||||
{user.firstName} {user.lastName}
|
{user.firstName} {user.lastName}
|
||||||
</p>
|
</p>
|
||||||
<p className="text-sm text-gray-500">{user.email}</p>
|
<p className="text-sm text-muted-foreground">{user.email}</p>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
onClick={() => handleGenerate(user.id)}
|
onClick={() => handleGenerate(user.id)}
|
||||||
disabled={generating === user.id}
|
disabled={generateRec.isPending}
|
||||||
className="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700 disabled:opacity-50"
|
className="btn-primary"
|
||||||
>
|
>
|
||||||
{generating === user.id ? "Generating..." : "Generate"}
|
{generateRec.isPending ? "Generating..." : "Generate"}
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
{users.length === 0 && (
|
{users.length === 0 && (
|
||||||
<p className="text-gray-500 italic">No users found.</p>
|
<p className="text-muted-foreground italic">No users found.</p>
|
||||||
)}
|
)}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Pending Approvals Section */}
|
{/* Pending Approvals Section */}
|
||||||
<div>
|
<div className="card-modern">
|
||||||
<h2 className="text-2xl font-semibold mb-4">Pending Approvals</h2>
|
<div className="mb-6">
|
||||||
<div className="bg-white shadow rounded-lg p-6">
|
<h3 className="text-lg font-semibold">Pending Approvals</h3>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Review and approve AI-generated recommendations
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
{pendingRecommendations.length === 0 ? (
|
{pendingRecommendations.length === 0 ? (
|
||||||
<p className="text-gray-500 italic">
|
<p className="text-muted-foreground italic">
|
||||||
No pending recommendations.
|
No pending recommendations.
|
||||||
</p>
|
</p>
|
||||||
) : (
|
) : (
|
||||||
<ul className="space-y-6">
|
<ul className="space-y-4">
|
||||||
{pendingRecommendations.map((rec) => (
|
{pendingRecommendations.map((rec) => (
|
||||||
<li key={rec.id} className="border rounded p-4">
|
<li
|
||||||
<div className="flex justify-between items-start mb-2">
|
key={rec.id}
|
||||||
<h3 className="font-bold">For: User {rec.userId}</h3>
|
className="border border-border rounded-lg p-4"
|
||||||
<span className="text-xs text-gray-500">
|
>
|
||||||
|
<div className="flex justify-between items-start mb-3">
|
||||||
|
<h4 className="font-semibold">For: User {rec.userId}</h4>
|
||||||
|
<span className="text-xs text-muted-foreground">
|
||||||
{new Date(rec.createdAt).toLocaleDateString()}
|
{new Date(rec.createdAt).toLocaleDateString()}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-2 text-sm mb-4">
|
<div className="space-y-2 text-sm mb-4">
|
||||||
<div>
|
<div>
|
||||||
<span className="font-semibold">Advice:</span>{" "}
|
<span className="font-medium">Advice:</span>{" "}
|
||||||
{rec.recommendationText}
|
{rec.recommendationText}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<span className="font-semibold">Activity:</span>{" "}
|
<span className="font-medium">Activity:</span>{" "}
|
||||||
{rec.activityPlan}
|
{rec.activityPlan}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<span className="font-semibold">Diet:</span>{" "}
|
<span className="font-medium">Diet:</span> {rec.dietPlan}
|
||||||
{rec.dietPlan}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex space-x-2">
|
<div className="flex gap-2">
|
||||||
<button
|
<button
|
||||||
onClick={() => handleEdit(rec)}
|
onClick={() => handleEdit(rec)}
|
||||||
className="flex-1 bg-blue-500 text-white py-2 rounded hover:bg-blue-600"
|
className="btn-secondary flex-1"
|
||||||
>
|
>
|
||||||
Edit
|
Edit
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={() => handleApprove(rec.id, "approved")}
|
onClick={() => handleApprove(rec.id, "approved")}
|
||||||
className="flex-1 bg-green-600 text-white py-2 rounded hover:bg-green-700"
|
className="btn-primary flex-1 bg-emerald-600 hover:bg-emerald-700"
|
||||||
>
|
>
|
||||||
Approve
|
Approve
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={() => handleApprove(rec.id, "rejected")}
|
onClick={() => handleApprove(rec.id, "rejected")}
|
||||||
className="flex-1 bg-red-600 text-white py-2 rounded hover:bg-red-700"
|
className="btn-danger flex-1"
|
||||||
>
|
>
|
||||||
Reject
|
Reject
|
||||||
</button>
|
</button>
|
||||||
@@ -288,6 +199,5 @@ export default function RecommendationsPage() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,18 @@
|
|||||||
import { UserManagement } from '@/components/users/UserManagement'
|
import { UserManagement } from "@/components/users/UserManagement";
|
||||||
|
import { PageHeader } from "@/components/ui/PageHeader";
|
||||||
|
|
||||||
export default function UsersPage() {
|
export default function UsersPage() {
|
||||||
return (
|
return (
|
||||||
<main className="min-h-screen bg-gray-50">
|
<div className="space-y-8">
|
||||||
<div className="container mx-auto px-4 py-8">
|
<PageHeader
|
||||||
|
title="Users"
|
||||||
|
description="Manage your gym members, trainers, and administrators"
|
||||||
|
breadcrumbs={[{ label: "Users", href: "/users" }]}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="card-modern">
|
||||||
<UserManagement />
|
<UserManagement />
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
@@ -71,7 +71,7 @@ export function Navigation(): ReactElement {
|
|||||||
<li key={item.href}>
|
<li key={item.href}>
|
||||||
<Link href={item.href} className="flex items-center gap-2">
|
<Link href={item.href} className="flex items-center gap-2">
|
||||||
<Button
|
<Button
|
||||||
variant={pathname === item.href ? "primary" : "secondary"}
|
variant={pathname === item.href ? "default" : "secondary"}
|
||||||
className={cn(
|
className={cn(
|
||||||
"h-9 px-4 py-2",
|
"h-9 px-4 py-2",
|
||||||
pathname === item.href &&
|
pathname === item.href &&
|
||||||
|
|||||||
@@ -1,75 +1,34 @@
|
|||||||
'use client'
|
"use client";
|
||||||
|
|
||||||
import { useState, useEffect } from 'react'
|
import { UserGrowthChart } from "@/components/charts/UserGrowthChart";
|
||||||
import { UserGrowthChart } from '@/components/charts/UserGrowthChart'
|
import { MembershipDistributionChart } from "@/components/charts/MembershipDistributionChart";
|
||||||
import { MembershipDistributionChart } from '@/components/charts/MembershipDistributionChart'
|
import { RevenueChart } from "@/components/charts/RevenueChart";
|
||||||
import { RevenueChart } from '@/components/charts/RevenueChart'
|
import { Card, CardHeader, CardContent } from "@/components/ui/card";
|
||||||
import { Card, CardHeader, CardContent } from '@/components/ui/card'
|
import { useAnalytics } from "@/hooks/use-api";
|
||||||
|
|
||||||
interface ChartData {
|
|
||||||
label: string
|
|
||||||
value: number
|
|
||||||
color?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export function AnalyticsDashboard() {
|
export function AnalyticsDashboard() {
|
||||||
const [userGrowthData, setUserGrowthData] = useState<ChartData[]>([])
|
const { data: analytics, isLoading } = useAnalytics(6);
|
||||||
const [membershipData, setMembershipData] = useState<ChartData[]>([])
|
|
||||||
const [revenueData, setRevenueData] = useState<ChartData[]>([])
|
|
||||||
const [loading, setLoading] = useState(true)
|
|
||||||
|
|
||||||
useEffect(() => {
|
const userGrowthData = analytics?.userGrowth ?? [];
|
||||||
fetchAnalyticsData()
|
const membershipData = analytics?.membershipDistribution ?? [];
|
||||||
}, [])
|
const revenueData = analytics?.revenue ?? [];
|
||||||
|
|
||||||
const fetchAnalyticsData = async () => {
|
const totalUsers =
|
||||||
setLoading(true)
|
userGrowthData.length > 0
|
||||||
try {
|
? userGrowthData[userGrowthData.length - 1].value
|
||||||
// Mock data for demonstration - replace with real API calls
|
: 0;
|
||||||
const mockUserGrowth = [
|
const totalRevenue = revenueData.reduce((sum, item) => sum + item.value, 0);
|
||||||
{ label: 'Jan', value: 45 },
|
const activeMembers = membershipData.reduce(
|
||||||
{ label: 'Feb', value: 52 },
|
(sum, item) => sum + item.value,
|
||||||
{ label: 'Mar', value: 61 },
|
0,
|
||||||
{ label: 'Apr', value: 58 },
|
);
|
||||||
{ label: 'May', value: 67 },
|
|
||||||
{ label: 'Jun', value: 74 },
|
|
||||||
]
|
|
||||||
|
|
||||||
const mockMembershipData = [
|
if (isLoading) {
|
||||||
{ label: 'Basic', value: 45, color: '#6b7280' },
|
|
||||||
{ label: 'Premium', value: 28, color: '#3b82f6' },
|
|
||||||
{ label: 'VIP', value: 12, color: '#f59e0b' },
|
|
||||||
]
|
|
||||||
|
|
||||||
const mockRevenueData = [
|
|
||||||
{ label: 'Jan', value: 12500, color: '#10b981' },
|
|
||||||
{ label: 'Feb', value: 14200, color: '#10b981' },
|
|
||||||
{ label: 'Mar', value: 16800, color: '#10b981' },
|
|
||||||
{ label: 'Apr', value: 15900, color: '#10b981' },
|
|
||||||
{ label: 'May', value: 18200, color: '#10b981' },
|
|
||||||
{ label: 'Jun', value: 19400, color: '#10b981' },
|
|
||||||
]
|
|
||||||
|
|
||||||
setUserGrowthData(mockUserGrowth)
|
|
||||||
setMembershipData(mockMembershipData)
|
|
||||||
setRevenueData(mockRevenueData)
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to fetch analytics data:', error)
|
|
||||||
} finally {
|
|
||||||
setLoading(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const totalUsers = userGrowthData.length > 0 ? userGrowthData[userGrowthData.length - 1].value : 0
|
|
||||||
const totalRevenue = revenueData.reduce((sum, item) => sum + item.value, 0)
|
|
||||||
const activeMembers = membershipData.reduce((sum, item) => sum + item.value, 0)
|
|
||||||
|
|
||||||
if (loading) {
|
|
||||||
return (
|
return (
|
||||||
<div className="flex justify-center items-center h-64">
|
<div className="flex justify-center items-center h-64">
|
||||||
<div className="text-lg">Loading analytics...</div>
|
<div className="text-lg">Loading analytics...</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -81,7 +40,9 @@ export function AnalyticsDashboard() {
|
|||||||
<Card>
|
<Card>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<div className="text-center">
|
<div className="text-center">
|
||||||
<div className="text-3xl font-bold text-blue-600">{totalUsers}</div>
|
<div className="text-3xl font-bold text-blue-600">
|
||||||
|
{totalUsers}
|
||||||
|
</div>
|
||||||
<div className="text-gray-600">Total Users</div>
|
<div className="text-gray-600">Total Users</div>
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
@@ -90,7 +51,9 @@ export function AnalyticsDashboard() {
|
|||||||
<Card>
|
<Card>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<div className="text-center">
|
<div className="text-center">
|
||||||
<div className="text-3xl font-bold text-green-600">${totalRevenue.toLocaleString()}</div>
|
<div className="text-3xl font-bold text-green-600">
|
||||||
|
${totalRevenue.toLocaleString()}
|
||||||
|
</div>
|
||||||
<div className="text-gray-600">Total Revenue</div>
|
<div className="text-gray-600">Total Revenue</div>
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
@@ -99,7 +62,9 @@ export function AnalyticsDashboard() {
|
|||||||
<Card>
|
<Card>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<div className="text-center">
|
<div className="text-center">
|
||||||
<div className="text-3xl font-bold text-purple-600">{activeMembers}</div>
|
<div className="text-3xl font-bold text-purple-600">
|
||||||
|
{activeMembers}
|
||||||
|
</div>
|
||||||
<div className="text-gray-600">Active Members</div>
|
<div className="text-gray-600">Active Members</div>
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
@@ -133,14 +98,14 @@ export function AnalyticsDashboard() {
|
|||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<RevenueChart
|
<RevenueChart
|
||||||
data={revenueData.map(item => ({
|
data={revenueData.map((item) => ({
|
||||||
category: item.label,
|
category: item.label,
|
||||||
value: item.value,
|
value: item.value,
|
||||||
color: item.color
|
color: item.color,
|
||||||
}))}
|
}))}
|
||||||
/>
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||||
|
import { useState, type ReactNode } from "react";
|
||||||
|
|
||||||
|
interface QueryProviderProps {
|
||||||
|
children: ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function QueryProvider({ children }: QueryProviderProps) {
|
||||||
|
const [queryClient] = useState(
|
||||||
|
() =>
|
||||||
|
new QueryClient({
|
||||||
|
defaultOptions: {
|
||||||
|
queries: {
|
||||||
|
staleTime: 60 * 1000,
|
||||||
|
refetchOnWindowFocus: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { ChevronRight, Home } from "lucide-react";
|
||||||
|
import Link from "next/link";
|
||||||
|
|
||||||
|
interface Breadcrumb {
|
||||||
|
label: string;
|
||||||
|
href?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PageHeaderProps {
|
||||||
|
title: string;
|
||||||
|
description?: string;
|
||||||
|
breadcrumbs?: Breadcrumb[];
|
||||||
|
actions?: React.ReactNode;
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PageHeader({
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
breadcrumbs,
|
||||||
|
actions,
|
||||||
|
className,
|
||||||
|
}: PageHeaderProps) {
|
||||||
|
return (
|
||||||
|
<div className={cn("space-y-4", className)}>
|
||||||
|
{breadcrumbs && breadcrumbs.length > 0 && (
|
||||||
|
<nav className="flex items-center gap-1 text-sm">
|
||||||
|
<Link
|
||||||
|
href="/"
|
||||||
|
className="flex items-center gap-1 text-muted-foreground hover:text-foreground transition-colors"
|
||||||
|
>
|
||||||
|
<Home className="h-4 w-4" />
|
||||||
|
<span>Home</span>
|
||||||
|
</Link>
|
||||||
|
{breadcrumbs.map((crumb, index) => (
|
||||||
|
<span key={index} className="flex items-center gap-1">
|
||||||
|
<ChevronRight className="h-4 w-4 text-muted-foreground" />
|
||||||
|
{crumb.href ? (
|
||||||
|
<Link
|
||||||
|
href={crumb.href}
|
||||||
|
className="text-muted-foreground hover:text-foreground transition-colors"
|
||||||
|
>
|
||||||
|
{crumb.label}
|
||||||
|
</Link>
|
||||||
|
) : (
|
||||||
|
<span className="font-medium text-foreground">
|
||||||
|
{crumb.label}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</nav>
|
||||||
|
)}
|
||||||
|
<div className="flex items-start justify-between gap-4">
|
||||||
|
<div className="space-y-1">
|
||||||
|
<h1 className="text-3xl font-bold tracking-tight">{title}</h1>
|
||||||
|
{description && (
|
||||||
|
<p className="text-muted-foreground">{description}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{actions && <div className="flex items-center gap-3">{actions}</div>}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PageSectionProps {
|
||||||
|
title?: string;
|
||||||
|
description?: string;
|
||||||
|
children: React.ReactNode;
|
||||||
|
actions?: React.ReactNode;
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PageSection({
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
children,
|
||||||
|
actions,
|
||||||
|
className,
|
||||||
|
}: PageSectionProps) {
|
||||||
|
return (
|
||||||
|
<section className={cn("space-y-4", className)}>
|
||||||
|
{(title || actions) && (
|
||||||
|
<div className="flex items-start justify-between gap-4">
|
||||||
|
<div className="space-y-1">
|
||||||
|
{title && (
|
||||||
|
<h2 className="text-xl font-semibold tracking-tight">{title}</h2>
|
||||||
|
)}
|
||||||
|
{description && (
|
||||||
|
<p className="text-sm text-muted-foreground">{description}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{actions && <div className="flex items-center gap-2">{actions}</div>}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{children}
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -9,60 +9,48 @@ import {
|
|||||||
CalendarCheck,
|
CalendarCheck,
|
||||||
CreditCard,
|
CreditCard,
|
||||||
Settings,
|
Settings,
|
||||||
LogOut,
|
|
||||||
Brain,
|
Brain,
|
||||||
|
ChevronLeft,
|
||||||
|
Activity,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { UserButton, useUser } from "@clerk/nextjs";
|
import { UserButton, useUser } from "@clerk/nextjs";
|
||||||
|
import { usePendingRecommendationsCount } from "@/hooks/use-api";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
interface Recommendation {
|
interface NavItem {
|
||||||
id: string;
|
icon: React.ElementType;
|
||||||
status: string;
|
label: string;
|
||||||
|
href: string;
|
||||||
|
badge?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Sidebar() {
|
export function Sidebar() {
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const { user } = useUser();
|
const { user } = useUser();
|
||||||
const [pendingCount, setPendingCount] = useState(0);
|
const { data: pendingCount = 0 } = usePendingRecommendationsCount();
|
||||||
const [mounted, setMounted] = useState(false);
|
const [mounted, setMounted] = useState(false);
|
||||||
|
const [isCollapsed, setIsCollapsed] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setMounted(true);
|
setMounted(true);
|
||||||
|
const saved = localStorage.getItem("sidebar-collapsed");
|
||||||
|
if (saved) setIsCollapsed(JSON.parse(saved));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
const handleToggle = () => {
|
||||||
const fetchPending = async () => {
|
const newState = !isCollapsed;
|
||||||
try {
|
setIsCollapsed(newState);
|
||||||
const res = await fetch("/api/recommendations");
|
localStorage.setItem("sidebar-collapsed", JSON.stringify(newState));
|
||||||
if (res.ok) {
|
|
||||||
const data = await res.json();
|
|
||||||
const pending = (data.recommendations || []).filter(
|
|
||||||
(r: Recommendation) => r.status === "pending",
|
|
||||||
);
|
|
||||||
setPendingCount(pending.length);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Failed to fetch pending recommendations", e);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
fetchPending();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const menuItems = [
|
const navItems: NavItem[] = [
|
||||||
{ icon: LayoutDashboard, label: "Dashboard", href: "/" },
|
{ icon: LayoutDashboard, label: "Dashboard", href: "/" },
|
||||||
{ icon: Users, label: "Users", href: "/users" },
|
{ icon: Users, label: "Users", href: "/users" },
|
||||||
{
|
{
|
||||||
icon: Brain,
|
icon: Brain,
|
||||||
label: (
|
label: "AI Recommendations",
|
||||||
<span className="flex items-center">
|
|
||||||
AI Recommendations
|
|
||||||
{pendingCount > 0 && (
|
|
||||||
<span className="ml-2 inline-block bg-red-600 text-xs rounded-full px-2 py-0.5">
|
|
||||||
{pendingCount}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</span>
|
|
||||||
),
|
|
||||||
href: "/recommendations",
|
href: "/recommendations",
|
||||||
|
badge: pendingCount > 0 ? pendingCount : undefined,
|
||||||
},
|
},
|
||||||
{ icon: CalendarCheck, label: "Attendance", href: "/attendance" },
|
{ icon: CalendarCheck, label: "Attendance", href: "/attendance" },
|
||||||
{ icon: CreditCard, label: "Payments", href: "/payments" },
|
{ icon: CreditCard, label: "Payments", href: "/payments" },
|
||||||
@@ -70,60 +58,127 @@ export function Sidebar() {
|
|||||||
];
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<aside className="w-20 hover:w-64 bg-slate-900 text-white h-screen fixed left-0 top-0 flex flex-col border-r border-slate-800 transition-all duration-300 z-50 group overflow-hidden">
|
<aside
|
||||||
<div className="p-6 border-b border-slate-800 flex items-center overflow-hidden whitespace-nowrap">
|
className={cn(
|
||||||
<h1 className="text-2xl font-bold bg-gradient-to-r from-blue-400 to-indigo-400 bg-clip-text text-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-300">
|
"fixed left-0 top-0 z-40 h-screen transition-all duration-300 ease-in-out",
|
||||||
FitAI Admin
|
isCollapsed ? "w-[72px]" : "w-[260px]",
|
||||||
</h1>
|
"bg-gradient-to-b from-[var(--sidebar-background)] to-[#0f172a]",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<div className="flex h-full flex-col border-r border-white/5">
|
||||||
|
{/* Logo */}
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"flex h-16 items-center border-b border-white/5 px-4",
|
||||||
|
isCollapsed ? "justify-center" : "justify-between",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{!isCollapsed && (
|
||||||
|
<Link href="/" className="flex items-center gap-2">
|
||||||
|
<div className="flex h-9 w-9 items-center justify-center rounded-lg bg-gradient-to-br from-blue-500 to-indigo-600 shadow-lg shadow-blue-500/25">
|
||||||
|
<Activity className="h-5 w-5 text-white" />
|
||||||
|
</div>
|
||||||
|
<span className="text-lg font-bold text-white">FitAI</span>
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
|
{isCollapsed && (
|
||||||
|
<div className="flex h-9 w-9 items-center justify-center rounded-lg bg-gradient-to-br from-blue-500 to-indigo-600 shadow-lg shadow-blue-500/25">
|
||||||
|
<Activity className="h-5 w-5 text-white" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<nav className="flex-1 p-4 space-y-2">
|
{/* Toggle Button */}
|
||||||
{menuItems.map((item) => {
|
<button
|
||||||
|
onClick={handleToggle}
|
||||||
|
className={cn(
|
||||||
|
"absolute -right-3 top-20 z-50 flex h-6 w-6 items-center justify-center rounded-full border border-white/10 bg-slate-800 text-white/60 shadow-lg transition-all hover:bg-slate-700 hover:text-white",
|
||||||
|
isCollapsed ? "left-[60px]" : "left-[244px]",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<ChevronLeft
|
||||||
|
className={cn(
|
||||||
|
"h-3.5 w-3.5 transition-transform",
|
||||||
|
isCollapsed && "rotate-180",
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{/* Navigation */}
|
||||||
|
<nav className="flex-1 space-y-1 overflow-y-auto p-3">
|
||||||
|
{navItems.map((item) => {
|
||||||
const Icon = item.icon;
|
const Icon = item.icon;
|
||||||
const isActive = pathname === item.href;
|
const isActive =
|
||||||
const label =
|
pathname === item.href ||
|
||||||
typeof item.label === "string" ? item.label : item.label;
|
(item.href !== "/" && pathname.startsWith(item.href));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
key={item.href}
|
key={item.href}
|
||||||
href={item.href}
|
href={item.href}
|
||||||
className={`flex items-center gap-3 px-4 py-3 rounded-lg transition-all duration-200 ${
|
className={cn(
|
||||||
|
"group flex items-center gap-3 rounded-lg px-3 py-2.5 text-sm font-medium transition-all duration-200",
|
||||||
isActive
|
isActive
|
||||||
? "bg-blue-600 text-white shadow-lg shadow-blue-900/20"
|
? "bg-gradient-to-r from-blue-600 to-blue-500 text-white shadow-lg shadow-blue-500/25"
|
||||||
: "text-slate-400 hover:bg-slate-800 hover:text-white"
|
: "text-slate-400 hover:bg-white/5 hover:text-white",
|
||||||
}`}
|
isCollapsed && "justify-center px-2",
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
<div className="min-w-[20px]">
|
|
||||||
<Icon
|
<Icon
|
||||||
size={20}
|
className={cn(
|
||||||
className={
|
"h-5 w-5 flex-shrink-0 transition-colors",
|
||||||
isActive
|
isActive
|
||||||
? "text-white"
|
? "text-white"
|
||||||
: "text-slate-500 group-hover:text-white"
|
: "text-slate-500 group-hover:text-white",
|
||||||
}
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
{!isCollapsed && (
|
||||||
<span className="font-medium opacity-0 group-hover:opacity-100 transition-opacity duration-300 whitespace-nowrap overflow-hidden">
|
<>
|
||||||
{label}
|
<span className="flex-1">{item.label}</span>
|
||||||
|
{item.badge !== undefined && (
|
||||||
|
<span className="flex h-5 min-w-[20px] items-center justify-center rounded-full bg-red-500 px-1.5 text-xs font-bold text-white">
|
||||||
|
{item.badge > 99 ? "99+" : item.badge}
|
||||||
</span>
|
</span>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{isCollapsed && item.badge !== undefined && (
|
||||||
|
<span className="absolute -right-1 -top-1 flex h-4 min-w-[16px] items-center justify-center rounded-full bg-red-500 px-1 text-[10px] font-bold text-white">
|
||||||
|
{item.badge > 9 ? "9+" : item.badge}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</Link>
|
</Link>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div className="p-4 border-t border-slate-800">
|
{/* User Section */}
|
||||||
<div className="flex items-center gap-3 px-2 py-3 rounded-lg bg-slate-800/50 overflow-hidden whitespace-nowrap">
|
<div
|
||||||
<div className="min-w-[32px]">
|
className={cn(
|
||||||
|
"border-t border-white/5 p-3",
|
||||||
|
isCollapsed && "flex justify-center",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"flex items-center gap-3 rounded-lg bg-white/5 p-2 transition-colors hover:bg-white/10",
|
||||||
|
isCollapsed && "justify-center p-2",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<div className={cn("flex-shrink-0", isCollapsed ? "" : "ml-1")}>
|
||||||
{mounted && <UserButton afterSignOutUrl="/" />}
|
{mounted && <UserButton afterSignOutUrl="/" />}
|
||||||
</div>
|
</div>
|
||||||
<div className="flex-1 min-w-0 opacity-0 group-hover:opacity-100 transition-opacity duration-300">
|
{!isCollapsed && (
|
||||||
<p className="text-sm font-medium text-white truncate">
|
<div className="min-w-0 flex-1">
|
||||||
{user?.fullName || "Admin User"}
|
<p className="truncate text-sm font-medium text-white">
|
||||||
|
{user?.fullName || "Admin"}
|
||||||
</p>
|
</p>
|
||||||
<p className="text-xs text-slate-400 truncate">
|
<p className="truncate text-xs text-slate-400">
|
||||||
{user?.primaryEmailAddress?.emailAddress}
|
{user?.primaryEmailAddress?.emailAddress}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { LucideIcon } from "lucide-react";
|
import { LucideIcon } from "lucide-react";
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
import { cn } from "@/lib/utils";
|
||||||
|
import { TrendingUp, TrendingDown, Minus } from "lucide-react";
|
||||||
|
|
||||||
interface StatsCardProps {
|
interface StatsCardProps {
|
||||||
title: string;
|
title: string;
|
||||||
@@ -7,45 +8,132 @@ interface StatsCardProps {
|
|||||||
change?: string;
|
change?: string;
|
||||||
trend?: "up" | "down" | "neutral";
|
trend?: "up" | "down" | "neutral";
|
||||||
icon: LucideIcon;
|
icon: LucideIcon;
|
||||||
color?: "blue" | "green" | "purple" | "orange";
|
color?: "blue" | "green" | "purple" | "orange" | "red";
|
||||||
|
className?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function StatsCard({ title, value, change, trend, icon: Icon, color = "blue" }: StatsCardProps) {
|
export function StatsCard({
|
||||||
|
title,
|
||||||
|
value,
|
||||||
|
change,
|
||||||
|
trend,
|
||||||
|
icon: Icon,
|
||||||
|
color = "blue",
|
||||||
|
className,
|
||||||
|
}: StatsCardProps) {
|
||||||
const colorStyles = {
|
const colorStyles = {
|
||||||
blue: "bg-blue-50 text-blue-600",
|
blue: {
|
||||||
green: "bg-green-50 text-green-600",
|
gradient: "from-blue-500/10 to-blue-600/5",
|
||||||
purple: "bg-purple-50 text-purple-600",
|
iconBg: "bg-gradient-to-br from-blue-500 to-blue-600",
|
||||||
orange: "bg-orange-50 text-orange-600",
|
iconShadow: "shadow-blue-500/25",
|
||||||
|
text: "text-blue-600",
|
||||||
|
trendUp: "text-emerald-600",
|
||||||
|
trendDown: "text-red-600",
|
||||||
|
},
|
||||||
|
green: {
|
||||||
|
gradient: "from-emerald-500/10 to-emerald-600/5",
|
||||||
|
iconBg: "bg-gradient-to-br from-emerald-500 to-emerald-600",
|
||||||
|
iconShadow: "shadow-emerald-500/25",
|
||||||
|
text: "text-emerald-600",
|
||||||
|
trendUp: "text-emerald-600",
|
||||||
|
trendDown: "text-red-600",
|
||||||
|
},
|
||||||
|
purple: {
|
||||||
|
gradient: "from-violet-500/10 to-violet-600/5",
|
||||||
|
iconBg: "bg-gradient-to-br from-violet-500 to-violet-600",
|
||||||
|
iconShadow: "shadow-violet-500/25",
|
||||||
|
text: "text-violet-600",
|
||||||
|
trendUp: "text-emerald-600",
|
||||||
|
trendDown: "text-red-600",
|
||||||
|
},
|
||||||
|
orange: {
|
||||||
|
gradient: "from-amber-500/10 to-amber-600/5",
|
||||||
|
iconBg: "bg-gradient-to-br from-amber-500 to-orange-600",
|
||||||
|
iconShadow: "shadow-amber-500/25",
|
||||||
|
text: "text-amber-600",
|
||||||
|
trendUp: "text-emerald-600",
|
||||||
|
trendDown: "text-red-600",
|
||||||
|
},
|
||||||
|
red: {
|
||||||
|
gradient: "from-rose-500/10 to-rose-600/5",
|
||||||
|
iconBg: "bg-gradient-to-br from-rose-500 to-rose-600",
|
||||||
|
iconShadow: "shadow-rose-500/25",
|
||||||
|
text: "text-rose-600",
|
||||||
|
trendUp: "text-emerald-600",
|
||||||
|
trendDown: "text-red-600",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const styles = colorStyles[color];
|
||||||
|
const TrendIcon =
|
||||||
|
trend === "up" ? TrendingUp : trend === "down" ? TrendingDown : Minus;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card>
|
<div
|
||||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
className={cn(
|
||||||
<CardTitle className="text-sm font-medium text-muted-foreground">
|
"group relative overflow-hidden rounded-2xl border border-border/50 bg-gradient-to-br p-6 transition-all duration-300 hover:shadow-lg hover:-translate-y-1",
|
||||||
{title}
|
styles.gradient,
|
||||||
</CardTitle>
|
className,
|
||||||
<div className={`p-2 rounded-lg ${colorStyles[color]}`}>
|
)}
|
||||||
<Icon size={16} />
|
>
|
||||||
|
<div className="flex items-start justify-between">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<p className="text-sm font-medium text-muted-foreground">{title}</p>
|
||||||
|
<div className="flex items-baseline gap-2">
|
||||||
|
<span className="text-3xl font-bold tracking-tight">{value}</span>
|
||||||
</div>
|
</div>
|
||||||
</CardHeader>
|
|
||||||
<CardContent>
|
|
||||||
<div className="text-2xl font-bold">{value}</div>
|
|
||||||
{change && (
|
{change && (
|
||||||
<p className="text-xs text-muted-foreground mt-1">
|
<div className="flex items-center gap-1 text-sm">
|
||||||
|
<TrendIcon
|
||||||
|
className={cn(
|
||||||
|
"h-4 w-4",
|
||||||
|
trend === "up" && styles.trendUp,
|
||||||
|
trend === "down" && styles.trendDown,
|
||||||
|
trend === "neutral" && "text-muted-foreground",
|
||||||
|
)}
|
||||||
|
/>
|
||||||
<span
|
<span
|
||||||
className={`font-medium ${trend === "up"
|
className={cn(
|
||||||
? "text-green-600"
|
"font-medium",
|
||||||
: trend === "down"
|
trend === "up" && styles.trendUp,
|
||||||
? "text-red-600"
|
trend === "down" && styles.trendDown,
|
||||||
: "text-slate-600"
|
trend === "neutral" && "text-muted-foreground",
|
||||||
}`}
|
)}
|
||||||
>
|
>
|
||||||
{change}
|
{change}
|
||||||
</span>{" "}
|
</span>
|
||||||
vs last month
|
<span className="text-muted-foreground">vs last month</span>
|
||||||
</p>
|
</div>
|
||||||
)}
|
)}
|
||||||
</CardContent>
|
</div>
|
||||||
</Card>
|
<div
|
||||||
|
className={cn(
|
||||||
|
"flex h-12 w-12 items-center justify-center rounded-xl bg-gradient-to-br shadow-lg transition-transform duration-300 group-hover:scale-110",
|
||||||
|
styles.iconBg,
|
||||||
|
styles.iconShadow,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Icon className="h-6 w-6 text-white" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Decorative corner gradient */}
|
||||||
|
<div className="absolute -right-8 -top-8 h-32 w-32 rounded-full bg-gradient-to-br from-white/20 to-transparent opacity-0 transition-opacity duration-300 group-hover:opacity-100" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function StatsCardSkeleton() {
|
||||||
|
return (
|
||||||
|
<div className="animate-pulse rounded-2xl border border-border/50 bg-gradient-to-br from-muted/30 to-muted/20 p-6">
|
||||||
|
<div className="flex items-start justify-between">
|
||||||
|
<div className="space-y-3">
|
||||||
|
<div className="h-4 w-24 rounded bg-muted" />
|
||||||
|
<div className="h-9 w-32 rounded bg-muted" />
|
||||||
|
<div className="h-4 w-20 rounded bg-muted" />
|
||||||
|
</div>
|
||||||
|
<div className="h-12 w-12 rounded-xl bg-muted" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { cva, type VariantProps } from "class-variance-authority";
|
||||||
|
|
||||||
|
const badgeVariants = cva(
|
||||||
|
"inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
variant: {
|
||||||
|
default: "bg-primary/10 text-primary",
|
||||||
|
secondary: "bg-secondary text-secondary-foreground",
|
||||||
|
success:
|
||||||
|
"bg-emerald-100 text-emerald-800 dark:bg-emerald-900/30 dark:text-emerald-400",
|
||||||
|
warning:
|
||||||
|
"bg-amber-100 text-amber-800 dark:bg-amber-900/30 dark:text-amber-400",
|
||||||
|
destructive:
|
||||||
|
"bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400",
|
||||||
|
info: "bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-400",
|
||||||
|
outline: "border border-input text-foreground",
|
||||||
|
gray: "bg-slate-100 text-slate-800 dark:bg-slate-800 dark:text-slate-300",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: "default",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export interface BadgeProps
|
||||||
|
extends React.HTMLAttributes<HTMLDivElement>,
|
||||||
|
VariantProps<typeof badgeVariants> {}
|
||||||
|
|
||||||
|
export function Badge({ className, variant, ...props }: BadgeProps) {
|
||||||
|
return (
|
||||||
|
<div className={cn(badgeVariants({ variant }), className)} {...props} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function StatusBadge({ status }: { status: string }) {
|
||||||
|
const statusConfig: Record<
|
||||||
|
string,
|
||||||
|
{ variant: BadgeProps["variant"]; label: string }
|
||||||
|
> = {
|
||||||
|
active: { variant: "success", label: "Active" },
|
||||||
|
inactive: { variant: "gray", label: "Inactive" },
|
||||||
|
pending: { variant: "warning", label: "Pending" },
|
||||||
|
approved: { variant: "success", label: "Approved" },
|
||||||
|
rejected: { variant: "destructive", label: "Rejected" },
|
||||||
|
completed: { variant: "success", label: "Completed" },
|
||||||
|
failed: { variant: "destructive", label: "Failed" },
|
||||||
|
suspended: { variant: "destructive", label: "Suspended" },
|
||||||
|
basic: { variant: "default", label: "Basic" },
|
||||||
|
premium: { variant: "info", label: "Premium" },
|
||||||
|
vip: { variant: "warning", label: "VIP" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const config = statusConfig[status.toLowerCase()] || {
|
||||||
|
variant: "outline",
|
||||||
|
label: status,
|
||||||
|
};
|
||||||
|
|
||||||
|
return <Badge variant={config.variant}>{config.label}</Badge>;
|
||||||
|
}
|
||||||
@@ -1,49 +1,60 @@
|
|||||||
import React from 'react'
|
import React from "react";
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from "@/lib/utils";
|
||||||
import { Loader2 } from 'lucide-react'
|
import { Loader2 } from "lucide-react";
|
||||||
|
import { cva, type VariantProps } from "class-variance-authority";
|
||||||
|
|
||||||
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
const buttonVariants = cva(
|
||||||
variant?: 'primary' | 'secondary' | 'ghost' | 'destructive' | 'outline' | 'default'
|
"inline-flex items-center justify-center rounded-lg text-sm font-medium transition-all duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
|
||||||
size?: 'default' | 'sm' | 'lg' | 'icon'
|
{
|
||||||
isLoading?: boolean
|
variants: {
|
||||||
children: React.ReactNode
|
variant: {
|
||||||
|
default:
|
||||||
|
"bg-primary text-primary-foreground shadow-sm hover:bg-primary/90 hover:shadow",
|
||||||
|
destructive:
|
||||||
|
"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90 hover:shadow",
|
||||||
|
outline:
|
||||||
|
"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
|
||||||
|
secondary:
|
||||||
|
"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
|
||||||
|
ghost: "hover:bg-accent hover:text-accent-foreground",
|
||||||
|
link: "text-primary underline-offset-4 hover:underline",
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
default: "h-10 px-4 py-2",
|
||||||
|
sm: "h-9 rounded-md px-3",
|
||||||
|
lg: "h-11 rounded-md px-8",
|
||||||
|
icon: "h-10 w-10",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: "default",
|
||||||
|
size: "default",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export interface ButtonProps
|
||||||
|
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
||||||
|
VariantProps<typeof buttonVariants> {
|
||||||
|
isLoading?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Button({
|
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
||||||
variant = 'primary',
|
(
|
||||||
size = 'default',
|
{ className, variant, size, isLoading, children, disabled, ...props },
|
||||||
isLoading = false,
|
ref,
|
||||||
children,
|
) => {
|
||||||
className = '',
|
|
||||||
disabled,
|
|
||||||
...props
|
|
||||||
}: ButtonProps) {
|
|
||||||
const baseClasses = 'inline-flex items-center justify-center rounded-md font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50'
|
|
||||||
|
|
||||||
const variantClasses = {
|
|
||||||
primary: 'bg-blue-600 text-white hover:bg-blue-700 shadow hover:bg-blue-700/90',
|
|
||||||
default: 'bg-blue-600 text-white hover:bg-blue-700 shadow hover:bg-blue-700/90',
|
|
||||||
secondary: 'bg-slate-100 text-slate-900 hover:bg-slate-200/80',
|
|
||||||
ghost: 'hover:bg-slate-100 hover:text-slate-900',
|
|
||||||
destructive: 'bg-red-500 text-white hover:bg-red-600/90',
|
|
||||||
outline: 'border border-input bg-transparent shadow-sm hover:bg-slate-100 hover:text-slate-900'
|
|
||||||
}
|
|
||||||
|
|
||||||
const sizeClasses = {
|
|
||||||
default: 'h-9 px-4 py-2',
|
|
||||||
sm: 'h-8 rounded-md px-3 text-xs',
|
|
||||||
lg: 'h-10 rounded-md px-8',
|
|
||||||
icon: 'h-9 w-9'
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
className={cn(baseClasses, variantClasses[variant], sizeClasses[size], className)}
|
className={cn(buttonVariants({ variant, size, className }))}
|
||||||
|
ref={ref}
|
||||||
disabled={disabled || isLoading}
|
disabled={disabled || isLoading}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
{isLoading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
{isLoading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
||||||
{children}
|
{children}
|
||||||
</button>
|
</button>
|
||||||
)
|
);
|
||||||
}
|
},
|
||||||
|
);
|
||||||
|
Button.displayName = "Button";
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
interface SkeletonProps {
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Skeleton({ className }: SkeletonProps) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"animate-pulse rounded-md bg-slate-200 dark:bg-slate-700",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function StatsCardSkeleton() {
|
||||||
|
return (
|
||||||
|
<div className="bg-white rounded-xl shadow-sm border border-slate-100 p-6">
|
||||||
|
<div className="flex items-center gap-4">
|
||||||
|
<Skeleton className="h-12 w-12 rounded-full" />
|
||||||
|
<div className="flex-1 space-y-2">
|
||||||
|
<Skeleton className="h-4 w-20" />
|
||||||
|
<Skeleton className="h-8 w-16" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TableSkeleton({ rows = 5 }: { rows?: number }) {
|
||||||
|
return (
|
||||||
|
<div className="space-y-3">
|
||||||
|
{Array.from({ length: rows }).map((_, i) => (
|
||||||
|
<div key={i} className="flex gap-4">
|
||||||
|
<Skeleton className="h-12 flex-1" />
|
||||||
|
<Skeleton className="h-12 w-32" />
|
||||||
|
<Skeleton className="h-12 w-24" />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CardSkeleton() {
|
||||||
|
return (
|
||||||
|
<div className="bg-white rounded-xl shadow-sm border border-slate-100 p-6 space-y-4">
|
||||||
|
<Skeleton className="h-6 w-40" />
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Skeleton className="h-4 w-full" />
|
||||||
|
<Skeleton className="h-4 w-3/4" />
|
||||||
|
<Skeleton className="h-4 w-5/6" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -9,9 +9,10 @@ import { formatDate } from "@/lib/utils";
|
|||||||
|
|
||||||
ModuleRegistry.registerModules([AllCommunityModule]);
|
ModuleRegistry.registerModules([AllCommunityModule]);
|
||||||
|
|
||||||
function getTimeAgo(date: Date): string {
|
function getTimeAgo(date: Date | string): string {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const diffMs = now.getTime() - date.getTime();
|
const d = typeof date === "string" ? new Date(date) : date;
|
||||||
|
const diffMs = now.getTime() - d.getTime();
|
||||||
const diffMins = Math.floor(diffMs / 60000);
|
const diffMins = Math.floor(diffMs / 60000);
|
||||||
const diffHours = Math.floor(diffMins / 60);
|
const diffHours = Math.floor(diffMins / 60);
|
||||||
const diffDays = Math.floor(diffHours / 24);
|
const diffDays = Math.floor(diffHours / 24);
|
||||||
@@ -22,7 +23,7 @@ function getTimeAgo(date: Date): string {
|
|||||||
return `${diffDays}d ago`;
|
return `${diffDays}d ago`;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface User {
|
export interface User {
|
||||||
id: string;
|
id: string;
|
||||||
email: string;
|
email: string;
|
||||||
firstName: string;
|
firstName: string;
|
||||||
@@ -31,15 +32,18 @@ interface User {
|
|||||||
phone?: string;
|
phone?: string;
|
||||||
gymId?: string;
|
gymId?: string;
|
||||||
gymName?: string | null;
|
gymName?: string | null;
|
||||||
createdAt: Date;
|
createdAt?: string | Date;
|
||||||
isCheckedIn?: boolean;
|
isCheckedIn?: boolean;
|
||||||
checkInTime?: Date;
|
checkInTime?: string | Date;
|
||||||
|
lastCheckInTime?: string | Date;
|
||||||
|
checkInsThisWeek?: number;
|
||||||
|
checkInsThisMonth?: number;
|
||||||
client?: {
|
client?: {
|
||||||
id: string;
|
id: string;
|
||||||
membershipType: string;
|
membershipType: string;
|
||||||
membershipStatus: string;
|
membershipStatus: string;
|
||||||
joinDate: Date;
|
joinDate: string | Date;
|
||||||
lastVisit?: Date;
|
lastVisit?: string | Date;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,43 +1,23 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useState, useEffect } from "react";
|
import { useState } from "react";
|
||||||
import { UserGrid } from "@/components/users/UserGrid";
|
import { UserGrid, type User } from "@/components/users/UserGrid";
|
||||||
// import { Button } from "@/components/ui/button";
|
|
||||||
import { Card, CardHeader, CardContent } from "@/components/ui/card";
|
import { Card, CardHeader, CardContent } from "@/components/ui/card";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { useUser } from "@clerk/nextjs";
|
import { useUser } from "@clerk/nextjs";
|
||||||
import { getGymIdFromUser } from "@/lib/error-helpers";
|
|
||||||
import log from "@/lib/logger";
|
import log from "@/lib/logger";
|
||||||
import { toast } from "@/lib/toast";
|
import { toast } from "@/lib/toast";
|
||||||
import { CreateUserModal } from "./CreateUserModal";
|
import { CreateUserModal } from "./CreateUserModal";
|
||||||
|
import {
|
||||||
interface User {
|
useUsers,
|
||||||
id: string;
|
useGyms,
|
||||||
email: string;
|
useUpdateUser,
|
||||||
firstName: string;
|
useDeleteUser,
|
||||||
lastName: string;
|
useSendInvitation,
|
||||||
role: string;
|
} from "@/hooks/use-api";
|
||||||
phone?: string;
|
|
||||||
gymId?: string;
|
|
||||||
createdAt: Date;
|
|
||||||
isCheckedIn?: boolean;
|
|
||||||
checkInTime?: Date;
|
|
||||||
lastCheckInTime?: Date;
|
|
||||||
checkInsThisWeek?: number;
|
|
||||||
checkInsThisMonth?: number;
|
|
||||||
client?: {
|
|
||||||
id: string;
|
|
||||||
membershipType: string;
|
|
||||||
membershipStatus: string;
|
|
||||||
joinDate: Date;
|
|
||||||
lastVisit?: Date;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function UserManagement() {
|
export function UserManagement() {
|
||||||
const { user } = useUser();
|
const { user } = useUser();
|
||||||
const [users, setUsers] = useState<User[]>([]);
|
|
||||||
const [loading, setLoading] = useState(true);
|
|
||||||
const [filter, setFilter] = useState<string>("all");
|
const [filter, setFilter] = useState<string>("all");
|
||||||
const [selectedUser, setSelectedUser] = useState<User | null>(null);
|
const [selectedUser, setSelectedUser] = useState<User | null>(null);
|
||||||
const [isEditing, setIsEditing] = useState(false);
|
const [isEditing, setIsEditing] = useState(false);
|
||||||
@@ -52,68 +32,17 @@ export function UserManagement() {
|
|||||||
gymId: string;
|
gymId: string;
|
||||||
} | null>(null);
|
} | null>(null);
|
||||||
|
|
||||||
// Active gyms for dropdown
|
const {
|
||||||
const [gyms, setGyms] = useState<Array<{ id: string; name: string }>>([]);
|
data: users = [],
|
||||||
|
isLoading,
|
||||||
// Load gyms when modal opens or refreshes
|
refetch,
|
||||||
useEffect(() => {
|
} = useUsers({
|
||||||
if (isEditing) {
|
role: filter !== "all" ? filter : undefined,
|
||||||
(async () => {
|
|
||||||
try {
|
|
||||||
const res = await fetch("/api/gyms");
|
|
||||||
const data = await res.json();
|
|
||||||
if (Array.isArray(data)) {
|
|
||||||
// map down to id and name to avoid extra payload use here
|
|
||||||
setGyms(data.map((g: any) => ({ id: g.id, name: g.name })));
|
|
||||||
} else {
|
|
||||||
setGyms([]);
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
setGyms([]);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
}, [isEditing]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
fetchUsers();
|
|
||||||
}, [filter]);
|
|
||||||
|
|
||||||
const fetchUsers = async () => {
|
|
||||||
setLoading(true);
|
|
||||||
try {
|
|
||||||
const ts = Date.now();
|
|
||||||
const url =
|
|
||||||
filter === "all"
|
|
||||||
? `/api/users?ts=${ts}`
|
|
||||||
: `/api/users?role=${filter}&ts=${ts}`;
|
|
||||||
|
|
||||||
log.debug("Fetching users", { url });
|
|
||||||
const response = await fetch(url, { cache: "no-store" });
|
|
||||||
log.debug("Users fetch response", {
|
|
||||||
ok: response.ok,
|
|
||||||
status: response.status,
|
|
||||||
});
|
});
|
||||||
const responseData = await response.json();
|
const { data: gyms = [] } = useGyms();
|
||||||
const data = responseData.data || responseData; // Handle both old and new API response formats
|
const updateUser = useUpdateUser();
|
||||||
log.debug("Received users data", {
|
const deleteUser = useDeleteUser();
|
||||||
count: Array.isArray(data.users) ? data.users.length : 0,
|
const sendInvitation = useSendInvitation();
|
||||||
sample:
|
|
||||||
data.users && data.users[0]
|
|
||||||
? {
|
|
||||||
id: data.users[0].id,
|
|
||||||
gymId: data.users[0].gymId,
|
|
||||||
role: data.users[0].role,
|
|
||||||
}
|
|
||||||
: null,
|
|
||||||
});
|
|
||||||
setUsers(data.users || []);
|
|
||||||
} catch (error) {
|
|
||||||
log.error("Failed to fetch users", error);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleUserSelect = (user: User | null) => {
|
const handleUserSelect = (user: User | null) => {
|
||||||
setSelectedUser(user);
|
setSelectedUser(user);
|
||||||
@@ -144,17 +73,12 @@ export function UserManagement() {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/users", {
|
const deletePromises = users.map((u) =>
|
||||||
method: "DELETE",
|
fetch(`/api/users?id=${u.id}`, { method: "DELETE" }),
|
||||||
headers: { "Content-Type": "application/json" },
|
);
|
||||||
body: JSON.stringify({ ids: users.map((u) => u.id) }),
|
await Promise.all(deletePromises);
|
||||||
});
|
refetch();
|
||||||
if (response.ok) {
|
|
||||||
fetchUsers();
|
|
||||||
toast.success("Users deleted successfully");
|
toast.success("Users deleted successfully");
|
||||||
} else {
|
|
||||||
toast.error("Error deleting users");
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error("Failed to delete users", error);
|
log.error("Failed to delete users", error);
|
||||||
}
|
}
|
||||||
@@ -196,7 +120,7 @@ export function UserManagement() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleRefresh = () => {
|
const handleRefresh = () => {
|
||||||
fetchUsers();
|
refetch();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSaveEdit = async () => {
|
const handleSaveEdit = async () => {
|
||||||
@@ -204,7 +128,6 @@ export function UserManagement() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (selectedUser) {
|
if (selectedUser) {
|
||||||
// Update existing user
|
|
||||||
const payload = {
|
const payload = {
|
||||||
id: selectedUser.id,
|
id: selectedUser.id,
|
||||||
email: editForm.email,
|
email: editForm.email,
|
||||||
@@ -214,80 +137,21 @@ export function UserManagement() {
|
|||||||
phone: editForm.phone,
|
phone: editForm.phone,
|
||||||
gymId: editForm.gymId === "" ? null : editForm.gymId,
|
gymId: editForm.gymId === "" ? null : editForm.gymId,
|
||||||
};
|
};
|
||||||
log.debug("Updating user", payload);
|
|
||||||
const response = await fetch("/api/users", {
|
await updateUser.mutateAsync(payload);
|
||||||
method: "PUT",
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify(payload),
|
|
||||||
});
|
|
||||||
log.debug("User update response", {
|
|
||||||
ok: response.ok,
|
|
||||||
status: response.status,
|
|
||||||
});
|
|
||||||
if (response.ok) {
|
|
||||||
// Optimistically update local state so grid reflects changes immediately
|
|
||||||
setUsers((prev) =>
|
|
||||||
prev.map((u) =>
|
|
||||||
u.id === selectedUser.id
|
|
||||||
? {
|
|
||||||
...u,
|
|
||||||
email: editForm.email,
|
|
||||||
firstName: editForm.firstName,
|
|
||||||
lastName: editForm.lastName,
|
|
||||||
role: editForm.role,
|
|
||||||
phone: editForm.phone || undefined,
|
|
||||||
gymId: editForm.gymId === "" ? undefined : editForm.gymId,
|
|
||||||
}
|
|
||||||
: u,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
setSelectedUser((prev) =>
|
|
||||||
prev
|
|
||||||
? {
|
|
||||||
...prev,
|
|
||||||
email: editForm.email,
|
|
||||||
firstName: editForm.firstName,
|
|
||||||
lastName: editForm.lastName,
|
|
||||||
role: editForm.role,
|
|
||||||
phone: editForm.phone || undefined,
|
|
||||||
gymId: editForm.gymId === "" ? undefined : editForm.gymId,
|
|
||||||
}
|
|
||||||
: prev,
|
|
||||||
);
|
|
||||||
setIsEditing(false);
|
setIsEditing(false);
|
||||||
setEditForm(null);
|
setEditForm(null);
|
||||||
// Still re-fetch from server to ensure consistency
|
refetch();
|
||||||
log.debug("Re-fetching users after successful edit");
|
|
||||||
fetchUsers();
|
|
||||||
toast.success("User updated successfully");
|
toast.success("User updated successfully");
|
||||||
} else {
|
} else {
|
||||||
const errText = await response.text().catch(() => "");
|
await sendInvitation.mutateAsync({
|
||||||
log.error("User update failed", new Error(errText), {
|
email: editForm.email,
|
||||||
status: response.status,
|
role: editForm.role,
|
||||||
});
|
});
|
||||||
toast.error("Error updating user");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Create (Invite) new user
|
|
||||||
const response = await fetch("/api/invitations", {
|
|
||||||
method: "POST",
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify({
|
|
||||||
inviteeEmail: editForm.email,
|
|
||||||
roleAssigned: editForm.role,
|
|
||||||
gymId: editForm.gymId || undefined,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.ok) {
|
|
||||||
setIsEditing(false);
|
setIsEditing(false);
|
||||||
setEditForm(null);
|
setEditForm(null);
|
||||||
fetchUsers();
|
refetch();
|
||||||
toast.success("Invitation sent successfully!");
|
toast.success("Invitation sent successfully!");
|
||||||
} else {
|
|
||||||
const errorData = await response.json();
|
|
||||||
toast.error(`Error sending invitation: ${errorData.error}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@@ -299,17 +163,11 @@ export function UserManagement() {
|
|||||||
if (!selectedUser) return;
|
if (!selectedUser) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/users?id=${selectedUser.id}`, {
|
await deleteUser.mutateAsync(selectedUser.id);
|
||||||
method: "DELETE",
|
|
||||||
});
|
|
||||||
if (response.ok) {
|
|
||||||
setIsDeleting(false);
|
setIsDeleting(false);
|
||||||
setSelectedUser(null);
|
setSelectedUser(null);
|
||||||
fetchUsers();
|
refetch();
|
||||||
toast.success("User deleted successfully");
|
toast.success("User deleted successfully");
|
||||||
} else {
|
|
||||||
toast.error("Error deleting user");
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error("Failed to delete user", error);
|
log.error("Failed to delete user", error);
|
||||||
}
|
}
|
||||||
@@ -397,7 +255,7 @@ export function UserManagement() {
|
|||||||
onEditUser={handleEditUser}
|
onEditUser={handleEditUser}
|
||||||
onDeleteUser={handleDeleteUser}
|
onDeleteUser={handleDeleteUser}
|
||||||
onBulkDelete={handleBulkDelete}
|
onBulkDelete={handleBulkDelete}
|
||||||
loading={loading}
|
loading={isLoading}
|
||||||
/>
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
@@ -591,7 +449,9 @@ export function UserManagement() {
|
|||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<span className="font-medium">Joined:</span>{" "}
|
<span className="font-medium">Joined:</span>{" "}
|
||||||
{new Date(selectedUser.createdAt).toLocaleDateString()}
|
{selectedUser.createdAt
|
||||||
|
? new Date(selectedUser.createdAt).toLocaleDateString()
|
||||||
|
: "N/A"}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -653,7 +513,7 @@ export function UserManagement() {
|
|||||||
<CreateUserModal
|
<CreateUserModal
|
||||||
open={createModalOpen}
|
open={createModalOpen}
|
||||||
onOpenChange={setCreateModalOpen}
|
onOpenChange={setCreateModalOpen}
|
||||||
onSuccess={() => fetchUsers()}
|
onSuccess={() => refetch()}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,381 @@
|
|||||||
|
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
|
|
||||||
|
export interface DashboardStats {
|
||||||
|
totalUsers: number;
|
||||||
|
activeClients: number;
|
||||||
|
totalRevenue: number;
|
||||||
|
revenueGrowth: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface User {
|
||||||
|
id: string;
|
||||||
|
email: string;
|
||||||
|
firstName: string;
|
||||||
|
lastName: string;
|
||||||
|
role: string;
|
||||||
|
phone?: string;
|
||||||
|
gymId?: string;
|
||||||
|
gymName?: string | null;
|
||||||
|
createdAt?: string;
|
||||||
|
isCheckedIn?: boolean;
|
||||||
|
checkInTime?: string;
|
||||||
|
lastCheckInTime?: string;
|
||||||
|
checkInsThisWeek?: number;
|
||||||
|
checkInsThisMonth?: number;
|
||||||
|
client?: {
|
||||||
|
id: string;
|
||||||
|
membershipType: string;
|
||||||
|
membershipStatus: string;
|
||||||
|
joinDate: string;
|
||||||
|
lastVisit?: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Recommendation {
|
||||||
|
id: string;
|
||||||
|
userId: string;
|
||||||
|
type: string;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
content?: string;
|
||||||
|
recommendationText?: string;
|
||||||
|
activityPlan?: string;
|
||||||
|
dietPlan?: string;
|
||||||
|
status: "pending" | "approved" | "rejected";
|
||||||
|
createdAt: string;
|
||||||
|
user?: User;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Gym {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
address?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AttendanceRecord {
|
||||||
|
id: string;
|
||||||
|
userId: string;
|
||||||
|
checkIn: string;
|
||||||
|
checkOut?: string;
|
||||||
|
date: string;
|
||||||
|
type?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchApi<T>(url: string, options?: RequestInit): Promise<T> {
|
||||||
|
const response = await fetch(url, {
|
||||||
|
...options,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
...options?.headers,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const error = await response
|
||||||
|
.json()
|
||||||
|
.catch(() => ({ error: "Request failed" }));
|
||||||
|
throw new Error(error.error || `HTTP ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useDashboardStats(gymId?: string) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["dashboard-stats", gymId],
|
||||||
|
queryFn: () => {
|
||||||
|
const url = gymId
|
||||||
|
? `/api/admin/stats?gymId=${gymId}`
|
||||||
|
: "/api/admin/stats";
|
||||||
|
return fetchApi<{ data: { stats: DashboardStats } }>(url).then(
|
||||||
|
(res) => res.data?.stats,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useUsers(filters?: {
|
||||||
|
role?: string;
|
||||||
|
gymId?: string;
|
||||||
|
search?: string;
|
||||||
|
}) {
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
if (filters?.role) params.set("role", filters.role);
|
||||||
|
if (filters?.gymId) params.set("gymId", filters.gymId);
|
||||||
|
if (filters?.search) params.set("search", filters.search);
|
||||||
|
|
||||||
|
const queryString = params.toString();
|
||||||
|
const url = queryString ? `/api/users?${queryString}` : "/api/users";
|
||||||
|
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["users", filters],
|
||||||
|
queryFn: () =>
|
||||||
|
fetchApi<{ data: { users: User[] } }>(url).then(
|
||||||
|
(res) => res.data?.users ?? [],
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useUser(userId: string) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["user", userId],
|
||||||
|
queryFn: () =>
|
||||||
|
fetchApi<{ data: { user: User } }>(`/api/users?id=${userId}`).then(
|
||||||
|
(res) => res.data?.user,
|
||||||
|
),
|
||||||
|
enabled: !!userId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useRecommendations(filters?: {
|
||||||
|
userId?: string;
|
||||||
|
status?: string;
|
||||||
|
}) {
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
if (filters?.userId) params.set("userId", filters.userId);
|
||||||
|
if (filters?.status) params.set("status", filters.status);
|
||||||
|
|
||||||
|
const queryString = params.toString();
|
||||||
|
const url = queryString
|
||||||
|
? `/api/recommendations?${queryString}`
|
||||||
|
: "/api/recommendations";
|
||||||
|
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["recommendations", filters],
|
||||||
|
queryFn: () =>
|
||||||
|
fetchApi<{ data: { recommendations: Recommendation[] } }>(url).then(
|
||||||
|
(res) => res.data?.recommendations ?? [],
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function usePendingRecommendationsCount() {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["pending-recommendations-count"],
|
||||||
|
queryFn: () =>
|
||||||
|
fetchApi<{ data: { recommendations: Recommendation[] } }>(
|
||||||
|
"/api/recommendations",
|
||||||
|
).then(
|
||||||
|
(res) =>
|
||||||
|
(res.data?.recommendations ?? []).filter(
|
||||||
|
(r) => r.status === "pending",
|
||||||
|
).length,
|
||||||
|
),
|
||||||
|
refetchInterval: 30000,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useGyms() {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["gyms"],
|
||||||
|
queryFn: () =>
|
||||||
|
fetchApi<{ data: { gyms: Gym[] } }>("/api/gyms").then(
|
||||||
|
(res) => res.data?.gyms ?? [],
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useAttendance(filters?: { userId?: string; date?: string }) {
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
if (filters?.userId) params.set("userId", filters.userId);
|
||||||
|
if (filters?.date) params.set("date", filters.date);
|
||||||
|
|
||||||
|
const queryString = params.toString();
|
||||||
|
const url = queryString
|
||||||
|
? `/api/admin/attendance?${queryString}`
|
||||||
|
: "/api/admin/attendance";
|
||||||
|
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["attendance", filters],
|
||||||
|
queryFn: () =>
|
||||||
|
fetchApi<{ data: { records: AttendanceRecord[] } }>(url).then(
|
||||||
|
(res) => res.data?.records ?? [],
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useCreateUser() {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (data: {
|
||||||
|
email: string;
|
||||||
|
firstName: string;
|
||||||
|
lastName: string;
|
||||||
|
role: string;
|
||||||
|
phone?: string;
|
||||||
|
gymId?: string;
|
||||||
|
}) =>
|
||||||
|
fetchApi<{ data: { userId: string } }>("/api/users/create", {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
}).then((res) => res.data),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["users"] });
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["dashboard-stats"] });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useUpdateUser() {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (data: { id: string; [key: string]: unknown }) =>
|
||||||
|
fetchApi<{ data: { success: boolean } }>(`/api/users?id=${data.id}`, {
|
||||||
|
method: "PUT",
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
}),
|
||||||
|
onSuccess: (_, variables) => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["users"] });
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["user", variables.id] });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useDeleteUser() {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (userId: string) =>
|
||||||
|
fetchApi<{ data: { success: boolean } }>(`/api/users?id=${userId}`, {
|
||||||
|
method: "DELETE",
|
||||||
|
}),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["users"] });
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["dashboard-stats"] });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useGenerateRecommendations() {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (userId?: string) =>
|
||||||
|
fetchApi<{
|
||||||
|
data: { success: boolean; recommendations?: Recommendation[] };
|
||||||
|
}>("/api/recommendations/generate", {
|
||||||
|
method: "POST",
|
||||||
|
body: userId ? JSON.stringify({ userId }) : undefined,
|
||||||
|
}),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["recommendations"] });
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ["pending-recommendations-count"],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useApproveRecommendation() {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (data: { recommendationId: string; approved: boolean }) =>
|
||||||
|
fetchApi<{ data: { success: boolean } }>("/api/recommendations/approve", {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
}),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["recommendations"] });
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ["pending-recommendations-count"],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useUpdateRecommendation() {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (data: {
|
||||||
|
id: string;
|
||||||
|
content?: string;
|
||||||
|
activityPlan?: string;
|
||||||
|
dietPlan?: string;
|
||||||
|
}) =>
|
||||||
|
fetchApi<{ data: { success: boolean } }>("/api/recommendations", {
|
||||||
|
method: "PUT",
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
}),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["recommendations"] });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useCheckIn() {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (userId: string) =>
|
||||||
|
fetchApi<{ data: { success: boolean; record: AttendanceRecord } }>(
|
||||||
|
"/api/attendance/check-in",
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({ userId }),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["attendance"] });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useCheckOut() {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (userId: string) =>
|
||||||
|
fetchApi<{ data: { success: boolean } }>("/api/attendance/check-out", {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({ userId }),
|
||||||
|
}),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["attendance"] });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useInvitations() {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["invitations"],
|
||||||
|
queryFn: () =>
|
||||||
|
fetchApi<{ data: { invitations: unknown[] } }>("/api/invitations").then(
|
||||||
|
(res) => res.data?.invitations ?? [],
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useSendInvitation() {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (data: { email: string; role: string }) =>
|
||||||
|
fetchApi<{ data: { success: boolean } }>("/api/invitations", {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
}),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["invitations"] });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AnalyticsData {
|
||||||
|
userGrowth: { label: string; value: number }[];
|
||||||
|
membershipDistribution: { label: string; value: number; color: string }[];
|
||||||
|
revenue: { label: string; value: number; color: string }[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useAnalytics(months: number = 6) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["analytics", months],
|
||||||
|
queryFn: () =>
|
||||||
|
fetchApi<{ data: { analytics: AnalyticsData } }>(
|
||||||
|
`/api/admin/analytics?months=${months}`,
|
||||||
|
).then((res) => res.data?.analytics),
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -96,9 +96,13 @@ export default function OnboardingScreen() {
|
|||||||
|
|
||||||
const fitnessData = {
|
const fitnessData = {
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
height: parseFloat(fitnessProfile.height),
|
height: fitnessProfile.height
|
||||||
weight: parseFloat(fitnessProfile.weight),
|
? parseFloat(fitnessProfile.height)
|
||||||
age: parseInt(fitnessProfile.age),
|
: undefined,
|
||||||
|
weight: fitnessProfile.weight
|
||||||
|
? parseFloat(fitnessProfile.weight)
|
||||||
|
: undefined,
|
||||||
|
age: fitnessProfile.age ? parseInt(fitnessProfile.age, 10) : undefined,
|
||||||
fitnessGoals: fitnessProfile.goals ? [fitnessProfile.goals] : [],
|
fitnessGoals: fitnessProfile.goals ? [fitnessProfile.goals] : [],
|
||||||
medicalConditions: fitnessProfile.medicalConditions || undefined,
|
medicalConditions: fitnessProfile.medicalConditions || undefined,
|
||||||
allergies: fitnessProfile.dietaryRestrictions || undefined,
|
allergies: fitnessProfile.dietaryRestrictions || undefined,
|
||||||
|
|||||||
@@ -13,8 +13,10 @@ import {
|
|||||||
import { useRouter, Stack } from "expo-router";
|
import { useRouter, Stack } from "expo-router";
|
||||||
import { useAuth } from "@clerk/clerk-expo";
|
import { useAuth } from "@clerk/clerk-expo";
|
||||||
import { Ionicons } from "@expo/vector-icons";
|
import { Ionicons } from "@expo/vector-icons";
|
||||||
import { LinearGradient } from "expo-linear-gradient";
|
import { useTheme } from "../contexts/ThemeContext";
|
||||||
import { theme } from "../styles/theme";
|
import { MinimalCard } from "../components/MinimalCard";
|
||||||
|
import { MinimalButton } from "../components/MinimalButton";
|
||||||
|
import { IconContainer } from "../components/IconContainer";
|
||||||
import { API_BASE_URL } from "../config/api";
|
import { API_BASE_URL } from "../config/api";
|
||||||
|
|
||||||
interface FitnessProfileData {
|
interface FitnessProfileData {
|
||||||
@@ -30,13 +32,13 @@ interface FitnessProfileData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const GENDER_OPTIONS = [
|
const GENDER_OPTIONS = [
|
||||||
{ label: "Male", value: "male", icon: "male" },
|
{ label: "Male", value: "male", icon: "male-outline" },
|
||||||
{ label: "Female", value: "female", icon: "female" },
|
{ label: "Female", value: "female", icon: "female-outline" },
|
||||||
{ label: "Other", value: "other", icon: "transgender" },
|
{ label: "Other", value: "other", icon: "transgender-outline" },
|
||||||
{
|
{
|
||||||
label: "Prefer not to say",
|
label: "Prefer not to say",
|
||||||
value: "prefer_not_to_say",
|
value: "prefer_not_to_say",
|
||||||
icon: "help-circle",
|
icon: "help-circle-outline",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -45,31 +47,26 @@ const FITNESS_GOAL_OPTIONS = [
|
|||||||
label: "Weight Loss",
|
label: "Weight Loss",
|
||||||
value: "weight_loss",
|
value: "weight_loss",
|
||||||
icon: "trending-down",
|
icon: "trending-down",
|
||||||
color: theme.colors.danger,
|
color: "#FF3B3B",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Muscle Gain",
|
label: "Muscle Gain",
|
||||||
value: "muscle_gain",
|
value: "muscle_gain",
|
||||||
icon: "barbell",
|
icon: "barbell",
|
||||||
color: theme.colors.primary,
|
color: "#0066FF",
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "Endurance",
|
|
||||||
value: "endurance",
|
|
||||||
icon: "bicycle",
|
|
||||||
color: theme.colors.success,
|
|
||||||
},
|
},
|
||||||
|
{ label: "Endurance", value: "endurance", icon: "bicycle", color: "#00D26A" },
|
||||||
{
|
{
|
||||||
label: "Flexibility",
|
label: "Flexibility",
|
||||||
value: "flexibility",
|
value: "flexibility",
|
||||||
icon: "body",
|
icon: "body",
|
||||||
color: theme.colors.purple,
|
color: "#7B2CBF",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "General Fitness",
|
label: "General Fitness",
|
||||||
value: "general_fitness",
|
value: "general_fitness",
|
||||||
icon: "fitness",
|
icon: "fitness",
|
||||||
color: theme.colors.warning,
|
color: "#FFB800",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -99,6 +96,7 @@ const ACTIVITY_LEVEL_OPTIONS = [
|
|||||||
|
|
||||||
export default function FitnessProfileScreen() {
|
export default function FitnessProfileScreen() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const { colors, typography } = useTheme();
|
||||||
const { userId, getToken } = useAuth();
|
const { userId, getToken } = useAuth();
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [fetchingProfile, setFetchingProfile] = useState(true);
|
const [fetchingProfile, setFetchingProfile] = useState(true);
|
||||||
@@ -124,7 +122,6 @@ export default function FitnessProfileScreen() {
|
|||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if (data.profile) {
|
if (data.profile) {
|
||||||
// Normalize old activity level values to new schema
|
|
||||||
let activityLevel = data.profile.activityLevel || "";
|
let activityLevel = data.profile.activityLevel || "";
|
||||||
if (activityLevel === "light") activityLevel = "lightly_active";
|
if (activityLevel === "light") activityLevel = "lightly_active";
|
||||||
if (activityLevel === "moderate") activityLevel = "moderately_active";
|
if (activityLevel === "moderate") activityLevel = "moderately_active";
|
||||||
@@ -159,8 +156,6 @@ export default function FitnessProfileScreen() {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
const token = await getToken();
|
const token = await getToken();
|
||||||
|
|
||||||
// Prepare data with userId and convert fitnessGoal to fitnessGoals array
|
|
||||||
// Convert empty strings to undefined for optional enum fields
|
|
||||||
const dataToSave = {
|
const dataToSave = {
|
||||||
userId: userId,
|
userId: userId,
|
||||||
height: profileData.height,
|
height: profileData.height,
|
||||||
@@ -205,8 +200,13 @@ export default function FitnessProfileScreen() {
|
|||||||
|
|
||||||
if (fetchingProfile) {
|
if (fetchingProfile) {
|
||||||
return (
|
return (
|
||||||
<View style={styles.loadingContainer}>
|
<View
|
||||||
<ActivityIndicator size="large" color={theme.colors.primary} />
|
style={[
|
||||||
|
styles.loadingContainer,
|
||||||
|
{ backgroundColor: colors.background },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<ActivityIndicator size="large" color={colors.primary} />
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -214,18 +214,28 @@ export default function FitnessProfileScreen() {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Stack.Screen options={{ headerShown: false }} />
|
<Stack.Screen options={{ headerShown: false }} />
|
||||||
<View style={styles.container}>
|
<View style={[styles.container, { backgroundColor: colors.background }]}>
|
||||||
{/* Header */}
|
{/* Header */}
|
||||||
<LinearGradient colors={theme.gradients.primary} style={styles.header}>
|
<View
|
||||||
|
style={[
|
||||||
|
styles.header,
|
||||||
|
{
|
||||||
|
backgroundColor: colors.primary,
|
||||||
|
paddingTop: Platform.OS === "ios" ? 60 : 40,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
style={styles.backButton}
|
style={styles.backButton}
|
||||||
onPress={() => router.back()}
|
onPress={() => router.back()}
|
||||||
>
|
>
|
||||||
<Ionicons name="arrow-back" size={24} color="#fff" />
|
<Ionicons name="arrow-back" size={24} color="#fff" />
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
<Text style={styles.headerTitle}>Fitness Profile</Text>
|
<Text style={[typography.h2, { color: "#fff" }]}>
|
||||||
|
Fitness Profile
|
||||||
|
</Text>
|
||||||
<View style={{ width: 40 }} />
|
<View style={{ width: 40 }} />
|
||||||
</LinearGradient>
|
</View>
|
||||||
|
|
||||||
<ScrollView
|
<ScrollView
|
||||||
style={styles.scrollView}
|
style={styles.scrollView}
|
||||||
@@ -234,19 +244,41 @@ export default function FitnessProfileScreen() {
|
|||||||
>
|
>
|
||||||
{/* Basic Information */}
|
{/* Basic Information */}
|
||||||
<View style={styles.section}>
|
<View style={styles.section}>
|
||||||
<Text style={styles.sectionTitle}>Basic Information</Text>
|
<Text
|
||||||
<View style={styles.card}>
|
style={[
|
||||||
<View style={styles.row}>
|
typography.h3,
|
||||||
|
{ color: colors.textPrimary, marginBottom: 16 },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
Basic Information
|
||||||
|
</Text>
|
||||||
|
<MinimalCard variant="elevated" style={styles.card}>
|
||||||
|
<View style={styles.inputRow}>
|
||||||
<View style={styles.inputGroup}>
|
<View style={styles.inputGroup}>
|
||||||
<Text style={styles.label}>Height (cm)</Text>
|
<Text
|
||||||
<View style={styles.inputContainer}>
|
style={[
|
||||||
|
typography.label,
|
||||||
|
{ color: colors.textSecondary, marginBottom: 8 },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
HEIGHT (CM)
|
||||||
|
</Text>
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
styles.inputContainer,
|
||||||
|
{
|
||||||
|
backgroundColor: colors.surfaceElevated,
|
||||||
|
borderColor: colors.border,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
<Ionicons
|
<Ionicons
|
||||||
name="resize-outline"
|
name="resize"
|
||||||
size={20}
|
size={20}
|
||||||
color={theme.colors.gray400}
|
color={colors.textTertiary}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
style={styles.input}
|
style={[styles.input, { color: colors.textPrimary }]}
|
||||||
value={profileData.height?.toString() || ""}
|
value={profileData.height?.toString() || ""}
|
||||||
onChangeText={(text) =>
|
onChangeText={(text) =>
|
||||||
updateField(
|
updateField(
|
||||||
@@ -256,20 +288,35 @@ export default function FitnessProfileScreen() {
|
|||||||
}
|
}
|
||||||
keyboardType="decimal-pad"
|
keyboardType="decimal-pad"
|
||||||
placeholder="175"
|
placeholder="175"
|
||||||
placeholderTextColor={theme.colors.gray400}
|
placeholderTextColor={colors.textTertiary}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<View style={styles.inputGroup}>
|
<View style={styles.inputGroup}>
|
||||||
<Text style={styles.label}>Weight (kg)</Text>
|
<Text
|
||||||
<View style={styles.inputContainer}>
|
style={[
|
||||||
|
typography.label,
|
||||||
|
{ color: colors.textSecondary, marginBottom: 8 },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
WEIGHT (KG)
|
||||||
|
</Text>
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
styles.inputContainer,
|
||||||
|
{
|
||||||
|
backgroundColor: colors.surfaceElevated,
|
||||||
|
borderColor: colors.border,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
<Ionicons
|
<Ionicons
|
||||||
name="scale-outline"
|
name="scale"
|
||||||
size={20}
|
size={20}
|
||||||
color={theme.colors.gray400}
|
color={colors.textTertiary}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
style={styles.input}
|
style={[styles.input, { color: colors.textPrimary }]}
|
||||||
value={profileData.weight?.toString() || ""}
|
value={profileData.weight?.toString() || ""}
|
||||||
onChangeText={(text) =>
|
onChangeText={(text) =>
|
||||||
updateField(
|
updateField(
|
||||||
@@ -279,45 +326,75 @@ export default function FitnessProfileScreen() {
|
|||||||
}
|
}
|
||||||
keyboardType="decimal-pad"
|
keyboardType="decimal-pad"
|
||||||
placeholder="70"
|
placeholder="70"
|
||||||
placeholderTextColor={theme.colors.gray400}
|
placeholderTextColor={colors.textTertiary}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<View style={styles.inputGroup}>
|
<View style={styles.inputGroup}>
|
||||||
<Text style={styles.label}>Age</Text>
|
<Text
|
||||||
<View style={styles.inputContainer}>
|
style={[
|
||||||
|
typography.label,
|
||||||
|
{ color: colors.textSecondary, marginBottom: 8 },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
AGE
|
||||||
|
</Text>
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
styles.inputContainer,
|
||||||
|
{
|
||||||
|
backgroundColor: colors.surfaceElevated,
|
||||||
|
borderColor: colors.border,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
<Ionicons
|
<Ionicons
|
||||||
name="calendar-outline"
|
name="calendar"
|
||||||
size={20}
|
size={20}
|
||||||
color={theme.colors.gray400}
|
color={colors.textTertiary}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
style={styles.input}
|
style={[styles.input, { color: colors.textPrimary }]}
|
||||||
value={profileData.age?.toString() || ""}
|
value={profileData.age?.toString() || ""}
|
||||||
onChangeText={(text) =>
|
onChangeText={(text) =>
|
||||||
updateField("age", text ? parseInt(text, 10) : undefined)
|
updateField("age", text ? parseInt(text, 10) : undefined)
|
||||||
}
|
}
|
||||||
keyboardType="number-pad"
|
keyboardType="number-pad"
|
||||||
placeholder="25"
|
placeholder="25"
|
||||||
placeholderTextColor={theme.colors.gray400}
|
placeholderTextColor={colors.textTertiary}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</MinimalCard>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
{/* Gender Selection */}
|
{/* Gender Selection */}
|
||||||
<View style={styles.section}>
|
<View style={styles.section}>
|
||||||
<Text style={styles.sectionTitle}>Gender</Text>
|
<Text
|
||||||
<View style={styles.optionsRow}>
|
style={[
|
||||||
|
typography.h3,
|
||||||
|
{ color: colors.textPrimary, marginBottom: 16 },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
Gender
|
||||||
|
</Text>
|
||||||
|
<View style={styles.genderRow}>
|
||||||
{GENDER_OPTIONS.map((option) => (
|
{GENDER_OPTIONS.map((option) => (
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
key={option.value}
|
key={option.value}
|
||||||
style={[
|
style={[
|
||||||
styles.optionCard,
|
styles.genderCard,
|
||||||
profileData.gender === option.value &&
|
{
|
||||||
styles.optionCardActive,
|
backgroundColor:
|
||||||
|
profileData.gender === option.value
|
||||||
|
? colors.primary
|
||||||
|
: colors.surfaceElevated,
|
||||||
|
borderColor:
|
||||||
|
profileData.gender === option.value
|
||||||
|
? colors.primary
|
||||||
|
: colors.border,
|
||||||
|
},
|
||||||
]}
|
]}
|
||||||
onPress={() => updateField("gender", option.value)}
|
onPress={() => updateField("gender", option.value)}
|
||||||
>
|
>
|
||||||
@@ -326,15 +403,22 @@ export default function FitnessProfileScreen() {
|
|||||||
size={24}
|
size={24}
|
||||||
color={
|
color={
|
||||||
profileData.gender === option.value
|
profileData.gender === option.value
|
||||||
? theme.colors.primary
|
? "#fff"
|
||||||
: theme.colors.gray400
|
: colors.textTertiary
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<Text
|
<Text
|
||||||
style={[
|
style={[
|
||||||
styles.optionLabel,
|
typography.caption,
|
||||||
profileData.gender === option.value &&
|
{
|
||||||
styles.optionLabelActive,
|
color:
|
||||||
|
profileData.gender === option.value
|
||||||
|
? "#fff"
|
||||||
|
: colors.textSecondary,
|
||||||
|
fontWeight:
|
||||||
|
profileData.gender === option.value ? "700" : "500",
|
||||||
|
marginTop: 6,
|
||||||
|
},
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
{option.label}
|
{option.label}
|
||||||
@@ -346,8 +430,15 @@ export default function FitnessProfileScreen() {
|
|||||||
|
|
||||||
{/* Fitness Goal */}
|
{/* Fitness Goal */}
|
||||||
<View style={styles.section}>
|
<View style={styles.section}>
|
||||||
<Text style={styles.sectionTitle}>Primary Fitness Goal</Text>
|
<Text
|
||||||
<View style={styles.card}>
|
style={[
|
||||||
|
typography.h3,
|
||||||
|
{ color: colors.textPrimary, marginBottom: 16 },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
Primary Fitness Goal
|
||||||
|
</Text>
|
||||||
|
<MinimalCard variant="elevated" style={styles.card}>
|
||||||
{FITNESS_GOAL_OPTIONS.map((option, index) => (
|
{FITNESS_GOAL_OPTIONS.map((option, index) => (
|
||||||
<React.Fragment key={option.value}>
|
<React.Fragment key={option.value}>
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
@@ -366,27 +457,46 @@ export default function FitnessProfileScreen() {
|
|||||||
color={option.color}
|
color={option.color}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
<Text style={styles.listItemText}>{option.label}</Text>
|
<Text
|
||||||
|
style={[
|
||||||
|
typography.bodyEmphasis,
|
||||||
|
{ color: colors.textPrimary, flex: 1 },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
{option.label}
|
||||||
|
</Text>
|
||||||
{profileData.fitnessGoal === option.value && (
|
{profileData.fitnessGoal === option.value && (
|
||||||
<Ionicons
|
<Ionicons
|
||||||
name="checkmark-circle"
|
name="checkmark-circle"
|
||||||
size={24}
|
size={24}
|
||||||
color={theme.colors.primary}
|
color={colors.primary}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
{index < FITNESS_GOAL_OPTIONS.length - 1 && (
|
{index < FITNESS_GOAL_OPTIONS.length - 1 && (
|
||||||
<View style={styles.divider} />
|
<View
|
||||||
|
style={[
|
||||||
|
styles.divider,
|
||||||
|
{ backgroundColor: colors.border },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
))}
|
))}
|
||||||
</View>
|
</MinimalCard>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
{/* Activity Level */}
|
{/* Activity Level */}
|
||||||
<View style={styles.section}>
|
<View style={styles.section}>
|
||||||
<Text style={styles.sectionTitle}>Activity Level</Text>
|
<Text
|
||||||
<View style={styles.card}>
|
style={[
|
||||||
|
typography.h3,
|
||||||
|
{ color: colors.textPrimary, marginBottom: 16 },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
Activity Level
|
||||||
|
</Text>
|
||||||
|
<MinimalCard variant="elevated" style={styles.card}>
|
||||||
{ACTIVITY_LEVEL_OPTIONS.map((option, index) => (
|
{ACTIVITY_LEVEL_OPTIONS.map((option, index) => (
|
||||||
<React.Fragment key={option.value}>
|
<React.Fragment key={option.value}>
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
@@ -394,8 +504,20 @@ export default function FitnessProfileScreen() {
|
|||||||
onPress={() => updateField("activityLevel", option.value)}
|
onPress={() => updateField("activityLevel", option.value)}
|
||||||
>
|
>
|
||||||
<View style={{ flex: 1 }}>
|
<View style={{ flex: 1 }}>
|
||||||
<Text style={styles.listItemText}>{option.label}</Text>
|
<Text
|
||||||
<Text style={styles.listItemDescription}>
|
style={[
|
||||||
|
typography.bodyEmphasis,
|
||||||
|
{ color: colors.textPrimary },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
{option.label}
|
||||||
|
</Text>
|
||||||
|
<Text
|
||||||
|
style={[
|
||||||
|
typography.caption,
|
||||||
|
{ color: colors.textTertiary, marginTop: 2 },
|
||||||
|
]}
|
||||||
|
>
|
||||||
{option.description}
|
{option.description}
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
@@ -403,90 +525,141 @@ export default function FitnessProfileScreen() {
|
|||||||
<Ionicons
|
<Ionicons
|
||||||
name="checkmark-circle"
|
name="checkmark-circle"
|
||||||
size={24}
|
size={24}
|
||||||
color={theme.colors.primary}
|
color={colors.primary}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
{index < ACTIVITY_LEVEL_OPTIONS.length - 1 && (
|
{index < ACTIVITY_LEVEL_OPTIONS.length - 1 && (
|
||||||
<View style={styles.divider} />
|
<View
|
||||||
|
style={[
|
||||||
|
styles.divider,
|
||||||
|
{ backgroundColor: colors.border },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
))}
|
))}
|
||||||
</View>
|
</MinimalCard>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
{/* Health Information */}
|
{/* Health Information */}
|
||||||
<View style={styles.section}>
|
<View style={styles.section}>
|
||||||
<Text style={styles.sectionTitle}>
|
<Text
|
||||||
Health Information (Optional)
|
style={[
|
||||||
|
typography.h3,
|
||||||
|
{ color: colors.textPrimary, marginBottom: 16 },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
Health Information
|
||||||
</Text>
|
</Text>
|
||||||
<View style={styles.card}>
|
<MinimalCard variant="elevated" style={styles.card}>
|
||||||
<View style={styles.inputGroup}>
|
<View style={styles.inputGroup}>
|
||||||
<Text style={styles.label}>Medical Conditions</Text>
|
<Text
|
||||||
|
style={[
|
||||||
|
typography.label,
|
||||||
|
{ color: colors.textSecondary, marginBottom: 8 },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
MEDICAL CONDITIONS
|
||||||
|
</Text>
|
||||||
<TextInput
|
<TextInput
|
||||||
style={[styles.textArea]}
|
style={[
|
||||||
|
styles.textArea,
|
||||||
|
{
|
||||||
|
backgroundColor: colors.surfaceElevated,
|
||||||
|
borderColor: colors.border,
|
||||||
|
color: colors.textPrimary,
|
||||||
|
},
|
||||||
|
]}
|
||||||
value={profileData.medicalConditions || ""}
|
value={profileData.medicalConditions || ""}
|
||||||
onChangeText={(text) =>
|
onChangeText={(text) =>
|
||||||
updateField("medicalConditions", text)
|
updateField("medicalConditions", text)
|
||||||
}
|
}
|
||||||
placeholder="e.g., Asthma, diabetes..."
|
placeholder="e.g., Asthma, diabetes..."
|
||||||
placeholderTextColor={theme.colors.gray400}
|
placeholderTextColor={colors.textTertiary}
|
||||||
multiline
|
multiline
|
||||||
numberOfLines={3}
|
numberOfLines={3}
|
||||||
textAlignVertical="top"
|
textAlignVertical="top"
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
<View style={styles.inputGroup}>
|
<View style={styles.inputGroup}>
|
||||||
<Text style={styles.label}>Allergies</Text>
|
<Text
|
||||||
|
style={[
|
||||||
|
typography.label,
|
||||||
|
{ color: colors.textSecondary, marginBottom: 8 },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
ALLERGIES
|
||||||
|
</Text>
|
||||||
<TextInput
|
<TextInput
|
||||||
style={[styles.textArea]}
|
style={[
|
||||||
|
styles.textArea,
|
||||||
|
{
|
||||||
|
backgroundColor: colors.surfaceElevated,
|
||||||
|
borderColor: colors.border,
|
||||||
|
color: colors.textPrimary,
|
||||||
|
},
|
||||||
|
]}
|
||||||
value={profileData.allergies || ""}
|
value={profileData.allergies || ""}
|
||||||
onChangeText={(text) => updateField("allergies", text)}
|
onChangeText={(text) => updateField("allergies", text)}
|
||||||
placeholder="e.g., Peanuts, latex..."
|
placeholder="e.g., Peanuts, latex..."
|
||||||
placeholderTextColor={theme.colors.gray400}
|
placeholderTextColor={colors.textTertiary}
|
||||||
multiline
|
multiline
|
||||||
numberOfLines={3}
|
numberOfLines={3}
|
||||||
textAlignVertical="top"
|
textAlignVertical="top"
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
<View style={styles.inputGroup}>
|
<View style={styles.inputGroup}>
|
||||||
<Text style={styles.label}>Injuries</Text>
|
<Text
|
||||||
|
style={[
|
||||||
|
typography.label,
|
||||||
|
{ color: colors.textSecondary, marginBottom: 8 },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
INJURIES
|
||||||
|
</Text>
|
||||||
<TextInput
|
<TextInput
|
||||||
style={[styles.textArea]}
|
style={[
|
||||||
|
styles.textArea,
|
||||||
|
{
|
||||||
|
backgroundColor: colors.surfaceElevated,
|
||||||
|
borderColor: colors.border,
|
||||||
|
color: colors.textPrimary,
|
||||||
|
},
|
||||||
|
]}
|
||||||
value={profileData.injuries || ""}
|
value={profileData.injuries || ""}
|
||||||
onChangeText={(text) => updateField("injuries", text)}
|
onChangeText={(text) => updateField("injuries", text)}
|
||||||
placeholder="e.g., Previous knee injury..."
|
placeholder="e.g., Previous knee injury..."
|
||||||
placeholderTextColor={theme.colors.gray400}
|
placeholderTextColor={colors.textTertiary}
|
||||||
multiline
|
multiline
|
||||||
numberOfLines={3}
|
numberOfLines={3}
|
||||||
textAlignVertical="top"
|
textAlignVertical="top"
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
</MinimalCard>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
|
||||||
|
<View style={{ height: 120 }} />
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
{/* Save Button */}
|
{/* Save Button */}
|
||||||
<View style={styles.footer}>
|
<View
|
||||||
<TouchableOpacity
|
style={[
|
||||||
style={[styles.saveButton, loading && styles.saveButtonDisabled]}
|
styles.footer,
|
||||||
|
{
|
||||||
|
backgroundColor: colors.background,
|
||||||
|
borderTopColor: colors.border,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<MinimalButton
|
||||||
|
title="Save Profile"
|
||||||
onPress={handleSave}
|
onPress={handleSave}
|
||||||
disabled={loading}
|
variant="primary"
|
||||||
>
|
size="xl"
|
||||||
<LinearGradient
|
fullWidth
|
||||||
colors={theme.gradients.primary}
|
loading={loading}
|
||||||
style={styles.saveButtonGradient}
|
/>
|
||||||
>
|
|
||||||
{loading ? (
|
|
||||||
<ActivityIndicator color="#fff" />
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<Ionicons name="checkmark-circle" size={20} color="#fff" />
|
|
||||||
<Text style={styles.saveButtonText}>Save Profile</Text>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</LinearGradient>
|
|
||||||
</TouchableOpacity>
|
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</>
|
</>
|
||||||
@@ -496,35 +669,27 @@ export default function FitnessProfileScreen() {
|
|||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {
|
container: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
backgroundColor: theme.colors.background,
|
|
||||||
},
|
},
|
||||||
loadingContainer: {
|
loadingContainer: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
backgroundColor: theme.colors.background,
|
|
||||||
},
|
},
|
||||||
header: {
|
header: {
|
||||||
flexDirection: "row",
|
flexDirection: "row",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
justifyContent: "space-between",
|
justifyContent: "space-between",
|
||||||
paddingTop: Platform.OS === "ios" ? 60 : 40,
|
|
||||||
paddingBottom: 20,
|
paddingBottom: 20,
|
||||||
paddingHorizontal: 20,
|
paddingHorizontal: 20,
|
||||||
},
|
},
|
||||||
backButton: {
|
backButton: {
|
||||||
width: 40,
|
width: 40,
|
||||||
height: 40,
|
height: 40,
|
||||||
borderRadius: 20,
|
borderRadius: 12,
|
||||||
backgroundColor: "rgba(255, 255, 255, 0.2)",
|
backgroundColor: "rgba(255, 255, 255, 0.2)",
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
},
|
},
|
||||||
headerTitle: {
|
|
||||||
fontSize: theme.typography.fontSize["2xl"],
|
|
||||||
fontWeight: theme.typography.fontWeight.bold,
|
|
||||||
color: "#fff",
|
|
||||||
},
|
|
||||||
scrollView: {
|
scrollView: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
},
|
},
|
||||||
@@ -533,118 +698,69 @@ const styles = StyleSheet.create({
|
|||||||
paddingBottom: 100,
|
paddingBottom: 100,
|
||||||
},
|
},
|
||||||
section: {
|
section: {
|
||||||
marginBottom: 24,
|
marginBottom: 28,
|
||||||
},
|
|
||||||
sectionTitle: {
|
|
||||||
fontSize: theme.typography.fontSize.lg,
|
|
||||||
fontWeight: theme.typography.fontWeight.bold,
|
|
||||||
color: theme.colors.gray900,
|
|
||||||
marginBottom: 12,
|
|
||||||
},
|
},
|
||||||
card: {
|
card: {
|
||||||
backgroundColor: "#fff",
|
padding: 4,
|
||||||
borderRadius: theme.borderRadius.xl,
|
|
||||||
padding: 16,
|
|
||||||
...theme.shadows.subtle,
|
|
||||||
borderWidth: 1,
|
|
||||||
borderColor: theme.colors.gray100,
|
|
||||||
},
|
},
|
||||||
row: {
|
inputRow: {
|
||||||
flexDirection: "row",
|
flexDirection: "row",
|
||||||
gap: 12,
|
gap: 12,
|
||||||
marginBottom: 16,
|
|
||||||
},
|
},
|
||||||
inputGroup: {
|
inputGroup: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
marginBottom: 16,
|
marginBottom: 4,
|
||||||
},
|
|
||||||
label: {
|
|
||||||
fontSize: theme.typography.fontSize.sm,
|
|
||||||
fontWeight: theme.typography.fontWeight.semibold,
|
|
||||||
color: theme.colors.gray700,
|
|
||||||
marginBottom: 8,
|
|
||||||
},
|
},
|
||||||
inputContainer: {
|
inputContainer: {
|
||||||
flexDirection: "row",
|
flexDirection: "row",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
backgroundColor: theme.colors.gray50,
|
borderRadius: 14,
|
||||||
borderRadius: theme.borderRadius.lg,
|
borderWidth: 1.5,
|
||||||
borderWidth: 1,
|
paddingHorizontal: 14,
|
||||||
borderColor: theme.colors.gray200,
|
gap: 10,
|
||||||
paddingHorizontal: 12,
|
|
||||||
gap: 8,
|
|
||||||
},
|
},
|
||||||
input: {
|
input: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
paddingVertical: 12,
|
paddingVertical: 14,
|
||||||
fontSize: theme.typography.fontSize.base,
|
fontSize: 16,
|
||||||
color: theme.colors.gray900,
|
fontWeight: "600",
|
||||||
},
|
},
|
||||||
textArea: {
|
textArea: {
|
||||||
backgroundColor: theme.colors.gray50,
|
borderRadius: 14,
|
||||||
borderRadius: theme.borderRadius.lg,
|
borderWidth: 1.5,
|
||||||
borderWidth: 1,
|
padding: 14,
|
||||||
borderColor: theme.colors.gray200,
|
fontSize: 16,
|
||||||
padding: 12,
|
minHeight: 90,
|
||||||
fontSize: theme.typography.fontSize.base,
|
|
||||||
color: theme.colors.gray900,
|
|
||||||
minHeight: 80,
|
|
||||||
},
|
},
|
||||||
optionsRow: {
|
genderRow: {
|
||||||
flexDirection: "row",
|
flexDirection: "row",
|
||||||
gap: 12,
|
gap: 10,
|
||||||
},
|
},
|
||||||
optionCard: {
|
genderCard: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
backgroundColor: "#fff",
|
paddingVertical: 16,
|
||||||
borderRadius: theme.borderRadius.lg,
|
paddingHorizontal: 8,
|
||||||
padding: 16,
|
borderRadius: 14,
|
||||||
alignItems: "center",
|
|
||||||
gap: 8,
|
|
||||||
borderWidth: 2,
|
borderWidth: 2,
|
||||||
borderColor: theme.colors.gray200,
|
alignItems: "center",
|
||||||
...theme.shadows.subtle,
|
|
||||||
},
|
|
||||||
optionCardActive: {
|
|
||||||
borderColor: theme.colors.primary,
|
|
||||||
backgroundColor: `${theme.colors.primary}10`,
|
|
||||||
},
|
|
||||||
optionLabel: {
|
|
||||||
fontSize: theme.typography.fontSize.sm,
|
|
||||||
fontWeight: theme.typography.fontWeight.medium,
|
|
||||||
color: theme.colors.gray600,
|
|
||||||
},
|
|
||||||
optionLabelActive: {
|
|
||||||
color: theme.colors.primary,
|
|
||||||
fontWeight: theme.typography.fontWeight.bold,
|
|
||||||
},
|
},
|
||||||
listItem: {
|
listItem: {
|
||||||
flexDirection: "row",
|
flexDirection: "row",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
paddingVertical: 12,
|
paddingVertical: 14,
|
||||||
gap: 12,
|
paddingHorizontal: 12,
|
||||||
|
gap: 14,
|
||||||
},
|
},
|
||||||
iconCircle: {
|
iconCircle: {
|
||||||
width: 40,
|
width: 44,
|
||||||
height: 40,
|
height: 44,
|
||||||
borderRadius: 20,
|
borderRadius: 12,
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
},
|
},
|
||||||
listItemText: {
|
|
||||||
flex: 1,
|
|
||||||
fontSize: theme.typography.fontSize.base,
|
|
||||||
fontWeight: theme.typography.fontWeight.medium,
|
|
||||||
color: theme.colors.gray900,
|
|
||||||
},
|
|
||||||
listItemDescription: {
|
|
||||||
fontSize: theme.typography.fontSize.xs,
|
|
||||||
color: theme.colors.gray500,
|
|
||||||
marginTop: 2,
|
|
||||||
},
|
|
||||||
divider: {
|
divider: {
|
||||||
height: 1,
|
height: 1,
|
||||||
backgroundColor: theme.colors.gray100,
|
marginLeft: 58,
|
||||||
},
|
},
|
||||||
footer: {
|
footer: {
|
||||||
position: "absolute",
|
position: "absolute",
|
||||||
@@ -652,29 +768,7 @@ const styles = StyleSheet.create({
|
|||||||
left: 0,
|
left: 0,
|
||||||
right: 0,
|
right: 0,
|
||||||
padding: 20,
|
padding: 20,
|
||||||
paddingBottom: Platform.OS === "ios" ? 40 : 20,
|
paddingBottom: 34,
|
||||||
backgroundColor: "#fff",
|
|
||||||
borderTopWidth: 1,
|
borderTopWidth: 1,
|
||||||
borderTopColor: theme.colors.gray100,
|
|
||||||
...theme.shadows.medium,
|
|
||||||
},
|
|
||||||
saveButton: {
|
|
||||||
borderRadius: theme.borderRadius.lg,
|
|
||||||
overflow: "hidden",
|
|
||||||
},
|
|
||||||
saveButtonGradient: {
|
|
||||||
flexDirection: "row",
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "center",
|
|
||||||
paddingVertical: 16,
|
|
||||||
gap: 8,
|
|
||||||
},
|
|
||||||
saveButtonDisabled: {
|
|
||||||
opacity: 0.6,
|
|
||||||
},
|
|
||||||
saveButtonText: {
|
|
||||||
fontSize: theme.typography.fontSize.base,
|
|
||||||
fontWeight: theme.typography.fontWeight.bold,
|
|
||||||
color: "#fff",
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user