mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 16:31:13 -05:00
Fix: Resolve privacy settings type errors
This commit is contained in:
@@ -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));
|
||||
|
||||
|
||||
@@ -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<PrivacySettings | null>(null);
|
||||
|
||||
const form = useForm<PrivacyFormData>({
|
||||
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);
|
||||
setPreferences(validatedSettings);
|
||||
|
||||
form.reset({
|
||||
privacy_level: profile?.privacy_level || 'public',
|
||||
show_pronouns: profile?.show_pronouns || false,
|
||||
...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
|
||||
|
||||
@@ -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()
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user