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