From c2f903b20f3d1412a5bbfabeb515a151d8676806 Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Mon, 10 Nov 2025 23:55:51 +0000 Subject: [PATCH] Notification trigger utility for consistent notification handling cgen-efead2eedd674d03bd26b7274a7b19ed --- client/lib/notification-triggers.ts | 163 ++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 client/lib/notification-triggers.ts diff --git a/client/lib/notification-triggers.ts b/client/lib/notification-triggers.ts new file mode 100644 index 00000000..e57a494b --- /dev/null +++ b/client/lib/notification-triggers.ts @@ -0,0 +1,163 @@ +import { aethexNotificationService } from "./aethex-database-adapter"; + +export const notificationTriggers = { + async achievementUnlocked( + userId: string, + achievementName: string, + xpReward: number, + ): Promise { + try { + await aethexNotificationService.createNotification( + userId, + "success", + `🏆 Achievement Unlocked: ${achievementName}`, + `You've earned ${xpReward} XP!`, + ); + } catch (error) { + console.warn("Failed to create achievement notification:", error); + } + }, + + async teamCreated(userId: string, teamName: string): Promise { + try { + await aethexNotificationService.createNotification( + userId, + "success", + `🎯 Team Created: ${teamName}`, + `Your team "${teamName}" is ready to go!`, + ); + } catch (error) { + console.warn("Failed to create team notification:", error); + } + }, + + async addedToTeam(userId: string, teamName: string, role: string): Promise { + try { + await aethexNotificationService.createNotification( + userId, + "info", + `👥 Added to Team: ${teamName}`, + `You've been added as a ${role} to the team.`, + ); + } catch (error) { + console.warn("Failed to create team member notification:", error); + } + }, + + async projectCreated(userId: string, projectName: string): Promise { + try { + await aethexNotificationService.createNotification( + userId, + "success", + `🚀 Project Created: ${projectName}`, + "Your new project is ready to go!", + ); + } catch (error) { + console.warn("Failed to create project notification:", error); + } + }, + + async addedToProject(userId: string, projectName: string, role: string): Promise { + try { + await aethexNotificationService.createNotification( + userId, + "info", + `📌 Added to Project: ${projectName}`, + `You've been added as a ${role} to the project.`, + ); + } catch (error) { + console.warn("Failed to create project member notification:", error); + } + }, + + async projectCompleted(userId: string, projectName: string): Promise { + try { + await aethexNotificationService.createNotification( + userId, + "success", + `✅ Project Completed: ${projectName}`, + "Congratulations on finishing your project!", + ); + } catch (error) { + console.warn("Failed to create project completion notification:", error); + } + }, + + async projectStarted(userId: string, projectName: string): Promise { + try { + await aethexNotificationService.createNotification( + userId, + "info", + `⏱️ Project Started: ${projectName}`, + "You've started working on this project.", + ); + } catch (error) { + console.warn("Failed to create project start notification:", error); + } + }, + + async levelUp(userId: string, newLevel: number): Promise { + try { + await aethexNotificationService.createNotification( + userId, + "success", + "⬆️ Level Up!", + `You've reached level ${newLevel}! Keep it up!`, + ); + } catch (error) { + console.warn("Failed to create level up notification:", error); + } + }, + + async onboardingComplete(userId: string): Promise { + try { + await aethexNotificationService.createNotification( + userId, + "success", + "🎉 Welcome to AeThex!", + "You've completed your profile setup. Let's get started!", + ); + } catch (error) { + console.warn("Failed to create onboarding notification:", error); + } + }, + + async accountLinked(userId: string, provider: string): Promise { + try { + await aethexNotificationService.createNotification( + userId, + "success", + `🔗 Account Linked: ${provider}`, + `Your ${provider} account has been successfully linked.`, + ); + } catch (error) { + console.warn("Failed to create account link notification:", error); + } + }, + + async emailVerified(userId: string): Promise { + try { + await aethexNotificationService.createNotification( + userId, + "success", + "✉️ Email Verified", + "Your email address has been verified successfully.", + ); + } catch (error) { + console.warn("Failed to create email verification notification:", error); + } + }, + + async customNotification( + userId: string, + type: "success" | "info" | "warning" | "error", + title: string, + message: string, + ): Promise { + try { + await aethexNotificationService.createNotification(userId, type, title, message); + } catch (error) { + console.warn("Failed to create custom notification:", error); + } + }, +};