|
| 1 | +import { auth } from "@/auth"; |
| 2 | +import { redirect } from "next/navigation"; |
| 3 | +import { Metadata } from "next"; |
| 4 | +import { config } from "@/config/environment"; |
| 5 | +import { WrappedSlideshow } from "@/components/wrapped/wrapped-slideshow"; |
| 6 | +import { getWrappedData } from "@/services/wrapped"; |
| 7 | + |
| 8 | +export async function generateMetadata(): Promise<Metadata> { |
| 9 | + return { |
| 10 | + title: `Wrapped ${new Date().getFullYear()} | ${config.brandName}`, |
| 11 | + }; |
| 12 | +} |
| 13 | + |
| 14 | +export default async function WrappedPage() { |
| 15 | + const session: any = await auth(); |
| 16 | + if (!session || !session.user) redirect("/login"); |
| 17 | + |
| 18 | + // Only allow access for specific email |
| 19 | + const allowedEmail = "hernandeztomas584@gmail.com"; |
| 20 | + if (session.user.email !== allowedEmail) { |
| 21 | + redirect("/"); |
| 22 | + } |
| 23 | + |
| 24 | + const currentYear = new Date().getFullYear(); |
| 25 | + |
| 26 | + const wrappedData = await getWrappedData(currentYear); |
| 27 | + |
| 28 | + // Only use hardcoded goals for specific user (6786fc3d59e0d0be0d34416c) |
| 29 | + // For other users, use most completed tasks |
| 30 | + const specificUserId = "6786fc3d59e0d0be0d34416c"; |
| 31 | + const isSpecificUser = wrappedData.userId === specificUserId; |
| 32 | + |
| 33 | + const goalsAchieved = isSpecificUser ? [ |
| 34 | + "Certificado de A2 en Alemán", |
| 35 | + "Di una conferencia de Informática", |
| 36 | + "Estabilidad mental mayor", |
| 37 | + "Darme más tiempo a divulgar y pensar", |
| 38 | + "Llegué a 120kg en press banca", |
| 39 | + "Certificado en Deep Learning", |
| 40 | + "Surfee un montón", |
| 41 | + "Vi a Stone Temple Pilots", |
| 42 | + "Cambié mi PC entera", |
| 43 | + "Empecé Kyzen", |
| 44 | + "Aprendí CI/CD y profundice Docker. Aplicándolo en el mundo laboral", |
| 45 | + "Leí un montón, y me ayudó mucho para abrirme hacia otras personas y poder escucharlas mejor", |
| 46 | + "Empecé a Invertir", |
| 47 | + ] : wrappedData.mostCompletedTasks.map(task => task.name); |
| 48 | + |
| 49 | + // Generate AI summary based on actual data |
| 50 | + const aiSummary = `En ${currentYear}, demostraste una dedicación excepcional. Transformaste la constancia en resultados: tu racha de ${wrappedData.stats.longestStreak} días y ${wrappedData.stats.tasksCompleted} tareas completadas no son solo números, son prueba de tu compromiso. ${wrappedData.stats.mostConsistentHabit !== "Ninguno" ? `"${wrappedData.stats.mostConsistentHabit}" se convirtió en tu ancla,` : "Construiste hábitos sólidos,"} y cuando conectaste con ${wrappedData.stats.friendsConnected} personas en la plataforma, llevaste tu crecimiento al siguiente nivel. ${wrappedData.stats.moodImprovement > 0 ? `Tu mood mejoró un ${wrappedData.stats.moodImprovement}%` : "Tu bienestar se mantuvo estable"} porque construiste sistemas que funcionan. Esto recién empieza.`; |
| 51 | + |
| 52 | + const userData = { |
| 53 | + name: session.user.name || "Usuario", |
| 54 | + username: session.user.username ? `@${session.user.username}` : "@usuario", |
| 55 | + avatar: wrappedData.userImage || session.user.name?.charAt(0).toUpperCase() || "U", |
| 56 | + year: currentYear, |
| 57 | + stats: wrappedData.stats, |
| 58 | + habitsFormed: wrappedData.habitsFormed, |
| 59 | + goalsAchieved, |
| 60 | + aiSummary, |
| 61 | + isSpecificUser, |
| 62 | + mostCompletedTasks: wrappedData.mostCompletedTasks, |
| 63 | + }; |
| 64 | + |
| 65 | + return <WrappedSlideshow userData={userData} />; |
| 66 | +} |
| 67 | + |
0 commit comments