mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-27 09:26:58 -05:00
feat: Implement Novu username and update functionality
This commit is contained in:
@@ -16,6 +16,7 @@ import { useAuth } from '@/hooks/useAuth';
|
||||
import { supabase } from '@/integrations/supabase/client';
|
||||
import { User, Upload, Trash2 } from 'lucide-react';
|
||||
import { PhotoUpload } from '@/components/upload/PhotoUpload';
|
||||
import { notificationService } from '@/lib/notificationService';
|
||||
|
||||
const profileSchema = z.object({
|
||||
username: z.string().min(3).max(30).regex(/^[a-zA-Z0-9_-]+$/),
|
||||
@@ -54,6 +55,8 @@ export function AccountProfileTab() {
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
const usernameChanged = profile?.username !== data.username;
|
||||
|
||||
const { error } = await supabase
|
||||
.from('profiles')
|
||||
.update({
|
||||
@@ -69,6 +72,15 @@ export function AccountProfileTab() {
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
// Update Novu subscriber if username changed
|
||||
if (usernameChanged && notificationService.isEnabled()) {
|
||||
await notificationService.updateSubscriber({
|
||||
subscriberId: user.id,
|
||||
email: user.email,
|
||||
firstName: data.username, // Send username as firstName to Novu
|
||||
});
|
||||
}
|
||||
|
||||
await refreshProfile();
|
||||
toast({
|
||||
title: 'Profile updated',
|
||||
|
||||
@@ -111,6 +111,14 @@ export function NotificationsTab() {
|
||||
|
||||
if (result.success) {
|
||||
toast.success("Notification preferences saved successfully");
|
||||
|
||||
// Also update Novu subscriber profile to sync channel preferences
|
||||
if (notificationService.isEnabled()) {
|
||||
await notificationService.updateSubscriber({
|
||||
subscriberId: user.id,
|
||||
email: user.email,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
throw new Error(result.error || 'Failed to save preferences');
|
||||
}
|
||||
|
||||
@@ -71,6 +71,30 @@ class NotificationService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing Novu subscriber's profile information
|
||||
*/
|
||||
async updateSubscriber(subscriberData: SubscriberData): Promise<{ success: boolean; error?: string }> {
|
||||
if (!this.isNovuEnabled) {
|
||||
console.warn('Novu is not configured. Skipping subscriber update.');
|
||||
return { success: false, error: 'Novu not configured' };
|
||||
}
|
||||
|
||||
try {
|
||||
const { data, error } = await supabase.functions.invoke('update-novu-subscriber', {
|
||||
body: subscriberData,
|
||||
});
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
console.log('Novu subscriber updated successfully');
|
||||
return { success: true };
|
||||
} catch (error: any) {
|
||||
console.error('Error updating Novu subscriber:', error);
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update subscriber preferences in Novu
|
||||
*/
|
||||
|
||||
@@ -147,7 +147,7 @@ export default function Auth() {
|
||||
notificationService.createSubscriber({
|
||||
subscriberId: data.user.id,
|
||||
email: formData.email,
|
||||
firstName: formData.displayName || formData.username,
|
||||
firstName: formData.username, // Send username as firstName to Novu
|
||||
data: {
|
||||
username: formData.username,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user