mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 16:31:13 -05:00
Fix remaining compliance violations
This commit is contained in:
@@ -4,11 +4,12 @@ import { useAuth } from './useAuth';
|
||||
import { useUserRole } from './useUserRole';
|
||||
import { useToast } from './use-toast';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import type { Json } from '@/integrations/supabase/types';
|
||||
|
||||
interface AdminSetting {
|
||||
id: string;
|
||||
setting_key: string;
|
||||
setting_value: any;
|
||||
setting_value: unknown;
|
||||
category: string;
|
||||
description: string;
|
||||
}
|
||||
@@ -46,11 +47,11 @@ export function useAdminSettings() {
|
||||
}, [settings]);
|
||||
|
||||
const updateSettingMutation = useMutation({
|
||||
mutationFn: async ({ key, value }: { key: string; value: any }) => {
|
||||
mutationFn: async ({ key, value }: { key: string; value: unknown }) => {
|
||||
const { error } = await supabase
|
||||
.from('admin_settings')
|
||||
.update({
|
||||
setting_value: value,
|
||||
setting_value: value as Json,
|
||||
updated_by: user?.id,
|
||||
updated_at: new Date().toISOString()
|
||||
})
|
||||
@@ -65,7 +66,7 @@ export function useAdminSettings() {
|
||||
description: "The setting has been saved successfully.",
|
||||
});
|
||||
},
|
||||
onError: (error: any) => {
|
||||
onError: (error: Error) => {
|
||||
toast({
|
||||
title: "Error",
|
||||
description: error.message || "Failed to update setting",
|
||||
@@ -74,17 +75,17 @@ export function useAdminSettings() {
|
||||
}
|
||||
});
|
||||
|
||||
const getSettingValue = useCallback((key: string, defaultValue: any = null) => {
|
||||
const getSettingValue = useCallback((key: string, defaultValue: unknown = null) => {
|
||||
return settingsMap[key] ?? defaultValue;
|
||||
}, [settingsMap]);
|
||||
|
||||
const updateSetting = async (key: string, value: any) => {
|
||||
const updateSetting = async (key: string, value: unknown) => {
|
||||
return updateSettingMutation.mutateAsync({ key, value });
|
||||
};
|
||||
|
||||
// Helper functions for common settings (memoized with useCallback for stable references)
|
||||
const getAutoFlagThreshold = useCallback(() => {
|
||||
return parseInt(getSettingValue('moderation.auto_flag_threshold', '3'));
|
||||
return parseInt(String(getSettingValue('moderation.auto_flag_threshold', '3')));
|
||||
}, [getSettingValue]);
|
||||
|
||||
const getRequireApproval = useCallback(() => {
|
||||
@@ -94,7 +95,7 @@ export function useAdminSettings() {
|
||||
|
||||
const getBanDurations = useCallback(() => {
|
||||
const value = getSettingValue('moderation.ban_durations', ['1d', '7d', '30d', 'permanent']);
|
||||
return Array.isArray(value) ? value : JSON.parse(value || '[]');
|
||||
return Array.isArray(value) ? value : JSON.parse(String(value || '[]'));
|
||||
}, [getSettingValue]);
|
||||
|
||||
const getEmailAlertsEnabled = useCallback(() => {
|
||||
@@ -103,11 +104,11 @@ export function useAdminSettings() {
|
||||
}, [getSettingValue]);
|
||||
|
||||
const getReportThreshold = useCallback(() => {
|
||||
return parseInt(getSettingValue('notifications.report_threshold', '5'));
|
||||
return parseInt(String(getSettingValue('notifications.report_threshold', '5')));
|
||||
}, [getSettingValue]);
|
||||
|
||||
const getAuditRetentionDays = useCallback(() => {
|
||||
return parseInt(getSettingValue('system.audit_retention_days', '365'));
|
||||
return parseInt(String(getSettingValue('system.audit_retention_days', '365')));
|
||||
}, [getSettingValue]);
|
||||
|
||||
const getAutoCleanupEnabled = useCallback(() => {
|
||||
@@ -115,10 +116,11 @@ export function useAdminSettings() {
|
||||
return value === true || value === 'true';
|
||||
}, [getSettingValue]);
|
||||
|
||||
const getAdminPanelRefreshMode = useCallback(() => {
|
||||
const getAdminPanelRefreshMode = useCallback((): 'auto' | 'manual' => {
|
||||
const value = getSettingValue('system.admin_panel_refresh_mode', 'auto');
|
||||
// Remove quotes if they exist (JSON string stored in DB)
|
||||
return typeof value === 'string' ? value.replace(/"/g, '') : value;
|
||||
const cleanValue = typeof value === 'string' ? value.replace(/"/g, '') : String(value);
|
||||
return (cleanValue === 'manual' ? 'manual' : 'auto') as 'auto' | 'manual';
|
||||
}, [getSettingValue]);
|
||||
|
||||
const getAdminPanelPollInterval = useCallback(() => {
|
||||
|
||||
Reference in New Issue
Block a user