diff --git a/src/components/privacy/BlockedUsers.tsx b/src/components/privacy/BlockedUsers.tsx index 04f8bfe5..346358d4 100644 --- a/src/components/privacy/BlockedUsers.tsx +++ b/src/components/privacy/BlockedUsers.tsx @@ -114,7 +114,7 @@ export function BlockedUsers() { } // Log to audit trail - await supabase.from('profile_audit_log').insert({ + await supabase.from('profile_audit_log').insert([{ user_id: user.id, changed_by: user.id, action: 'user_unblocked', @@ -122,8 +122,8 @@ export function BlockedUsers() { blocked_user_id: blockedUserId, username, timestamp: new Date().toISOString() - } - }); + } as any + }]); setBlockedUsers(prev => prev.filter(block => block.id !== blockId)); diff --git a/src/components/settings/PrivacyTab.tsx b/src/components/settings/PrivacyTab.tsx index 22819342..053eff6e 100644 --- a/src/components/settings/PrivacyTab.tsx +++ b/src/components/settings/PrivacyTab.tsx @@ -1,5 +1,6 @@ import { useState, useEffect } from 'react'; import { useForm } from 'react-hook-form'; +import { zodResolver } from '@hookform/resolvers/zod'; import { Button } from '@/components/ui/button'; import { Label } from '@/components/ui/label'; import { Switch } from '@/components/ui/switch'; @@ -24,8 +25,11 @@ export function PrivacyTab() { const [preferences, setPreferences] = useState(null); const form = useForm({ + resolver: zodResolver(privacyFormSchema), defaultValues: { - privacy_level: profile?.privacy_level || 'public', + privacy_level: (profile?.privacy_level === 'public' || profile?.privacy_level === 'private') + ? profile.privacy_level + : 'public', show_pronouns: profile?.show_pronouns || false, ...DEFAULT_PRIVACY_SETTINGS } @@ -58,13 +62,15 @@ export function PrivacyTab() { if (data?.privacy_settings) { // Validate the data before using it const validatedSettings = privacySettingsSchema.parse(data.privacy_settings); - setPreferences(validatedSettings); - - form.reset({ - privacy_level: profile?.privacy_level || 'public', - show_pronouns: profile?.show_pronouns || false, - ...validatedSettings - }); + setPreferences(validatedSettings); + + form.reset({ + privacy_level: (profile?.privacy_level === 'public' || profile?.privacy_level === 'private') + ? profile.privacy_level + : 'public', + show_pronouns: profile?.show_pronouns || false, + ...validatedSettings + }); } else { // Initialize preferences if they don't exist await initializePreferences(); @@ -103,12 +109,14 @@ export function PrivacyTab() { throw error; } - setPreferences(DEFAULT_PRIVACY_SETTINGS); - form.reset({ - privacy_level: profile?.privacy_level || 'public', - show_pronouns: profile?.show_pronouns || false, - ...DEFAULT_PRIVACY_SETTINGS - }); + setPreferences(DEFAULT_PRIVACY_SETTINGS); + form.reset({ + privacy_level: (profile?.privacy_level === 'public' || profile?.privacy_level === 'private') + ? profile.privacy_level + : 'public', + show_pronouns: profile?.show_pronouns || false, + ...DEFAULT_PRIVACY_SETTINGS + }); } catch (error) { logger.error('Error initializing privacy preferences', { userId: user.id, @@ -174,17 +182,17 @@ export function PrivacyTab() { throw prefsError; } - // Log to audit trail - await supabase.from('profile_audit_log').insert({ - user_id: user.id, - changed_by: user.id, - action: 'privacy_settings_updated', - changes: { - previous: preferences, - updated: privacySettings, - timestamp: new Date().toISOString() - } - }); + // Log to audit trail + await supabase.from('profile_audit_log').insert([{ + user_id: user.id, + changed_by: user.id, + action: 'privacy_settings_updated', + changes: { + previous: preferences, + updated: privacySettings, + timestamp: new Date().toISOString() + } as any + }]); await refreshProfile(); setPreferences(privacySettings); @@ -205,16 +213,16 @@ export function PrivacyTab() { error: error instanceof Error ? error.message : String(error) }); - if (error instanceof z.ZodError) { - handleError( - new AppError( - 'Invalid privacy settings', - 'VALIDATION_ERROR', - error.errors.map(e => e.message).join(', ') - ), - { action: 'Validate privacy settings', userId: user.id } - ); - } else { + if (error instanceof z.ZodError) { + handleError( + new AppError( + 'Invalid privacy settings', + 'VALIDATION_ERROR', + error.issues.map(e => e.message).join(', ') + ), + { action: 'Validate privacy settings', userId: user.id } + ); + } else { handleError(error, { action: 'Update privacy settings', userId: user.id diff --git a/src/lib/privacyValidation.ts b/src/lib/privacyValidation.ts index 1cfc05e1..f77072f8 100644 --- a/src/lib/privacyValidation.ts +++ b/src/lib/privacyValidation.ts @@ -20,9 +20,7 @@ import { z } from 'zod'; * Schema for privacy settings in user_preferences */ export const privacySettingsSchema = z.object({ - activity_visibility: z.enum(['public', 'private'], { - errorMap: () => ({ message: 'Activity visibility must be public or private' }) - }), + activity_visibility: z.enum(['public', 'private'] as const), search_visibility: z.boolean(), show_location: z.boolean(), show_age: z.boolean(), @@ -36,9 +34,7 @@ export const privacySettingsSchema = z.object({ * Schema for profile privacy settings */ export const profilePrivacySchema = z.object({ - privacy_level: z.enum(['public', 'private'], { - errorMap: () => ({ message: 'Privacy level must be public or private' }) - }), + privacy_level: z.enum(['public', 'private'] as const), show_pronouns: z.boolean() });